getArtistAlbums method
Retrieves a list of albums by a specific artist given the artist's ID.
Implementation
Future<List<AlbumDetailed>> getArtistAlbums(String artistId) async {
final artistData =
await constructRequest("browse", body: {"browseId": artistId});
final artistAlbumsData =
traverseList(artistData, ["musicCarouselShelfRenderer"])[0];
final browseBody =
traverse(artistAlbumsData, ["moreContentButton", "browseEndpoint"]);
if (browseBody is List) {
return [];
}
final albumsData = await constructRequest(
"browse",
body: browseBody is List ? {} : browseBody,
);
return [
...traverseList(albumsData, ["musicTwoRowItemRenderer"])
.map(
(item) => AlbumParser.parseArtistAlbum(
item,
ArtistBasic(
artistId: artistId,
name: traverseString(albumsData, ["header", "runs", "text"]) ??
'',
),
),
)
.where(
(album) => album.artist.artistId == artistId,
),
];
}