parseVideo function

JsonMap parseVideo(
  1. JsonMap result
)

Parses a video from result.

Implementation

JsonMap parseVideo(JsonMap result) {
  final JsonMap realResult;
  if (result.containsKey(MTRIR)) {
    realResult = nav(result, [MTRIR]) as JsonMap;
  } else {
    realResult = result;
  }
  final runs = nav(realResult, SUBTITLE_RUNS);
  final artistsLen = getDotSeparatorIndex(runs as List);
  var videoId = nav(realResult, NAVIGATION_VIDEO_ID, nullIfAbsent: true);
  if (videoId == null) {
    for (final entry in nav(realResult, MENU_ITEMS) as Iterable) {
      final candidate = nav(entry, [
        ...MENU_SERVICE,
        ...QUEUE_VIDEO_ID,
      ], nullIfAbsent: true);
      if (candidate != null) {
        videoId = candidate;
        break;
      }
    }
  }
  return {
    'title': nav(realResult, TITLE_TEXT),
    'videoId': videoId,
    'artists': parseSongArtistsRuns(runs.sublist(0, artistsLen)),
    'playlistId': nav(realResult, NAVIGATION_PLAYLIST_ID, nullIfAbsent: true),
    'thumbnails': nav(realResult, THUMBNAIL_RENDERER, nullIfAbsent: true),
    'views': (List<JsonMap>.from(runs).last['text'] as String).split(' ')[0],
  };
}