2020-06-07 15:11:07 +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-07 15:11:07 +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-07 15:11:07 +02:00
|
|
|
|
2020-10-17 22:09:52 +02:00
|
|
|
test('Get closed captions of a video', () async {
|
2021-03-11 14:20:10 +01:00
|
|
|
var manifest = await yt!.videos.closedCaptions.getManifest('WOxr2dmLHLo');
|
2020-10-17 22:09:52 +02:00
|
|
|
expect(manifest.tracks, isNotEmpty);
|
|
|
|
});
|
|
|
|
test('Get closed caption track of a video', () async {
|
2021-03-11 14:20:10 +01:00
|
|
|
var manifest = await yt!.videos.closedCaptions.getManifest('WOxr2dmLHLo');
|
2020-10-17 22:09:52 +02:00
|
|
|
var trackInfo = manifest.tracks.first;
|
2021-03-11 14:20:10 +01:00
|
|
|
var track = await yt!.videos.closedCaptions.get(trackInfo);
|
2020-06-07 15:11:07 +02:00
|
|
|
|
2020-10-17 22:09:52 +02:00
|
|
|
expect(track.captions, isNotEmpty);
|
|
|
|
});
|
2020-12-30 15:00:11 +01:00
|
|
|
|
|
|
|
test('Get closed auto translated caption track file of a video', () async {
|
2021-03-11 14:20:10 +01:00
|
|
|
var manifest = await yt!.videos.closedCaptions.getManifest('WOxr2dmLHLo');
|
2020-12-30 15:00:11 +01:00
|
|
|
var trackInfo = manifest.tracks.first;
|
2021-01-01 22:32:12 +01:00
|
|
|
|
2021-03-11 14:20:10 +01:00
|
|
|
var subtitles = await yt!.videos.closedCaptions
|
2021-01-01 22:32:12 +01:00
|
|
|
.getSubTitles(trackInfo.autoTranslate('it'));
|
2020-12-30 15:00:11 +01:00
|
|
|
|
|
|
|
expect(subtitles, isNotEmpty);
|
|
|
|
});
|
2020-11-06 22:46:47 +01:00
|
|
|
test('Get closed caption track at a specific time', () async {
|
2021-03-11 14:20:10 +01:00
|
|
|
var manifest = await yt!.videos.closedCaptions.getManifest('qfJthDvcZ08');
|
|
|
|
var trackInfo = manifest.getByLanguage('en',
|
|
|
|
autoGenerated: false); // ignore: avoid_redundant_argument_values
|
|
|
|
var track = await yt!.videos.closedCaptions.get(trackInfo.first);
|
|
|
|
var caption = track.getByTime(const Duration(
|
|
|
|
hours: 0, // ignore: avoid_redundant_argument_values
|
|
|
|
minutes: 1,
|
|
|
|
seconds: 48)); // ignore: avoid_redundant_argument_values
|
2020-11-06 22:46:47 +01:00
|
|
|
|
|
|
|
expect(caption, isNotNull);
|
2021-03-11 14:20:10 +01:00
|
|
|
expect(caption?.parts, isEmpty);
|
|
|
|
expect(caption?.text, 'But what if you don\'t have a captions file');
|
2020-11-06 22:46:47 +01:00
|
|
|
});
|
|
|
|
|
2020-11-02 13:03:56 +01:00
|
|
|
test('Get auto-generated closed caption track at a specific time', () async {
|
2021-03-11 14:20:10 +01:00
|
|
|
var manifest = await yt!.videos.closedCaptions.getManifest('ppJy5uGZLi4');
|
2020-12-30 15:00:11 +01:00
|
|
|
var trackInfo = manifest.getByLanguage('en', autoGenerated: true);
|
2021-03-11 14:20:10 +01:00
|
|
|
var track = await yt!.videos.closedCaptions.get(trackInfo.first);
|
|
|
|
var caption = track.getByTime(const Duration(
|
|
|
|
hours: 0, // ignore: avoid_redundant_argument_values
|
|
|
|
minutes: 13,
|
|
|
|
seconds: 22)); // ignore: avoid_redundant_argument_values
|
|
|
|
var captionPart = caption!.getPartByTime(const Duration(milliseconds: 200));
|
2020-06-07 15:11:07 +02:00
|
|
|
|
2020-10-17 22:09:52 +02:00
|
|
|
expect(caption, isNotNull);
|
|
|
|
expect(captionPart, isNotNull);
|
|
|
|
expect(caption.text, 'how about this black there are some');
|
2021-03-11 14:20:10 +01:00
|
|
|
expect(captionPart?.text, ' about');
|
2020-06-07 15:11:07 +02:00
|
|
|
});
|
|
|
|
}
|