[youtube] /live URLs should raise error if channel is not live

Fixes: https://github.com/ytdl-org/youtube-dl/issues/29090
This commit is contained in:
pukkandan 2021-05-21 20:04:30 +05:30
parent cd59e22191
commit 09f1580e2d
No known key found for this signature in database
GPG key ID: 0F00D95A001F4698
2 changed files with 27 additions and 19 deletions

View file

@ -128,7 +128,7 @@ ### Differences in default behavior
* `playlist_index` behaves differently when used with options like `--playlist-reverse` and `--playlist-items`. See [#302](https://github.com/yt-dlp/yt-dlp/issues/302) for details. You can use `--compat-options playlist-index` if you want to keep the earlier behavior * `playlist_index` behaves differently when used with options like `--playlist-reverse` and `--playlist-items`. See [#302](https://github.com/yt-dlp/yt-dlp/issues/302) for details. You can use `--compat-options playlist-index` if you want to keep the earlier behavior
* The output of `-F` is listed in a new format. Use `--compat-options list-formats` to revert this * The output of `-F` is listed in a new format. Use `--compat-options list-formats` to revert this
* Youtube live chat (if available) is considered as a subtitle. Use `--sub-langs all,-live_chat` to download all subtitles except live chat. You can also use `--compat-options no-live-chat` to prevent live chat from downloading * Youtube live chat (if available) is considered as a subtitle. Use `--sub-langs all,-live_chat` to download all subtitles except live chat. You can also use `--compat-options no-live-chat` to prevent live chat from downloading
* Youtube channel URLs are automatically redirected to `/video`. Either append a `/featured` to the URL or use `--compat-options no-youtube-channel-redirect` to download only the videos in the home page * Youtube channel URLs are automatically redirected to `/video`. Append a `/featured` to the URL to download only the videos in the home page. If the channel does not have a videos tab, we try to download the equivalent `UU` playlist instead. Also, `/live` URLs raise an error if there are no live videos instead of silently downloading the entire channel. You may use `--compat-options no-youtube-channel-redirect` to revert all these redirections
* Unavailable videos are also listed for youtube playlists. Use `--compat-options no-youtube-unavailable-videos` to remove this * Unavailable videos are also listed for youtube playlists. Use `--compat-options no-youtube-unavailable-videos` to remove this
For ease of use, a few more compat options are available: For ease of use, a few more compat options are available:

View file

@ -2854,6 +2854,10 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
}, { }, {
'url': 'https://www.youtube.com/c/CommanderVideoHq/live', 'url': 'https://www.youtube.com/c/CommanderVideoHq/live',
'only_matching': True, 'only_matching': True,
}, {
'note': 'A channel that is not live. Should raise error',
'url': 'https://www.youtube.com/user/numberphile/live',
'only_matching': True,
}, { }, {
'url': 'https://www.youtube.com/feed/trending', 'url': 'https://www.youtube.com/feed/trending',
'only_matching': True, 'only_matching': True,
@ -3710,23 +3714,26 @@ def get_mobj(url):
if tabs: if tabs:
selected_tab = self._extract_selected_tab(tabs) selected_tab = self._extract_selected_tab(tabs)
tab_name = selected_tab.get('title', '') tab_name = selected_tab.get('title', '')
if (mobj['tab'] == '/videos' and tab_name.lower() != mobj['tab'][1:] if 'no-youtube-channel-redirect' not in compat_opts:
and 'no-youtube-channel-redirect' not in compat_opts): if mobj['tab'] == '/live':
if not mobj['not_channel'] and item_id[:2] == 'UC': # Live tab should have redirected to the video
# Topic channels don't have /videos. Use the equivalent playlist instead raise ExtractorError('The channel is not currently live', expected=True)
self.report_warning('The URL does not have a %s tab. Trying to redirect to playlist UU%s instead' % (mobj['tab'][1:], item_id[2:])) if mobj['tab'] == '/videos' and tab_name.lower() != mobj['tab'][1:]:
pl_id = 'UU%s' % item_id[2:] if not mobj['not_channel'] and item_id[:2] == 'UC':
pl_url = 'https://www.youtube.com/playlist?list=%s%s' % (pl_id, mobj['post']) # Topic channels don't have /videos. Use the equivalent playlist instead
try: self.report_warning('The URL does not have a %s tab. Trying to redirect to playlist UU%s instead' % (mobj['tab'][1:], item_id[2:]))
pl_webpage, pl_data = self._extract_webpage(pl_url, pl_id) pl_id = 'UU%s' % item_id[2:]
for alert_type, alert_message in self._extract_alerts(pl_data): pl_url = 'https://www.youtube.com/playlist?list=%s%s' % (pl_id, mobj['post'])
if alert_type == 'error': try:
raise ExtractorError('Youtube said: %s' % alert_message) pl_webpage, pl_data = self._extract_webpage(pl_url, pl_id)
item_id, url, webpage, data = pl_id, pl_url, pl_webpage, pl_data for alert_type, alert_message in self._extract_alerts(pl_data):
except ExtractorError: if alert_type == 'error':
self.report_warning('The playlist gave error. Falling back to channel URL') raise ExtractorError('Youtube said: %s' % alert_message)
else: item_id, url, webpage, data = pl_id, pl_url, pl_webpage, pl_data
self.report_warning('The URL does not have a %s tab. %s is being downloaded instead' % (mobj['tab'][1:], tab_name)) except ExtractorError:
self.report_warning('The playlist gave error. Falling back to channel URL')
else:
self.report_warning('The URL does not have a %s tab. %s is being downloaded instead' % (mobj['tab'][1:], tab_name))
self.write_debug('Final URL: %s' % url) self.write_debug('Final URL: %s' % url)
@ -3749,7 +3756,8 @@ def get_mobj(url):
data, lambda x: x['currentVideoEndpoint']['watchEndpoint']['videoId'], data, lambda x: x['currentVideoEndpoint']['watchEndpoint']['videoId'],
compat_str) or video_id compat_str) or video_id
if video_id: if video_id:
self.report_warning('Unable to recognize playlist. Downloading just video %s' % video_id) if mobj['tab'] != '/live': # live tab is expected to redirect to video
self.report_warning('Unable to recognize playlist. Downloading just video %s' % video_id)
return self.url_result(video_id, ie=YoutubeIE.ie_key(), video_id=video_id) return self.url_result(video_id, ie=YoutubeIE.ie_key(), video_id=video_id)
raise ExtractorError('Unable to recognize tab page') raise ExtractorError('Unable to recognize tab page')