youtube_explode/test/channel_test.dart

76 lines
2.2 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() {
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-06-05 16:17:08 +02:00
2020-10-27 14:44:11 +01:00
tearDownAll(() {
2020-10-17 22:09:52 +02:00
yt.close();
});
2020-06-05 16:17:08 +02:00
2020-10-17 22:09:52 +02:00
test('Get metadata of a channel', () async {
var channelUrl = 'https://www.youtube.com/channel/UCEnBXANsKmyj2r9xVyKoDiQ';
var channel = await yt.channels.get(ChannelId(channelUrl));
expect(channel.url, channelUrl);
expect(channel.title, 'Tyrrrz');
expect(channel.logoUrl, isNotEmpty);
expect(channel.logoUrl, isNot(equalsIgnoringWhitespace('')));
});
2020-06-05 16:17:08 +02:00
2020-10-17 22:09:52 +02:00
group('Get metadata of any channel', () {
for (var val in {
'UC46807r_RiRjH8IU-h_DrDQ',
'UCJ6td3C9QlPO9O_J5dF4ZzA',
'UCiGm_E4ZwYSHV3bcW1pnSeQ'
}) {
test('Channel - $val', () async {
var channelId = ChannelId(val);
var channel = await yt.channels.get(channelId);
expect(channel.id, channelId);
});
}
});
2020-06-05 16:17:08 +02:00
2020-10-17 22:09:52 +02:00
test('Get metadata of a channel by username', () async {
var channel = await yt.channels.getByUsername(Username('TheTyrrr'));
expect(channel.id.value, 'UCEnBXANsKmyj2r9xVyKoDiQ');
});
2020-06-05 16:17:08 +02:00
2020-10-17 22:09:52 +02:00
test('Get metadata of a channel by a video', () async {
var channel = await yt.channels.getByVideo(VideoId('5NmxuoNyDss'));
expect(channel.id.value, 'UCEnBXANsKmyj2r9xVyKoDiQ');
});
2020-06-05 16:17:08 +02:00
2020-10-17 22:09:52 +02:00
test('Get the videos of a youtube channel', () async {
var videos = await yt.channels
.getUploads(ChannelId(
'https://www.youtube.com/channel/UCEnBXANsKmyj2r9xVyKoDiQ'))
.toList();
expect(videos.length, greaterThanOrEqualTo(80));
});
2020-06-05 16:17:08 +02:00
2020-10-17 22:09:52 +02:00
group('Get the videos of any youtube channel', () {
for (var val in {
'UC46807r_RiRjH8IU-h_DrDQ',
'UCJ6td3C9QlPO9O_J5dF4ZzA',
'UCiGm_E4ZwYSHV3bcW1pnSeQ'
}) {
test('Channel - $val', () async {
var videos = await yt.channels.getUploads(ChannelId(val)).toList();
expect(videos, isNotEmpty);
});
}
});
2020-08-15 15:32:01 +02:00
2020-10-17 22:09:52 +02:00
test('Get videos of a youtube channel from the uploads page', () async {
var videos = await yt.channels
.getUploadsFromPage('UCEnBXANsKmyj2r9xVyKoDiQ')
.take(30)
.toList();
expect(videos, hasLength(30));
2020-06-05 16:17:08 +02:00
});
}