getVideoManifest method
Implementation
Future<googleapis_client_scheme.YoutubeVideoManifest> getVideoManifest({
required String video_id,
}) async {
googleapis_client_scheme.YoutubeSchemaText youtubeSchemaText =
GoogleApisClientUtils.parseTextToYoutube(text: video_id);
if (youtubeSchemaText["@type"] == "error") {
return googleapis_client_scheme.YoutubeVideoManifest(
youtubeSchemaText.rawData);
}
if (youtubeSchemaText["type"] == "channel_username") {
return googleapis_client_scheme.YoutubeVideoManifest(
youtubeSchemaText.rawData);
}
StreamManifest streamManifest =
await youtubeExplode.videos.streams.getManifest(youtubeSchemaText.data);
List<MuxedStreamInfo> muxed_stream = streamManifest.muxed.toList();
List<AudioStreamInfo> audios_stream = streamManifest.audio.toList();
List<VideoStreamInfo> videos_stream = streamManifest.video.toList();
List<StreamInfo> stream_stream = streamManifest.streams.toList();
List<Map> jsonAudios = audios_stream.map((AudioStreamInfo audioStreamInfo) {
Map jsonData = {
"@type": "youtubeVideoManifestAudio",
"video_codec": audioStreamInfo.audioCodec,
"bitrate": audioStreamInfo.bitrate.bitsPerSecond,
"mime_type": audioStreamInfo.codec.mimeType,
"container_name": audioStreamInfo.container.name,
"is_throttled": audioStreamInfo.isThrottled,
"quality": audioStreamInfo.qualityLabel,
"size": audioStreamInfo.size.totalBytes,
"tag": audioStreamInfo.tag,
"url": audioStreamInfo.url.toString(),
};
return jsonData;
}).toList();
List<Map> jsonMuxeds = muxed_stream.map((MuxedStreamInfo muxedStreamInfo) {
// muxedStreamInfo.videoResolution.
Map jsonData = {
"@type": "youtubeVideoManifestMuxed",
"audio_codec": muxedStreamInfo.audioCodec,
"framerate": muxedStreamInfo.framerate.framesPerSecond,
"video_codec": muxedStreamInfo.videoCodec,
"video_quality": muxedStreamInfo.videoQuality.name,
"height": muxedStreamInfo.videoResolution.height,
"width": muxedStreamInfo.videoResolution.width,
"bitrate": muxedStreamInfo.bitrate.bitsPerSecond,
"mime_type": muxedStreamInfo.codec.mimeType,
"container_name": muxedStreamInfo.container.name,
"is_throttled": muxedStreamInfo.isThrottled,
"quality": muxedStreamInfo.qualityLabel,
"size": muxedStreamInfo.size.totalBytes,
"tag": muxedStreamInfo.tag,
"url": muxedStreamInfo.url.toString(),
};
return jsonData;
}).toList();
List<Map> jsonVideos = videos_stream.map((VideoStreamInfo videoStreamInfo) {
Map jsonData = {
"@type": "youtubeVideoManifestVideo",
"framerate": videoStreamInfo.framerate.framesPerSecond,
"video_codec": videoStreamInfo.videoCodec,
"video_quality": videoStreamInfo.videoQuality.name,
"height": videoStreamInfo.videoResolution.height,
"width": videoStreamInfo.videoResolution.width,
"bitrate": videoStreamInfo.bitrate.bitsPerSecond,
"mime_type": videoStreamInfo.codec.mimeType,
"container_name": videoStreamInfo.container.name,
"is_throttled": videoStreamInfo.isThrottled,
"quality": videoStreamInfo.qualityLabel,
"size": videoStreamInfo.size.totalBytes,
"tag": videoStreamInfo.tag,
"url": videoStreamInfo.url.toString(),
};
return jsonData;
}).toList();
List<Map> jsonStreams = stream_stream.map((StreamInfo streamInfo) {
Map jsonData = {
"@type": "youtubeVideoManifestStream",
"bitrate": streamInfo.bitrate.bitsPerSecond,
"mime_type": streamInfo.codec.mimeType,
"container_name": streamInfo.container.name,
"is_throttled": streamInfo.isThrottled,
"quality": streamInfo.qualityLabel,
"size": streamInfo.size.totalBytes,
"tag": streamInfo.tag,
"url": streamInfo.url.toString(),
};
return jsonData;
}).toList();
Map jsonData = {
"@type": "youtubeVideoManifest",
"audios": jsonAudios,
"videos": jsonVideos,
"muxeds": jsonMuxeds,
"streams": jsonStreams,
};
return googleapis_client_scheme.YoutubeVideoManifest(jsonData);
}