parent
a51cb11428
commit
c7f8ef49fe
|
@ -46,9 +46,11 @@ class ChannelClient {
|
|||
/// Gets the info found on a YouTube Channel About page.
|
||||
/// [id] must be either a [ChannelId] or a string
|
||||
/// which is parsed to a [ChannelId]
|
||||
Future<ChannelAbout> getAboutPage(dynamic id) async {
|
||||
id = ChannelId.fromString(id);
|
||||
Future<ChannelAbout> getAboutPage(dynamic channelId) async {
|
||||
channelId = ChannelId.fromString(channelId);
|
||||
|
||||
final aboutPage = await ChannelAboutPage.get(_httpClient, channelId.value);
|
||||
final id = aboutPage.initialData;
|
||||
return ChannelAbout(
|
||||
id.description,
|
||||
id.viewCount,
|
||||
|
@ -56,7 +58,7 @@ class ChannelClient {
|
|||
id.title,
|
||||
[
|
||||
for (var e in id.avatar)
|
||||
Thumbnail(Uri.parse(e.url), e.height, e.width)
|
||||
Thumbnail(Uri.parse(e['url']), e['height'], e['width'])
|
||||
],
|
||||
id.country,
|
||||
id.channelLinks);
|
||||
|
|
|
@ -76,7 +76,7 @@ class _InitialData {
|
|||
.get('contents')!
|
||||
.get('twoColumnBrowseResultsRenderer')!
|
||||
.getList('tabs')!
|
||||
.elementAtSafe(5)!
|
||||
.firstWhere((e) => e['tabRenderer']?['content'] != null)
|
||||
.get('tabRenderer')!
|
||||
.get('content')!
|
||||
.get('sectionListRenderer')!
|
||||
|
@ -126,7 +126,8 @@ class _InitialData {
|
|||
late final List<Map<String, dynamic>> avatar =
|
||||
content.get('avatar')!.getList('thumbnails')!;
|
||||
|
||||
String get country => content.get('country')!.getT<String>('simpleText')!;
|
||||
late final String country =
|
||||
content.get('country')!.getT<String>('simpleText')!;
|
||||
|
||||
String parseRuns(List<dynamic>? runs) =>
|
||||
runs?.map((e) => e.text).join() ?? '';
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
library youtube_explode.base;
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'channels/channels.dart';
|
||||
import 'playlists/playlist_client.dart';
|
||||
import 'reverse_engineering/youtube_http_client.dart';
|
||||
|
@ -8,7 +10,8 @@ import 'videos/video_client.dart';
|
|||
|
||||
/// Library entry point.
|
||||
class YoutubeExplode {
|
||||
final YoutubeHttpClient _httpClient;
|
||||
@visibleForTesting
|
||||
final YoutubeHttpClient httpClient;
|
||||
|
||||
/// Queries related to YouTube videos.
|
||||
late final VideoClient videos;
|
||||
|
@ -24,14 +27,14 @@ class YoutubeExplode {
|
|||
|
||||
/// Initializes an instance of [YoutubeClient].
|
||||
YoutubeExplode([YoutubeHttpClient? httpClient])
|
||||
: _httpClient = httpClient ?? YoutubeHttpClient() {
|
||||
videos = VideoClient(_httpClient);
|
||||
playlists = PlaylistClient(_httpClient);
|
||||
channels = ChannelClient(_httpClient);
|
||||
search = SearchClient(_httpClient);
|
||||
: httpClient = httpClient ?? YoutubeHttpClient() {
|
||||
videos = VideoClient(this.httpClient);
|
||||
playlists = PlaylistClient(this.httpClient);
|
||||
channels = ChannelClient(this.httpClient);
|
||||
search = SearchClient(this.httpClient);
|
||||
}
|
||||
|
||||
/// Closes the HttpClient assigned to this [YoutubeHttpClient].
|
||||
/// Should be called after this is not used anymore.
|
||||
void close() => _httpClient.close();
|
||||
void close() => httpClient.close();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: youtube_explode_dart
|
||||
description: A port in dart of the youtube explode library. Supports several API functions without the need of Youtube API Key.
|
||||
version: 1.9.0-nullsafety.4
|
||||
version: 1.9.0-nullsafety.5
|
||||
|
||||
homepage: https://github.com/Hexer10/youtube_explode_dart
|
||||
|
||||
|
|
|
@ -72,4 +72,16 @@ void main() {
|
|||
.toList();
|
||||
expect(videos, hasLength(30));
|
||||
});
|
||||
|
||||
test('Get about page of a youtube', () async {
|
||||
var aboutPage = await yt!.channels.getAboutPageByUsername(
|
||||
'PewDiePie'); // or yt.channels.getAboutPage(channelId)
|
||||
expect(aboutPage.title, 'PewDiePie');
|
||||
expect(aboutPage.viewCount, greaterThanOrEqualTo(27123740560));
|
||||
expect(aboutPage.description, isNotEmpty);
|
||||
expect(aboutPage.thumbnails, isNotEmpty); // Avatar list
|
||||
expect(aboutPage.channelLinks, isNotEmpty);
|
||||
expect(aboutPage.country, 'United States');
|
||||
expect(aboutPage.joinDate, 'Apr 29, 2010');
|
||||
});
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ void main() {
|
|||
test('Get more than 100 videos in a playlist', () async {
|
||||
var videos = await yt!.playlists
|
||||
.getVideos(PlaylistId(
|
||||
'https://www.youtube.com/playlist?list=PLCSusC_jlo14J0uBgFqfHsKu7gc5W2HyM'))
|
||||
'https://www.youtube.com/playlist?list=PLCSusC_jlo14J0uBgFqfHsKu7gc5W2HyM'))
|
||||
.toList();
|
||||
expect(videos.length, greaterThan(100));
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue