getVideoDetails method
Implementation
Future<void> getVideoDetails(String videoId, {bool isLive = false}) async {
try {
videosList.clear();
if (isLive) {
final videoUrl =
await yt.videos.streams.getHttpLiveStreamUrl(VideoId(videoId));
final response = await get(Uri.parse(videoUrl));
String m3u8Content = response.body;
List<Map<String, String>> qualities = parseM3U8Content(m3u8Content);
for (var element in qualities) {
videosList.add(
VideoData(
url: element['url'] ?? "",
quality: element['resolution'].toString().split("x").last,
),
);
}
} else {
final videoInfo =
await yt.videos.streams.getManifest(videoId, ytClients: [
YoutubeApiClient.android,
YoutubeApiClient.androidVr,
]);
if (videoInfo.videoOnly.isNotEmpty) {
for (var element in videoInfo.videoOnly) {
videosList.add(
VideoData(
url: element.url.toString(),
quality: element.videoQualityLabel,
audioUrl: videoInfo.audioOnly.first.url.toString(),
format: element.videoQuality.name,
),
);
}
}
// final videoinfo = await getVideos(videoId);
// if (videoinfo['videos']?.isNotEmpty ?? false) {
// for (var element in videoinfo['videos']) {
// final video = VideoData(
// url: element['url'].toString(),
// quality: element['height'].toString(),
// format: element['ext'].toString(),
// audioUrl:
// (videoinfo['audios'] as List).firstOrNull['url'].toString(),
// );
// videosList.add(video);
// }
// }
}
sortByQuality();
} catch (e) {
rethrow;
}
}