From c0784dc22d486a699f842e92b85cce901c9fcaa2 Mon Sep 17 00:00:00 2001 From: Thomas Coleman Date: Sun, 19 Jul 2020 23:31:48 -0700 Subject: [PATCH 1/2] Add Channel Image in JSON info dict for YoutubeChannelIE --- youtube_dl/YoutubeDL.py | 3 +++ youtube_dl/extractor/youtube.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 19370f62b..b3935518c 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -864,6 +864,8 @@ class YoutubeDL(object): elif result_type == 'url': # We have to add extra_info to the results because it may be # contained in a playlist + if ie_result.get('channel_image'): + extra_info['channel_image'] = ie_result.get('channel_image') return self.extract_info(ie_result['url'], download, ie_key=ie_result.get('ie_key'), @@ -998,6 +1000,7 @@ class YoutubeDL(object): 'extractor_key': ie_result['extractor_key'], } + extra.update(extra_info) reason = self._match_entry(entry, incomplete=True) if reason is not None: self.to_screen('[download] ' + reason) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index b35bf03aa..527cf1922 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -2962,6 +2962,8 @@ class YoutubeChannelIE(YoutubePlaylistBaseInfoExtractor): if channel_page is False: channel_playlist_id = False else: + channel_image = self._html_search_meta( + 'og:image', channel_page, 'channel image', default=None) channel_playlist_id = self._html_search_meta( 'channelId', channel_page, 'channel id', default=None) if not channel_playlist_id: @@ -2974,8 +2976,10 @@ class YoutubeChannelIE(YoutubePlaylistBaseInfoExtractor): channel_url, 'channel id', default=None) if channel_playlist_id and channel_playlist_id.startswith('UC'): playlist_id = 'UU' + channel_playlist_id[2:] - return self.url_result( + url_result = self.url_result( compat_urlparse.urljoin(url, '/playlist?list=%s' % playlist_id), 'YoutubePlaylist') + url_result['channel_image'] = channel_image + return url_result channel_page = self._download_webpage(url, channel_id, 'Downloading page #1') autogenerated = re.search(r'''(?x) From ed007e9f010e824b7e1025750f987e7c5051470c Mon Sep 17 00:00:00 2001 From: Thomas Coleman Date: Mon, 20 Jul 2020 12:06:16 -0700 Subject: [PATCH 2/2] Include channel_title in the channel extra_info --- youtube_dl/YoutubeDL.py | 2 ++ youtube_dl/extractor/youtube.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index b3935518c..51cb0af1c 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -866,6 +866,8 @@ class YoutubeDL(object): # contained in a playlist if ie_result.get('channel_image'): extra_info['channel_image'] = ie_result.get('channel_image') + if ie_result.get('channel_title'): + extra_info['channel_title'] = ie_result.get('channel_title') return self.extract_info(ie_result['url'], download, ie_key=ie_result.get('ie_key'), diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 527cf1922..42dc2df15 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -2952,6 +2952,7 @@ class YoutubeChannelIE(YoutubePlaylistBaseInfoExtractor): channel_id = self._match_id(url) url = self._build_template_url(url, channel_id) + extra_info = dict() # Channel by page listing is restricted to 35 pages of 30 items, i.e. 1050 videos total (see #5778) # Workaround by extracting as a playlist if managed to obtain channel playlist URL @@ -2962,8 +2963,10 @@ class YoutubeChannelIE(YoutubePlaylistBaseInfoExtractor): if channel_page is False: channel_playlist_id = False else: - channel_image = self._html_search_meta( + extra_info['channel_image'] = self._html_search_meta( 'og:image', channel_page, 'channel image', default=None) + extra_info['channel_title'] = self._html_search_meta( + 'og:title', channel_page, 'channel title', default=None) channel_playlist_id = self._html_search_meta( 'channelId', channel_page, 'channel id', default=None) if not channel_playlist_id: @@ -2978,7 +2981,7 @@ class YoutubeChannelIE(YoutubePlaylistBaseInfoExtractor): playlist_id = 'UU' + channel_playlist_id[2:] url_result = self.url_result( compat_urlparse.urljoin(url, '/playlist?list=%s' % playlist_id), 'YoutubePlaylist') - url_result['channel_image'] = channel_image + url_result.update(extra_info) return url_result channel_page = self._download_webpage(url, channel_id, 'Downloading page #1')