youtube_explode/test/streams_test.dart

58 lines
1.7 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() {
2020-10-17 22:09:52 +02:00
YoutubeExplode yt;
setUp(() {
yt = YoutubeExplode();
});
2020-06-05 16:17:08 +02:00
2020-10-17 22:09:52 +02:00
tearDown(() {
yt.close();
});
2020-06-05 16:17:08 +02:00
2020-10-17 22:09:52 +02:00
group('Get streams of any video', () {
for (var val in {
VideoId('5VGm0dczmHc'), // rating is not allowed
VideoId('ZGdLIwrGHG8'), // unlisted
VideoId('rsAAeyAr-9Y'),
VideoId('AI7ULzgf8RU')
}) {
test('VideoId - ${val.value}', () async {
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', () {
expect(yt.videos.streamsClient.getManifest(VideoId('p3dDcKOFXQg')),
throwsA(const TypeMatcher<VideoRequiresPurchaseException>()));
});
group('Stream of unavailable videos throws VideoUnavailableException', () {
for (var val in {VideoId('qld9w0b-1ao'), VideoId('pb_hHv3fByo')}) {
test('VideoId - ${val.value}', () {
expect(yt.videos.streamsClient.getManifest(val),
throwsA(const TypeMatcher<VideoUnavailableException>()));
});
}
});
2020-06-05 16:17:08 +02:00
2020-10-17 22:09:52 +02:00
group('Get stream of any playable video', () {
for (var val in {
2020-10-24 14:54:42 +02:00
VideoId('5VGm0dczmHc'), // rating is not allowed
VideoId('ZGdLIwrGHG8'), // unlisted
2020-10-17 22:09:52 +02:00
VideoId('rsAAeyAr-9Y'),
2020-10-24 14:54:42 +02:00
VideoId('AI7ULzgf8RU')
2020-10-17 22:09:52 +02:00
}) {
test('VideoId - ${val.value}', () async {
var manifest = await yt.videos.streamsClient.getManifest(val);
2020-06-05 16:17:08 +02:00
for (var streamInfo in manifest.streams) {
2020-10-17 22:13:39 +02:00
expect(yt.videos.streamsClient.get(streamInfo), emits(isNotNull));
2020-06-05 16:17:08 +02:00
}
2020-10-17 22:09:52 +02:00
});
}
}, skip: 'Occasionally may fail with certain videos');
2020-06-05 16:17:08 +02:00
}