parseSearchResult static method

VideoDetailed parseSearchResult(
  1. dynamic item
)

Implementation

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

  final title = columns.firstWhere(isTitle, orElse: () => null);
  final artist = columns.firstWhere(isArtist, orElse: () => columns[1]);
  final duration = columns.firstWhere(isDuration, orElse: () => null);

  return VideoDetailed(
    type: "VIDEO",
    videoId:
        traverseString(item, ["playNavigationEndpoint", "videoId"]) ?? '',
    name: traverseString(title, ["text"]) ?? '',
    artist: ArtistBasic(
      artistId: traverseString(artist, ["browseId"]),
      name: traverseString(artist, ["text"]) ?? '',
    ),
    duration: Parser.parseDuration(duration?['text']),
    thumbnails: traverseList(item, ["thumbnails"])
        .map((item) => ThumbnailFull.fromMap(item))
        .toList(),
  );
}