3 from __future__
import unicode_literals
14 from .common
import InfoExtractor
, SearchInfoExtractor
15 from ..jsinterp
import JSInterpreter
16 from ..swfinterp
import SWFInterpreter
17 from ..compat
import (
22 compat_urllib_parse_unquote
,
23 compat_urllib_parse_unquote_plus
,
24 compat_urllib_parse_urlencode
,
25 compat_urllib_parse_urlparse
,
36 get_element_by_attribute
,
59 class YoutubeBaseInfoExtractor(InfoExtractor
):
60 """Provide base functions for Youtube extractors"""
61 _LOGIN_URL
= 'https://accounts.google.com/ServiceLogin'
62 _TWOFACTOR_URL
= 'https://accounts.google.com/signin/challenge'
64 _LOOKUP_URL
= 'https://accounts.google.com/_/signin/sl/lookup'
65 _CHALLENGE_URL
= 'https://accounts.google.com/_/signin/sl/challenge'
66 _TFA_URL
= 'https://accounts.google.com/_/signin/challenge?hl=en&TL={0}'
68 _NETRC_MACHINE
= 'youtube'
69 # If True it will raise an error if no login info is provided
70 _LOGIN_REQUIRED
= False
72 _PLAYLIST_ID_RE
= r
'(?:PL|LL|EC|UU|FL|RD|UL|TL|PU|OLAK5uy_)[0-9A-Za-z-_]{10,}'
74 _YOUTUBE_CLIENT_HEADERS
= {
75 'x-youtube-client-name': '1',
76 'x-youtube-client-version': '1.20200609.04.02',
79 def _set_language(self
):
81 '.youtube.com', 'PREF', 'f1=50000000&f6=8&hl=en',
82 # YouTube sets the expire time to about two months
83 expire_time
=time
.time() + 2 * 30 * 24 * 3600)
85 def _ids_to_results(self
, ids
):
87 self
.url_result(vid_id
, 'Youtube', video_id
=vid_id
)
92 Attempt to log in to YouTube.
93 True is returned if successful or skipped.
94 False is returned if login failed.
96 If _LOGIN_REQUIRED is set and no authentication was provided, an error is raised.
98 username
, password
= self
._get
_login
_info
()
99 # No authentication to be performed
101 if self
._LOGIN
_REQUIRED
and self
._downloader
.params
.get('cookiefile') is None:
102 raise ExtractorError('No login info available, needed for using %s.' % self
.IE_NAME
, expected
=True)
103 if self
._downloader
.params
.get('cookiefile') and False: # TODO remove 'and False' later - too many people using outdated cookies and open issues, remind them.
104 self
.to_screen('[Cookies] Reminder - Make sure to always use up to date cookies!')
107 login_page
= self
._download
_webpage
(
108 self
._LOGIN
_URL
, None,
109 note
='Downloading login page',
110 errnote
='unable to fetch login page', fatal
=False)
111 if login_page
is False:
114 login_form
= self
._hidden
_inputs
(login_page
)
116 def req(url
, f_req
, note
, errnote
):
117 data
= login_form
.copy()
120 'checkConnection': 'youtube',
121 'checkedDomains': 'youtube',
123 'deviceinfo': '[null,null,null,[],null,"US",null,null,[],"GlifWebSignIn",null,[null,null,[]]]',
124 'f.req': json
.dumps(f_req
),
125 'flowName': 'GlifWebSignIn',
126 'flowEntry': 'ServiceLogin',
127 # TODO: reverse actual botguard identifier generation algo
128 'bgRequest': '["identifier",""]',
130 return self
._download
_json
(
131 url
, None, note
=note
, errnote
=errnote
,
132 transform_source
=lambda s
: re
.sub(r
'^[^[]*', '', s
),
134 data
=urlencode_postdata(data
), headers
={
135 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
136 'Google-Accounts-XSRF': 1,
140 self
._downloader
.report_warning(message
)
144 None, [], None, 'US', None, None, 2, False, True,
148 'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn',
150 1, [None, None, []], None, None, None, True
155 lookup_results
= req(
156 self
._LOOKUP
_URL
, lookup_req
,
157 'Looking up account info', 'Unable to look up account info')
159 if lookup_results
is False:
162 user_hash
= try_get(lookup_results
, lambda x
: x
[0][2], compat_str
)
164 warn('Unable to extract user hash')
169 None, 1, None, [1, None, None, None, [password
, None, True]],
171 None, None, [2, 1, None, 1, 'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn', None, [], 4],
172 1, [None, None, []], None, None, None, True
175 challenge_results
= req(
176 self
._CHALLENGE
_URL
, challenge_req
,
177 'Logging in', 'Unable to log in')
179 if challenge_results
is False:
182 login_res
= try_get(challenge_results
, lambda x
: x
[0][5], list)
184 login_msg
= try_get(login_res
, lambda x
: x
[5], compat_str
)
186 'Unable to login: %s' % 'Invalid password'
187 if login_msg
== 'INCORRECT_ANSWER_ENTERED' else login_msg
)
190 res
= try_get(challenge_results
, lambda x
: x
[0][-1], list)
192 warn('Unable to extract result entry')
195 login_challenge
= try_get(res
, lambda x
: x
[0][0], list)
197 challenge_str
= try_get(login_challenge
, lambda x
: x
[2], compat_str
)
198 if challenge_str
== 'TWO_STEP_VERIFICATION':
199 # SEND_SUCCESS - TFA code has been successfully sent to phone
200 # QUOTA_EXCEEDED - reached the limit of TFA codes
201 status
= try_get(login_challenge
, lambda x
: x
[5], compat_str
)
202 if status
== 'QUOTA_EXCEEDED':
203 warn('Exceeded the limit of TFA codes, try later')
206 tl
= try_get(challenge_results
, lambda x
: x
[1][2], compat_str
)
208 warn('Unable to extract TL')
211 tfa_code
= self
._get
_tfa
_info
('2-step verification code')
215 'Two-factor authentication required. Provide it either interactively or with --twofactor <code>'
216 '(Note that only TOTP (Google Authenticator App) codes work at this time.)')
219 tfa_code
= remove_start(tfa_code
, 'G-')
222 user_hash
, None, 2, None,
224 9, None, None, None, None, None, None, None,
225 [None, tfa_code
, True, 2]
229 self
._TFA
_URL
.format(tl
), tfa_req
,
230 'Submitting TFA code', 'Unable to submit TFA code')
232 if tfa_results
is False:
235 tfa_res
= try_get(tfa_results
, lambda x
: x
[0][5], list)
237 tfa_msg
= try_get(tfa_res
, lambda x
: x
[5], compat_str
)
239 'Unable to finish TFA: %s' % 'Invalid TFA code'
240 if tfa_msg
== 'INCORRECT_ANSWER_ENTERED' else tfa_msg
)
243 check_cookie_url
= try_get(
244 tfa_results
, lambda x
: x
[0][-1][2], compat_str
)
247 'LOGIN_CHALLENGE': "This device isn't recognized. For your security, Google wants to make sure it's really you.",
248 'USERNAME_RECOVERY': 'Please provide additional information to aid in the recovery process.',
249 'REAUTH': "There is something unusual about your activity. For your security, Google wants to make sure it's really you.",
251 challenge
= CHALLENGES
.get(
253 '%s returned error %s.' % (self
.IE_NAME
, challenge_str
))
254 warn('%s\nGo to https://accounts.google.com/, login and solve a challenge.' % challenge
)
257 check_cookie_url
= try_get(res
, lambda x
: x
[2], compat_str
)
259 if not check_cookie_url
:
260 warn('Unable to extract CheckCookie URL')
263 check_cookie_results
= self
._download
_webpage
(
264 check_cookie_url
, None, 'Checking cookie', fatal
=False)
266 if check_cookie_results
is False:
269 if 'https://myaccount.google.com/' not in check_cookie_results
:
270 warn('Unable to log in')
275 def _download_webpage_handle(self
, *args
, **kwargs
):
276 query
= kwargs
.get('query', {}).copy()
277 query
['disable_polymer'] = 'true'
278 kwargs
['query'] = query
279 return super(YoutubeBaseInfoExtractor
, self
)._download
_webpage
_handle
(
280 *args
, **compat_kwargs(kwargs
))
282 def _real_initialize(self
):
283 if self
._downloader
is None:
286 if not self
._login
():
290 class YoutubeEntryListBaseInfoExtractor(YoutubeBaseInfoExtractor
):
291 # Extract entries from page with "Load more" button
292 def _entries(self
, page
, playlist_id
):
293 more_widget_html
= content_html
= page
294 for page_num
in itertools
.count(1):
295 for entry
in self
._process
_page
(content_html
):
298 mobj
= re
.search(r
'data-uix-load-more-href="/?(?P<more>[^"]+)"', more_widget_html
)
304 while count
<= retries
:
306 # Downloading page may result in intermittent 5xx HTTP error
307 # that is usually worked around with a retry
308 more
= self
._download
_json
(
309 'https://www.youtube.com/%s' % mobj
.group('more'), playlist_id
,
310 'Downloading page #%s%s'
311 % (page_num
, ' (retry #%d)' % count
if count
else ''),
312 transform_source
=uppercase_escape
,
313 headers
=self
._YOUTUBE
_CLIENT
_HEADERS
)
315 except ExtractorError
as e
:
316 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
in (500, 503):
322 content_html
= more
['content_html']
323 if not content_html
.strip():
324 # Some webpages show a "Load more" button but they don't
327 more_widget_html
= more
['load_more_widget_html']
330 class YoutubePlaylistBaseInfoExtractor(YoutubeEntryListBaseInfoExtractor
):
331 def _process_page(self
, content
):
332 for video_id
, video_title
in self
.extract_videos_from_page(content
):
333 yield self
.url_result(video_id
, 'Youtube', video_id
, video_title
)
335 def extract_videos_from_page_impl(self
, video_re
, page
, ids_in_page
, titles_in_page
):
336 for mobj
in re
.finditer(video_re
, page
):
337 # The link with index 0 is not the first video of the playlist (not sure if still actual)
338 if 'index' in mobj
.groupdict() and mobj
.group('id') == '0':
340 video_id
= mobj
.group('id')
341 video_title
= unescapeHTML(
342 mobj
.group('title')) if 'title' in mobj
.groupdict() else None
344 video_title
= video_title
.strip()
345 if video_title
== '► Play all':
348 idx
= ids_in_page
.index(video_id
)
349 if video_title
and not titles_in_page
[idx
]:
350 titles_in_page
[idx
] = video_title
352 ids_in_page
.append(video_id
)
353 titles_in_page
.append(video_title
)
355 def extract_videos_from_page(self
, page
):
358 self
.extract_videos_from_page_impl(
359 self
._VIDEO
_RE
, page
, ids_in_page
, titles_in_page
)
360 return zip(ids_in_page
, titles_in_page
)
363 class YoutubePlaylistsBaseInfoExtractor(YoutubeEntryListBaseInfoExtractor
):
364 def _process_page(self
, content
):
365 for playlist_id
in orderedSet(re
.findall(
366 r
'<h3[^>]+class="[^"]*yt-lockup-title[^"]*"[^>]*><a[^>]+href="/?playlist\?list=([0-9A-Za-z-_]{10,})"',
368 yield self
.url_result(
369 'https://www.youtube.com/playlist?list=%s' % playlist_id
, 'YoutubePlaylist')
371 def _real_extract(self
, url
):
372 playlist_id
= self
._match
_id
(url
)
373 webpage
= self
._download
_webpage
(url
, playlist_id
)
374 title
= self
._og
_search
_title
(webpage
, fatal
=False)
375 return self
.playlist_result(self
._entries
(webpage
, playlist_id
), playlist_id
, title
)
378 class YoutubeIE(YoutubeBaseInfoExtractor
):
379 IE_DESC
= 'YouTube.com'
380 _VALID_URL
= r
"""(?x)^
382 (?:https?://|//) # http(s):// or protocol-independent URL
383 (?:(?:(?:(?:\w+\.)?[yY][oO][uU][tT][uU][bB][eE](?:-nocookie|kids)?\.com/|
384 (?:www\.)?deturl\.com/www\.youtube\.com/|
385 (?:www\.)?pwnyoutube\.com/|
386 (?:www\.)?hooktube\.com/|
387 (?:www\.)?yourepeat\.com/|
388 tube\.majestyc\.net/|
389 # Invidious instances taken from https://github.com/omarroth/invidious/wiki/Invidious-Instances
390 (?:(?:www|dev)\.)?invidio\.us/|
391 (?:(?:www|no)\.)?invidiou\.sh/|
392 (?:(?:www|fi|de)\.)?invidious\.snopyta\.org/|
393 (?:www\.)?invidious\.kabi\.tk/|
394 (?:www\.)?invidious\.13ad\.de/|
395 (?:www\.)?invidious\.mastodon\.host/|
396 (?:www\.)?invidious\.nixnet\.xyz/|
397 (?:www\.)?invidious\.drycat\.fr/|
398 (?:www\.)?tube\.poal\.co/|
399 (?:www\.)?vid\.wxzm\.sx/|
400 (?:www\.)?yewtu\.be/|
401 (?:www\.)?yt\.elukerio\.org/|
402 (?:www\.)?yt\.lelux\.fi/|
403 (?:www\.)?invidious\.ggc-project\.de/|
404 (?:www\.)?yt\.maisputain\.ovh/|
405 (?:www\.)?invidious\.13ad\.de/|
406 (?:www\.)?invidious\.toot\.koeln/|
407 (?:www\.)?invidious\.fdn\.fr/|
408 (?:www\.)?watch\.nettohikari\.com/|
409 (?:www\.)?kgg2m7yk5aybusll\.onion/|
410 (?:www\.)?qklhadlycap4cnod\.onion/|
411 (?:www\.)?axqzx4s6s54s32yentfqojs3x5i7faxza6xo3ehd4bzzsg2ii4fv2iid\.onion/|
412 (?:www\.)?c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid\.onion/|
413 (?:www\.)?fz253lmuao3strwbfbmx46yu7acac2jz27iwtorgmbqlkurlclmancad\.onion/|
414 (?:www\.)?invidious\.l4qlywnpwqsluw65ts7md3khrivpirse744un3x7mlskqauz5pyuzgqd\.onion/|
415 (?:www\.)?owxfohz4kjyv25fvlqilyxast7inivgiktls3th44jhk3ej3i7ya\.b32\.i2p/|
416 (?:www\.)?4l2dgddgsrkf2ous66i6seeyi6etzfgrue332grh2n7madpwopotugyd\.onion/|
417 youtube\.googleapis\.com/) # the various hostnames, with wildcard subdomains
418 (?:.*?\#/)? # handle anchor (#/) redirect urls
419 (?: # the various things that can precede the ID:
420 (?:(?:v|embed|e)/(?!videoseries)) # v/ or embed/ or e/
421 |(?: # or the v= param in all its forms
422 (?:(?:watch|movie)(?:_popup)?(?:\.php)?/?)? # preceding watch(_popup|.php) or nothing (like /?v=xxxx)
423 (?:\?|\#!?) # the params delimiter ? or # or #!
424 (?:.*?[&;])?? # any other preceding param (like /?s=tuff&v=xxxx or ?s=tuff&v=V36LpHqtcDY)
429 youtu\.be| # just youtu.be/xxxx
430 vid\.plus| # or vid.plus/xxxx
431 zwearz\.com/watch| # or zwearz.com/watch/xxxx
433 |(?:www\.)?cleanvideosearch\.com/media/action/yt/watch\?videoId=
435 )? # all until now is optional -> you can pass the naked ID
436 ([0-9A-Za-z_-]{11}) # here is it! the YouTube video ID
439 %(playlist_id)s| # combined list/video URLs are handled by the playlist IE
440 WL # WL are handled by the watch later IE
443 (?(1).+)? # if we found the ID, everything can follow
444 $""" % {'playlist_id': YoutubeBaseInfoExtractor._PLAYLIST_ID_RE}
445 _NEXT_URL_RE
= r
'[\?&]next_url=([^&]+)'
447 r
'/(?P<id>[a-zA-Z0-9_-]{8,})/player_ias\.vflset(?:/[a-zA-Z]{2,3}_[a-zA-Z]{2,3})?/base\.(?P<ext>[a-z]+)$',
448 r
'\b(?P<id>vfl[a-zA-Z0-9_-]+)\b.*?\.(?P<ext>[a-z]+)$',
451 '5': {'ext': 'flv', 'width': 400, 'height': 240, 'acodec': 'mp3', 'abr': 64, 'vcodec': 'h263'}
,
452 '6': {'ext': 'flv', 'width': 450, 'height': 270, 'acodec': 'mp3', 'abr': 64, 'vcodec': 'h263'}
,
453 '13': {'ext': '3gp', 'acodec': 'aac', 'vcodec': 'mp4v'}
,
454 '17': {'ext': '3gp', 'width': 176, 'height': 144, 'acodec': 'aac', 'abr': 24, 'vcodec': 'mp4v'}
,
455 '18': {'ext': 'mp4', 'width': 640, 'height': 360, 'acodec': 'aac', 'abr': 96, 'vcodec': 'h264'}
,
456 '22': {'ext': 'mp4', 'width': 1280, 'height': 720, 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264'}
,
457 '34': {'ext': 'flv', 'width': 640, 'height': 360, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'}
,
458 '35': {'ext': 'flv', 'width': 854, 'height': 480, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'}
,
459 # itag 36 videos are either 320x180 (BaW_jenozKc) or 320x240 (__2ABJjxzNo), abr varies as well
460 '36': {'ext': '3gp', 'width': 320, 'acodec': 'aac', 'vcodec': 'mp4v'}
,
461 '37': {'ext': 'mp4', 'width': 1920, 'height': 1080, 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264'}
,
462 '38': {'ext': 'mp4', 'width': 4096, 'height': 3072, 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264'}
,
463 '43': {'ext': 'webm', 'width': 640, 'height': 360, 'acodec': 'vorbis', 'abr': 128, 'vcodec': 'vp8'}
,
464 '44': {'ext': 'webm', 'width': 854, 'height': 480, 'acodec': 'vorbis', 'abr': 128, 'vcodec': 'vp8'}
,
465 '45': {'ext': 'webm', 'width': 1280, 'height': 720, 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8'}
,
466 '46': {'ext': 'webm', 'width': 1920, 'height': 1080, 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8'}
,
467 '59': {'ext': 'mp4', 'width': 854, 'height': 480, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'}
,
468 '78': {'ext': 'mp4', 'width': 854, 'height': 480, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'}
,
472 '82': {'ext': 'mp4', 'height': 360, 'format_note': '3D', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -20}
,
473 '83': {'ext': 'mp4', 'height': 480, 'format_note': '3D', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -20}
,
474 '84': {'ext': 'mp4', 'height': 720, 'format_note': '3D', 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264', 'preference': -20}
,
475 '85': {'ext': 'mp4', 'height': 1080, 'format_note': '3D', 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264', 'preference': -20}
,
476 '100': {'ext': 'webm', 'height': 360, 'format_note': '3D', 'acodec': 'vorbis', 'abr': 128, 'vcodec': 'vp8', 'preference': -20}
,
477 '101': {'ext': 'webm', 'height': 480, 'format_note': '3D', 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8', 'preference': -20}
,
478 '102': {'ext': 'webm', 'height': 720, 'format_note': '3D', 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8', 'preference': -20}
,
480 # Apple HTTP Live Streaming
481 '91': {'ext': 'mp4', 'height': 144, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 48, 'vcodec': 'h264', 'preference': -10}
,
482 '92': {'ext': 'mp4', 'height': 240, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 48, 'vcodec': 'h264', 'preference': -10}
,
483 '93': {'ext': 'mp4', 'height': 360, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -10}
,
484 '94': {'ext': 'mp4', 'height': 480, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -10}
,
485 '95': {'ext': 'mp4', 'height': 720, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 256, 'vcodec': 'h264', 'preference': -10}
,
486 '96': {'ext': 'mp4', 'height': 1080, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 256, 'vcodec': 'h264', 'preference': -10}
,
487 '132': {'ext': 'mp4', 'height': 240, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 48, 'vcodec': 'h264', 'preference': -10}
,
488 '151': {'ext': 'mp4', 'height': 72, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 24, 'vcodec': 'h264', 'preference': -10}
,
491 '133': {'ext': 'mp4', 'height': 240, 'format_note': 'DASH video', 'vcodec': 'h264'}
,
492 '134': {'ext': 'mp4', 'height': 360, 'format_note': 'DASH video', 'vcodec': 'h264'}
,
493 '135': {'ext': 'mp4', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'h264'}
,
494 '136': {'ext': 'mp4', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'h264'}
,
495 '137': {'ext': 'mp4', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'h264'}
,
496 '138': {'ext': 'mp4', 'format_note': 'DASH video', 'vcodec': 'h264'}
, # Height can vary (https://github.com/ytdl-org/youtube-dl/issues/4559)
497 '160': {'ext': 'mp4', 'height': 144, 'format_note': 'DASH video', 'vcodec': 'h264'}
,
498 '212': {'ext': 'mp4', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'h264'}
,
499 '264': {'ext': 'mp4', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'h264'}
,
500 '298': {'ext': 'mp4', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'h264', 'fps': 60}
,
501 '299': {'ext': 'mp4', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'h264', 'fps': 60}
,
502 '266': {'ext': 'mp4', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'h264'}
,
505 '139': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'abr': 48, 'container': 'm4a_dash'}
,
506 '140': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'abr': 128, 'container': 'm4a_dash'}
,
507 '141': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'abr': 256, 'container': 'm4a_dash'}
,
508 '256': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'container': 'm4a_dash'}
,
509 '258': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'container': 'm4a_dash'}
,
510 '325': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'dtse', 'container': 'm4a_dash'}
,
511 '328': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'ec-3', 'container': 'm4a_dash'}
,
514 '167': {'ext': 'webm', 'height': 360, 'width': 640, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'}
,
515 '168': {'ext': 'webm', 'height': 480, 'width': 854, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'}
,
516 '169': {'ext': 'webm', 'height': 720, 'width': 1280, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'}
,
517 '170': {'ext': 'webm', 'height': 1080, 'width': 1920, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'}
,
518 '218': {'ext': 'webm', 'height': 480, 'width': 854, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'}
,
519 '219': {'ext': 'webm', 'height': 480, 'width': 854, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'}
,
520 '278': {'ext': 'webm', 'height': 144, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp9'}
,
521 '242': {'ext': 'webm', 'height': 240, 'format_note': 'DASH video', 'vcodec': 'vp9'}
,
522 '243': {'ext': 'webm', 'height': 360, 'format_note': 'DASH video', 'vcodec': 'vp9'}
,
523 '244': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'}
,
524 '245': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'}
,
525 '246': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'}
,
526 '247': {'ext': 'webm', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'vp9'}
,
527 '248': {'ext': 'webm', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'vp9'}
,
528 '271': {'ext': 'webm', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'vp9'}
,
529 # itag 272 videos are either 3840x2160 (e.g. RtoitU2A-3E) or 7680x4320 (sLprVF6d7Ug)
530 '272': {'ext': 'webm', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'vp9'}
,
531 '302': {'ext': 'webm', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60}
,
532 '303': {'ext': 'webm', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60}
,
533 '308': {'ext': 'webm', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60}
,
534 '313': {'ext': 'webm', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'vp9'}
,
535 '315': {'ext': 'webm', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60}
,
538 '171': {'ext': 'webm', 'acodec': 'vorbis', 'format_note': 'DASH audio', 'abr': 128}
,
539 '172': {'ext': 'webm', 'acodec': 'vorbis', 'format_note': 'DASH audio', 'abr': 256}
,
541 # Dash webm audio with opus inside
542 '249': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 50}
,
543 '250': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 70}
,
544 '251': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 160}
,
547 '_rtmp': {'protocol': 'rtmp'}
,
549 # av01 video only formats sometimes served with "unknown" codecs
550 '394': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'}
,
551 '395': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'}
,
552 '396': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'}
,
553 '397': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'}
,
555 _SUBTITLE_FORMATS
= ('json3', 'srv1', 'srv2', 'srv3', 'ttml', 'vtt')
562 'url': 'https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9',
566 'title': 'youtube-dl test video "\'/\\ä↭𝕐',
567 'uploader': 'Philipp Hagemeister',
568 'uploader_id': 'phihag',
569 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/phihag',
570 'channel_id': 'UCLqxVugv74EIW3VWh2NOa3Q',
571 'channel_url': r
're:https?://(?:www\.)?youtube\.com/channel/UCLqxVugv74EIW3VWh2NOa3Q',
572 'upload_date': '20121002',
573 'description': 'test chars: "\'/\\ä↭𝕐\ntest URL: https://github.com/rg3/youtube-dl/issues/1892\n\nThis is a test video for youtube-dl.\n\nFor more information, contact phihag@phihag.de .',
574 'categories': ['Science & Technology'],
575 'tags': ['youtube-dl'],
579 'dislike_count': int,
585 'url': '//www.YouTube.com/watch?v=yZIXLfi8CZQ',
586 'note': 'Embed-only video (#1746)',
590 'upload_date': '20120608',
591 'title': 'Principal Sexually Assaults A Teacher - Episode 117 - 8th June 2012',
592 'description': 'md5:09b78bd971f1e3e289601dfba15ca4f7',
593 'uploader': 'SET India',
594 'uploader_id': 'setindia',
595 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/setindia',
600 'url': 'https://www.youtube.com/watch?v=BaW_jenozKc&v=UxxajLWwzqY',
601 'note': 'Use the first video ID in the URL',
605 'title': 'youtube-dl test video "\'/\\ä↭𝕐',
606 'uploader': 'Philipp Hagemeister',
607 'uploader_id': 'phihag',
608 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/phihag',
609 'upload_date': '20121002',
610 'description': 'test chars: "\'/\\ä↭𝕐\ntest URL: https://github.com/rg3/youtube-dl/issues/1892\n\nThis is a test video for youtube-dl.\n\nFor more information, contact phihag@phihag.de .',
611 'categories': ['Science & Technology'],
612 'tags': ['youtube-dl'],
616 'dislike_count': int,
619 'skip_download': True,
623 'url': 'https://www.youtube.com/watch?v=a9LDPn-MO4I',
624 'note': '256k DASH audio (format 141) via DASH manifest',
628 'upload_date': '20121002',
629 'uploader_id': '8KVIDEO',
630 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/8KVIDEO',
632 'uploader': '8KVIDEO',
633 'title': 'UHDTV TEST 8K VIDEO.mp4'
636 'youtube_include_dash_manifest': True,
639 'skip': 'format 141 not served anymore',
643 'url': 'https://www.youtube.com/watch?v=T4XJQO3qol8',
648 'upload_date': '20100909',
649 'uploader': 'Amazing Atheist',
650 'uploader_id': 'TheAmazingAtheist',
651 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/TheAmazingAtheist',
652 'title': 'Burning Everyone\'s Koran',
653 'description': 'SUBSCRIBE: http://www.youtube.com/saturninefilms\n\nEven Obama has taken a stand against freedom on this issue: http://www.huffingtonpost.com/2010/09/09/obama-gma-interview-quran_n_710282.html',
656 # Normal age-gate video (embed allowed)
658 'url': 'https://youtube.com/watch?v=HtVdAasjOgU',
662 'title': 'The Witcher 3: Wild Hunt - The Sword Of Destiny Trailer',
663 'description': r
're:(?s).{100,}About the Game\n.*?The Witcher 3: Wild Hunt.{100,}',
665 'uploader': 'The Witcher',
666 'uploader_id': 'WitcherGame',
667 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/WitcherGame',
668 'upload_date': '20140605',
672 # Olympics (https://github.com/ytdl-org/youtube-dl/issues/4431)
674 'url': 'lqQg6PlCWgI',
679 'upload_date': '20150827',
680 'uploader_id': 'olympic',
681 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/olympic',
682 'description': 'HO09 - Women - GER-AUS - Hockey - 31 July 2012 - London 2012 Olympic Games',
683 'uploader': 'Olympic',
684 'title': 'Hockey - Women - GER-AUS - London 2012 Olympic Games',
687 'skip_download': 'requires avconv',
692 'url': 'https://www.youtube.com/watch?v=_b-2C3KPAM0',
696 'stretched_ratio': 16 / 9.,
698 'upload_date': '20110310',
699 'uploader_id': 'AllenMeow',
700 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/AllenMeow',
701 'description': 'made by Wacom from Korea | 字幕&加油添醋 by TY\'s Allen | 感謝heylisa00cavey1001同學熱情提供梗及翻譯',
703 'title': '[A-made] 變態妍字幕版 太妍 我就是這樣的人',
706 # url_encoded_fmt_stream_map is empty string
708 'url': 'qEJwOuvDf7I',
712 'title': 'Обсуждение судебной практики по выборам 14 сентября 2014 года в Санкт-Петербурге',
714 'upload_date': '20150404',
715 'uploader_id': 'spbelect',
716 'uploader': 'Наблюдатели Петербурга',
719 'skip_download': 'requires avconv',
721 'skip': 'This live event has ended.',
723 # Extraction from multiple DASH manifests (https://github.com/ytdl-org/youtube-dl/pull/6097)
725 'url': 'https://www.youtube.com/watch?v=FIl7x6_3R5Y',
729 'title': 'md5:7b81415841e02ecd4313668cde88737a',
730 'description': 'md5:116377fd2963b81ec4ce64b542173306',
732 'upload_date': '20150625',
733 'uploader_id': 'dorappi2000',
734 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/dorappi2000',
735 'uploader': 'dorappi2000',
736 'formats': 'mincount:31',
738 'skip': 'not actual anymore',
740 # DASH manifest with segment_list
742 'url': 'https://www.youtube.com/embed/CsmdDsKjzN8',
743 'md5': '8ce563a1d667b599d21064e982ab9e31',
747 'upload_date': '20150501', # According to '<meta itemprop="datePublished"', but in other places it's 20150510
748 'uploader': 'Airtek',
749 'description': 'Retransmisión en directo de la XVIII media maratón de Zaragoza.',
750 'uploader_id': 'UCzTzUmjXxxacNnL8I3m4LnQ',
751 'title': 'Retransmisión XVIII Media maratón Zaragoza 2015',
754 'youtube_include_dash_manifest': True,
755 'format': '135', # bestvideo
757 'skip': 'This live event has ended.',
760 # Multifeed videos (multiple cameras), URL is for Main Camera
761 'url': 'https://www.youtube.com/watch?v=jqWvoWXjCVs',
764 'title': 'teamPGP: Rocket League Noob Stream',
765 'description': 'md5:dc7872fb300e143831327f1bae3af010',
771 'title': 'teamPGP: Rocket League Noob Stream (Main Camera)',
772 'description': 'md5:dc7872fb300e143831327f1bae3af010',
774 'upload_date': '20150721',
775 'uploader': 'Beer Games Beer',
776 'uploader_id': 'beergamesbeer',
777 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/beergamesbeer',
778 'license': 'Standard YouTube License',
784 'title': 'teamPGP: Rocket League Noob Stream (kreestuh)',
785 'description': 'md5:dc7872fb300e143831327f1bae3af010',
787 'upload_date': '20150721',
788 'uploader': 'Beer Games Beer',
789 'uploader_id': 'beergamesbeer',
790 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/beergamesbeer',
791 'license': 'Standard YouTube License',
797 'title': 'teamPGP: Rocket League Noob Stream (grizzle)',
798 'description': 'md5:dc7872fb300e143831327f1bae3af010',
800 'upload_date': '20150721',
801 'uploader': 'Beer Games Beer',
802 'uploader_id': 'beergamesbeer',
803 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/beergamesbeer',
804 'license': 'Standard YouTube License',
810 'title': 'teamPGP: Rocket League Noob Stream (zim)',
811 'description': 'md5:dc7872fb300e143831327f1bae3af010',
813 'upload_date': '20150721',
814 'uploader': 'Beer Games Beer',
815 'uploader_id': 'beergamesbeer',
816 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/beergamesbeer',
817 'license': 'Standard YouTube License',
821 'skip_download': True,
823 'skip': 'This video is not available.',
826 # Multifeed video with comma in title (see https://github.com/ytdl-org/youtube-dl/issues/8536)
827 'url': 'https://www.youtube.com/watch?v=gVfLd0zydlo',
830 'title': 'DevConf.cz 2016 Day 2 Workshops 1 14:00 - 15:30',
833 'skip': 'Not multifeed anymore',
836 'url': 'https://vid.plus/FlRa-iH7PGw',
837 'only_matching': True,
840 'url': 'https://zwearz.com/watch/9lWxNJF-ufM/electra-woman-dyna-girl-official-trailer-grace-helbig.html',
841 'only_matching': True,
844 # Title with JS-like syntax "};" (see https://github.com/ytdl-org/youtube-dl/issues/7468)
845 # Also tests cut-off URL expansion in video description (see
846 # https://github.com/ytdl-org/youtube-dl/issues/1892,
847 # https://github.com/ytdl-org/youtube-dl/issues/8164)
848 'url': 'https://www.youtube.com/watch?v=lsguqyKfVQg',
852 'title': '{dark walk}; Loki/AC/Dishonored; collab w/Elflover21',
853 'alt_title': 'Dark Walk - Position Music',
854 'description': 'md5:8085699c11dc3f597ce0410b0dcbb34a',
856 'upload_date': '20151119',
857 'uploader_id': 'IronSoulElf',
858 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/IronSoulElf',
859 'uploader': 'IronSoulElf',
860 'creator': 'Todd Haberman, Daniel Law Heath and Aaron Kaplan',
861 'track': 'Dark Walk - Position Music',
862 'artist': 'Todd Haberman, Daniel Law Heath and Aaron Kaplan',
863 'album': 'Position Music - Production Music Vol. 143 - Dark Walk',
866 'skip_download': True,
870 # Tags with '};' (see https://github.com/ytdl-org/youtube-dl/issues/7468)
871 'url': 'https://www.youtube.com/watch?v=Ms7iBXnlUO8',
872 'only_matching': True,
875 # Video with yt:stretch=17:0
876 'url': 'https://www.youtube.com/watch?v=Q39EVAstoRM',
880 'title': 'Clash Of Clans#14 Dicas De Ataque Para CV 4',
881 'description': 'md5:ee18a25c350637c8faff806845bddee9',
882 'upload_date': '20151107',
883 'uploader_id': 'UCCr7TALkRbo3EtFzETQF1LA',
884 'uploader': 'CH GAMER DROID',
887 'skip_download': True,
889 'skip': 'This video does not exist.',
892 # Video licensed under Creative Commons
893 'url': 'https://www.youtube.com/watch?v=M4gD1WSo5mA',
897 'title': 'md5:e41008789470fc2533a3252216f1c1d1',
898 'description': 'md5:a677553cf0840649b731a3024aeff4cc',
900 'upload_date': '20150127',
901 'uploader_id': 'BerkmanCenter',
902 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/BerkmanCenter',
903 'uploader': 'The Berkman Klein Center for Internet & Society',
904 'license': 'Creative Commons Attribution license (reuse allowed)',
907 'skip_download': True,
911 # Channel-like uploader_url
912 'url': 'https://www.youtube.com/watch?v=eQcmzGIKrzg',
916 'title': 'Democratic Socialism and Foreign Policy | Bernie Sanders',
917 'description': 'md5:dda0d780d5a6e120758d1711d062a867',
919 'upload_date': '20151119',
920 'uploader': 'Bernie Sanders',
921 'uploader_id': 'UCH1dpzjCEiGAt8CXkryhkZg',
922 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/channel/UCH1dpzjCEiGAt8CXkryhkZg',
923 'license': 'Creative Commons Attribution license (reuse allowed)',
926 'skip_download': True,
930 'url': 'https://www.youtube.com/watch?feature=player_embedded&amp;v=V36LpHqtcDY',
931 'only_matching': True,
934 # YouTube Red paid video (https://github.com/ytdl-org/youtube-dl/issues/10059)
935 'url': 'https://www.youtube.com/watch?v=i1Ko8UG-Tdo',
936 'only_matching': True,
939 # Rental video preview
940 'url': 'https://www.youtube.com/watch?v=yYr8q0y5Jfg',
944 'title': 'Piku - Trailer',
945 'description': 'md5:c36bd60c3fd6f1954086c083c72092eb',
946 'upload_date': '20150811',
947 'uploader': 'FlixMatrix',
948 'uploader_id': 'FlixMatrixKaravan',
949 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/FlixMatrixKaravan',
950 'license': 'Standard YouTube License',
953 'skip_download': True,
955 'skip': 'This video is not available.',
958 # YouTube Red video with episode data
959 'url': 'https://www.youtube.com/watch?v=iqKdEhx-dD4',
963 'title': 'Isolation - Mind Field (Ep 1)',
964 'description': 'md5:46a29be4ceffa65b92d277b93f463c0f',
966 'upload_date': '20170118',
967 'uploader': 'Vsauce',
968 'uploader_id': 'Vsauce',
969 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/Vsauce',
970 'series': 'Mind Field',
975 'skip_download': True,
977 'expected_warnings': [
978 'Skipping DASH manifest',
982 # The following content has been identified by the YouTube community
983 # as inappropriate or offensive to some audiences.
984 'url': 'https://www.youtube.com/watch?v=6SJNVb0GnPI',
988 'title': 'Race Differences in Intelligence',
989 'description': 'md5:5d161533167390427a1f8ee89a1fc6f1',
991 'upload_date': '20140124',
992 'uploader': 'New Century Foundation',
993 'uploader_id': 'UCEJYpZGqgUob0zVVEaLhvVg',
994 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/channel/UCEJYpZGqgUob0zVVEaLhvVg',
997 'skip_download': True,
1002 'url': '1t24XAntNCY',
1003 'only_matching': True,
1006 # geo restricted to JP
1007 'url': 'sJL6WA-aGkQ',
1008 'only_matching': True,
1011 'url': 'https://www.youtube.com/watch?v=MuAGGZNfUkU&list=RDMM',
1012 'only_matching': True,
1015 'url': 'https://invidio.us/watch?v=BaW_jenozKc',
1016 'only_matching': True,
1020 'url': 'https://www.youtube.com/watch?v=s7_qI6_mIXc',
1021 'only_matching': True,
1024 # Video with unsupported adaptive stream type formats
1025 'url': 'https://www.youtube.com/watch?v=Z4Vy8R84T1U',
1027 'id': 'Z4Vy8R84T1U',
1029 'title': 'saman SMAN 53 Jakarta(Sancety) opening COFFEE4th at SMAN 53 Jakarta',
1030 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
1032 'upload_date': '20130923',
1033 'uploader': 'Amelia Putri Harwita',
1034 'uploader_id': 'UCpOxM49HJxmC1qCalXyB3_Q',
1035 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/channel/UCpOxM49HJxmC1qCalXyB3_Q',
1036 'formats': 'maxcount:10',
1039 'skip_download': True,
1040 'youtube_include_dash_manifest': False,
1042 'skip': 'not actual anymore',
1045 # Youtube Music Auto-generated description
1046 'url': 'https://music.youtube.com/watch?v=MgNrAu2pzNs',
1048 'id': 'MgNrAu2pzNs',
1050 'title': 'Voyeur Girl',
1051 'description': 'md5:7ae382a65843d6df2685993e90a8628f',
1052 'upload_date': '20190312',
1053 'uploader': 'Stephen - Topic',
1054 'uploader_id': 'UC-pWHpBjdGG69N9mM2auIAA',
1055 'artist': 'Stephen',
1056 'track': 'Voyeur Girl',
1057 'album': 'it\'s too much love to know my dear',
1058 'release_date': '20190313',
1059 'release_year': 2019,
1062 'skip_download': True,
1066 # Youtube Music Auto-generated description
1067 # Retrieve 'artist' field from 'Artist:' in video description
1068 # when it is present on youtube music video
1069 'url': 'https://www.youtube.com/watch?v=k0jLE7tTwjY',
1071 'id': 'k0jLE7tTwjY',
1073 'title': 'Latch Feat. Sam Smith',
1074 'description': 'md5:3cb1e8101a7c85fcba9b4fb41b951335',
1075 'upload_date': '20150110',
1076 'uploader': 'Various Artists - Topic',
1077 'uploader_id': 'UCNkEcmYdjrH4RqtNgh7BZ9w',
1078 'artist': 'Disclosure',
1079 'track': 'Latch Feat. Sam Smith',
1080 'album': 'Latch Featuring Sam Smith',
1081 'release_date': '20121008',
1082 'release_year': 2012,
1085 'skip_download': True,
1089 # Youtube Music Auto-generated description
1090 # handle multiple artists on youtube music video
1091 'url': 'https://www.youtube.com/watch?v=74qn0eJSjpA',
1093 'id': '74qn0eJSjpA',
1095 'title': 'Eastside',
1096 'description': 'md5:290516bb73dcbfab0dcc4efe6c3de5f2',
1097 'upload_date': '20180710',
1098 'uploader': 'Benny Blanco - Topic',
1099 'uploader_id': 'UCzqz_ksRu_WkIzmivMdIS7A',
1100 'artist': 'benny blanco, Halsey, Khalid',
1101 'track': 'Eastside',
1102 'album': 'Eastside',
1103 'release_date': '20180713',
1104 'release_year': 2018,
1107 'skip_download': True,
1111 # Youtube Music Auto-generated description
1112 # handle youtube music video with release_year and no release_date
1113 'url': 'https://www.youtube.com/watch?v=-hcAI0g-f5M',
1115 'id': '-hcAI0g-f5M',
1117 'title': 'Put It On Me',
1118 'description': 'md5:f6422397c07c4c907c6638e1fee380a5',
1119 'upload_date': '20180426',
1120 'uploader': 'Matt Maeson - Topic',
1121 'uploader_id': 'UCnEkIGqtGcQMLk73Kp-Q5LQ',
1122 'artist': 'Matt Maeson',
1123 'track': 'Put It On Me',
1124 'album': 'The Hearse',
1125 'release_date': None,
1126 'release_year': 2018,
1129 'skip_download': True,
1133 'url': 'https://www.youtubekids.com/watch?v=3b8nCWDgZ6Q',
1134 'only_matching': True,
1137 # invalid -> valid video id redirection
1138 'url': 'DJztXj2GPfl',
1140 'id': 'DJztXj2GPfk',
1142 'title': 'Panjabi MC - Mundian To Bach Ke (The Dictator Soundtrack)',
1143 'description': 'md5:bf577a41da97918e94fa9798d9228825',
1144 'upload_date': '20090125',
1145 'uploader': 'Prochorowka',
1146 'uploader_id': 'Prochorowka',
1147 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/Prochorowka',
1148 'artist': 'Panjabi MC',
1149 'track': 'Beware of the Boys (Mundian to Bach Ke) - Motivo Hi-Lectro Remix',
1150 'album': 'Beware of the Boys (Mundian To Bach Ke)',
1153 'skip_download': True,
1157 # empty description results in an empty string
1158 'url': 'https://www.youtube.com/watch?v=x41yOUIvK2k',
1160 'id': 'x41yOUIvK2k',
1162 'title': 'IMG 3456',
1164 'upload_date': '20170613',
1165 'uploader_id': 'ElevageOrVert',
1166 'uploader': 'ElevageOrVert',
1169 'skip_download': True,
1174 def __init__(self
, *args
, **kwargs
):
1175 super(YoutubeIE
, self
).__init
__(*args
, **kwargs
)
1176 self
._player
_cache
= {}
1178 def report_video_info_webpage_download(self
, video_id
):
1179 """Report attempt to download video info webpage."""
1180 self
.to_screen('%s: Downloading video info webpage' % video_id
)
1182 def report_information_extraction(self
, video_id
):
1183 """Report attempt to extract video information."""
1184 self
.to_screen('%s: Extracting video information' % video_id
)
1186 def report_unavailable_format(self
, video_id
, format
):
1187 """Report extracted video URL."""
1188 self
.to_screen('%s: Format %s not available' % (video_id
, format
))
1190 def report_rtmp_download(self
):
1191 """Indicate the download will use the RTMP protocol."""
1192 self
.to_screen('RTMP download detected')
1194 def _signature_cache_id(self
, example_sig
):
1195 """ Return a string representation of a signature """
1196 return '.'.join(compat_str(len(part
)) for part
in example_sig
.split('.'))
1199 def _extract_player_info(cls
, player_url
):
1200 for player_re
in cls
._PLAYER
_INFO
_RE
:
1201 id_m
= re
.search(player_re
, player_url
)
1205 raise ExtractorError('Cannot identify player %r' % player_url
)
1206 return id_m
.group('ext'), id_m
.group('id')
1208 def _extract_signature_function(self
, video_id
, player_url
, example_sig
):
1209 player_type
, player_id
= self
._extract
_player
_info
(player_url
)
1211 # Read from filesystem cache
1212 func_id
= '%s_%s_%s' % (
1213 player_type
, player_id
, self
._signature
_cache
_id
(example_sig
))
1214 assert os
.path
.basename(func_id
) == func_id
1216 cache_spec
= self
._downloader
.cache
.load('youtube-sigfuncs', func_id
)
1217 if cache_spec
is not None:
1218 return lambda s
: ''.join(s
[i
] for i
in cache_spec
)
1221 'Downloading player %s' % player_url
1222 if self
._downloader
.params
.get('verbose') else
1223 'Downloading %s player %s' % (player_type
, player_id
)
1225 if player_type
== 'js':
1226 code
= self
._download
_webpage
(
1227 player_url
, video_id
,
1229 errnote
='Download of %s failed' % player_url
)
1230 res
= self
._parse
_sig
_js
(code
)
1231 elif player_type
== 'swf':
1232 urlh
= self
._request
_webpage
(
1233 player_url
, video_id
,
1235 errnote
='Download of %s failed' % player_url
)
1237 res
= self
._parse
_sig
_swf
(code
)
1239 assert False, 'Invalid player type %r' % player_type
1241 test_string
= ''.join(map(compat_chr
, range(len(example_sig
))))
1242 cache_res
= res(test_string
)
1243 cache_spec
= [ord(c
) for c
in cache_res
]
1245 self
._downloader
.cache
.store('youtube-sigfuncs', func_id
, cache_spec
)
1248 def _print_sig_code(self
, func
, example_sig
):
1249 def gen_sig_code(idxs
):
1250 def _genslice(start
, end
, step
):
1251 starts
= '' if start
== 0 else str(start
)
1252 ends
= (':%d' % (end
+ step
)) if end
+ step
>= 0 else ':'
1253 steps
= '' if step
== 1 else (':%d' % step
)
1254 return 's[%s%s%s]' % (starts
, ends
, steps
)
1257 # Quelch pyflakes warnings - start will be set when step is set
1258 start
= '(Never used)'
1259 for i
, prev
in zip(idxs
[1:], idxs
[:-1]):
1260 if step
is not None:
1261 if i
- prev
== step
:
1263 yield _genslice(start
, prev
, step
)
1266 if i
- prev
in [-1, 1]:
1271 yield 's[%d]' % prev
1275 yield _genslice(start
, i
, step
)
1277 test_string
= ''.join(map(compat_chr
, range(len(example_sig
))))
1278 cache_res
= func(test_string
)
1279 cache_spec
= [ord(c
) for c
in cache_res
]
1280 expr_code
= ' + '.join(gen_sig_code(cache_spec
))
1281 signature_id_tuple
= '(%s)' % (
1282 ', '.join(compat_str(len(p
)) for p
in example_sig
.split('.')))
1283 code
= ('if tuple(len(p) for p in s.split(\'.\')) == %s:\n'
1284 ' return %s\n') % (signature_id_tuple
, expr_code
)
1285 self
.to_screen('Extracted signature function:\n' + code
)
1287 def _parse_sig_js(self
, jscode
):
1288 funcname
= self
._search
_regex
(
1289 (r
'\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
1290 r
'\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
1291 r
'(?:\b|[^a-zA-Z0-9$])(?P<sig>[a-zA-Z0-9$]{2})\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)',
1292 r
'(?P<sig>[a-zA-Z0-9$]+)\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)',
1294 r
'(["\'])signature\
1\s
*,\s
*(?P
<sig
>[a
-zA
-Z0
-9$
]+)\
(',
1295 r'\
.sig\|\|
(?P
<sig
>[a
-zA
-Z0
-9$
]+)\
(',
1296 r'yt\
.akamaized\
.net
/\
)\s
*\|\|\s
*.*?\s
*[cs
]\s
*&&\s
*[adf
]\
.set\
([^
,]+\s
*,\s
*(?
:encodeURIComponent\s
*\
()?\s
*(?P
<sig
>[a
-zA
-Z0
-9$
]+)\
(',
1297 r'\b[cs
]\s
*&&\s
*[adf
]\
.set\
([^
,]+\s
*,\s
*(?P
<sig
>[a
-zA
-Z0
-9$
]+)\
(',
1298 r'\b[a
-zA
-Z0
-9]+\s
*&&\s
*[a
-zA
-Z0
-9]+\
.set\
([^
,]+\s
*,\s
*(?P
<sig
>[a
-zA
-Z0
-9$
]+)\
(',
1299 r'\bc\s
*&&\s
*a\
.set\
([^
,]+\s
*,\s
*\
([^
)]*\
)\s
*\
(\s
*(?P
<sig
>[a
-zA
-Z0
-9$
]+)\
(',
1300 r'\bc\s
*&&\s
*[a
-zA
-Z0
-9]+\
.set\
([^
,]+\s
*,\s
*\
([^
)]*\
)\s
*\
(\s
*(?P
<sig
>[a
-zA
-Z0
-9$
]+)\
(',
1301 r'\bc\s
*&&\s
*[a
-zA
-Z0
-9]+\
.set\
([^
,]+\s
*,\s
*\
([^
)]*\
)\s
*\
(\s
*(?P
<sig
>[a
-zA
-Z0
-9$
]+)\
('),
1302 jscode, 'Initial JS player signature function name
', group='sig
')
1304 jsi = JSInterpreter(jscode)
1305 initial_function = jsi.extract_function(funcname)
1306 return lambda s: initial_function([s])
1308 def _parse_sig_swf(self, file_contents):
1309 swfi = SWFInterpreter(file_contents)
1310 TARGET_CLASSNAME = 'SignatureDecipher
'
1311 searched_class = swfi.extract_class(TARGET_CLASSNAME)
1312 initial_function = swfi.extract_function(searched_class, 'decipher
')
1313 return lambda s: initial_function([s])
1315 def _decrypt_signature(self, s, video_id, player_url, age_gate=False):
1316 """Turn the encrypted s field into a working signature"""
1318 if player_url is None:
1319 raise ExtractorError('Cannot decrypt signature without player_url
')
1321 if player_url.startswith('//'):
1322 player_url = 'https
:' + player_url
1323 elif not re.match(r'https?
://', player_url):
1324 player_url = compat_urlparse.urljoin(
1325 'https
://www
.youtube
.com
', player_url)
1327 player_id = (player_url, self._signature_cache_id(s))
1328 if player_id not in self._player_cache:
1329 func = self._extract_signature_function(
1330 video_id, player_url, s
1332 self._player_cache[player_id] = func
1333 func = self._player_cache[player_id]
1334 if self._downloader.params.get('youtube_print_sig_code
'):
1335 self._print_sig_code(func, s)
1337 except Exception as e:
1338 tb = traceback.format_exc()
1339 raise ExtractorError(
1340 'Signature extraction failed
: ' + tb, cause=e)
1342 def _get_subtitles(self, video_id, webpage, has_live_chat_replay):
1344 subs_doc = self._download_xml(
1345 'https
://video
.google
.com
/timedtext?hl
=en
&type=list&v
=%s' % video_id,
1346 video_id, note=False)
1347 except ExtractorError as err:
1348 self._downloader.report_warning('unable to download video subtitles
: %s' % error_to_compat_str(err))
1352 for track in subs_doc.findall('track
'):
1353 lang = track.attrib['lang_code
']
1354 if lang in sub_lang_list:
1357 for ext in self._SUBTITLE_FORMATS:
1358 params = compat_urllib_parse_urlencode({
1362 'name
': track.attrib['name
'].encode('utf
-8'),
1364 sub_formats.append({
1365 'url
': 'https
://www
.youtube
.com
/api
/timedtext?
' + params,
1368 sub_lang_list[lang] = sub_formats
1369 if has_live_chat_replay:
1370 sub_lang_list['live_chat
'] = [
1372 'video_id
': video_id,
1374 'protocol
': 'youtube_live_chat_replay
',
1377 if not sub_lang_list:
1378 self._downloader.report_warning('video doesn
\'t have subtitles
')
1380 return sub_lang_list
1382 def _get_ytplayer_config(self, video_id, webpage):
1384 # User data may contain arbitrary character sequences that may affect
1385 # JSON extraction with regex, e.g. when '};' is contained the second
1386 # regex won't capture the whole JSON
. Yet working around by trying more
1387 # concrete regex first keeping in mind proper quoted string handling
1388 # to be implemented in future that will replace this workaround (see
1389 # https://github.com/ytdl-org/youtube-dl/issues/7468,
1390 # https://github.com/ytdl-org/youtube-dl/pull/7599)
1391 r
';ytplayer\.config\s*=\s*({.+?});ytplayer',
1392 r
';ytplayer\.config\s*=\s*({.+?});',
1394 config
= self
._search
_regex
(
1395 patterns
, webpage
, 'ytplayer.config', default
=None)
1397 return self
._parse
_json
(
1398 uppercase_escape(config
), video_id
, fatal
=False)
1400 def _get_yt_initial_data(self
, video_id
, webpage
):
1401 config
= self
._search
_regex
(
1402 (r
'window\["ytInitialData"\]\s*=\s*(.*?)(?<=});',
1403 r
'var\s+ytInitialData\s*=\s*(.*?)(?<=});'),
1404 webpage
, 'ytInitialData', default
=None)
1406 return self
._parse
_json
(
1407 uppercase_escape(config
), video_id
, fatal
=False)
1409 def _get_music_metadata_from_yt_initial(self
, yt_initial
):
1416 contents
= try_get(yt_initial
, lambda x
: x
['contents']['twoColumnWatchNextResults']['results']['results']['contents'])
1417 if type(contents
) is list:
1418 for content
in contents
:
1420 if type(content
) is not dict:
1422 videoSecondaryInfoRenderer
= try_get(content
, lambda x
: x
['videoSecondaryInfoRenderer'])
1423 if type(videoSecondaryInfoRenderer
) is not dict:
1425 rows
= try_get(videoSecondaryInfoRenderer
, lambda x
: x
['metadataRowContainer']['metadataRowContainerRenderer']['rows'])
1426 if type(rows
) is not list:
1429 metadataRowRenderer
= try_get(row
, lambda x
: x
['metadataRowRenderer'])
1430 if type(metadataRowRenderer
) is not dict:
1432 key
= try_get(metadataRowRenderer
, lambda x
: x
['title']['simpleText'])
1433 value
= try_get(metadataRowRenderer
, lambda x
: x
['contents'][0]['simpleText']) or \
1434 try_get(metadataRowRenderer
, lambda x
: x
['contents'][0]['runs'][0]['text'])
1435 if type(key
) is not str or type(value
) is not str:
1438 if key_map
[key
] in music_track
:
1439 # we've started on a new track
1440 music_metadata
.append(music_track
)
1442 music_track
[key_map
[key
]] = value
1443 if len(music_track
.keys()):
1444 music_metadata
.append(music_track
)
1445 return music_metadata
1447 def _get_automatic_captions(self
, video_id
, webpage
):
1448 """We need the webpage for getting the captions url, pass it as an
1449 argument to speed up the process."""
1450 self
.to_screen('%s: Looking for automatic captions' % video_id
)
1451 player_config
= self
._get
_ytplayer
_config
(video_id
, webpage
)
1452 err_msg
= 'Couldn\'t find automatic captions for %s' % video_id
1453 if not player_config
:
1454 self
._downloader
.report_warning(err_msg
)
1457 args
= player_config
['args']
1458 caption_url
= args
.get('ttsurl')
1460 timestamp
= args
['timestamp']
1461 # We get the available subtitles
1462 list_params
= compat_urllib_parse_urlencode({
1467 list_url
= caption_url
+ '&' + list_params
1468 caption_list
= self
._download
_xml
(list_url
, video_id
)
1469 original_lang_node
= caption_list
.find('track')
1470 if original_lang_node
is None:
1471 self
._downloader
.report_warning('Video doesn\'t have automatic captions')
1473 original_lang
= original_lang_node
.attrib
['lang_code']
1474 caption_kind
= original_lang_node
.attrib
.get('kind', '')
1477 for lang_node
in caption_list
.findall('target'):
1478 sub_lang
= lang_node
.attrib
['lang_code']
1480 for ext
in self
._SUBTITLE
_FORMATS
:
1481 params
= compat_urllib_parse_urlencode({
1482 'lang': original_lang
,
1486 'kind': caption_kind
,
1488 sub_formats
.append({
1489 'url': caption_url
+ '&' + params
,
1492 sub_lang_list
[sub_lang
] = sub_formats
1493 return sub_lang_list
1495 def make_captions(sub_url
, sub_langs
):
1496 parsed_sub_url
= compat_urllib_parse_urlparse(sub_url
)
1497 caption_qs
= compat_parse_qs(parsed_sub_url
.query
)
1499 for sub_lang
in sub_langs
:
1501 for ext
in self
._SUBTITLE
_FORMATS
:
1503 'tlang': [sub_lang
],
1506 sub_url
= compat_urlparse
.urlunparse(parsed_sub_url
._replace
(
1507 query
=compat_urllib_parse_urlencode(caption_qs
, True)))
1508 sub_formats
.append({
1512 captions
[sub_lang
] = sub_formats
1515 # New captions format as of 22.06.2017
1516 player_response
= args
.get('player_response')
1517 if player_response
and isinstance(player_response
, compat_str
):
1518 player_response
= self
._parse
_json
(
1519 player_response
, video_id
, fatal
=False)
1521 renderer
= player_response
['captions']['playerCaptionsTracklistRenderer']
1522 caption_tracks
= renderer
['captionTracks']
1523 for caption_track
in caption_tracks
:
1524 if 'kind' not in caption_track
:
1525 # not an automatic transcription
1527 base_url
= caption_track
['baseUrl']
1529 for lang
in renderer
['translationLanguages']:
1530 lang_code
= lang
.get('languageCode')
1532 sub_lang_list
.append(lang_code
)
1533 return make_captions(base_url
, sub_lang_list
)
1535 self
._downloader
.report_warning("Couldn't find automatic captions for %s" % video_id
)
1537 # Some videos don't provide ttsurl but rather caption_tracks and
1538 # caption_translation_languages (e.g. 20LmZk1hakA)
1539 # Does not used anymore as of 22.06.2017
1540 caption_tracks
= args
['caption_tracks']
1541 caption_translation_languages
= args
['caption_translation_languages']
1542 caption_url
= compat_parse_qs(caption_tracks
.split(',')[0])['u'][0]
1544 for lang
in caption_translation_languages
.split(','):
1545 lang_qs
= compat_parse_qs(compat_urllib_parse_unquote_plus(lang
))
1546 sub_lang
= lang_qs
.get('lc', [None])[0]
1548 sub_lang_list
.append(sub_lang
)
1549 return make_captions(caption_url
, sub_lang_list
)
1550 # An extractor error can be raise by the download process if there are
1551 # no automatic captions but there are subtitles
1552 except (KeyError, IndexError, ExtractorError
):
1553 self
._downloader
.report_warning(err_msg
)
1556 def _mark_watched(self
, video_id
, video_info
, player_response
):
1557 playback_url
= url_or_none(try_get(
1559 lambda x
: x
['playbackTracking']['videostatsPlaybackUrl']['baseUrl']) or try_get(
1560 video_info
, lambda x
: x
['videostats_playback_base_url'][0]))
1561 if not playback_url
:
1563 parsed_playback_url
= compat_urlparse
.urlparse(playback_url
)
1564 qs
= compat_urlparse
.parse_qs(parsed_playback_url
.query
)
1566 # cpn generation algorithm is reverse engineered from base.js.
1567 # In fact it works even with dummy cpn.
1568 CPN_ALPHABET
= 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'
1569 cpn
= ''.join((CPN_ALPHABET
[random
.randint(0, 256) & 63] for _
in range(0, 16)))
1575 playback_url
= compat_urlparse
.urlunparse(
1576 parsed_playback_url
._replace
(query
=compat_urllib_parse_urlencode(qs
, True)))
1578 self
._download
_webpage
(
1579 playback_url
, video_id
, 'Marking watched',
1580 'Unable to mark watched', fatal
=False)
1583 def _extract_urls(webpage
):
1584 # Embedded YouTube player
1586 unescapeHTML(mobj
.group('url'))
1587 for mobj
in re
.finditer(r
'''(?x)
1597 (?P
<url
>(?
:https?
:)?
//(?
:www\
.)?
youtube(?
:-nocookie
)?\
.com
/
1598 (?
:embed|v|p
)/[0-9A
-Za
-z_
-]{11}
.*?
)
1601 # lazyYT YouTube embed
1602 entries.extend(list(map(
1604 re.findall(r'class="lazyYT" data-youtube-id="([^"]+)"', webpage))))
1606 # Wordpress "YouTube Video Importer" plugin
1607 matches = re.findall(r'''(?x
)<div
[^
>]+
1608 class=(?P
<q1
>[\'"])[^\'"]*\byvii
_single
_video
_player
\b[^
\'"]*(?P=q1)[^>]+
1609 data-video_id=(?P<q2>[\'"])([^
\'"]+)(?P=q2)''', webpage)
1610 entries.extend(m[-1] for m in matches)
1615 def _extract_url(webpage):
1616 urls = YoutubeIE._extract_urls(webpage)
1617 return urls[0] if urls else None
1620 def extract_id(cls, url):
1621 mobj = re.match(cls._VALID_URL, url, re.VERBOSE)
1623 raise ExtractorError('Invalid URL: %s' % url)
1624 video_id = mobj.group(2)
1627 def _extract_chapters_from_json(self, webpage, video_id, duration):
1630 initial_data = self._parse_json(
1632 r'window\["ytInitialData
"\] = (.+);\n', webpage,
1633 'player args', default='{}'),
1634 video_id, fatal=False)
1635 if not initial_data or not isinstance(initial_data, dict):
1637 chapters_list = try_get(
1639 lambda x: x['playerOverlays']
1640 ['playerOverlayRenderer']
1641 ['decoratedPlayerBarRenderer']
1642 ['decoratedPlayerBarRenderer']
1644 ['chapteredPlayerBarRenderer']
1647 if not chapters_list:
1650 def chapter_time(chapter):
1651 return float_or_none(
1654 lambda x: x['chapterRenderer']['timeRangeStartMillis'],
1658 for next_num, chapter in enumerate(chapters_list, start=1):
1659 start_time = chapter_time(chapter)
1660 if start_time is None:
1662 end_time = (chapter_time(chapters_list[next_num])
1663 if next_num < len(chapters_list) else duration)
1664 if end_time is None:
1667 chapter, lambda x: x['chapterRenderer']['title']['simpleText'],
1670 'start_time': start_time,
1671 'end_time': end_time,
1677 def _extract_chapters_from_description(description, duration):
1680 chapter_lines = re.findall(
1681 r'(?:^|<br\s*/>)([^<]*<a[^>]+onclick=["\']yt\
.www\
.watch\
.player\
.seekTo
[^
>]+>(\d{1,2}
:\d{1,2}
(?
::\d{1,2}
)?
)</a
>[^
>]*)(?
=$|
<br\s
*/>)',
1683 if not chapter_lines:
1686 for next_num, (chapter_line, time_point) in enumerate(
1687 chapter_lines, start=1):
1688 start_time = parse_duration(time_point)
1689 if start_time is None:
1691 if start_time > duration:
1693 end_time = (duration if next_num == len(chapter_lines)
1694 else parse_duration(chapter_lines[next_num][1]))
1695 if end_time is None:
1697 if end_time > duration:
1699 if start_time > end_time:
1701 chapter_title = re.sub(
1702 r'<a
[^
>]+>[^
<]+</a
>', '', chapter_line).strip(' \t-')
1703 chapter_title = re.sub(r'\s
+', ' ', chapter_title)
1705 'start_time
': start_time,
1706 'end_time
': end_time,
1707 'title
': chapter_title,
1711 def _extract_chapters(self, webpage, description, video_id, duration):
1712 return (self._extract_chapters_from_json(webpage, video_id, duration)
1713 or self._extract_chapters_from_description(description, duration))
1715 def _real_extract(self, url):
1716 url, smuggled_data = unsmuggle_url(url, {})
1719 'http
' if self._downloader.params.get('prefer_insecure
', False)
1724 parsed_url = compat_urllib_parse_urlparse(url)
1725 for component in [parsed_url.fragment, parsed_url.query]:
1726 query = compat_parse_qs(component)
1727 if start_time is None and 't
' in query:
1728 start_time = parse_duration(query['t
'][0])
1729 if start_time is None and 'start
' in query:
1730 start_time = parse_duration(query['start
'][0])
1731 if end_time is None and 'end
' in query:
1732 end_time = parse_duration(query['end
'][0])
1734 # Extract original video URL from URL with redirection, like age verification, using next_url parameter
1735 mobj = re.search(self._NEXT_URL_RE, url)
1737 url = proto + '://www
.youtube
.com
/' + compat_urllib_parse_unquote(mobj.group(1)).lstrip('/')
1738 video_id = self.extract_id(url)
1741 url = proto + '://www
.youtube
.com
/watch?v
=%s&gl
=US
&hl
=en
&has_verified
=1&bpctr
=9999999999' % video_id
1742 video_webpage, urlh = self._download_webpage_handle(url, video_id)
1744 qs = compat_parse_qs(compat_urllib_parse_urlparse(urlh.geturl()).query)
1745 video_id = qs.get('v
', [None])[0] or video_id
1747 # Attempt to extract SWF player URL
1748 mobj = re.search(r'swfConfig
.*?
"(https?:\\/\\/.*?watch.*?-.*?\.swf)"', video_webpage)
1749 if mobj is not None:
1750 player_url = re.sub(r'\\(.)', r'\
1', mobj.group(1))
1756 def add_dash_mpd(video_info):
1757 dash_mpd = video_info.get('dashmpd
')
1758 if dash_mpd and dash_mpd[0] not in dash_mpds:
1759 dash_mpds.append(dash_mpd[0])
1761 def add_dash_mpd_pr(pl_response):
1762 dash_mpd = url_or_none(try_get(
1763 pl_response, lambda x: x['streamingData
']['dashManifestUrl
'],
1765 if dash_mpd and dash_mpd not in dash_mpds:
1766 dash_mpds.append(dash_mpd)
1771 def extract_view_count(v_info):
1772 return int_or_none(try_get(v_info, lambda x: x['view_count
'][0]))
1774 def extract_player_response(player_response, video_id):
1775 pl_response = str_or_none(player_response)
1778 pl_response = self._parse_json(pl_response, video_id, fatal=False)
1779 if isinstance(pl_response, dict):
1780 add_dash_mpd_pr(pl_response)
1783 def extract_embedded_config(embed_webpage, video_id):
1784 embedded_config = self._search_regex(
1785 r'setConfig\
(({.*}
)\
);',
1786 embed_webpage, 'ytInitialData
', default=None)
1788 return embedded_config
1790 player_response = {}
1794 embed_webpage = None
1795 if (self._og_search_property('restrictions
:age
', video_webpage, default=None) == '18+'
1796 or re.search(r'player
-age
-gate
-content
">', video_webpage) is not None):
1797 cookie_keys = self._get_cookies('https://www.youtube.com').keys()
1799 # We simulate the access to the video from www.youtube.com/v/{video_id}
1800 # this can be viewed without login into Youtube
1801 url = proto + '://www.youtube.com/embed/%s' % video_id
1802 embed_webpage = self._download_webpage(url, video_id, 'Downloading embed webpage')
1803 ext = extract_embedded_config(embed_webpage, video_id)
1804 # playabilityStatus = re.search(r'{\\\"status\\\":\\\"(?P<playabilityStatus>[^\"]+)\\\"', ext)
1805 playable_in_embed = re.search(r'{\\\"playableInEmbed\\\":(?P<playableinEmbed>[^\,]+)', ext)
1806 if not playable_in_embed:
1807 self.to_screen('Could not determine whether playabale in embed for video %s' % video_id)
1808 playable_in_embed = ''
1810 playable_in_embed = playable_in_embed.group('playableinEmbed')
1811 # check if video is only playable on youtube in other words not playable in embed - if so it requires auth (cookies)
1812 # if re.search(r'player-unavailable">', embed_webpage) is not None:
1813 if playable_in_embed == 'false
':
1815 # TODO apply this patch when Support for Python 2.6(!) and above drops
1816 if ({'VISITOR_INFO1_LIVE', 'HSID', 'SSID', 'SID'} <= cookie_keys
1817 or {'VISITOR_INFO1_LIVE', '__Secure-3PSID', 'LOGIN_INFO'} <= cookie_keys):
1819 if (set(('VISITOR_INFO1_LIVE
', 'HSID
', 'SSID
', 'SID
')) <= set(cookie_keys)
1820 or set(('VISITOR_INFO1_LIVE
', '__Secure
-3PSID
', 'LOGIN_INFO
')) <= set(cookie_keys)):
1822 # Try looking directly into the video webpage
1823 ytplayer_config = self._get_ytplayer_config(video_id, video_webpage)
1825 args = ytplayer_config['args
']
1826 if args.get('url_encoded_fmt_stream_map
') or args.get('hlsvp
'):
1827 # Convert to the same format returned by compat_parse_qs
1828 video_info = dict((k, [v]) for k, v in args.items())
1829 add_dash_mpd(video_info)
1830 # Rental video is not rented but preview is available (e.g.
1831 # https://www.youtube.com/watch?v=yYr8q0y5Jfg,
1832 # https://github.com/ytdl-org/youtube-dl/issues/10532)
1833 if not video_info and args.get('ypc_vid
'):
1834 return self.url_result(
1835 args['ypc_vid
'], YoutubeIE.ie_key(), video_id=args['ypc_vid
'])
1836 if args.get('livestream
') == '1' or args.get('live_playback
') == 1:
1838 if not player_response:
1839 player_response = extract_player_response(args.get('player_response
'), video_id)
1840 if not video_info or self._downloader.params.get('youtube_include_dash_manifest
', True):
1841 add_dash_mpd_pr(player_response)
1843 raise ExtractorError('Video
is age restricted
and only playable on Youtube
. Requires cookies
!', expected=True)
1845 data = compat_urllib_parse_urlencode({
1846 'video_id
': video_id,
1847 'eurl
': 'https
://youtube
.googleapis
.com
/v
/' + video_id,
1848 'sts
': self._search_regex(
1849 r'"sts"\s
*:\s
*(\d
+)', embed_webpage, 'sts
', default=''),
1851 video_info_url = proto + '://www
.youtube
.com
/get_video_info?
' + data
1853 video_info_webpage = self._download_webpage(
1854 video_info_url, video_id,
1855 note='Refetching age
-gated info webpage
',
1856 errnote='unable to download video info webpage
')
1857 except ExtractorError:
1858 video_info_webpage = None
1859 if video_info_webpage:
1860 video_info = compat_parse_qs(video_info_webpage)
1861 pl_response = video_info.get('player_response
', [None])[0]
1862 player_response = extract_player_response(pl_response, video_id)
1863 add_dash_mpd(video_info)
1864 view_count = extract_view_count(video_info)
1867 # Try looking directly into the video webpage
1868 ytplayer_config = self._get_ytplayer_config(video_id, video_webpage)
1870 args = ytplayer_config['args
']
1871 if args.get('url_encoded_fmt_stream_map
') or args.get('hlsvp
'):
1872 # Convert to the same format returned by compat_parse_qs
1873 video_info = dict((k, [v]) for k, v in args.items())
1874 add_dash_mpd(video_info)
1875 # Rental video is not rented but preview is available (e.g.
1876 # https://www.youtube.com/watch?v=yYr8q0y5Jfg,
1877 # https://github.com/ytdl-org/youtube-dl/issues/10532)
1878 if not video_info and args.get('ypc_vid
'):
1879 return self.url_result(
1880 args['ypc_vid
'], YoutubeIE.ie_key(), video_id=args['ypc_vid
'])
1881 if args.get('livestream
') == '1' or args.get('live_playback
') == 1:
1883 if not player_response:
1884 player_response = extract_player_response(args.get('player_response
'), video_id)
1885 if not video_info or self._downloader.params.get('youtube_include_dash_manifest
', True):
1886 add_dash_mpd_pr(player_response)
1888 def extract_unavailable_message():
1890 for tag, kind in (('h1
', 'message
'), ('div
', 'submessage
')):
1891 msg = self._html_search_regex(
1892 r'(?s
)<{tag}
[^
>]+id=["\']unavailable-{kind}["\'][^
>]*>(.+?
)</{tag}
>'.format(tag=tag, kind=kind),
1893 video_webpage, 'unavailable
%s' % kind, default=None)
1895 messages.append(msg)
1897 return '\n'.join(messages)
1899 if not video_info and not player_response:
1900 unavailable_message = extract_unavailable_message()
1901 if not unavailable_message:
1902 unavailable_message = 'Unable to extract video data
'
1903 raise ExtractorError(
1904 'YouTube said
: %s' % unavailable_message, expected=True, video_id=video_id)
1906 if not isinstance(video_info, dict):
1909 video_details = try_get(
1910 player_response, lambda x: x['videoDetails
'], dict) or {}
1912 microformat = try_get(
1913 player_response, lambda x: x['microformat
']['playerMicroformatRenderer
'], dict) or {}
1915 video_title = video_info.get('title
', [None])[0] or video_details.get('title
')
1917 self._downloader.report_warning('Unable to extract video title
')
1920 description_original = video_description = get_element_by_id("eow-description", video_webpage)
1921 if video_description:
1924 redir_url = compat_urlparse.urljoin(url, m.group(1))
1925 parsed_redir_url = compat_urllib_parse_urlparse(redir_url)
1926 if re.search(r'^
(?
:www\
.)?
(?
:youtube(?
:-nocookie
)?\
.com|youtu\
.be
)$
', parsed_redir_url.netloc) and parsed_redir_url.path == '/redirect
':
1927 qs = compat_parse_qs(parsed_redir_url.query)
1933 description_original = video_description = re.sub(r'''(?x)
1935 (?:[a-zA-Z-]+="[^"]*"\s+)*?
1936 (?:title|href)="([^"]+)"\s+
1937 (?:[a-zA-Z-]+="[^"]*"\s+)*?
1941 ''', replace_url, video_description)
1942 video_description = clean_html(video_description)
1944 video_description = video_details.get('shortDescription
')
1945 if video_description is None:
1946 video_description = self._html_search_meta('description
', video_webpage)
1948 if not smuggled_data.get('force_singlefeed
', False):
1949 if not self._downloader.params.get('noplaylist
'):
1950 multifeed_metadata_list = try_get(
1952 lambda x: x['multicamera
']['playerLegacyMulticameraRenderer
']['metadataList
'],
1953 compat_str) or try_get(
1954 video_info, lambda x: x['multifeed_metadata_list
'][0], compat_str)
1955 if multifeed_metadata_list:
1958 for feed in multifeed_metadata_list.split(','):
1959 # Unquote should take place before split on comma (,) since textual
1960 # fields may contain comma as well (see
1961 # https://github.com/ytdl-org/youtube-dl/issues/8536)
1962 feed_data = compat_parse_qs(compat_urllib_parse_unquote_plus(feed))
1964 def feed_entry(name):
1965 return try_get(feed_data, lambda x: x[name][0], compat_str)
1967 feed_id = feed_entry('id')
1970 feed_title = feed_entry('title
')
1973 title += ' (%s)' % feed_title
1975 '_type
': 'url_transparent
',
1976 'ie_key
': 'Youtube
',
1978 '%s://www
.youtube
.com
/watch?v
=%s' % (proto, feed_data['id'][0]),
1979 {'force_singlefeed': True}),
1982 feed_ids.append(feed_id)
1984 'Downloading multifeed
video (%s) - add
--no
-playlist to just download video
%s'
1985 % (', '.join(feed_ids), video_id))
1986 return self.playlist_result(entries, video_id, video_title, video_description)
1988 self.to_screen('Downloading just video
%s because of
--no
-playlist
' % video_id)
1990 if view_count is None:
1991 view_count = extract_view_count(video_info)
1992 if view_count is None and video_details:
1993 view_count = int_or_none(video_details.get('viewCount
'))
1994 if view_count is None and microformat:
1995 view_count = int_or_none(microformat.get('viewCount
'))
1998 is_live = bool_or_none(video_details.get('isLive
'))
2000 has_live_chat_replay = False
2002 yt_initial_data = self._get_yt_initial_data(video_id, video_webpage)
2004 yt_initial_data['contents
']['twoColumnWatchNextResults
']['conversationBar
']['liveChatRenderer
']['continuations
'][0]['reloadContinuationData
']['continuation
']
2005 has_live_chat_replay = True
2006 except (KeyError, IndexError, TypeError):
2009 # Check for "rental" videos
2010 if 'ypc_video_rental_bar_text
' in video_info and 'author
' not in video_info:
2011 raise ExtractorError('"rental" videos
not supported
. See https
://github
.com
/ytdl
-org
/youtube
-dl
/issues
/359 for more information
.', expected=True)
2013 def _extract_filesize(media_url):
2014 return int_or_none(self._search_regex(
2015 r'\bclen
[=/](\d
+)', media_url, 'filesize
', default=None))
2017 streaming_formats = try_get(player_response, lambda x: x['streamingData
']['formats
'], list) or []
2018 streaming_formats.extend(try_get(player_response, lambda x: x['streamingData
']['adaptiveFormats
'], list) or [])
2020 if 'conn
' in video_info and video_info['conn
'][0].startswith('rtmp
'):
2021 self.report_rtmp_download()
2023 'format_id
': '_rtmp
',
2025 'url
': video_info['conn
'][0],
2026 'player_url
': player_url,
2028 elif not is_live and (streaming_formats or len(video_info.get('url_encoded_fmt_stream_map
', [''])[0]) >= 1 or len(video_info.get('adaptive_fmts
', [''])[0]) >= 1):
2029 encoded_url_map = video_info.get('url_encoded_fmt_stream_map
', [''])[0] + ',' + video_info.get('adaptive_fmts
', [''])[0]
2030 if 'rtmpe
%3Dyes
' in encoded_url_map:
2031 raise ExtractorError('rtmpe downloads are
not supported
, see https
://github
.com
/ytdl
-org
/youtube
-dl
/issues
/343 for more information
.', expected=True)
2034 fmt_list = video_info.get('fmt_list
', [''])[0]
2036 for fmt in fmt_list.split(','):
2037 spec = fmt.split('/')
2039 width_height = spec[1].split('x
')
2040 if len(width_height) == 2:
2041 formats_spec[spec[0]] = {
2042 'resolution
': spec[1],
2043 'width
': int_or_none(width_height[0]),
2044 'height
': int_or_none(width_height[1]),
2046 for fmt in streaming_formats:
2047 itag = str_or_none(fmt.get('itag
'))
2050 quality = fmt.get('quality
')
2051 quality_label = fmt.get('qualityLabel
') or quality
2052 formats_spec[itag] = {
2053 'asr
': int_or_none(fmt.get('audioSampleRate
')),
2054 'filesize
': int_or_none(fmt.get('contentLength
')),
2055 'format_note
': quality_label,
2056 'fps
': int_or_none(fmt.get('fps
')),
2057 'height
': int_or_none(fmt.get('height
')),
2058 # bitrate for itag 43 is always 2147483647
2059 'tbr
': float_or_none(fmt.get('averageBitrate
') or fmt.get('bitrate
'), 1000) if itag != '43' else None,
2060 'width
': int_or_none(fmt.get('width
')),
2063 for fmt in streaming_formats:
2064 if fmt.get('drmFamilies
') or fmt.get('drm_families
'):
2066 url = url_or_none(fmt.get('url
'))
2069 cipher = fmt.get('cipher
') or fmt.get('signatureCipher
')
2072 url_data = compat_parse_qs(cipher)
2073 url = url_or_none(try_get(url_data, lambda x: x['url
'][0], compat_str))
2078 url_data = compat_parse_qs(compat_urllib_parse_urlparse(url).query)
2080 stream_type = int_or_none(try_get(url_data, lambda x: x['stream_type
'][0]))
2081 # Unsupported FORMAT_STREAM_TYPE_OTF
2082 if stream_type == 3:
2085 format_id = fmt.get('itag
') or url_data['itag
'][0]
2088 format_id = compat_str(format_id)
2091 if 's
' in url_data or self._downloader.params.get('youtube_include_dash_manifest
', True):
2092 ASSETS_RE = r'(?
:"assets":.+?
"js":\s
*("[^"]+"))|(?:"jsUrl
":\s*("[^
"]+"))'
2093 jsplayer_url_json = self._search_regex(
2095 embed_webpage if age_gate else video_webpage,
2096 'JS player
URL (1)', default=None)
2097 if not jsplayer_url_json and not age_gate:
2098 # We need the embed website after all
2099 if embed_webpage is None:
2100 embed_url = proto + '://www
.youtube
.com
/embed
/%s' % video_id
2101 embed_webpage = self._download_webpage(
2102 embed_url, video_id, 'Downloading embed webpage
')
2103 jsplayer_url_json = self._search_regex(
2104 ASSETS_RE, embed_webpage, 'JS player URL
')
2106 player_url = json.loads(jsplayer_url_json)
2107 if player_url is None:
2108 player_url_json = self._search_regex(
2109 r'ytplayer\
.config
.*?
"url"\s
*:\s
*("[^"]+")',
2110 video_webpage, 'age gate player URL')
2111 player_url = json.loads(player_url_json)
2113 if 'sig' in url_data:
2114 url += '&signature=' + url_data['sig'][0]
2115 elif 's' in url_data:
2116 encrypted_sig = url_data['s'][0]
2118 if self._downloader.params.get('verbose'):
2119 if player_url is None:
2120 player_desc = 'unknown'
2122 player_type, player_version = self._extract_player_info(player_url)
2123 player_desc = '%s player %s' % ('flash' if player_type == 'swf' else 'html5', player_version)
2124 parts_sizes = self._signature_cache_id(encrypted_sig)
2125 self.to_screen('{%s} signature length %s, %s' %
2126 (format_id, parts_sizes, player_desc))
2128 signature = self._decrypt_signature(
2129 encrypted_sig, video_id, player_url, age_gate)
2130 sp = try_get(url_data, lambda x: x['sp'][0], compat_str) or 'signature'
2131 url += '&%s=%s' % (sp, signature)
2132 if 'ratebypass' not in url:
2133 url += '&ratebypass=yes'
2136 'format_id': format_id,
2138 'player_url': player_url,
2140 if format_id in self._formats:
2141 dct.update(self._formats[format_id])
2142 if format_id in formats_spec:
2143 dct.update(formats_spec[format_id])
2145 # Some itags are not included in DASH manifest thus corresponding formats will
2146 # lack metadata (see https://github.com/ytdl-org/youtube-dl/pull/5993).
2147 # Trying to extract metadata from url_encoded_fmt_stream_map entry.
2148 mobj = re.search(r'^(?P<width>\d+)[xX](?P<height>\d+)$', url_data.get('size', [''])[0])
2149 width, height = (int(mobj.group('width')), int(mobj.group('height'))) if mobj else (None, None)
2152 width = int_or_none(fmt.get('width'))
2154 height = int_or_none(fmt.get('height'))
2156 filesize = int_or_none(url_data.get(
2157 'clen', [None])[0]) or _extract_filesize(url)
2159 quality = url_data.get('quality', [None])[0] or fmt.get('quality')
2160 quality_label = url_data.get('quality_label', [None])[0] or fmt.get('qualityLabel')
2162 tbr = (float_or_none(url_data.get('bitrate', [None])[0], 1000)
2163 or float_or_none(fmt.get('bitrate'), 1000)) if format_id != '43' else None
2164 fps = int_or_none(url_data.get('fps', [None])[0]) or int_or_none(fmt.get('fps'))
2167 'filesize': filesize,
2172 'format_note': quality_label or quality,
2174 for key, value in more_fields.items():
2177 type_ = url_data.get('type', [None])[0] or fmt.get('mimeType')
2179 type_split = type_.split(';')
2180 kind_ext = type_split[0].split('/')
2181 if len(kind_ext) == 2:
2183 dct['ext'] = mimetype2ext(type_split[0])
2184 if kind in ('audio', 'video'):
2186 for mobj in re.finditer(
2187 r'(?P<key>[a-zA-Z_-]+)=(?P<quote>["\']?
)(?P
<val
>.+?
)(?P
=quote
)(?
:;|$
)', type_):
2188 if mobj.group('key
') == 'codecs
':
2189 codecs = mobj.group('val
')
2192 dct.update(parse_codecs(codecs))
2193 if dct.get('acodec
') == 'none
' or dct.get('vcodec
') == 'none
':
2194 dct['downloader_options
'] = {
2195 # Youtube throttles chunks >~10M
2196 'http_chunk_size
': 10485760,
2201 url_or_none(try_get(
2203 lambda x: x['streamingData
']['hlsManifestUrl
'],
2205 or url_or_none(try_get(
2206 video_info, lambda x: x['hlsvp
'][0], compat_str)))
2209 m3u8_formats = self._extract_m3u8_formats(
2210 manifest_url, video_id, 'mp4
', fatal=False)
2211 for a_format in m3u8_formats:
2212 itag = self._search_regex(
2213 r'/itag
/(\d
+)/', a_format['url
'], 'itag
', default=None)
2215 a_format['format_id
'] = itag
2216 if itag in self._formats:
2217 dct = self._formats[itag].copy()
2218 dct.update(a_format)
2220 a_format['player_url
'] = player_url
2221 # Accept-Encoding header causes failures in live streams on Youtube and Youtube Gaming
2222 a_format.setdefault('http_headers
', {})['Youtubedl
-no
-compression
'] = 'True'
2223 if self._downloader.params.get('youtube_include_hls_manifest
', True):
2224 formats.append(a_format)
2226 error_message = extract_unavailable_message()
2227 if not error_message:
2228 error_message = clean_html(try_get(
2229 player_response, lambda x: x['playabilityStatus
']['reason
'],
2231 if not error_message:
2232 error_message = clean_html(
2233 try_get(video_info, lambda x: x['reason
'][0], compat_str))
2235 raise ExtractorError(error_message, expected=True)
2236 raise ExtractorError('no conn
, hlsvp
, hlsManifestUrl
or url_encoded_fmt_stream_map information found
in video info
')
2239 video_uploader = try_get(
2240 video_info, lambda x: x['author
'][0],
2241 compat_str) or str_or_none(video_details.get('author
'))
2243 video_uploader = compat_urllib_parse_unquote_plus(video_uploader)
2245 self._downloader.report_warning('unable to extract uploader name
')
2248 video_uploader_id = None
2249 video_uploader_url = None
2251 r'<link itemprop
="url" href
="(?P<uploader_url>https?://www\.youtube\.com/(?:user|channel)/(?P<uploader_id>[^"]+))">',
2253 if mobj is not None:
2254 video_uploader_id = mobj.group('uploader_id')
2255 video_uploader_url = mobj.group('uploader_url')
2257 owner_profile_url = url_or_none(microformat.get('ownerProfileUrl'))
2258 if owner_profile_url:
2259 video_uploader_id = self._search_regex(
2260 r'(?:user|channel)/([^/]+)', owner_profile_url, 'uploader id',
2262 video_uploader_url = owner_profile_url
2265 str_or_none(video_details.get('channelId'))
2266 or self._html_search_meta(
2267 'channelId', video_webpage, 'channel id', default=None)
2268 or self._search_regex(
2269 r'data-channel-external-id=(["\'])(?P
<id>(?
:(?
!\
1).)+)\
1',
2270 video_webpage, 'channel
id', default=None, group='id'))
2271 channel_url = 'http
://www
.youtube
.com
/channel
/%s' % channel_id if channel_id else None
2274 thumbnails_list = try_get(
2275 video_details, lambda x: x['thumbnail
']['thumbnails
'], list) or []
2276 for t in thumbnails_list:
2277 if not isinstance(t, dict):
2279 thumbnail_url = url_or_none(t.get('url
'))
2280 if not thumbnail_url:
2283 'url
': thumbnail_url,
2284 'width
': int_or_none(t.get('width
')),
2285 'height
': int_or_none(t.get('height
')),
2289 video_thumbnail = None
2290 # We try first to get a high quality image:
2291 m_thumb = re.search(r'<span itemprop
="thumbnail".*?href
="(.*?)">',
2292 video_webpage, re.DOTALL)
2293 if m_thumb is not None:
2294 video_thumbnail = m_thumb.group(1)
2295 thumbnail_url = try_get(video_info, lambda x: x['thumbnail_url
'][0], compat_str)
2297 video_thumbnail = compat_urllib_parse_unquote_plus(thumbnail_url)
2299 thumbnails.append({'url': video_thumbnail})
2302 upload_date = self._html_search_meta(
2303 'datePublished
', video_webpage, 'upload date
', default=None)
2305 upload_date = self._search_regex(
2306 [r'(?s
)id="eow-date.*?>(.*?)</span>',
2307 r'(?:id="watch
-uploader
-info
".*?>.*?|["\']simpleText
["\']\s*:\s*["\'])(?
:Published|Uploaded|Streamed live|Started
) on (.+?
)[<"\']'],
2308 video_webpage, 'upload date', default=None)
2310 upload_date = microformat.get('publishDate') or microformat.get('uploadDate')
2311 upload_date = unified_strdate(upload_date)
2313 video_license = self._html_search_regex(
2314 r'<h4[^>]+class="title
"[^>]*>\s*License\s*</h4>\s*<ul[^>]*>\s*<li>(.+?)</li',
2315 video_webpage, 'license', default=None)
2317 m_music = re.search(
2319 <h4[^>]+class="title
"[^>]*>\s*Music\s*</h4>\s*
2327 \bhref=["\']/red
[^
>]*>|
# drop possible
2328 >\s
*Listen ad
-free
with YouTube Red
# YouTube Red ad
2335 video_alt_title = remove_quotes(unescapeHTML(m_music.group('title')))
2336 video_creator = clean_html(m_music.group('creator'))
2338 video_alt_title = video_creator = None
2340 def extract_meta(field):
2341 return self._html_search_regex(
2342 r'<h4[^>]+class="title"[^>]*>\s*%s\s*</h4>\s*<ul[^>]*>\s*<li>(.+?)</li>\s*' % field,
2343 video_webpage, field, default=None)
2345 track = extract_meta('Song')
2346 artist = extract_meta('Artist')
2347 album = extract_meta('Album')
2349 # Youtube Music Auto-generated description
2350 release_date = release_year = None
2351 if video_description:
2352 mobj = re.search(r'(?s)Provided to YouTube by [^\n]+\n+(?P<track>[^·]+)·(?P<artist>[^\n]+)\n+(?P<album>[^\n]+)(?:.+?℗\s*(?P<release_year>\d{4})(?!\d))?(?:.+?Released on\s*:\s*(?P<release_date>\d{4}-\d{2}-\d{2}))?(.+?\nArtist\s*:\s*(?P<clean_artist>[^\n]+))?', video_description)
2355 track = mobj.group('track').strip()
2357 artist = mobj.group('clean_artist') or ', '.join(a.strip() for a in mobj.group('artist').split('·'))
2359 album = mobj.group('album'.strip())
2360 release_year = mobj.group('release_year')
2361 release_date = mobj.group('release_date')
2363 release_date = release_date.replace('-', '')
2364 if not release_year:
2365 release_year = int(release_date[:4])
2367 release_year = int(release_year)
2369 yt_initial = self._get_yt_initial_data(video_id, video_webpage)
2371 music_metadata = self._get_music_metadata_from_yt_initial(yt_initial)
2372 if len(music_metadata):
2373 album = music_metadata[0].get('album')
2374 artist = music_metadata[0].get('artist')
2375 track = music_metadata[0].get('track')
2377 m_episode = re.search(
2378 r'<div[^>]+id="watch7-headline"[^>]*>\s*<span[^>]*>.*?>(?P<series>[^<]+)</a></b>\s*S(?P<season>\d+)\s*•\s*E(?P<episode>\d+)</span>',
2381 series = unescapeHTML(m_episode.group('series'))
2382 season_number = int(m_episode.group('season'))
2383 episode_number = int(m_episode.group('episode'))
2385 series = season_number = episode_number = None
2387 m_cat_container = self._search_regex(
2388 r'(?s)<h4[^>]*>\s*Category\s*</h4>\s*<ul[^>]*>(.*?)</ul>',
2389 video_webpage, 'categories', default=None)
2392 category = self._html_search_regex(
2393 r'(?s)<a[^<]+>(.*?)</a>', m_cat_container, 'category',
2397 microformat, lambda x: x['category'], compat_str)
2398 video_categories = None if category is None else [category]
2401 unescapeHTML(m.group('content'))
2402 for m in re.finditer(self._meta_regex('og:video:tag'), video_webpage)]
2404 video_tags = try_get(video_details, lambda x: x['keywords'], list)
2406 def _extract_count(count_name):
2407 return str_to_int(self._search_regex(
2408 r'"accessibilityData":\{"label":"([\d,\w]+) %ss"\}'
2409 % re.escape(count_name),
2410 video_webpage, count_name, default=None))
2412 like_count = _extract_count('like')
2413 dislike_count = _extract_count('dislike')
2415 if view_count is None:
2416 view_count = str_to_int(self._search_regex(
2417 r'<[^>]+class=["\']watch-view-count[^>]+>\s*([\d,\s]+)', video_webpage,
2418 'view count', default=None))
2421 float_or_none(video_details.get('averageRating'))
2422 or try_get(video_info, lambda x: float_or_none(x['avg_rating'][0])))
2425 video_subtitles = self.extract_subtitles(
2426 video_id, video_webpage, has_live_chat_replay)
2427 automatic_captions = self.extract_automatic_captions(video_id, video_webpage)
2429 video_duration = try_get(
2430 video_info, lambda x: int_or_none(x['length_seconds'][0]))
2431 if not video_duration:
2432 video_duration = int_or_none(video_details.get('lengthSeconds'))
2433 if not video_duration:
2434 video_duration = parse_duration(self._html_search_meta(
2435 'duration', video_webpage, 'video duration'))
2437 # Get Subscriber Count of channel
2438 subscriber_count = parse_count(self._search_regex(
2439 r'"text":"([\d\.]+\w?) subscribers"',
2446 video_annotations = None
2447 if self._downloader.params.get('writeannotations', False):
2448 xsrf_token = self._search_regex(
2449 r'([\'"])XSRF_TOKEN\1\s*:\s*([\'"])(?P<xsrf_token>[A-Za-z0-9+/=]+)\2',
2450 video_webpage, 'xsrf token', group='xsrf_token', fatal=False)
2451 invideo_url = try_get(
2452 player_response, lambda x: x['annotations'][0]['playerAnnotationsUrlsRenderer']['invideoUrl'], compat_str)
2453 if xsrf_token and invideo_url:
2454 xsrf_field_name = self._search_regex(
2455 r'([\'"])XSRF_FIELD_NAME\1\s*:\s*([\'"])(?P<xsrf_field_name>\w+)\2',
2456 video_webpage, 'xsrf field name',
2457 group='xsrf_field_name', default='session_token')
2458 video_annotations = self._download_webpage(
2459 self._proto_relative_url(invideo_url),
2460 video_id, note='Downloading annotations',
2461 errnote='Unable to download video annotations', fatal=False,
2462 data=urlencode_postdata({xsrf_field_name: xsrf_token}))
2464 chapters = self._extract_chapters(video_webpage, description_original, video_id, video_duration)
2466 # Look for the DASH manifest
2467 if self._downloader.params.get('youtube_include_dash_manifest', True):
2468 dash_mpd_fatal = True
2469 for mpd_url in dash_mpds:
2472 def decrypt_sig(mobj):
2474 dec_s = self._decrypt_signature(s, video_id, player_url, age_gate)
2475 return '/signature/%s' % dec_s
2477 mpd_url = re.sub(r'/s/([a-fA-F0-9\.]+)', decrypt_sig, mpd_url)
2479 for df in self._extract_mpd_formats(
2480 mpd_url, video_id, fatal=dash_mpd_fatal,
2481 formats_dict=self._formats):
2482 if not df.get('filesize'):
2483 df['filesize'] = _extract_filesize(df['url'])
2484 # Do not overwrite DASH format found in some previous DASH manifest
2485 if df['format_id'] not in dash_formats:
2486 dash_formats[df['format_id']] = df
2487 # Additional DASH manifests may end up in HTTP Error 403 therefore
2488 # allow them to fail without bug report message if we already have
2489 # some DASH manifest succeeded. This is temporary workaround to reduce
2490 # burst of bug reports until we figure out the reason and whether it
2491 # can be fixed at all.
2492 dash_mpd_fatal = False
2493 except (ExtractorError, KeyError) as e:
2494 self.report_warning(
2495 'Skipping DASH manifest: %r' % e, video_id)
2497 # Remove the formats we found through non-DASH, they
2498 # contain less info and it can be wrong, because we use
2499 # fixed values (for example the resolution). See
2500 # https://github.com/ytdl-org/youtube-dl/issues/5774 for an
2502 formats = [f for f in formats if f['format_id'] not in dash_formats.keys()]
2503 formats.extend(dash_formats.values())
2505 # Check for malformed aspect ratio
2506 stretched_m = re.search(
2507 r'<meta\s+property="og:video:tag".*?content="yt:stretch=(?P<w>[0-9]+):(?P<h>[0-9]+)">',
2510 w = float(stretched_m.group('w'))
2511 h = float(stretched_m.group('h'))
2512 # yt:stretch may hold invalid ratio data (e.g. for Q39EVAstoRM ratio is 17:0).
2513 # We will only process correct ratios.
2517 if f.get('vcodec') != 'none':
2518 f['stretched_ratio'] = ratio
2521 if 'reason' in video_info:
2522 if 'The uploader has not made this video available in your country.' in video_info['reason']:
2523 regions_allowed = self._html_search_meta(
2524 'regionsAllowed', video_webpage, default=None)
2525 countries = regions_allowed.split(',') if regions_allowed else None
2526 self.raise_geo_restricted(
2527 msg=video_info['reason'][0], countries=countries)
2528 reason = video_info['reason'][0]
2529 if 'Invalid parameters' in reason:
2530 unavailable_message = extract_unavailable_message()
2531 if unavailable_message:
2532 reason = unavailable_message
2533 raise ExtractorError(
2534 'YouTube said: %s' % reason,
2535 expected=True, video_id=video_id)
2536 if video_info.get('license_info') or try_get(player_response, lambda x: x['streamingData']['licenseInfos']):
2537 raise ExtractorError('This video is DRM protected.', expected=True)
2539 self._sort_formats(formats)
2541 self.mark_watched(video_id, video_info, player_response)
2545 'uploader': video_uploader,
2546 'uploader_id': video_uploader_id,
2547 'uploader_url': video_uploader_url,
2548 'channel_id': channel_id,
2549 'channel_url': channel_url,
2550 'upload_date': upload_date,
2551 'license': video_license,
2552 'creator': video_creator or artist,
2553 'title': video_title,
2554 'alt_title': video_alt_title or track,
2555 'thumbnails': thumbnails,
2556 'description': video_description,
2557 'categories': video_categories,
2559 'subtitles': video_subtitles,
2560 'automatic_captions': automatic_captions,
2561 'duration': video_duration,
2562 'age_limit': 18 if age_gate else 0,
2563 'annotations': video_annotations,
2564 'chapters': chapters,
2565 'webpage_url': proto + '://www.youtube.com/watch?v=%s' % video_id,
2566 'view_count': view_count,
2567 'like_count': like_count,
2568 'dislike_count': dislike_count,
2569 'average_rating': average_rating,
2572 'start_time': start_time,
2573 'end_time': end_time,
2575 'season_number': season_number,
2576 'episode_number': episode_number,
2580 'release_date': release_date,
2581 'release_year': release_year,
2582 'subscriber_count': subscriber_count,
2586 class YoutubePlaylistIE(YoutubePlaylistBaseInfoExtractor):
2587 IE_DESC = 'YouTube.com playlists'
2588 _VALID_URL = r"""(?x)(?:
2593 youtube(?:kids)?\.com|
2598 (?:course|view_play_list|my_playlists|artist|playlist|watch|embed/(?:videoseries|[0-9A-Za-z_-]{11}))
2599 \? (?:.*?[&;])*? (?:p|a|list)=
2602 youtu\.be/[0-9A-Za-z_-]{11}\?.*?\blist=
2605 (?:PL|LL|EC|UU|FL|RD|UL|TL|PU|OLAK5uy_)?[0-9A-Za-z-_]{10,}
2606 # Top tracks, they can also include dots
2612 )""" % {'playlist_id': YoutubeBaseInfoExtractor._PLAYLIST_ID_RE}
2613 _TEMPLATE_URL = 'https://www.youtube.com/playlist?list=%s'
2614 _VIDEO_RE_TPL = r'href="\s*/watch\?v=%s(?:&(?:[^"]*?index=(?P<index>\d+))?(?:[^>]+>(?P<title>[^<]+))?)?'
2615 _VIDEO_RE = _VIDEO_RE_TPL % r'(?P<id>[0-9A-Za-z_-]{11})'
2616 IE_NAME = 'youtube:playlist'
2618 'url': 'https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc',
2620 'uploader_id': 'UCmlqkdCBesrv2Lak1mF_MxA',
2621 'uploader': 'Sergey M.',
2622 'id': 'PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc',
2623 'title': 'youtube-dl public playlist',
2625 'playlist_count': 1,
2627 'url': 'https://www.youtube.com/playlist?list=PL4lCao7KL_QFodcLWhDpGCYnngnHtQ-Xf',
2629 'uploader_id': 'UCmlqkdCBesrv2Lak1mF_MxA',
2630 'uploader': 'Sergey M.',
2631 'id': 'PL4lCao7KL_QFodcLWhDpGCYnngnHtQ-Xf',
2632 'title': 'youtube-dl empty playlist',
2634 'playlist_count': 0,
2636 'note': 'Playlist with deleted videos (#651). As a bonus, the video #51 is also twice in this list.',
2637 'url': 'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC',
2639 'title': '29C3: Not my department',
2640 'id': 'PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC',
2641 'uploader': 'Christiaan008',
2642 'uploader_id': 'ChRiStIaAn008',
2644 'playlist_count': 96,
2646 'note': 'issue #673',
2647 'url': 'PLBB231211A4F62143',
2649 'title': '[OLD]Team Fortress 2 (Class-based LP)',
2650 'id': 'PLBB231211A4F62143',
2651 'uploader': 'Wickydoo',
2652 'uploader_id': 'Wickydoo',
2654 'playlist_mincount': 26,
2656 'note': 'Large playlist',
2657 'url': 'https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q',
2659 'title': 'Uploads from Cauchemar',
2660 'id': 'UUBABnxM4Ar9ten8Mdjj1j0Q',
2661 'uploader': 'Cauchemar',
2662 'uploader_id': 'Cauchemar89',
2664 'playlist_mincount': 799,
2666 'url': 'PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl',
2668 'title': 'YDL_safe_search',
2669 'id': 'PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl',
2671 'playlist_count': 2,
2672 'skip': 'This playlist is private',
2675 'url': 'https://www.youtube.com/embed/videoseries?list=PL6IaIsEjSbf96XFRuNccS_RuEXwNdsoEu',
2676 'playlist_count': 4,
2679 'id': 'PL6IaIsEjSbf96XFRuNccS_RuEXwNdsoEu',
2680 'uploader': 'milan',
2681 'uploader_id': 'UCEI1-PVPcYXjB73Hfelbmaw',
2684 'url': 'http://www.youtube.com/embed/_xDOZElKyNU?list=PLsyOSbh5bs16vubvKePAQ1x3PhKavfBIl',
2685 'playlist_mincount': 485,
2687 'title': '2018 Chinese New Singles (11/6 updated)',
2688 'id': 'PLsyOSbh5bs16vubvKePAQ1x3PhKavfBIl',
2690 'uploader_id': 'sdragonfang',
2693 'note': 'Embedded SWF player',
2694 'url': 'https://www.youtube.com/p/YN5VISEtHet5D4NEvfTd0zcgFk84NqFZ?hl=en_US&fs=1&rel=0',
2695 'playlist_count': 4,
2698 'id': 'YN5VISEtHet5D4NEvfTd0zcgFk84NqFZ',
2700 'skip': 'This playlist does not exist',
2702 'note': 'Buggy playlist: the webpage has a "Load more" button but it doesn\'t have more videos',
2703 'url': 'https://www.youtube.com/playlist?list=UUXw-G3eDE9trcvY2sBMM_aA',
2705 'title': 'Uploads from Interstellar Movie',
2706 'id': 'UUXw-G3eDE9trcvY2sBMM_aA',
2707 'uploader': 'Interstellar Movie',
2708 'uploader_id': 'InterstellarMovie1',
2710 'playlist_mincount': 21,
2712 # Playlist URL that does not actually serve a playlist
2713 'url': 'https://www.youtube.com/watch?v=FqZTN594JQw&list=PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4',
2715 'id': 'FqZTN594JQw',
2717 'title': "Smiley's People 01 detective, Adventure Series, Action",
2718 'uploader': 'STREEM',
2719 'uploader_id': 'UCyPhqAZgwYWZfxElWVbVJng',
2720 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UCyPhqAZgwYWZfxElWVbVJng',
2721 'upload_date': '20150526',
2722 'license': 'Standard YouTube License',
2723 'description': 'md5:507cdcb5a49ac0da37a920ece610be80',
2724 'categories': ['People & Blogs'],
2728 'dislike_count': int,
2731 'skip_download': True,
2733 'skip': 'This video is not available.',
2734 'add_ie': [YoutubeIE.ie_key()],
2736 'url': 'https://youtu.be/yeWKywCrFtk?list=PL2qgrgXsNUG5ig9cat4ohreBjYLAPC0J5',
2738 'id': 'yeWKywCrFtk',
2740 'title': 'Small Scale Baler and Braiding Rugs',
2741 'uploader': 'Backus-Page House Museum',
2742 'uploader_id': 'backuspagemuseum',
2743 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/backuspagemuseum',
2744 'upload_date': '20161008',
2745 'description': 'md5:800c0c78d5eb128500bffd4f0b4f2e8a',
2746 'categories': ['Nonprofits & Activism'],
2749 'dislike_count': int,
2753 'skip_download': True,
2756 # https://github.com/ytdl-org/youtube-dl/issues/21844
2757 'url': 'https://www.youtube.com/playlist?list=PLzH6n4zXuckpfMu_4Ff8E7Z1behQks5ba',
2759 'title': 'Data Analysis with Dr Mike Pound',
2760 'id': 'PLzH6n4zXuckpfMu_4Ff8E7Z1behQks5ba',
2761 'uploader_id': 'Computerphile',
2762 'uploader': 'Computerphile',
2764 'playlist_mincount': 11,
2766 'url': 'https://youtu.be/uWyaPkt-VOI?list=PL9D9FC436B881BA21',
2767 'only_matching': True,
2769 'url': 'TLGGrESM50VT6acwMjAyMjAxNw',
2770 'only_matching': True,
2772 # music album playlist
2773 'url': 'OLAK5uy_m4xAFdmMC5rX3Ji3g93pQe3hqLZw_9LhM',
2774 'only_matching': True,
2776 'url': 'https://invidio.us/playlist?list=PLDIoUOhQQPlXr63I_vwF9GD8sAKh77dWU',
2777 'only_matching': True,
2779 'url': 'https://www.youtubekids.com/watch?v=Agk7R8I8o5U&list=PUZ6jURNr1WQZCNHF0ao-c0g',
2780 'only_matching': True,
2783 def _real_initialize(self):
2786 def extract_videos_from_page(self, page):
2790 for item in re.findall(
2791 r'(<[^>]*\bdata-video-id\s*=\s*["\'][0-9A-Za-z_-]{11}[^>]+>)', page):
2792 attrs = extract_attributes(item)
2793 video_id = attrs['data-video-id']
2794 video_title = unescapeHTML(attrs.get('data-title'))
2796 video_title = video_title.strip()
2797 ids_in_page.append(video_id)
2798 titles_in_page.append(video_title)
2800 # Fallback with old _VIDEO_RE
2801 self.extract_videos_from_page_impl(
2802 self._VIDEO_RE, page, ids_in_page, titles_in_page)
2805 self.extract_videos_from_page_impl(
2806 r'href="\s*/watch\?v\s*=\s*(?P<id>[0-9A-Za-z_-]{11})', page,
2807 ids_in_page, titles_in_page)
2808 self.extract_videos_from_page_impl(
2809 r'data-video-ids\s*=\s*["\'](?P<id>[0-9A-Za-z_-]{11})', page,
2810 ids_in_page, titles_in_page)
2812 return zip(ids_in_page, titles_in_page)
2814 def _extract_mix(self, playlist_id):
2815 # The mixes are generated from a single video
2816 # the id of the playlist is just 'RD' + video_id
2818 last_id = playlist_id[-11:]
2819 for n in itertools.count(1):
2820 url = 'https://www.youtube.com/watch?v=%s&list=%s' % (last_id, playlist_id)
2821 webpage = self._download_webpage(
2822 url, playlist_id, 'Downloading page {0} of Youtube mix'.format(n))
2823 new_ids = orderedSet(re.findall(
2824 r'''(?xs
)data
-video
-username
=".*?".*?
2825 href
="/watch\?v=([0-9A-Za-z_-]{11})&[^"]*?
list=%s''' % re.escape(playlist_id),
2827 # Fetch new pages until all the videos are repeated, it seems that
2828 # there are always 51 unique videos.
2829 new_ids = [_id for _id in new_ids if _id not in ids]
2835 url_results = self._ids_to_results(ids)
2837 search_title = lambda class_name: get_element_by_attribute('class', class_name, webpage)
2839 search_title('playlist-title')
2840 or search_title('title long-title')
2841 or search_title('title'))
2842 title = clean_html(title_span)
2844 return self.playlist_result(url_results, playlist_id, title)
2846 def _extract_playlist(self, playlist_id):
2847 url = self._TEMPLATE_URL % playlist_id
2848 page = self._download_webpage(url, playlist_id)
2850 # the yt-alert-message now has tabindex attribute (see https://github.com/ytdl-org/youtube-dl/issues/11604)
2851 for match in re.findall(r'<div class="yt-alert-message"[^>]*>([^<]+)</div>', page):
2852 match = match.strip()
2853 # Check if the playlist exists or is private
2854 mobj = re.match(r'[^<]*(?:The|This) playlist (?P<reason>does not exist|is private)[^<]*', match)
2856 reason = mobj.group('reason')
2857 message = 'This playlist %s' % reason
2858 if 'private' in reason:
2859 message += ', use --username or --netrc to access it'
2861 raise ExtractorError(message, expected=True)
2862 elif re.match(r'[^<]*Invalid parameters[^<]*', match):
2863 raise ExtractorError(
2864 'Invalid parameters. Maybe URL is incorrect.',
2866 elif re.match(r'[^<]*Choose your language[^<]*', match):
2869 self.report_warning('Youtube gives an alert message: ' + match)
2871 playlist_title = self._html_search_regex(
2872 r'(?s)<h1 class="pl-header-title[^"]*"[^>]*>\s*(.*?)\s*</h1>',
2873 page, 'title', default=None)
2875 _UPLOADER_BASE = r'class=["\']pl-header-details[^>]+>\s*<li>\s*<a[^>]+\bhref='
2876 uploader = self._html_search_regex(
2877 r'%s["\']/(?:user|channel)/[^>]+>([^<]+)' % _UPLOADER_BASE,
2878 page, 'uploader', default=None)
2880 r'%s(["\'])(?P<path>/(?:user|channel)/(?P<uploader_id>.+?))\1' % _UPLOADER_BASE,
2883 uploader_id = mobj.group('uploader_id')
2884 uploader_url = compat_urlparse.urljoin(url, mobj.group('path'))
2886 uploader_id = uploader_url = None
2890 if not playlist_title:
2892 # Some playlist URLs don't actually serve a playlist (e.g.
2893 # https://www.youtube.com/watch?v=FqZTN594JQw&list=PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4)
2894 next(self._entries(page, playlist_id))
2895 except StopIteration:
2898 playlist = self.playlist_result(
2899 self._entries(page, playlist_id), playlist_id, playlist_title)
2901 'uploader': uploader,
2902 'uploader_id': uploader_id,
2903 'uploader_url': uploader_url,
2906 return has_videos, playlist
2908 def _check_download_just_video(self, url, playlist_id):
2909 # Check if it's a video-specific URL
2910 query_dict = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
2911 video_id = query_dict.get('v', [None])[0] or self._search_regex(
2912 r'(?:(?:^|//)youtu\.be/|youtube\.com/embed/(?!videoseries))([0-9A-Za-z_-]{11})', url,
2913 'video id', default=None)
2915 if self._downloader.params.get('noplaylist'):
2916 self.to_screen('Downloading just video %s because of --no-playlist' % video_id)
2917 return video_id, self.url_result(video_id, 'Youtube', video_id=video_id)
2919 self.to_screen('Downloading playlist %s - add --no-playlist to just download video %s' % (playlist_id, video_id))
2920 return video_id, None
2923 def _real_extract(self, url):
2924 # Extract playlist id
2925 mobj = re.match(self._VALID_URL, url)
2927 raise ExtractorError('Invalid URL: %s' % url)
2928 playlist_id = mobj.group(1) or mobj.group(2)
2930 video_id, video = self._check_download_just_video(url, playlist_id)
2934 if playlist_id.startswith(('RD', 'UL', 'PU')):
2935 # Mixes require a custom extraction process
2936 return self._extract_mix(playlist_id)
2938 has_videos, playlist = self._extract_playlist(playlist_id)
2939 if has_videos or not video_id:
2942 # Some playlist URLs don't actually serve a playlist (see
2943 # https://github.com/ytdl-org/youtube-dl/issues/10537).
2944 # Fallback to plain video extraction if there is a video id
2945 # along with playlist id.
2946 return self.url_result(video_id, 'Youtube', video_id=video_id)
2949 class YoutubeChannelIE(YoutubePlaylistBaseInfoExtractor):
2950 IE_DESC = 'YouTube.com channels'
2951 _VALID_URL = r'https?://(?:youtu\.be|(?:\w+\.)?youtube(?:-nocookie|kids)?\.com|(?:www\.)?invidio\.us)/channel/(?P<id>[0-9A-Za-z_-]+)'
2952 _TEMPLATE_URL = 'https://www.youtube.com/channel/%s/videos'
2953 _VIDEO_RE = r'(?:title="(?P<title>[^"]+)"[^>]+)?href="/watch\?v=(?P<id>[0-9A-Za-z_-]+)&?'
2954 IE_NAME = 'youtube:channel'
2956 'note': 'paginated channel',
2957 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
2958 'playlist_mincount': 91,
2960 'id': 'UUKfVa3S1e4PHvxWcwyMMg8w',
2961 'title': 'Uploads from lex will',
2962 'uploader': 'lex will',
2963 'uploader_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
2966 'note': 'Age restricted channel',
2967 # from https://www.youtube.com/user/DeusExOfficial
2968 'url': 'https://www.youtube.com/channel/UCs0ifCMCm1icqRbqhUINa0w',
2969 'playlist_mincount': 64,
2971 'id': 'UUs0ifCMCm1icqRbqhUINa0w',
2972 'title': 'Uploads from Deus Ex',
2973 'uploader': 'Deus Ex',
2974 'uploader_id': 'DeusExOfficial',
2977 'url': 'https://invidio.us/channel/UC23qupoDRn9YOAVzeoxjOQA',
2978 'only_matching': True,
2980 'url': 'https://www.youtubekids.com/channel/UCyu8StPfZWapR6rfW_JgqcA',
2981 'only_matching': True,
2985 def suitable(cls, url):
2986 return (False if YoutubePlaylistsIE.suitable(url) or YoutubeLiveIE.suitable(url)
2987 else super(YoutubeChannelIE, cls).suitable(url))
2989 def _build_template_url(self, url, channel_id):
2990 return self._TEMPLATE_URL % channel_id
2992 def _real_extract(self, url):
2993 channel_id = self._match_id(url)
2995 url = self._build_template_url(url, channel_id)
2997 # Channel by page listing is restricted to 35 pages of 30 items, i.e. 1050 videos total (see #5778)
2998 # Workaround by extracting as a playlist if managed to obtain channel playlist URL
2999 # otherwise fallback on channel by page extraction
3000 channel_page = self._download_webpage(
3001 url + '?view=57', channel_id,
3002 'Downloading channel page', fatal=False)
3003 if channel_page is False:
3004 channel_playlist_id = False
3006 channel_playlist_id = self._html_search_meta(
3007 'channelId', channel_page, 'channel id', default=None)
3008 if not channel_playlist_id:
3009 channel_url = self._html_search_meta(
3010 ('al:ios:url', 'twitter:app:url:iphone', 'twitter:app:url:ipad'),
3011 channel_page, 'channel url', default=None)
3013 channel_playlist_id = self._search_regex(
3014 r'vnd\.youtube://user/([0-9A-Za-z_-]+)',
3015 channel_url, 'channel id', default=None)
3016 if channel_playlist_id and channel_playlist_id.startswith('UC'):
3017 playlist_id = 'UU' + channel_playlist_id[2:]
3018 return self.url_result(
3019 compat_urlparse.urljoin(url, '/playlist?list=%s' % playlist_id), 'YoutubePlaylist')
3021 channel_page = self._download_webpage(url, channel_id, 'Downloading page #1')
3022 autogenerated = re.search(r'''(?x
)
3024 channel
-header
-autogenerated
-label|
3025 yt
-channel
-title
-autogenerated
3026 )[^
"]*"''', channel_page) is not None
3029 # The videos are contained in a single page
3030 # the ajax pages can't be used, they are empty
3033 video_id, 'Youtube', video_id=video_id,
3034 video_title=video_title)
3035 for video_id, video_title in self.extract_videos_from_page(channel_page)]
3036 return self.playlist_result(entries, channel_id)
3039 next(self._entries(channel_page, channel_id))
3040 except StopIteration:
3041 alert_message = self._html_search_regex(
3042 r'(?s)<div[^>]+class=(["\']).*?\byt-alert-message\b.*?\1[^>]*>(?P<alert>[^<]+)</div>',
3043 channel_page, 'alert', default=None, group='alert')
3045 raise ExtractorError('Youtube said: %s' % alert_message, expected=True)
3047 return self.playlist_result(self._entries(channel_page, channel_id), channel_id)
3050 class YoutubeUserIE(YoutubeChannelIE):
3051 IE_DESC = 'YouTube.com user videos (URL or "ytuser" keyword)'
3052 _VALID_URL = r'(?:(?:https?://(?:\w+\.)?youtube\.com/(?:(?P<user>user|c)/)?(?!(?:attribution_link|watch|results|shared)(?:$|[^a-z_A-Z0-9%-])))|ytuser:)(?!feed/)(?P<id>[A-Za-z0-9_%-]+)'
3053 _TEMPLATE_URL = 'https://www.youtube.com/%s/%s/videos'
3054 IE_NAME = 'youtube:user'
3057 'url': 'https://www.youtube.com/user/TheLinuxFoundation',
3058 'playlist_mincount': 320,
3060 'id': 'UUfX55Sx5hEFjoC3cNs6mCUQ',
3061 'title': 'Uploads from The Linux Foundation',
3062 'uploader': 'The Linux Foundation',
3063 'uploader_id': 'TheLinuxFoundation',
3066 # Only available via https://www.youtube.com/c/12minuteathlete/videos
3067 # but not https://www.youtube.com/user/12minuteathlete/videos
3068 'url': 'https://www.youtube.com/c/12minuteathlete/videos',
3069 'playlist_mincount': 249,
3071 'id': 'UUVjM-zV6_opMDx7WYxnjZiQ',
3072 'title': 'Uploads from 12 Minute Athlete',
3073 'uploader': '12 Minute Athlete',
3074 'uploader_id': 'the12minuteathlete',
3077 'url': 'ytuser:phihag',
3078 'only_matching': True,
3080 'url': 'https://www.youtube.com/c/gametrailers',
3081 'only_matching': True,
3083 'url': 'https://www.youtube.com/c/Pawe%C5%82Zadro%C5%BCniak',
3084 'only_matching': True,
3086 'url': 'https://www.youtube.com/gametrailers',
3087 'only_matching': True,
3089 # This channel is not available, geo restricted to JP
3090 'url': 'https://www.youtube.com/user/kananishinoSMEJ/videos',
3091 'only_matching': True,
3095 def suitable(cls, url):
3096 # Don't return True if the url can be extracted with other youtube
3097 # extractor, the regex would is too permissive and it would match.
3098 other_yt_ies = iter(klass for (name, klass) in globals().items() if name.startswith('Youtube') and name.endswith('IE') and klass is not cls)
3099 if any(ie.suitable(url) for ie in other_yt_ies):
3102 return super(YoutubeUserIE, cls).suitable(url)
3104 def _build_template_url(self, url, channel_id):
3105 mobj = re.match(self._VALID_URL, url)
3106 return self._TEMPLATE_URL % (mobj.group('user') or 'user', mobj.group('id'))
3109 class YoutubeLiveIE(YoutubeBaseInfoExtractor):
3110 IE_DESC = 'YouTube.com live streams'
3111 _VALID_URL = r'(?P<base_url>https?://(?:\w+\.)?youtube\.com/(?:(?:user|channel|c)/)?(?P<id>[^/]+))/live'
3112 IE_NAME = 'youtube:live'
3115 'url': 'https://www.youtube.com/user/TheYoungTurks/live',
3117 'id': 'a48o2S1cPoo',
3119 'title': 'The Young Turks - Live Main Show',
3120 'uploader': 'The Young Turks',
3121 'uploader_id': 'TheYoungTurks',
3122 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/TheYoungTurks',
3123 'upload_date': '20150715',
3124 'license': 'Standard YouTube License',
3125 'description': 'md5:438179573adcdff3c97ebb1ee632b891',
3126 'categories': ['News & Politics'],
3127 'tags': ['Cenk Uygur (TV Program Creator)', 'The Young Turks (Award-Winning Work)', 'Talk Show (TV Genre)'],
3129 'dislike_count': int,
3132 'skip_download': True,
3135 'url': 'https://www.youtube.com/channel/UC1yBKRuGpC1tSM73A0ZjYjQ/live',
3136 'only_matching': True,
3138 'url': 'https://www.youtube.com/c/CommanderVideoHq/live',
3139 'only_matching': True,
3141 'url': 'https://www.youtube.com/TheYoungTurks/live',
3142 'only_matching': True,
3145 def _real_extract(self, url):
3146 mobj = re.match(self._VALID_URL, url)
3147 channel_id = mobj.group('id')
3148 base_url = mobj.group('base_url')
3149 webpage = self._download_webpage(url, channel_id, fatal=False)
3151 page_type = self._og_search_property(
3152 'type', webpage, 'page type', default='')
3153 video_id = self._html_search_meta(
3154 'videoId', webpage, 'video id', default=None)
3155 if page_type.startswith('video') and video_id and re.match(
3156 r'^[0-9A-Za-z_-]{11}$', video_id):
3157 return self.url_result(video_id, YoutubeIE.ie_key())
3158 return self.url_result(base_url)
3161 class YoutubePlaylistsIE(YoutubePlaylistsBaseInfoExtractor):
3162 IE_DESC = 'YouTube.com user/channel playlists'
3163 _VALID_URL = r'https?://(?:\w+\.)?youtube\.com/(?:user|channel|c)/(?P<id>[^/]+)/playlists'
3164 IE_NAME = 'youtube:playlists'
3167 'url': 'https://www.youtube.com/user/ThirstForScience/playlists',
3168 'playlist_mincount': 4,
3170 'id': 'ThirstForScience',
3171 'title': 'ThirstForScience',
3174 # with "Load more" button
3175 'url': 'https://www.youtube.com/user/igorkle1/playlists?view=1&sort=dd',
3176 'playlist_mincount': 70,
3179 'title': 'Игорь Клейнер',
3182 'url': 'https://www.youtube.com/channel/UCiU1dHvZObB2iP6xkJ__Icw/playlists',
3183 'playlist_mincount': 17,
3185 'id': 'UCiU1dHvZObB2iP6xkJ__Icw',
3186 'title': 'Chem Player',
3190 'url': 'https://www.youtube.com/c/ChristophLaimer/playlists',
3191 'only_matching': True,
3195 class YoutubeSearchBaseInfoExtractor(YoutubePlaylistBaseInfoExtractor):
3196 _VIDEO_RE = r'href="\s*/watch\?v=(?P<id>[0-9A-Za-z_-]{11})(?:[^"]*"[^>]+\btitle="(?P<title>[^"]+))?'
3199 class YoutubeSearchIE(SearchInfoExtractor, YoutubeSearchBaseInfoExtractor):
3200 IE_DESC = 'YouTube.com searches'
3201 # there doesn't appear to be a real limit, for example if you search for
3202 # 'python' you get more than 8.000.000 results
3203 _MAX_RESULTS = float('inf')
3204 IE_NAME = 'youtube:search'
3205 _SEARCH_KEY = 'ytsearch'
3206 _SEARCH_PARAMS = None
3209 def _entries(self, query, n):
3213 'clientName': 'WEB',
3214 'clientVersion': '2.20201021.03.00',
3219 if self._SEARCH_PARAMS:
3220 data['params'] = self._SEARCH_PARAMS
3222 for page_num in itertools.count(1):
3223 search = self._download_json(
3224 'https://www.youtube.com/youtubei/v1/search?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
3225 video_id='query "%s"' % query,
3226 note='Downloading page %s' % page_num,
3227 errnote='Unable to download API page', fatal=False,
3228 data=json.dumps(data).encode('utf8'),
3229 headers={'content-type': 'application/json'})
3232 slr_contents = try_get(
3234 (lambda x: x['contents']['twoColumnSearchResultsRenderer']['primaryContents']['sectionListRenderer']['contents'],
3235 lambda x: x['onResponseReceivedCommands'][0]['appendContinuationItemsAction']['continuationItems']),
3237 if not slr_contents:
3239 isr_contents = try_get(
3241 lambda x: x[0]['itemSectionRenderer']['contents'],
3243 if not isr_contents:
3245 for content in isr_contents:
3246 if not isinstance(content, dict):
3248 video = content.get('videoRenderer')
3249 if not isinstance(video, dict):
3251 video_id = video.get('videoId')
3254 title = try_get(video, lambda x: x['title']['runs'][0]['text'], compat_str)
3255 description = try_get(video, lambda x: x['descriptionSnippet']['runs'][0]['text'], compat_str)
3256 duration = parse_duration(try_get(video, lambda x: x['lengthText']['simpleText'], compat_str))
3257 view_count_text = try_get(video, lambda x: x['viewCountText']['simpleText'], compat_str) or ''
3258 view_count = int_or_none(self._search_regex(
3259 r'^(\d+)', re.sub(r'\s', '', view_count_text),
3260 'view count', default=None))
3261 uploader = try_get(video, lambda x: x['ownerText']['runs'][0]['text'], compat_str)
3264 '_type': 'url_transparent',
3265 'ie_key': YoutubeIE.ie_key(),
3269 'description': description,
3270 'duration': duration,
3271 'view_count': view_count,
3272 'uploader': uploader,
3278 lambda x: x[1]['continuationItemRenderer']['continuationEndpoint']['continuationCommand']['token'],
3282 data['continuation'] = token
3284 def _get_n_results(self, query, n):
3285 """Get a specified number of results for a query"""
3286 return self.playlist_result(self._entries(query, n), query)
3289 class YoutubeSearchDateIE(YoutubeSearchIE):
3290 IE_NAME = YoutubeSearchIE.IE_NAME + ':date'
3291 _SEARCH_KEY = 'ytsearchdate'
3292 IE_DESC = 'YouTube.com searches, newest videos first'
3293 _SEARCH_PARAMS = 'CAI%3D'
3296 class YoutubeSearchURLIE(YoutubeSearchBaseInfoExtractor):
3297 IE_DESC = 'YouTube.com search URLs'
3298 IE_NAME = 'youtube:search_url'
3299 _VALID_URL = r'https?://(?:www\.)?youtube\.com/results\?(.*?&)?(?:search_query|q)=(?P<query>[^&]+)(?:[&]|$)'
3300 _SEARCH_DATA = r'(?:window\["ytInitialData"\]|ytInitialData)\W?=\W?({.*?});'
3302 'url': 'https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video',
3303 'playlist_mincount': 5,
3305 'title': 'youtube-dl test video',
3308 'url': 'https://www.youtube.com/results?q=test&sp=EgQIBBgB',
3309 'only_matching': True,
3312 def _find_videos_in_json(self, extracted):
3315 def _real_find(obj):
3316 if obj is None or isinstance(obj, str):
3319 if type(obj) is list:
3323 if type(obj) is dict:
3324 if "videoId" in obj:
3328 for _, o in obj.items():
3331 _real_find(extracted)
3335 def extract_videos_from_page_impl(self, page, ids_in_page, titles_in_page):
3336 search_response = self._parse_json(self._search_regex(self._SEARCH_DATA, page, 'ytInitialData'), None)
3338 result_items = self._find_videos_in_json(search_response)
3340 for renderer in result_items:
3341 video_id = try_get(renderer, lambda x: x['videoId'])
3342 video_title = try_get(renderer, lambda x: x['title']['runs'][0]['text']) or try_get(renderer, lambda x: x['title']['simpleText'])
3344 if video_id is None or video_title is None:
3345 # we do not have a videoRenderer or title extraction broke
3348 video_title = video_title.strip()
3351 idx = ids_in_page.index(video_id)
3352 if video_title and not titles_in_page[idx]:
3353 titles_in_page[idx] = video_title
3355 ids_in_page.append(video_id)
3356 titles_in_page.append(video_title)
3358 def extract_videos_from_page(self, page):
3361 self.extract_videos_from_page_impl(page, ids_in_page, titles_in_page)
3362 return zip(ids_in_page, titles_in_page)
3364 def _real_extract(self, url):
3365 mobj = re.match(self._VALID_URL, url)
3366 query = compat_urllib_parse_unquote_plus(mobj.group('query'))
3367 webpage = self._download_webpage(url, query)
3368 return self.playlist_result(self._process_page(webpage), playlist_title=query)
3371 class YoutubeShowIE(YoutubePlaylistsBaseInfoExtractor):
3372 IE_DESC = 'YouTube.com (multi-season) shows'
3373 _VALID_URL = r'https?://(?:www\.)?youtube\.com/show/(?P<id>[^?#]*)'
3374 IE_NAME = 'youtube:show'
3376 'url': 'https://www.youtube.com/show/airdisasters',
3377 'playlist_mincount': 5,
3379 'id': 'airdisasters',
3380 'title': 'Air Disasters',
3384 def _real_extract(self, url):
3385 playlist_id = self._match_id(url)
3386 return super(YoutubeShowIE, self)._real_extract(
3387 'https://www.youtube.com/show/%s/playlists' % playlist_id)
3390 class YoutubeFeedsInfoExtractor(YoutubeBaseInfoExtractor):
3392 Base class for feed extractors
3393 Subclasses must define the _FEED_NAME and _PLAYLIST_TITLE properties.
3395 _LOGIN_REQUIRED = True
3396 _FEED_DATA = r'(?:window\["ytInitialData"\]|ytInitialData)\W?=\W?({.*?});'
3397 _YTCFG_DATA = r"ytcfg.set\(({.*?})\)"
3401 return 'youtube:%s' % self._FEED_NAME
3403 def _real_initialize(self):
3406 def _find_videos_in_json(self, extracted):
3410 def _real_find(obj):
3411 if obj is None or isinstance(obj, str):
3414 if type(obj) is list:
3418 if type(obj) is dict:
3419 if "videoId" in obj:
3423 if "nextContinuationData" in obj:
3424 c["continuation"] = obj["nextContinuationData"]
3427 for _, o in obj.items():
3430 _real_find(extracted)
3432 return videos, try_get(c, lambda x: x["continuation"])
3434 def _entries(self, page):
3437 yt_conf = self._parse_json(self._search_regex(self._YTCFG_DATA, page, 'ytcfg.set', default="null"), None, fatal=False)
3439 search_response = self._parse_json(self._search_regex(self._FEED_DATA, page, 'ytInitialData'), None)
3441 for page_num in itertools.count(1):
3442 video_info, continuation = self._find_videos_in_json(search_response)
3446 for v in video_info:
3447 v_id = try_get(v, lambda x: x['videoId'])
3453 if old['videoId'] == v_id:
3463 info.extend(new_info)
3465 for video in new_info:
3466 yield self.url_result(try_get(video, lambda x: x['videoId']), YoutubeIE.ie_key(), video_title=try_get(video, lambda x: x['title']['runs'][0]['text']) or try_get(video, lambda x: x['title']['simpleText']))
3468 if not continuation or not yt_conf:
3471 search_response = self._download_json(
3472 'https://www.youtube.com/browse_ajax', self._PLAYLIST_TITLE,
3473 'Downloading page #%s' % page_num,
3474 transform_source=uppercase_escape,
3476 "ctoken": try_get(continuation, lambda x: x["continuation"]),
3477 "continuation": try_get(continuation, lambda x: x["continuation"]),
3478 "itct": try_get(continuation, lambda x: x["clickTrackingParams"])
3481 "X-YouTube-Client-Name": try_get(yt_conf, lambda x: x["INNERTUBE_CONTEXT_CLIENT_NAME"]),
3482 "X-YouTube-Client-Version": try_get(yt_conf, lambda x: x["INNERTUBE_CONTEXT_CLIENT_VERSION"]),
3483 "X-Youtube-Identity-Token": try_get(yt_conf, lambda x: x["ID_TOKEN"]),
3484 "X-YouTube-Device": try_get(yt_conf, lambda x: x["DEVICE"]),
3485 "X-YouTube-Page-CL": try_get(yt_conf, lambda x: x["PAGE_CL"]),
3486 "X-YouTube-Page-Label": try_get(yt_conf, lambda x: x["PAGE_BUILD_LABEL"]),
3487 "X-YouTube-Variants-Checksum": try_get(yt_conf, lambda x: x["VARIANTS_CHECKSUM"]),
3490 def _real_extract(self, url):
3491 page = self._download_webpage(
3492 'https://www.youtube.com/feed/%s' % self._FEED_NAME,
3493 self._PLAYLIST_TITLE)
3494 return self.playlist_result(
3495 self._entries(page), playlist_title=self._PLAYLIST_TITLE)
3498 class YoutubeWatchLaterIE(YoutubePlaylistIE):
3499 IE_NAME = 'youtube:watchlater'
3500 IE_DESC = 'Youtube watch later list, ":ytwatchlater" for short (requires authentication)'
3501 _VALID_URL = r'https?://(?:www\.)?youtube\.com/(?:feed/watch_later|(?:playlist|watch)\?(?:.+&)?list=WL)|:ytwatchlater'
3504 'url': 'https://www.youtube.com/playlist?list=WL',
3505 'only_matching': True,
3507 'url': 'https://www.youtube.com/watch?v=bCNU9TrbiRk&index=1&list=WL',
3508 'only_matching': True,
3511 def _real_extract(self, url):
3512 _, video = self._check_download_just_video(url, 'WL')
3515 _, playlist = self._extract_playlist('WL')
3519 class YoutubeFavouritesIE(YoutubeBaseInfoExtractor):
3520 IE_NAME = 'youtube:favorites'
3521 IE_DESC = 'YouTube.com favourite videos, ":ytfav" for short (requires authentication)'
3522 _VALID_URL = r'https?://(?:www\.)?youtube\.com/my_favorites|:ytfav(?:ou?rites)?'
3523 _LOGIN_REQUIRED = True
3525 def _real_extract(self, url):
3526 webpage = self._download_webpage('https://www.youtube.com/my_favorites', 'Youtube Favourites videos')
3527 playlist_id = self._search_regex(r'list=(.+?)["&]', webpage, 'favourites playlist id')
3528 return self.url_result(playlist_id, 'YoutubePlaylist')
3531 class YoutubeRecommendedIE(YoutubeFeedsInfoExtractor):
3532 IE_DESC = 'YouTube.com recommended videos, ":ytrec" for short (requires authentication)'
3533 _VALID_URL = r'https?://(?:www\.)?youtube\.com/feed/recommended|:ytrec(?:ommended)?'
3534 _FEED_NAME = 'recommended'
3535 _PLAYLIST_TITLE = 'Youtube Recommended videos'
3538 class YoutubeSubscriptionsIE(YoutubeFeedsInfoExtractor):
3539 IE_DESC = 'YouTube.com subscriptions feed, "ytsubs" keyword (requires authentication)'
3540 _VALID_URL = r'https?://(?:www\.)?youtube\.com/feed/subscriptions|:ytsubs(?:criptions)?'
3541 _FEED_NAME = 'subscriptions'
3542 _PLAYLIST_TITLE = 'Youtube Subscriptions'
3545 class YoutubeHistoryIE(YoutubeFeedsInfoExtractor):
3546 IE_DESC = 'Youtube watch history, ":ythistory" for short (requires authentication)'
3547 _VALID_URL = r'https?://(?:www\.)?youtube\.com/feed/history|:ythistory'
3548 _FEED_NAME = 'history'
3549 _PLAYLIST_TITLE = 'Youtube History'
3552 class YoutubeTruncatedURLIE(InfoExtractor):
3553 IE_NAME = 'youtube:truncated_url'
3554 IE_DESC = False # Do not list
3555 _VALID_URL = r'''(?x
)
3557 (?
:\w
+\
.)?
[yY
][oO
][uU
][tT
][uU
][bB
][eE
](?
:-nocookie
)?\
.com
/
3560 annotation_id
=annotation_
[^
&]+|
3566 attribution_link
\?a
=[^
&]+
3572 'url': 'https://www.youtube.com/watch?annotation_id=annotation_3951667041',
3573 'only_matching': True,
3575 'url': 'https://www.youtube.com/watch?',
3576 'only_matching': True,
3578 'url': 'https://www.youtube.com/watch?x-yt-cl=84503534',
3579 'only_matching': True,
3581 'url': 'https://www.youtube.com/watch?feature=foo',
3582 'only_matching': True,
3584 'url': 'https://www.youtube.com/watch?hl=en-GB',
3585 'only_matching': True,
3587 'url': 'https://www.youtube.com/watch?t=2372',
3588 'only_matching': True,
3591 def _real_extract(self, url):
3592 raise ExtractorError(
3593 'Did you forget to quote the URL? Remember that & is a meta '
3594 'character in most shells, so you want to put the URL in quotes, '
3596 '"https://www.youtube.com/watch?feature=foo&v=BaW_jenozKc" '
3597 ' or simply youtube-dl BaW_jenozKc .',
3601 class YoutubeTruncatedIDIE(InfoExtractor):
3602 IE_NAME = 'youtube:truncated_id'
3603 IE_DESC = False # Do not list
3604 _VALID_URL = r'https?://(?:www\.)?youtube\.com/watch\?v=(?P<id>[0-9A-Za-z_-]{1,10})$'
3607 'url': 'https://www.youtube.com/watch?v=N_708QY7Ob',
3608 'only_matching': True,
3611 def _real_extract(self, url):
3612 video_id = self._match_id(url)
3613 raise ExtractorError(
3614 'Incomplete YouTube ID %s. URL %s looks truncated.' % (video_id, url),