parsePlaylistVideo static method

VideoDetailed parsePlaylistVideo(
  1. dynamic item
)

Implementation

static VideoDetailed parsePlaylistVideo(dynamic item) {
  final columns =
      traverseList(item, ["flexColumns", "runs"]).expand((e) => e).toList();

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

  return VideoDetailed(
    type: "VIDEO",
    videoId: traverseString(item, ["playNavigationEndpoint", "videoId"]) ??
        traverseList(item, ["thumbnails"])
            .first
            .url
            .split("https://i.ytimg.com/vi/")[1]
            .split("/")[0],
    name: traverseString(title, ["text"]) ?? '',
    artist: ArtistBasic(
      name: traverseString(artist, ["text"]) ?? '',
      artistId: traverseString(artist, ["browseId"]),
    ),
    duration: Parser.parseDuration(duration?.text),
    thumbnails: traverseList(item, ["thumbnails"])
        .map((item) => ThumbnailFull.fromMap(item))
        .toList(),
  );
}