youtube_explode/test/streams_test.dart

89 lines
3.5 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('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('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);
2021-09-28 16:49:38 +02:00
expect(manifest.videoOnly, isNotEmpty);
expect(manifest.audioOnly, isNotEmpty);
}, timeout: const Timeout(Duration(seconds: 90)));
2020-06-22 17:40:57 +02:00
}
2020-10-17 22:09:52 +02:00
});
2021-09-28 16:49:38 +02:00
// Seems that youtube broke something and now this throws VideoUnplayableException instead of VideoRequiresPurchaseException
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')),
2021-09-28 16:49:38 +02:00
throwsA(const TypeMatcher<VideoUnplayableException>()));
2020-10-17 22:09:52 +02:00
});
test('Stream of age-limited video throws VideoUnplayableException', () {
expect(yt!.videos.streamsClient.getManifest(VideoId('SkRSXFQerZs')),
2021-10-04 13:00:22 +02:00
throwsA(const TypeMatcher<VideoUnplayableException>()));
});
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);
});
2021-09-28 16:49:38 +02:00
// Seems that youtube broke something and now this throws VideoUnplayableException instead of VideoUnavailableException
group('Stream of unavailable videos throws VideoUnplayableException', () {
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),
2021-09-28 16:49:38 +02:00
throwsA(const TypeMatcher<VideoUnplayableException>()));
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 specific stream of any playable video', () {
2021-03-11 14:20:10 +01:00
for (final val in {
2021-10-04 13:00:22 +02:00
VideoId('9bZkp7q19f0'), //Normal
VideoId('rsAAeyAr-9Y'), //LiveStreamRecording
VideoId('V5Fsj_sCKdg'), //ContainsHighQualityStreams
2021-07-05 10:17:00 +02:00
VideoId('AI7ULzgf8RU'), //ContainsDashManifest
2021-10-04 13:00:22 +02:00
VideoId('-xNN-bJQ4vI'), //Omnidirectional
VideoId('vX2vsvdq8nw'), //HighDynamicRange
VideoId('YltHGKX80Y8'), //ContainsClosedCaptions
VideoId('_kmeFXjjGfk'), //EmbedRestrictedByYouTube
VideoId('MeJVWBSsPAY'), //EmbedRestrictedByAuthor
VideoId('hySoCSoH-g8'), //AgeRestrictedEmbedRestricted
2021-07-05 10:17:00 +02:00
VideoId('5VGm0dczmHc'), //RatingDisabled
2021-10-04 13:00:22 +02: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);
for (final streamInfo in manifest.streams) {
2022-02-03 12:06:09 +01:00
print('Stream: ${streamInfo.tag}');
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
}