youtube_explode/test/streams_test.dart

84 lines
3.0 KiB
Dart
Raw Normal View History

2020-06-05 16:17:08 +02:00
import 'package:test/test.dart';
import 'package:youtube_explode_dart/youtube_explode_dart.dart';
void main() {
2021-03-11 14:20:10 +01:00
YoutubeExplode? yt;
2020-10-27 14:44:11 +01:00
setUpAll(() {
2020-10-17 22:09:52 +02:00
yt = YoutubeExplode();
});
2020-06-05 16:17:08 +02:00
2020-10-27 14:44:11 +01:00
tearDownAll(() {
2021-03-11 14:20:10 +01:00
yt?.close();
2020-10-17 22:09:52 +02:00
});
2020-06-05 16:17:08 +02:00
2020-12-25 23:29:01 +01:00
group('Get streams manifest of any video', () {
2021-03-11 14:20:10 +01:00
for (final val in {
2021-07-05 10:17:00 +02:00
VideoId('9bZkp7q19f0'), //Normal
VideoId('ZGdLIwrGHG8'), //Unlisted
VideoId('rsAAeyAr-9Y'), //LiveStreamRecording
VideoId('V5Fsj_sCKdg'), //ContainsHighQualityStreams
VideoId('AI7ULzgf8RU'), //ContainsDashManifest
VideoId('-xNN-bJQ4vI'), //Omnidirectional
VideoId('vX2vsvdq8nw'), //HighDynamicRange
VideoId('YltHGKX80Y8'), //ContainsClosedCaptions
VideoId('_kmeFXjjGfk'), //EmbedRestrictedByYouTube
VideoId('MeJVWBSsPAY'), //EmbedRestrictedByAuthor
VideoId('SkRSXFQerZs'), //AgeRestricted
VideoId('hySoCSoH-g8'), //AgeRestrictedEmbedRestricted
VideoId('5VGm0dczmHc'), //RatingDisabled
2020-12-25 23:29:01 +01:00
VideoId('-xNN-bJQ4vI'), // 360° video
2020-10-17 22:09:52 +02:00
}) {
test('VideoId - ${val.value}', () async {
2021-03-11 14:20:10 +01:00
var manifest = await yt!.videos.streamsClient.getManifest(val);
2020-06-05 16:17:08 +02:00
expect(manifest.streams, isNotEmpty);
2020-06-22 17:40:57 +02:00
});
}
2020-10-17 22:09:52 +02:00
});
test('Stream of paid videos throw VideoRequiresPurchaseException', () {
2021-03-11 14:20:10 +01:00
expect(yt!.videos.streamsClient.getManifest(VideoId('p3dDcKOFXQg')),
2020-10-17 22:09:52 +02:00
throwsA(const TypeMatcher<VideoRequiresPurchaseException>()));
});
2021-07-05 10:17:00 +02:00
test('Get the hls manifest of a live stream', () async {
expect(
await yt!.videos.streamsClient
.getHttpLiveStreamUrl(VideoId('5qap5aO4i9A')),
isNotEmpty);
});
2020-10-17 22:09:52 +02:00
group('Stream of unavailable videos throws VideoUnavailableException', () {
2021-03-11 14:20:10 +01:00
for (final val in {VideoId('qld9w0b-1ao'), VideoId('pb_hHv3fByo')}) {
2020-10-17 22:09:52 +02:00
test('VideoId - ${val.value}', () {
2021-03-11 14:20:10 +01:00
expect(yt!.videos.streamsClient.getManifest(val),
2020-10-17 22:09:52 +02:00
throwsA(const TypeMatcher<VideoUnavailableException>()));
});
}
});
2020-06-05 16:17:08 +02:00
2020-12-25 23:29:01 +01:00
group('Get specific stream of any playable video', () {
2021-03-11 14:20:10 +01:00
for (final val in {
2021-07-05 10:17:00 +02:00
VideoId('9bZkp7q19f0'), //Normal
VideoId('ZGdLIwrGHG8'), //Unlisted
VideoId('rsAAeyAr-9Y'), //LiveStreamRecording
VideoId('V5Fsj_sCKdg'), //ContainsHighQualityStreams
VideoId('AI7ULzgf8RU'), //ContainsDashManifest
VideoId('-xNN-bJQ4vI'), //Omnidirectional
VideoId('vX2vsvdq8nw'), //HighDynamicRange
VideoId('YltHGKX80Y8'), //ContainsClosedCaptions
VideoId('_kmeFXjjGfk'), //EmbedRestrictedByYouTube
VideoId('MeJVWBSsPAY'), //EmbedRestrictedByAuthor
VideoId('SkRSXFQerZs'), //AgeRestricted
VideoId('hySoCSoH-g8'), //AgeRestrictedEmbedRestricted
VideoId('5VGm0dczmHc'), //RatingDisabled
2020-10-17 22:09:52 +02:00
}) {
test('VideoId - ${val.value}', () async {
2021-03-11 14:20:10 +01:00
var manifest = await yt!.videos.streamsClient.getManifest(val);
for (final streamInfo in manifest.streams) {
2021-05-20 10:21:22 +02:00
expect(yt!.videos.streamsClient.get(streamInfo).first, completes);
2020-06-05 16:17:08 +02:00
}
2021-05-20 10:21:22 +02:00
}, timeout: const Timeout(Duration(minutes: 5)));
2020-10-17 22:09:52 +02:00
}
2020-10-27 14:44:11 +01:00
});
2020-06-05 16:17:08 +02:00
}