[youtube] Match JSON in alert regex

pull/163/head
Ali Sherief 5 years ago
parent 69e3c6df5c
commit cc50cfa6c1
No known key found for this signature in database
GPG Key ID: 1C3D1D19C8E8B6D8

@ -2891,11 +2891,10 @@ class YoutubePlaylistIE(YoutubePlaylistBaseInfoExtractor):
url = self._TEMPLATE_URL % playlist_id url = self._TEMPLATE_URL % playlist_id
page = self._download_webpage(url, playlist_id) page = self._download_webpage(url, playlist_id)
# the yt-alert-message now has tabindex attribute (see https://github.com/ytdl-org/youtube-dl/issues/11604) prefix_reg = r'"alerts":\[\{"alertRenderer":.*?'
for match in re.findall(r'<div class="yt-alert-message"[^>]*>([^<]+)</div>', page): noexist_private_reg = r'(?:The|This) playlist (?P<reason>does not exist|is private)'
match = match.strip() mobj = re.search(prefix_reg + noexist_private_reg, page)
# Check if the playlist exists or is private mobj_other_reason = re.search(prefix_reg + r'"runs":\[\{"text":"(?P<message>[^"]+)', page)
mobj = re.match(r'[^<]*(?:The|This) playlist (?P<reason>does not exist|is private)[^<]*', match)
if mobj: if mobj:
reason = mobj.group('reason') reason = mobj.group('reason')
message = 'This playlist %s' % reason message = 'This playlist %s' % reason
@ -2903,14 +2902,15 @@ class YoutubePlaylistIE(YoutubePlaylistBaseInfoExtractor):
message += ', use --username or --netrc to access it' message += ', use --username or --netrc to access it'
message += '.' message += '.'
raise ExtractorError(message, expected=True) raise ExtractorError(message, expected=True)
elif re.match(r'[^<]*Invalid parameters[^<]*', match): elif re.search(prefix_reg + r'Invalid parameters', page):
raise ExtractorError( raise ExtractorError(
'Invalid parameters. Maybe URL is incorrect.', 'Invalid parameters. Maybe URL is incorrect.',
expected=True) expected=True)
elif re.match(r'[^<]*Choose your language[^<]*', match): elif re.search(prefix_reg + r'Choose your language', page):
continue pass
else: elif mobj_other_reason:
self.report_warning('Youtube gives an alert message: ' + match) message = mobj_other_reason.group("message")
self.report_warning('Youtube gives an alert message: ' + message)
playlist_title = self._html_search_regex( playlist_title = self._html_search_regex(
r'(?s)<h1 class="pl-header-title[^"]*"[^>]*>\s*(.*?)\s*</h1>', r'(?s)<h1 class="pl-header-title[^"]*"[^>]*>\s*(.*?)\s*</h1>',

Loading…
Cancel
Save