youtube_explode/test/closed_caption_test.dart

43 lines
1.4 KiB
Dart
Raw Normal View History

import 'package:test/test.dart';
import 'package:youtube_explode_dart/youtube_explode_dart.dart';
void main() {
group('Search', () {
YoutubeExplode yt;
setUp(() {
yt = YoutubeExplode();
});
tearDown(() {
yt.close();
});
test('GetClosedCaptionTracksOfAnyVideo', () async {
2020-09-11 15:45:50 +02:00
var manifest = await yt.videos.closedCaptions.getManifest('WOxr2dmLHLo');
expect(manifest.tracks, isNotEmpty);
});
test('GetClosedCaptionTrackOfAnyVideoSpecific', () async {
2020-09-11 15:45:50 +02:00
var manifest = await yt.videos.closedCaptions.getManifest('WOxr2dmLHLo');
var trackInfo = manifest.tracks.first;
var track = await yt.videos.closedCaptions.get(trackInfo);
2020-06-07 23:08:49 +02:00
expect(track.captions, isNotEmpty);
});
test('GetClosedCaptionTrackAtSpecificTime', () async {
var manifest = await yt.videos.closedCaptions
2020-09-11 15:45:50 +02:00
.getManifest('https://www.youtube.com/watch?v=ppJy5uGZLi4');
var trackInfo = manifest.getByLanguage('en');
var track = await yt.videos.closedCaptions.get(trackInfo);
var caption =
2020-09-11 15:45:50 +02:00
track.getByTime(const Duration(hours: 0, minutes: 13, seconds: 22));
var captionPart =
2020-09-11 15:45:50 +02:00
caption.getPartByTime(const Duration(milliseconds: 200));
2020-08-15 15:39:51 +02:00
expect(caption, isNotNull);
expect(captionPart, isNotNull);
2020-09-11 15:45:50 +02:00
expect(caption.text, 'how about this black there are some');
expect(captionPart.text, ' about');
});
});
}