parseSearchResult static method

PlaylistDetailed parseSearchResult(
  1. dynamic item
)

Implementation

static PlaylistDetailed parseSearchResult(dynamic item) {
  final columns = traverseList(item, ["flexColumns", "runs"])
      .expand((e) => e is List ? e : [e])
      .toList();

  // No specific way to identify the title
  final title = columns[0];
  final artist = columns.firstWhere(
    isArtist,
    orElse: () => columns.length > 2
        ? columns[3]
        : AlbumBasic(
            albumId: '',
            name: '',
          ),
  );

  return PlaylistDetailed(
    type: "PLAYLIST",
    playlistId: traverseString(item, ["overlay", "playlistId"]) ?? '',
    name: traverseString(title, ["text"]) ?? '',
    artist: ArtistBasic(
      name: traverseString(artist, ["text"]) ?? '',
      artistId: traverseString(artist, ["browseId"]),
    ),
    thumbnails: traverseList(item, ["thumbnails"])
        .map((item) => ThumbnailFull.fromMap(item))
        .toList(),
  );
}