[youtube:tab] Fix playlist title extraction (closes #27015)
This commit is contained in:
parent
7d509c613b
commit
f8c749f12c
1 changed files with 21 additions and 15 deletions
|
@ -2825,30 +2825,36 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
|
||||||
raise ExtractorError('Unable to find selected tab')
|
raise ExtractorError('Unable to find selected tab')
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
channel_id = self._match_id(url)
|
item_id = self._match_id(url)
|
||||||
url = compat_urlparse.urlunparse(
|
url = compat_urlparse.urlunparse(
|
||||||
compat_urlparse.urlparse(url)._replace(netloc='www.youtube.com'))
|
compat_urlparse.urlparse(url)._replace(netloc='www.youtube.com'))
|
||||||
webpage = self._download_webpage(url, channel_id)
|
webpage = self._download_webpage(url, item_id)
|
||||||
data = self._extract_yt_initial_data(channel_id, webpage)
|
data = self._extract_yt_initial_data(item_id, webpage)
|
||||||
tabs = data['contents']['twoColumnBrowseResultsRenderer']['tabs']
|
tabs = data['contents']['twoColumnBrowseResultsRenderer']['tabs']
|
||||||
selected_tab = self._extract_selected_tab(tabs)
|
selected_tab = self._extract_selected_tab(tabs)
|
||||||
channel_title = try_get(
|
renderer = try_get(
|
||||||
data, lambda x: x['metadata']['channelMetadataRenderer']['title'],
|
data, lambda x: x['metadata']['channelMetadataRenderer'], dict)
|
||||||
compat_str)
|
if renderer:
|
||||||
channel_external_id = try_get(
|
channel_title = renderer.get('title') or item_id
|
||||||
data, lambda x: x['metadata']['channelMetadataRenderer']['externalId'],
|
tab_title = selected_tab.get('title')
|
||||||
compat_str)
|
title = channel_title or item_id
|
||||||
tab_title = selected_tab.get('title')
|
if tab_title:
|
||||||
title = channel_title or channel_id
|
title += ' - %s' % tab_title
|
||||||
if tab_title:
|
description = renderer.get('description')
|
||||||
title += ' - %s' % tab_title
|
playlist_id = renderer.get('externalId')
|
||||||
|
renderer = try_get(
|
||||||
|
data, lambda x: x['metadata']['playlistMetadataRenderer'], dict)
|
||||||
|
if renderer:
|
||||||
|
title = renderer.get('title')
|
||||||
|
description = None
|
||||||
|
playlist_id = item_id
|
||||||
identity_token = self._search_regex(
|
identity_token = self._search_regex(
|
||||||
r'\bID_TOKEN["\']\s*:\s*["\'](.+?)["\']', webpage,
|
r'\bID_TOKEN["\']\s*:\s*["\'](.+?)["\']', webpage,
|
||||||
'identity token', default=None)
|
'identity token', default=None)
|
||||||
return self.playlist_result(
|
return self.playlist_result(
|
||||||
self._entries(selected_tab['content'], identity_token),
|
self._entries(selected_tab['content'], identity_token),
|
||||||
playlist_id=channel_external_id or channel_id,
|
playlist_id=playlist_id, playlist_title=title,
|
||||||
playlist_title=title)
|
playlist_description=description)
|
||||||
|
|
||||||
|
|
||||||
class YoutubePlaylistIE(InfoExtractor):
|
class YoutubePlaylistIE(InfoExtractor):
|
||||||
|
|
Loading…
Reference in a new issue