youtube_explode/test/closed_caption_test.dart

40 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() {
2020-10-17 22:09:52 +02:00
YoutubeExplode yt;
2020-10-27 14:44:11 +01:00
setUpAll(() {
2020-10-17 22:09:52 +02:00
yt = YoutubeExplode();
});
2020-10-27 14:44:11 +01:00
tearDownAll(() {
2020-10-17 22:09:52 +02:00
yt.close();
});
2020-10-17 22:09:52 +02:00
test('Get closed captions of a video', () async {
var manifest = await yt.videos.closedCaptions.getManifest('WOxr2dmLHLo');
expect(manifest.tracks, isNotEmpty);
});
test('Get closed caption track of a video', () async {
var manifest = await yt.videos.closedCaptions.getManifest('WOxr2dmLHLo');
var trackInfo = manifest.tracks.first;
var track = await yt.videos.closedCaptions.get(trackInfo);
2020-10-17 22:09:52 +02:00
expect(track.captions, isNotEmpty);
});
2020-11-02 13:03:56 +01:00
test('Get auto-generated closed caption track at a specific time', () async {
2020-10-17 22:09:52 +02:00
var manifest = await yt.videos.closedCaptions
2020-11-02 13:03:56 +01:00
.getManifest('https://www.youtube.com/watch?v=ppJy5uGZLi4', autoGenerated: true);
2020-10-17 22:09:52 +02:00
var trackInfo = manifest.getByLanguage('en');
2020-11-02 13:03:56 +01:00
var track = await yt.videos.closedCaptions.get(trackInfo.first);
2020-10-17 22:09:52 +02:00
var caption =
track.getByTime(const Duration(hours: 0, minutes: 13, seconds: 22));
var captionPart = caption.getPartByTime(const Duration(milliseconds: 200));
2020-10-17 22:09:52 +02:00
expect(caption, isNotNull);
expect(captionPart, isNotNull);
expect(caption.text, 'how about this black there are some');
expect(captionPart.text, ' about');
});
}