Add getChannelIdFromVideo

#15
This commit is contained in:
Hexah 2020-03-11 11:59:07 +01:00
parent a34e573c1e
commit bac2c6fc18
1 changed files with 13 additions and 0 deletions

View File

@ -64,6 +64,19 @@ extension ChannelExtension on YoutubeExplode {
return playlist.videos;
}
/// Returns the channel id for a given video.
Future<String> getChannelIdFromVideo(String videoId) async {
if (!YoutubeExplode.validateVideoId(videoId)) {
throw ArgumentError.value(videoId, 'videoId', 'Invalid YouTube video id');
}
var watchPage = await getVideoWatchPage(videoId);
var href = watchPage
.querySelector('.yt-user-info')
.querySelector('a')
.attributes['href'];
return href.replaceFirst('/channel/', '');
}
/// Returns the channel page document.
Future<Document> getChannelPage(String channelId) async {
var url = 'https://www.youtube.com/channel/$channelId?hl=en';