parse static method

ArtistFull parse(
  1. dynamic data,
  2. String artistId
)

Implementation

static ArtistFull parse(dynamic data, String artistId) {
  final artistBasic = ArtistBasic(
    artistId: artistId,
    name: traverseString(data, ["header", "title", "text"]) ?? '',
  );

  return ArtistFull(
    name: artistBasic.name,
    type: "ARTIST",
    artistId: artistId,
    thumbnails: traverseList(data, ["header", "thumbnails"])
        .map((item) => ThumbnailFull.fromMap(item))
        .toList(),
    topSongs: traverseList(data, ["musicShelfRenderer", "contents"])
        .map((item) => SongParser.parseArtistTopSong(item, artistBasic))
        .toList(),
    topAlbums: (traverseList(data, ["musicCarouselShelfRenderer"]).isEmpty
            ? <AlbumDetailed>[]
            : (traverseList(data, ["musicCarouselShelfRenderer"])
                        .elementAt(0)?['contents'] as List<dynamic>?)
                    ?.map((item) =>
                        AlbumParser.parseArtistTopAlbum(item, artistBasic))
                    .toList() ??
                <AlbumDetailed>[])
        .where(
          (album) => album.albumId.isNotEmpty,
        )
        .toList(),
    topSingles: (traverseList(data, ["musicCarouselShelfRenderer"]).length < 2
            ? <AlbumDetailed>[]
            : (traverseList(data, ["musicCarouselShelfRenderer"])
                        .elementAt(1)?['contents'] as List<dynamic>?)
                    ?.map((item) =>
                        AlbumParser.parseArtistTopAlbum(item, artistBasic))
                    .toList() ??
                <AlbumDetailed>[])
        .where(
          (single) =>
              single.albumId.isNotEmpty && single.albumId.startsWith('M'),
        )
        .toList(),
    topVideos: traverseList(data, ["musicCarouselShelfRenderer"]).length < 3
        ? <VideoDetailed>[]
        : (traverseList(data, ["musicCarouselShelfRenderer"])
                    .elementAt(2)?['contents'] as List<dynamic>?)
                ?.map((item) =>
                    VideoParser.parseArtistTopVideo(item, artistBasic))
                .toList() ??
            <VideoDetailed>[],
    featuredOn: traverseList(data, ["musicCarouselShelfRenderer"]).length < 4
        ? <PlaylistDetailed>[]
        : (traverseList(data, ["musicCarouselShelfRenderer"])
                    .elementAt(3)?['contents'] as List<dynamic>?)
                ?.map((item) =>
                    PlaylistParser.parseArtistFeaturedOn(item, artistBasic))
                .toList() ??
            <PlaylistDetailed>[],
    similarArtists:
        traverseList(data, ["musicCarouselShelfRenderer"]).length < 5
            ? <ArtistDetailed>[]
            : (traverseList(data, ["musicCarouselShelfRenderer"])
                        .elementAt(4)?['contents'] as List<dynamic>?)
                    ?.map((item) => parseSimilarArtists(item))
                    .toList() ??
                <ArtistDetailed>[],
  );
}