getArtistSingles method

Future<List<AlbumDetailed>> getArtistSingles(
  1. String artistId
)

Implementation

Future<List<AlbumDetailed>> getArtistSingles(String artistId) async {
  final artistData =
      await constructRequest("browse", body: {"browseId": artistId});

  final artistSinglesData =
      traverseList(artistData, ["musicCarouselShelfRenderer"]).length < 2
          ? []
          : traverseList(artistData, ["musicCarouselShelfRenderer"])
              .elementAt(1);

  final browseBody =
      traverse(artistSinglesData, ["moreContentButton", "browseEndpoint"]);
  if (browseBody is List) {
    return [];
  }

  final singlesData = await constructRequest(
    "browse",
    body: browseBody is List ? {} : browseBody,
  );

  return [
    ...traverseList(singlesData, ["musicTwoRowItemRenderer"])
        .map(
          (item) => AlbumParser.parseArtistAlbum(
            item,
            ArtistBasic(
              artistId: artistId,
              name: traverseString(singlesData, ["header", "runs", "text"]) ??
                  '',
            ),
          ),
        )
        .where(
          (album) => album.artist.artistId == artistId,
        ),
  ];
}