youtube_explode/test/channel_test.dart

92 lines
2.9 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() {
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 channel', () async {
2022-04-30 17:49:34 +02:00
var channelUrl =
'http://127.0.0.1:8080/www.youtube.com:443/channel/UCEnBXANsKmyj2r9xVyKoDiQ';
2021-03-11 14:20:10 +01:00
var channel = await yt!.channels.get(ChannelId(channelUrl));
2020-10-17 22:09:52 +02:00
expect(channel.url, channelUrl);
expect(channel.title, 'Tyrrrz');
expect(channel.logoUrl, isNotEmpty);
expect(channel.logoUrl, isNot(equalsIgnoringWhitespace('')));
2021-07-14 22:36:25 +02:00
expect(channel.subscribersCount, greaterThanOrEqualTo(190));
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 any channel', () {
2021-03-11 14:20:10 +01:00
for (final val in {
2020-10-17 22:09:52 +02:00
'UC46807r_RiRjH8IU-h_DrDQ',
'UCJ6td3C9QlPO9O_J5dF4ZzA',
'UCiGm_E4ZwYSHV3bcW1pnSeQ'
}) {
test('Channel - $val', () async {
var channelId = ChannelId(val);
2021-03-11 14:20:10 +01:00
var channel = await yt!.channels.get(channelId);
2020-10-17 22:09:52 +02:00
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 {
2021-03-11 14:20:10 +01:00
var channel = await yt!.channels.getByUsername(Username('TheTyrrr'));
2020-10-17 22:09:52 +02:00
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 {
2021-03-11 14:20:10 +01:00
var channel = await yt!.channels.getByVideo(VideoId('5NmxuoNyDss'));
2020-10-17 22:09:52 +02:00
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 {
2021-03-11 14:20:10 +01:00
var videos = await yt!.channels
2020-10-17 22:09:52 +02:00
.getUploads(ChannelId(
2022-04-30 17:49:34 +02:00
'http://127.0.0.1:8080/www.youtube.com:443/channel/UCEnBXANsKmyj2r9xVyKoDiQ'))
2020-10-17 22:09:52 +02:00
.toList();
2021-10-04 13:00:22 +02:00
expect(videos.length, greaterThanOrEqualTo(75));
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 the videos of any youtube channel', () {
2021-03-11 14:20:10 +01:00
for (final val in {
2020-10-17 22:09:52 +02:00
'UC46807r_RiRjH8IU-h_DrDQ',
'UCJ6td3C9QlPO9O_J5dF4ZzA',
'UCiGm_E4ZwYSHV3bcW1pnSeQ'
}) {
test('Channel - $val', () async {
2021-03-11 14:20:10 +01:00
var videos = await yt!.channels.getUploads(ChannelId(val)).toList();
2020-10-17 22:09:52 +02:00
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 {
2021-04-30 23:49:49 +02:00
var videos =
await yt!.channels.getUploadsFromPage('UCEnBXANsKmyj2r9xVyKoDiQ');
2020-10-17 22:09:52 +02:00
expect(videos, hasLength(30));
2020-06-05 16:17:08 +02:00
});
2021-03-28 11:55:45 +02:00
//TODO: Remove dupe test
test('Get about page of a youtube', () async {
var aboutPage = await yt!.channels.getAboutPageByUsername(
'PewDiePie'); // or yt.channels.getAboutPage(channelId)
expect(aboutPage.title, 'PewDiePie');
2021-04-30 23:49:49 +02:00
expect(
aboutPage.viewCount,
greaterThanOrEqualTo(
20000000000)); //Seems youtube likes to change and lower this number
expect(aboutPage.description, isNotEmpty);
expect(aboutPage.thumbnails, isNotEmpty); // Avatar list
2022-02-03 12:06:09 +01:00
expect(aboutPage.channelLinks, isEmpty);
expect(aboutPage.country, 'United States');
expect(aboutPage.joinDate, 'Apr 29, 2010');
});
2020-06-05 16:17:08 +02:00
}