youtube_explode/test/streams_test.dart

81 lines
2.6 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 {
2020-12-25 23:29:01 +01:00
VideoId('9bZkp7q19f0'), // very popular
2021-04-02 22:56:32 +02:00
VideoId(
'SkRSXFQerZs'), // age restricted (embed allowed) - This is unplayable
2020-12-25 23:29:01 +01:00
VideoId('hySoCSoH-g8'), // age restricted (embed not allowed)
VideoId('_kmeFXjjGfk'), // embed not allowed (type 1)
VideoId('MeJVWBSsPAY'), // embed not allowed (type 2)
VideoId('5VGm0dczmHc'), // rating not allowed
2020-10-17 22:09:52 +02:00
VideoId('ZGdLIwrGHG8'), // unlisted
2020-12-25 23:29:01 +01:00
VideoId('rsAAeyAr-9Y'), // recording of a live stream
VideoId('AI7ULzgf8RU'), // has DASH manifest
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>()));
});
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-05-20 10:21:22 +02:00
VideoId('9bZkp7q19f0'),
// very popular
VideoId(
'SkRSXFQerZs'), // age restricted (embed allowed) - This is unplayable
VideoId('hySoCSoH-g8'),
// age restricted (embed not allowed)
VideoId('_kmeFXjjGfk'),
// embed not allowed (type 1)
VideoId('MeJVWBSsPAY'),
// embed not allowed (type 2)
2021-06-24 15:23:35 +02:00
// VideoId('5VGm0dczmHc'),
2021-05-20 10:21:22 +02:00
// rating not allowed
VideoId('ZGdLIwrGHG8'),
// unlisted
VideoId('rsAAeyAr-9Y'),
// recording of a live stream
VideoId('AI7ULzgf8RU'),
// has DASH manifest
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) {
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
}