youtube_explode/test/video_test.dart

85 lines
3.1 KiB
Dart
Raw Permalink 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-10-17 22:09:52 +02:00
test('Get metadata of a video', () async {
2022-04-30 17:49:34 +02:00
var videoUrl =
'http://127.0.0.1:8080/www.youtube.com:443/watch?v=AI7ULzgf8RU';
2021-03-11 14:20:10 +01:00
var video = await yt!.videos.get(VideoId(videoUrl));
2020-10-17 22:09:52 +02:00
expect(video.id.value, 'AI7ULzgf8RU');
expect(video.url, videoUrl);
expect(video.title, 'Aka no Ha [Another] +HDHR');
expect(video.channelId.value, 'UCEnBXANsKmyj2r9xVyKoDiQ');
2020-10-17 22:09:52 +02:00
expect(video.author, 'Tyrrrz');
2021-07-02 00:48:10 +02:00
var rangeMs = DateTime(2017, 09, 30, 17, 15, 26).millisecondsSinceEpoch;
2020-10-17 22:09:52 +02:00
// 1day margin since the uploadDate could differ from timezones
2021-03-11 14:20:10 +01:00
expect(video.uploadDate!.millisecondsSinceEpoch,
2020-10-17 22:09:52 +02:00
inInclusiveRange(rangeMs - 86400000, rangeMs + 86400000));
expect(video.publishDate!.millisecondsSinceEpoch,
2021-07-02 00:48:10 +02:00
inInclusiveRange(rangeMs - 86400000, rangeMs + 86400000));
2020-10-17 22:09:52 +02:00
expect(video.description, contains('246pp'));
2020-11-06 22:53:48 +01:00
// Should be 1:38 but sometimes it differs
// so we're using a 10 seconds range from it.
2021-03-11 14:20:10 +01:00
expect(video.duration!.inSeconds, inInclusiveRange(108, 118));
2020-10-17 22:09:52 +02:00
expect(video.thumbnails.lowResUrl, isNotEmpty);
expect(video.thumbnails.mediumResUrl, isNotEmpty);
expect(video.thumbnails.highResUrl, isNotEmpty);
expect(video.thumbnails.standardResUrl, isNotEmpty);
expect(video.thumbnails.maxResUrl, isNotEmpty);
2020-12-25 23:29:01 +01:00
expect(
video.keywords,
containsAll([
'osu',
'mouse' /*, 'rhythm game'*/
]));
2020-10-17 22:09:52 +02:00
expect(video.engagement.viewCount, greaterThanOrEqualTo(134));
expect(video.engagement.likeCount, greaterThanOrEqualTo(5));
expect(video.engagement.dislikeCount, greaterThanOrEqualTo(0));
});
2020-06-05 16:17:08 +02:00
2020-10-17 22:09:52 +02:00
group('Get metadata of any video', () {
2021-03-11 14:20:10 +01:00
for (final val in {
2021-07-02 00:48:10 +02:00
VideoId('9bZkp7q19f0'), //Normal
VideoId('5qap5aO4i9A'), //LiveStream
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
VideoId('p3dDcKOFXQg'), //RequiresPurchase
2020-10-17 22:09:52 +02:00
}) {
test('VideoId - ${val.value}', () async {
2021-03-11 14:20:10 +01:00
var video = await yt!.videos.get(val);
2020-10-17 22:09:52 +02:00
expect(video.id.value, val.value);
2021-07-02 00:48:10 +02:00
expect(video.uploadDate, isNotNull);
expect(video.publishDate, isNotNull);
2020-10-17 22:09:52 +02:00
});
}
});
2020-06-05 16:17:08 +02:00
2020-10-17 22:09:52 +02:00
group('Get metadata of invalid 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', () {
2021-03-11 14:20:10 +01:00
expect(() async => yt!.videos.get(val),
2020-10-17 22:09:52 +02:00
throwsA(const TypeMatcher<VideoUnplayableException>()));
});
}
2020-06-05 16:17:08 +02:00
});
}