parseSearchResult static method

SongDetailed parseSearchResult(
  1. dynamic item
)

Implementation

static SongDetailed parseSearchResult(dynamic item) {
  final columns = traverseList(item, ["flexColumns", "runs"]);
  // It is not possible to identify the title and author
  final title = columns[0];
  final artist = columns.firstWhere(isArtist, orElse: () => columns[3]);
  final album = columns.firstWhere(isAlbum, orElse: () => null);
  final duration = columns.firstWhere(
      (item) => isDuration(item) && item != title,
      orElse: () => null);

  return SongDetailed(
    type: "SONG",
    videoId: traverseString(item, ["playlistItemData", "videoId"]) ?? '',
    name: traverseString(title, ["text"]) ?? '',
    artist: ArtistBasic(
      name: traverseString(artist, ["text"]) ?? '',
      artistId: traverseString(artist, ["browseId"]),
    ),
    album: album != null
        ? AlbumBasic(
            name: traverseString(album, ["text"]) ?? '',
            albumId: traverseString(album, ["browseId"]) ?? '',
          )
        : null,
    duration: Parser.parseDuration(duration?['text']),
    thumbnails: traverseList(item, ["thumbnails"])
        .map((item) => ThumbnailFull.fromMap(item))
        .toList(),
  );
}