3 from __future__ import unicode_literals
12 from .common import InfoExtractor, SearchInfoExtractor
13 from ..compat import (
18 compat_urllib_parse_unquote_plus,
19 compat_urllib_parse_urlencode,
20 compat_urllib_parse_urlparse,
23 from ..jsinterp import JSInterpreter
49 class YoutubeBaseInfoExtractor(InfoExtractor):
50 """Provide base functions for Youtube extractors"""
51 _LOGIN_URL = 'https://accounts.google.com/ServiceLogin'
52 _TWOFACTOR_URL = 'https://accounts.google.com/signin/challenge'
54 _LOOKUP_URL = 'https://accounts.google.com/_/signin/sl/lookup'
55 _CHALLENGE_URL = 'https://accounts.google.com/_/signin/sl/challenge'
56 _TFA_URL = 'https://accounts.google.com/_/signin/challenge?hl=en&TL={0}'
58 _NETRC_MACHINE = 'youtube'
59 # If True it will raise an error if no login info is provided
60 _LOGIN_REQUIRED = False
62 _PLAYLIST_ID_RE = r'(?:(?:PL|LL|EC|UU|FL|RD|UL|TL|PU|OLAK5uy_)[0-9A-Za-z-_]{10,}|RDMM)'
64 def _ids_to_results(self, ids):
66 self.url_result(vid_id, 'Youtube', video_id=vid_id)
71 Attempt to log in to YouTube.
72 True is returned if successful or skipped.
73 False is returned if login failed.
75 If _LOGIN_REQUIRED is set and no authentication was provided, an error is raised.
77 username, password = self._get_login_info()
78 # No authentication to be performed
80 if self._LOGIN_REQUIRED and self._downloader.params.get('cookiefile') is None:
81 raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True)
84 login_page = self._download_webpage(
85 self._LOGIN_URL, None,
86 note='Downloading login page',
87 errnote='unable to fetch login page', fatal=False)
88 if login_page is False:
91 login_form = self._hidden_inputs(login_page)
93 def req(url, f_req, note, errnote):
94 data = login_form.copy()
97 'checkConnection': 'youtube',
98 'checkedDomains': 'youtube',
100 'deviceinfo': '[null,null,null,[],null,"US",null,null,[],"GlifWebSignIn",null,[null,null,[]]]',
101 'f.req': json.dumps(f_req),
102 'flowName': 'GlifWebSignIn',
103 'flowEntry': 'ServiceLogin',
104 # TODO: reverse actual botguard identifier generation algo
105 'bgRequest': '["identifier",""]',
107 return self._download_json(
108 url, None, note=note, errnote=errnote,
109 transform_source=lambda s: re.sub(r'^[^[]*', '', s),
111 data=urlencode_postdata(data), headers={
112 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
113 'Google-Accounts-XSRF': 1,
117 self._downloader.report_warning(message)
121 None, [], None, 'US', None, None, 2, False, True,
125 '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',
127 1, [None, None, []], None, None, None, True
132 lookup_results = req(
133 self._LOOKUP_URL, lookup_req,
134 'Looking up account info', 'Unable to look up account info')
136 if lookup_results is False:
139 user_hash = try_get(lookup_results, lambda x: x[0][2], compat_str)
141 warn('Unable to extract user hash')
146 None, 1, None, [1, None, None, None, [password, None, True]],
148 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],
149 1, [None, None, []], None, None, None, True
152 challenge_results = req(
153 self._CHALLENGE_URL, challenge_req,
154 'Logging in', 'Unable to log in')
156 if challenge_results is False:
159 login_res = try_get(challenge_results, lambda x: x[0][5], list)
161 login_msg = try_get(login_res, lambda x: x[5], compat_str)
163 'Unable to login: %s' % 'Invalid password'
164 if login_msg == 'INCORRECT_ANSWER_ENTERED' else login_msg)
167 res = try_get(challenge_results, lambda x: x[0][-1], list)
169 warn('Unable to extract result entry')
172 login_challenge = try_get(res, lambda x: x[0][0], list)
174 challenge_str = try_get(login_challenge, lambda x: x[2], compat_str)
175 if challenge_str == 'TWO_STEP_VERIFICATION':
176 # SEND_SUCCESS - TFA code has been successfully sent to phone
177 # QUOTA_EXCEEDED - reached the limit of TFA codes
178 status = try_get(login_challenge, lambda x: x[5], compat_str)
179 if status == 'QUOTA_EXCEEDED':
180 warn('Exceeded the limit of TFA codes, try later')
183 tl = try_get(challenge_results, lambda x: x[1][2], compat_str)
185 warn('Unable to extract TL')
188 tfa_code = self._get_tfa_info('2-step verification code')
192 'Two-factor authentication required. Provide it either interactively or with --twofactor <code>'
193 '(Note that only TOTP (Google Authenticator App) codes work at this time.)')
196 tfa_code = remove_start(tfa_code, 'G-')
199 user_hash, None, 2, None,
201 9, None, None, None, None, None, None, None,
202 [None, tfa_code, True, 2]
206 self._TFA_URL.format(tl), tfa_req,
207 'Submitting TFA code', 'Unable to submit TFA code')
209 if tfa_results is False:
212 tfa_res = try_get(tfa_results, lambda x: x[0][5], list)
214 tfa_msg = try_get(tfa_res, lambda x: x[5], compat_str)
216 'Unable to finish TFA: %s' % 'Invalid TFA code'
217 if tfa_msg == 'INCORRECT_ANSWER_ENTERED' else tfa_msg)
220 check_cookie_url = try_get(
221 tfa_results, lambda x: x[0][-1][2], compat_str)
224 'LOGIN_CHALLENGE': "This device isn't recognized. For your security, Google wants to make sure it's really you.",
225 'USERNAME_RECOVERY': 'Please provide additional information to aid in the recovery process.',
226 'REAUTH': "There is something unusual about your activity. For your security, Google wants to make sure it's really you.",
228 challenge = CHALLENGES.get(
230 '%s returned error %s.' % (self.IE_NAME, challenge_str))
231 warn('%s\nGo to https://accounts.google.com/, login and solve a challenge.' % challenge)
234 check_cookie_url = try_get(res, lambda x: x[2], compat_str)
236 if not check_cookie_url:
237 warn('Unable to extract CheckCookie URL')
240 check_cookie_results = self._download_webpage(
241 check_cookie_url, None, 'Checking cookie', fatal=False)
243 if check_cookie_results is False:
246 if 'https://myaccount.google.com/' not in check_cookie_results:
247 warn('Unable to log in')
252 def _initialize_consent(self):
253 cookies = self._get_cookies('https://www.youtube.com/')
254 if cookies.get('__Secure-3PSID'):
257 consent = cookies.get('CONSENT')
259 if 'YES' in consent.value:
261 consent_id = self._search_regex(
262 r'PENDING\+(\d+)', consent.value, 'consent', default=None)
264 consent_id = random.randint(100, 999)
265 self._set_cookie('.youtube.com', 'CONSENT', 'YES+cb.20210328-17-p0.en+FX+%s' % consent_id)
267 def _real_initialize(self):
268 self._initialize_consent()
269 if self._downloader is None:
271 if not self._login():
274 _DEFAULT_API_DATA = {
278 'clientVersion': '2.20201021.03.00',
283 _YT_INITIAL_DATA_RE = r'(?:window\s*\[\s*["\']ytInitialData["\']\s*\]|ytInitialData)\s*=\s*({.+?})\s*;'
284 _YT_INITIAL_PLAYER_RESPONSE_RE = r'ytInitialPlayerResponse\s*=\s*({.+?})\s*;'
285 _YT_INITIAL_BOUNDARY_RE = r'(?:var\s+meta|</script|\n)'
287 def _call_api(self, ep, query, video_id, fatal=True):
288 data = self._DEFAULT_API_DATA.copy()
291 return self._download_json(
292 'https://www.youtube.com/youtubei/v1/%s' % ep, video_id=video_id,
293 note='Downloading API JSON', errnote='Unable to download API page',
294 data=json.dumps(data).encode('utf8'), fatal=fatal,
295 headers={'content-type': 'application/json'},
296 query={'key': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8'})
298 def _extract_yt_initial_data(self, video_id, webpage):
299 return self._parse_json(
301 (r'%s\s*%s' % (self._YT_INITIAL_DATA_RE, self._YT_INITIAL_BOUNDARY_RE),
302 self._YT_INITIAL_DATA_RE), webpage, 'yt initial data'),
305 def _extract_ytcfg(self, video_id, webpage):
306 return self._parse_json(
308 r'ytcfg\.set\s*\(\s*({.+?})\s*\)\s*;', webpage, 'ytcfg',
309 default='{}'), video_id, fatal=False)
311 def _extract_video(self, renderer):
312 video_id = renderer['videoId']
315 (lambda x: x['title']['runs'][0]['text'],
316 lambda x: x['title']['simpleText']), compat_str)
317 description = try_get(
318 renderer, lambda x: x['descriptionSnippet']['runs'][0]['text'],
320 duration = parse_duration(try_get(
321 renderer, lambda x: x['lengthText']['simpleText'], compat_str))
322 view_count_text = try_get(
323 renderer, lambda x: x['viewCountText']['simpleText'], compat_str) or ''
324 view_count = str_to_int(self._search_regex(
325 r'^([\d,]+)', re.sub(r'\s', '', view_count_text),
326 'view count', default=None))
329 (lambda x: x['ownerText']['runs'][0]['text'],
330 lambda x: x['shortBylineText']['runs'][0]['text']), compat_str)
333 'ie_key': YoutubeIE.ie_key(),
337 'description': description,
338 'duration': duration,
339 'view_count': view_count,
340 'uploader': uploader,
344 class YoutubeIE(YoutubeBaseInfoExtractor):
345 IE_DESC = 'YouTube.com'
347 # invidious-redirect websites
348 r'(?:www\.)?redirect\.invidious\.io',
349 r'(?:(?:www|dev)\.)?invidio\.us',
350 # Invidious instances taken from https://github.com/iv-org/documentation/blob/master/Invidious-Instances.md
351 r'(?:(?:www|no)\.)?invidiou\.sh',
352 r'(?:(?:www|fi)\.)?invidious\.snopyta\.org',
353 r'(?:www\.)?invidious\.kabi\.tk',
354 r'(?:www\.)?invidious\.13ad\.de',
355 r'(?:www\.)?invidious\.mastodon\.host',
356 r'(?:www\.)?invidious\.zapashcanon\.fr',
357 r'(?:www\.)?invidious\.kavin\.rocks',
358 r'(?:www\.)?invidious\.tube',
359 r'(?:www\.)?invidiou\.site',
360 r'(?:www\.)?invidious\.site',
361 r'(?:www\.)?invidious\.xyz',
362 r'(?:www\.)?invidious\.nixnet\.xyz',
363 r'(?:www\.)?invidious\.drycat\.fr',
364 r'(?:www\.)?tube\.poal\.co',
365 r'(?:www\.)?tube\.connect\.cafe',
366 r'(?:www\.)?vid\.wxzm\.sx',
367 r'(?:www\.)?vid\.mint\.lgbt',
368 r'(?:www\.)?yewtu\.be',
369 r'(?:www\.)?yt\.elukerio\.org',
370 r'(?:www\.)?yt\.lelux\.fi',
371 r'(?:www\.)?invidious\.ggc-project\.de',
372 r'(?:www\.)?yt\.maisputain\.ovh',
373 r'(?:www\.)?invidious\.13ad\.de',
374 r'(?:www\.)?invidious\.toot\.koeln',
375 r'(?:www\.)?invidious\.fdn\.fr',
376 r'(?:www\.)?watch\.nettohikari\.com',
377 r'(?:www\.)?kgg2m7yk5aybusll\.onion',
378 r'(?:www\.)?qklhadlycap4cnod\.onion',
379 r'(?:www\.)?axqzx4s6s54s32yentfqojs3x5i7faxza6xo3ehd4bzzsg2ii4fv2iid\.onion',
380 r'(?:www\.)?c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid\.onion',
381 r'(?:www\.)?fz253lmuao3strwbfbmx46yu7acac2jz27iwtorgmbqlkurlclmancad\.onion',
382 r'(?:www\.)?invidious\.l4qlywnpwqsluw65ts7md3khrivpirse744un3x7mlskqauz5pyuzgqd\.onion',
383 r'(?:www\.)?owxfohz4kjyv25fvlqilyxast7inivgiktls3th44jhk3ej3i7ya\.b32\.i2p',
384 r'(?:www\.)?4l2dgddgsrkf2ous66i6seeyi6etzfgrue332grh2n7madpwopotugyd\.onion',
386 _VALID_URL = r"""(?x)^
388 (?:https?://|//) # http(s):// or protocol-independent URL
389 (?:(?:(?:(?:\w+\.)?[yY][oO][uU][tT][uU][bB][eE](?:-nocookie|kids)?\.com|
390 (?:www\.)?deturl\.com/www\.youtube\.com|
391 (?:www\.)?pwnyoutube\.com|
392 (?:www\.)?hooktube\.com|
393 (?:www\.)?yourepeat\.com|
396 youtube\.googleapis\.com)/ # the various hostnames, with wildcard subdomains
397 (?:.*?\#/)? # handle anchor (#/) redirect urls
398 (?: # the various things that can precede the ID:
399 (?:(?:v|embed|e)/(?!videoseries)) # v/ or embed/ or e/
400 |(?: # or the v= param in all its forms
401 (?:(?:watch|movie)(?:_popup)?(?:\.php)?/?)? # preceding watch(_popup|.php) or nothing (like /?v=xxxx)
402 (?:\?|\#!?) # the params delimiter ? or # or #!
403 (?:.*?[&;])?? # any other preceding param (like /?s=tuff&v=xxxx or ?s=tuff&v=V36LpHqtcDY)
408 youtu\.be| # just youtu.be/xxxx
409 vid\.plus| # or vid.plus/xxxx
410 zwearz\.com/watch| # or zwearz.com/watch/xxxx
413 |(?:www\.)?cleanvideosearch\.com/media/action/yt/watch\?videoId=
415 )? # all until now is optional -> you can pass the naked ID
416 (?P<id>[0-9A-Za-z_-]{11}) # here is it! the YouTube video ID
419 %(playlist_id)s| # combined list/video URLs are handled by the playlist IE
420 WL # WL are handled by the watch later IE
423 (?(1).+)? # if we found the ID, everything can follow
425 'playlist_id': YoutubeBaseInfoExtractor._PLAYLIST_ID_RE,
426 'invidious': '|'.join(_INVIDIOUS_SITES),
429 r'/s/player/(?P<id>[a-zA-Z0-9_-]{8,})/player',
430 r'/(?P<id>[a-zA-Z0-9_-]{8,})/player(?:_ias\.vflset(?:/[a-zA-Z]{2,3}_[a-zA-Z]{2,3})?|-plasma-ias-(?:phone|tablet)-[a-z]{2}_[A-Z]{2}\.vflset)/base\.js$',
431 r'\b(?P<id>vfl[a-zA-Z0-9_-]+)\b.*?\.js$',
433 _SUBTITLE_FORMATS = ('srv1', 'srv2', 'srv3', 'ttml', 'vtt')
440 'url': 'https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9',
444 'title': 'youtube-dl test video "\'/\\ä↭𝕐',
445 'uploader': 'Philipp Hagemeister',
446 'uploader_id': 'phihag',
447 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/phihag',
448 'channel_id': 'UCLqxVugv74EIW3VWh2NOa3Q',
449 'channel_url': r're:https?://(?:www\.)?youtube\.com/channel/UCLqxVugv74EIW3VWh2NOa3Q',
450 'upload_date': '20121002',
451 '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 .',
452 'categories': ['Science & Technology'],
453 'tags': ['youtube-dl'],
457 'dislike_count': int,
463 'url': '//www.YouTube.com/watch?v=yZIXLfi8CZQ',
464 'note': 'Embed-only video (#1746)',
468 'upload_date': '20120608',
469 'title': 'Principal Sexually Assaults A Teacher - Episode 117 - 8th June 2012',
470 'description': 'md5:09b78bd971f1e3e289601dfba15ca4f7',
471 'uploader': 'SET India',
472 'uploader_id': 'setindia',
473 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/setindia',
476 'skip': 'Private video',
479 'url': 'https://www.youtube.com/watch?v=BaW_jenozKc&v=yZIXLfi8CZQ',
480 'note': 'Use the first video ID in the URL',
484 'title': 'youtube-dl test video "\'/\\ä↭𝕐',
485 'uploader': 'Philipp Hagemeister',
486 'uploader_id': 'phihag',
487 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/phihag',
488 'upload_date': '20121002',
489 '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 .',
490 'categories': ['Science & Technology'],
491 'tags': ['youtube-dl'],
495 'dislike_count': int,
498 'skip_download': True,
502 'url': 'https://www.youtube.com/watch?v=a9LDPn-MO4I',
503 'note': '256k DASH audio (format 141) via DASH manifest',
507 'upload_date': '20121002',
508 'uploader_id': '8KVIDEO',
509 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/8KVIDEO',
511 'uploader': '8KVIDEO',
512 'title': 'UHDTV TEST 8K VIDEO.mp4'
515 'youtube_include_dash_manifest': True,
518 'skip': 'format 141 not served anymore',
520 # DASH manifest with encrypted signature
522 'url': 'https://www.youtube.com/watch?v=IB3lcPjvWLA',
526 'title': 'Afrojack, Spree Wilson - The Spark (Official Music Video) ft. Spree Wilson',
527 'description': 'md5:8f5e2b82460520b619ccac1f509d43bf',
529 'uploader': 'AfrojackVEVO',
530 'uploader_id': 'AfrojackVEVO',
531 'upload_date': '20131011',
535 'youtube_include_dash_manifest': True,
536 'format': '141/bestaudio[ext=m4a]',
541 'url': 'https://www.youtube.com/watch?v=T4XJQO3qol8',
546 'upload_date': '20100909',
547 'uploader': 'Amazing Atheist',
548 'uploader_id': 'TheAmazingAtheist',
549 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/TheAmazingAtheist',
550 'title': 'Burning Everyone\'s Koran',
551 'description': 'SUBSCRIBE: http://www.youtube.com/saturninefilms \r\n\r\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',
554 # Normal age-gate video (No vevo, embed allowed), available via embed page
556 'url': 'https://youtube.com/watch?v=HtVdAasjOgU',
560 'title': 'The Witcher 3: Wild Hunt - The Sword Of Destiny Trailer',
561 'description': r're:(?s).{100,}About the Game\n.*?The Witcher 3: Wild Hunt.{100,}',
563 'uploader': 'The Witcher',
564 'uploader_id': 'WitcherGame',
565 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/WitcherGame',
566 'upload_date': '20140605',
571 # Age-gated video only available with authentication (unavailable
572 # via embed page workaround)
573 'url': 'XgnwCQzjau8',
574 'only_matching': True,
576 # video_info is None (https://github.com/ytdl-org/youtube-dl/issues/4421)
577 # YouTube Red ad is not captured for creator
579 'url': '__2ABJjxzNo',
584 'upload_date': '20100430',
585 'uploader_id': 'deadmau5',
586 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/deadmau5',
587 'creator': 'deadmau5',
588 'description': 'md5:6cbcd3a92ce1bc676fc4d6ab4ace2336',
589 'uploader': 'deadmau5',
590 'title': 'Deadmau5 - Some Chords (HD)',
591 'alt_title': 'Some Chords',
593 'expected_warnings': [
594 'DASH manifest missing',
597 # Olympics (https://github.com/ytdl-org/youtube-dl/issues/4431)
599 'url': 'lqQg6PlCWgI',
604 'upload_date': '20150827',
605 'uploader_id': 'olympic',
606 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/olympic',
607 'description': 'HO09 - Women - GER-AUS - Hockey - 31 July 2012 - London 2012 Olympic Games',
608 'uploader': 'Olympic',
609 'title': 'Hockey - Women - GER-AUS - London 2012 Olympic Games',
612 'skip_download': 'requires avconv',
617 'url': 'https://www.youtube.com/watch?v=_b-2C3KPAM0',
621 'stretched_ratio': 16 / 9.,
623 'upload_date': '20110310',
624 'uploader_id': 'AllenMeow',
625 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/AllenMeow',
626 'description': 'made by Wacom from Korea | 字幕&加油添醋 by TY\'s Allen | 感謝heylisa00cavey1001同學熱情提供梗及翻譯',
628 'title': '[A-made] 變態妍字幕版 太妍 我就是這樣的人',
631 # url_encoded_fmt_stream_map is empty string
633 'url': 'qEJwOuvDf7I',
637 'title': 'Обсуждение судебной практики по выборам 14 сентября 2014 года в Санкт-Петербурге',
639 'upload_date': '20150404',
640 'uploader_id': 'spbelect',
641 'uploader': 'Наблюдатели Петербурга',
644 'skip_download': 'requires avconv',
646 'skip': 'This live event has ended.',
648 # Extraction from multiple DASH manifests (https://github.com/ytdl-org/youtube-dl/pull/6097)
650 'url': 'https://www.youtube.com/watch?v=FIl7x6_3R5Y',
654 'title': 'md5:7b81415841e02ecd4313668cde88737a',
655 'description': 'md5:116377fd2963b81ec4ce64b542173306',
657 'upload_date': '20150625',
658 'uploader_id': 'dorappi2000',
659 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/dorappi2000',
660 'uploader': 'dorappi2000',
661 'formats': 'mincount:31',
663 'skip': 'not actual anymore',
665 # DASH manifest with segment_list
667 'url': 'https://www.youtube.com/embed/CsmdDsKjzN8',
668 'md5': '8ce563a1d667b599d21064e982ab9e31',
672 'upload_date': '20150501', # According to '<meta itemprop="datePublished"', but in other places it's 20150510
673 'uploader': 'Airtek',
674 'description': 'Retransmisión en directo de la XVIII media maratón de Zaragoza.',
675 'uploader_id': 'UCzTzUmjXxxacNnL8I3m4LnQ',
676 'title': 'Retransmisión XVIII Media maratón Zaragoza 2015',
679 'youtube_include_dash_manifest': True,
680 'format': '135', # bestvideo
682 'skip': 'This live event has ended.',
685 # Multifeed videos (multiple cameras), URL is for Main Camera
686 'url': 'https://www.youtube.com/watch?v=jvGDaLqkpTg',
689 'title': 'Tom Clancy Free Weekend Rainbow Whatever',
690 'description': 'md5:e03b909557865076822aa169218d6a5d',
696 'title': 'Tom Clancy Free Weekend Rainbow Whatever (Main Camera)',
697 'description': 'md5:e03b909557865076822aa169218d6a5d',
699 'upload_date': '20161111',
700 'uploader': 'Team PGP',
701 'uploader_id': 'UChORY56LMMETTuGjXaJXvLg',
702 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UChORY56LMMETTuGjXaJXvLg',
708 'title': 'Tom Clancy Free Weekend Rainbow Whatever (Camera 2)',
709 'description': 'md5:e03b909557865076822aa169218d6a5d',
711 'upload_date': '20161111',
712 'uploader': 'Team PGP',
713 'uploader_id': 'UChORY56LMMETTuGjXaJXvLg',
714 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UChORY56LMMETTuGjXaJXvLg',
720 'title': 'Tom Clancy Free Weekend Rainbow Whatever (Camera 3)',
721 'description': 'md5:e03b909557865076822aa169218d6a5d',
723 'upload_date': '20161111',
724 'uploader': 'Team PGP',
725 'uploader_id': 'UChORY56LMMETTuGjXaJXvLg',
726 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UChORY56LMMETTuGjXaJXvLg',
732 'title': 'Tom Clancy Free Weekend Rainbow Whatever (Camera 4)',
733 'description': 'md5:e03b909557865076822aa169218d6a5d',
735 'upload_date': '20161111',
736 'uploader': 'Team PGP',
737 'uploader_id': 'UChORY56LMMETTuGjXaJXvLg',
738 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UChORY56LMMETTuGjXaJXvLg',
742 'skip_download': True,
746 # Multifeed video with comma in title (see https://github.com/ytdl-org/youtube-dl/issues/8536)
747 'url': 'https://www.youtube.com/watch?v=gVfLd0zydlo',
750 'title': 'DevConf.cz 2016 Day 2 Workshops 1 14:00 - 15:30',
753 'skip': 'Not multifeed anymore',
756 'url': 'https://vid.plus/FlRa-iH7PGw',
757 'only_matching': True,
760 'url': 'https://zwearz.com/watch/9lWxNJF-ufM/electra-woman-dyna-girl-official-trailer-grace-helbig.html',
761 'only_matching': True,
764 # Title with JS-like syntax "};" (see https://github.com/ytdl-org/youtube-dl/issues/7468)
765 # Also tests cut-off URL expansion in video description (see
766 # https://github.com/ytdl-org/youtube-dl/issues/1892,
767 # https://github.com/ytdl-org/youtube-dl/issues/8164)
768 'url': 'https://www.youtube.com/watch?v=lsguqyKfVQg',
772 'title': '{dark walk}; Loki/AC/Dishonored; collab w/Elflover21',
773 'alt_title': 'Dark Walk - Position Music',
774 'description': 'md5:8085699c11dc3f597ce0410b0dcbb34a',
776 'upload_date': '20151119',
777 'uploader_id': 'IronSoulElf',
778 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/IronSoulElf',
779 'uploader': 'IronSoulElf',
780 'creator': 'Todd Haberman, Daniel Law Heath and Aaron Kaplan',
781 'track': 'Dark Walk - Position Music',
782 'artist': 'Todd Haberman, Daniel Law Heath and Aaron Kaplan',
783 'album': 'Position Music - Production Music Vol. 143 - Dark Walk',
786 'skip_download': True,
790 # Tags with '};' (see https://github.com/ytdl-org/youtube-dl/issues/7468)
791 'url': 'https://www.youtube.com/watch?v=Ms7iBXnlUO8',
792 'only_matching': True,
795 # Video with yt:stretch=17:0
796 'url': 'https://www.youtube.com/watch?v=Q39EVAstoRM',
800 'title': 'Clash Of Clans#14 Dicas De Ataque Para CV 4',
801 'description': 'md5:ee18a25c350637c8faff806845bddee9',
802 'upload_date': '20151107',
803 'uploader_id': 'UCCr7TALkRbo3EtFzETQF1LA',
804 'uploader': 'CH GAMER DROID',
807 'skip_download': True,
809 'skip': 'This video does not exist.',
812 # Video licensed under Creative Commons
813 'url': 'https://www.youtube.com/watch?v=M4gD1WSo5mA',
817 'title': 'md5:e41008789470fc2533a3252216f1c1d1',
818 'description': 'md5:a677553cf0840649b731a3024aeff4cc',
820 'upload_date': '20150127',
821 'uploader_id': 'BerkmanCenter',
822 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/BerkmanCenter',
823 'uploader': 'The Berkman Klein Center for Internet & Society',
824 'license': 'Creative Commons Attribution license (reuse allowed)',
827 'skip_download': True,
831 # Channel-like uploader_url
832 'url': 'https://www.youtube.com/watch?v=eQcmzGIKrzg',
836 'title': 'Democratic Socialism and Foreign Policy | Bernie Sanders',
837 'description': 'md5:13a2503d7b5904ef4b223aa101628f39',
839 'upload_date': '20151119',
840 'uploader': 'Bernie Sanders',
841 'uploader_id': 'UCH1dpzjCEiGAt8CXkryhkZg',
842 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UCH1dpzjCEiGAt8CXkryhkZg',
843 'license': 'Creative Commons Attribution license (reuse allowed)',
846 'skip_download': True,
850 'url': 'https://www.youtube.com/watch?feature=player_embedded&amp;v=V36LpHqtcDY',
851 'only_matching': True,
854 # YouTube Red paid video (https://github.com/ytdl-org/youtube-dl/issues/10059)
855 'url': 'https://www.youtube.com/watch?v=i1Ko8UG-Tdo',
856 'only_matching': True,
859 # Rental video preview
860 'url': 'https://www.youtube.com/watch?v=yYr8q0y5Jfg',
864 'title': 'Piku - Trailer',
865 'description': 'md5:c36bd60c3fd6f1954086c083c72092eb',
866 'upload_date': '20150811',
867 'uploader': 'FlixMatrix',
868 'uploader_id': 'FlixMatrixKaravan',
869 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/FlixMatrixKaravan',
870 'license': 'Standard YouTube License',
873 'skip_download': True,
875 'skip': 'This video is not available.',
878 # YouTube Red video with episode data
879 'url': 'https://www.youtube.com/watch?v=iqKdEhx-dD4',
883 'title': 'Isolation - Mind Field (Ep 1)',
884 'description': 'md5:f540112edec5d09fc8cc752d3d4ba3cd',
886 'upload_date': '20170118',
887 'uploader': 'Vsauce',
888 'uploader_id': 'Vsauce',
889 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/Vsauce',
890 'series': 'Mind Field',
895 'skip_download': True,
897 'expected_warnings': [
898 'Skipping DASH manifest',
902 # The following content has been identified by the YouTube community
903 # as inappropriate or offensive to some audiences.
904 'url': 'https://www.youtube.com/watch?v=6SJNVb0GnPI',
908 'title': 'Race Differences in Intelligence',
909 'description': 'md5:5d161533167390427a1f8ee89a1fc6f1',
911 'upload_date': '20140124',
912 'uploader': 'New Century Foundation',
913 'uploader_id': 'UCEJYpZGqgUob0zVVEaLhvVg',
914 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UCEJYpZGqgUob0zVVEaLhvVg',
917 'skip_download': True,
919 'skip': 'This video has been removed for violating YouTube\'s policy on hate speech.',
923 'url': '1t24XAntNCY',
924 'only_matching': True,
927 # geo restricted to JP
928 'url': 'sJL6WA-aGkQ',
929 'only_matching': True,
932 'url': 'https://invidio.us/watch?v=BaW_jenozKc',
933 'only_matching': True,
936 'url': 'https://redirect.invidious.io/watch?v=BaW_jenozKc',
937 'only_matching': True,
940 # from https://nitter.pussthecat.org/YouTube/status/1360363141947944964#m
941 'url': 'https://redirect.invidious.io/Yh0AhrY9GjA',
942 'only_matching': True,
946 'url': 'https://www.youtube.com/watch?v=s7_qI6_mIXc',
947 'only_matching': True,
950 # Video with unsupported adaptive stream type formats
951 'url': 'https://www.youtube.com/watch?v=Z4Vy8R84T1U',
955 'title': 'saman SMAN 53 Jakarta(Sancety) opening COFFEE4th at SMAN 53 Jakarta',
956 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
958 'upload_date': '20130923',
959 'uploader': 'Amelia Putri Harwita',
960 'uploader_id': 'UCpOxM49HJxmC1qCalXyB3_Q',
961 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UCpOxM49HJxmC1qCalXyB3_Q',
962 'formats': 'maxcount:10',
965 'skip_download': True,
966 'youtube_include_dash_manifest': False,
968 'skip': 'not actual anymore',
971 # Youtube Music Auto-generated description
972 'url': 'https://music.youtube.com/watch?v=MgNrAu2pzNs',
976 'title': 'Voyeur Girl',
977 'description': 'md5:7ae382a65843d6df2685993e90a8628f',
978 'upload_date': '20190312',
979 'uploader': 'Stephen - Topic',
980 'uploader_id': 'UC-pWHpBjdGG69N9mM2auIAA',
982 'track': 'Voyeur Girl',
983 'album': 'it\'s too much love to know my dear',
984 'release_date': '20190313',
985 'release_year': 2019,
988 'skip_download': True,
992 'url': 'https://www.youtubekids.com/watch?v=3b8nCWDgZ6Q',
993 'only_matching': True,
996 # invalid -> valid video id redirection
997 'url': 'DJztXj2GPfl',
1001 'title': 'Panjabi MC - Mundian To Bach Ke (The Dictator Soundtrack)',
1002 'description': 'md5:bf577a41da97918e94fa9798d9228825',
1003 'upload_date': '20090125',
1004 'uploader': 'Prochorowka',
1005 'uploader_id': 'Prochorowka',
1006 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/Prochorowka',
1007 'artist': 'Panjabi MC',
1008 'track': 'Beware of the Boys (Mundian to Bach Ke) - Motivo Hi-Lectro Remix',
1009 'album': 'Beware of the Boys (Mundian To Bach Ke)',
1012 'skip_download': True,
1014 'skip': 'Video unavailable',
1017 # empty description results in an empty string
1018 'url': 'https://www.youtube.com/watch?v=x41yOUIvK2k',
1020 'id': 'x41yOUIvK2k',
1022 'title': 'IMG 3456',
1024 'upload_date': '20170613',
1025 'uploader_id': 'ElevageOrVert',
1026 'uploader': 'ElevageOrVert',
1029 'skip_download': True,
1033 # with '};' inside yt initial data (see [1])
1034 # see [2] for an example with '};' inside ytInitialPlayerResponse
1035 # 1. https://github.com/ytdl-org/youtube-dl/issues/27093
1036 # 2. https://github.com/ytdl-org/youtube-dl/issues/27216
1037 'url': 'https://www.youtube.com/watch?v=CHqg6qOn4no',
1039 'id': 'CHqg6qOn4no',
1041 'title': 'Part 77 Sort a list of simple types in c#',
1042 'description': 'md5:b8746fa52e10cdbf47997903f13b20dc',
1043 'upload_date': '20130831',
1044 'uploader_id': 'kudvenkat',
1045 'uploader': 'kudvenkat',
1048 'skip_download': True,
1052 # another example of '};' in ytInitialData
1053 'url': 'https://www.youtube.com/watch?v=gVfgbahppCY',
1054 'only_matching': True,
1057 'url': 'https://www.youtube.com/watch_popup?v=63RmMXCd_bQ',
1058 'only_matching': True,
1061 # https://github.com/ytdl-org/youtube-dl/pull/28094
1062 'url': 'OtqTfy26tG0',
1064 'id': 'OtqTfy26tG0',
1066 'title': 'Burn Out',
1067 'description': 'md5:8d07b84dcbcbfb34bc12a56d968b6131',
1068 'upload_date': '20141120',
1069 'uploader': 'The Cinematic Orchestra - Topic',
1070 'uploader_id': 'UCIzsJBIyo8hhpFm1NK0uLgw',
1071 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UCIzsJBIyo8hhpFm1NK0uLgw',
1072 'artist': 'The Cinematic Orchestra',
1073 'track': 'Burn Out',
1074 'album': 'Every Day',
1075 'release_data': None,
1076 'release_year': None,
1079 'skip_download': True,
1083 # controversial video, only works with bpctr when authenticated with cookies
1084 'url': 'https://www.youtube.com/watch?v=nGC3D_FkCmg',
1085 'only_matching': True,
1088 # restricted location, https://github.com/ytdl-org/youtube-dl/issues/28685
1089 'url': 'cBvYw8_A0vQ',
1091 'id': 'cBvYw8_A0vQ',
1093 'title': '4K Ueno Okachimachi Street Scenes 上野御徒町歩き',
1094 'description': 'md5:ea770e474b7cd6722b4c95b833c03630',
1095 'upload_date': '20201120',
1096 'uploader': 'Walk around Japan',
1097 'uploader_id': 'UC3o_t8PzBmXf5S9b7GLx1Mw',
1098 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UC3o_t8PzBmXf5S9b7GLx1Mw',
1101 'skip_download': True,
1106 '5': {'ext': 'flv', 'width': 400, 'height': 240, 'acodec': 'mp3', 'abr': 64, 'vcodec': 'h263'},
1107 '6': {'ext': 'flv', 'width': 450, 'height': 270, 'acodec': 'mp3', 'abr': 64, 'vcodec': 'h263'},
1108 '13': {'ext': '3gp', 'acodec': 'aac', 'vcodec': 'mp4v'},
1109 '17': {'ext': '3gp', 'width': 176, 'height': 144, 'acodec': 'aac', 'abr': 24, 'vcodec': 'mp4v'},
1110 '18': {'ext': 'mp4', 'width': 640, 'height': 360, 'acodec': 'aac', 'abr': 96, 'vcodec': 'h264'},
1111 '22': {'ext': 'mp4', 'width': 1280, 'height': 720, 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264'},
1112 '34': {'ext': 'flv', 'width': 640, 'height': 360, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'},
1113 '35': {'ext': 'flv', 'width': 854, 'height': 480, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'},
1114 # itag 36 videos are either 320x180 (BaW_jenozKc) or 320x240 (__2ABJjxzNo), abr varies as well
1115 '36': {'ext': '3gp', 'width': 320, 'acodec': 'aac', 'vcodec': 'mp4v'},
1116 '37': {'ext': 'mp4', 'width': 1920, 'height': 1080, 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264'},
1117 '38': {'ext': 'mp4', 'width': 4096, 'height': 3072, 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264'},
1118 '43': {'ext': 'webm', 'width': 640, 'height': 360, 'acodec': 'vorbis', 'abr': 128, 'vcodec': 'vp8'},
1119 '44': {'ext': 'webm', 'width': 854, 'height': 480, 'acodec': 'vorbis', 'abr': 128, 'vcodec': 'vp8'},
1120 '45': {'ext': 'webm', 'width': 1280, 'height': 720, 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8'},
1121 '46': {'ext': 'webm', 'width': 1920, 'height': 1080, 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8'},
1122 '59': {'ext': 'mp4', 'width': 854, 'height': 480, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'},
1123 '78': {'ext': 'mp4', 'width': 854, 'height': 480, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'},
1127 '82': {'ext': 'mp4', 'height': 360, 'format_note': '3D', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -20},
1128 '83': {'ext': 'mp4', 'height': 480, 'format_note': '3D', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -20},
1129 '84': {'ext': 'mp4', 'height': 720, 'format_note': '3D', 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264', 'preference': -20},
1130 '85': {'ext': 'mp4', 'height': 1080, 'format_note': '3D', 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264', 'preference': -20},
1131 '100': {'ext': 'webm', 'height': 360, 'format_note': '3D', 'acodec': 'vorbis', 'abr': 128, 'vcodec': 'vp8', 'preference': -20},
1132 '101': {'ext': 'webm', 'height': 480, 'format_note': '3D', 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8', 'preference': -20},
1133 '102': {'ext': 'webm', 'height': 720, 'format_note': '3D', 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8', 'preference': -20},
1135 # Apple HTTP Live Streaming
1136 '91': {'ext': 'mp4', 'height': 144, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 48, 'vcodec': 'h264', 'preference': -10},
1137 '92': {'ext': 'mp4', 'height': 240, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 48, 'vcodec': 'h264', 'preference': -10},
1138 '93': {'ext': 'mp4', 'height': 360, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -10},
1139 '94': {'ext': 'mp4', 'height': 480, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -10},
1140 '95': {'ext': 'mp4', 'height': 720, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 256, 'vcodec': 'h264', 'preference': -10},
1141 '96': {'ext': 'mp4', 'height': 1080, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 256, 'vcodec': 'h264', 'preference': -10},
1142 '132': {'ext': 'mp4', 'height': 240, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 48, 'vcodec': 'h264', 'preference': -10},
1143 '151': {'ext': 'mp4', 'height': 72, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 24, 'vcodec': 'h264', 'preference': -10},
1146 '133': {'ext': 'mp4', 'height': 240, 'format_note': 'DASH video', 'vcodec': 'h264'},
1147 '134': {'ext': 'mp4', 'height': 360, 'format_note': 'DASH video', 'vcodec': 'h264'},
1148 '135': {'ext': 'mp4', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'h264'},
1149 '136': {'ext': 'mp4', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'h264'},
1150 '137': {'ext': 'mp4', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'h264'},
1151 '138': {'ext': 'mp4', 'format_note': 'DASH video', 'vcodec': 'h264'}, # Height can vary (https://github.com/ytdl-org/youtube-dl/issues/4559)
1152 '160': {'ext': 'mp4', 'height': 144, 'format_note': 'DASH video', 'vcodec': 'h264'},
1153 '212': {'ext': 'mp4', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'h264'},
1154 '264': {'ext': 'mp4', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'h264'},
1155 '298': {'ext': 'mp4', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'h264', 'fps': 60},
1156 '299': {'ext': 'mp4', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'h264', 'fps': 60},
1157 '266': {'ext': 'mp4', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'h264'},
1160 '139': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'abr': 48, 'container': 'm4a_dash'},
1161 '140': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'abr': 128, 'container': 'm4a_dash'},
1162 '141': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'abr': 256, 'container': 'm4a_dash'},
1163 '256': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'container': 'm4a_dash'},
1164 '258': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'container': 'm4a_dash'},
1165 '325': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'dtse', 'container': 'm4a_dash'},
1166 '328': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'ec-3', 'container': 'm4a_dash'},
1169 '167': {'ext': 'webm', 'height': 360, 'width': 640, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1170 '168': {'ext': 'webm', 'height': 480, 'width': 854, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1171 '169': {'ext': 'webm', 'height': 720, 'width': 1280, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1172 '170': {'ext': 'webm', 'height': 1080, 'width': 1920, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1173 '218': {'ext': 'webm', 'height': 480, 'width': 854, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1174 '219': {'ext': 'webm', 'height': 480, 'width': 854, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1175 '278': {'ext': 'webm', 'height': 144, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp9'},
1176 '242': {'ext': 'webm', 'height': 240, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1177 '243': {'ext': 'webm', 'height': 360, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1178 '244': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1179 '245': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1180 '246': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1181 '247': {'ext': 'webm', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1182 '248': {'ext': 'webm', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1183 '271': {'ext': 'webm', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1184 # itag 272 videos are either 3840x2160 (e.g. RtoitU2A-3E) or 7680x4320 (sLprVF6d7Ug)
1185 '272': {'ext': 'webm', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1186 '302': {'ext': 'webm', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60},
1187 '303': {'ext': 'webm', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60},
1188 '308': {'ext': 'webm', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60},
1189 '313': {'ext': 'webm', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1190 '315': {'ext': 'webm', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60},
1193 '171': {'ext': 'webm', 'acodec': 'vorbis', 'format_note': 'DASH audio', 'abr': 128},
1194 '172': {'ext': 'webm', 'acodec': 'vorbis', 'format_note': 'DASH audio', 'abr': 256},
1196 # Dash webm audio with opus inside
1197 '249': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 50},
1198 '250': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 70},
1199 '251': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 160},
1202 '_rtmp': {'protocol': 'rtmp'},
1204 # av01 video only formats sometimes served with "unknown" codecs
1205 '394': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'},
1206 '395': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'},
1207 '396': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'},
1208 '397': {'acodec': 'none', 'vcodec': 'av01.0.05M.08'},
1211 def __init__(self, *args, **kwargs):
1212 super(YoutubeIE, self).__init__(*args, **kwargs)
1213 self._code_cache = {}
1214 self._player_cache = {}
1216 def _signature_cache_id(self, example_sig):
1217 """ Return a string representation of a signature """
1218 return '.'.join(compat_str(len(part)) for part in example_sig.split('.'))
1221 def _extract_player_info(cls, player_url):
1222 for player_re in cls._PLAYER_INFO_RE:
1223 id_m = re.search(player_re, player_url)
1227 raise ExtractorError('Cannot identify player %r' % player_url)
1228 return id_m.group('id')
1230 def _extract_signature_function(self, video_id, player_url, example_sig):
1231 player_id = self._extract_player_info(player_url)
1233 # Read from filesystem cache
1234 func_id = 'js_%s_%s' % (
1235 player_id, self._signature_cache_id(example_sig))
1236 assert os.path.basename(func_id) == func_id
1238 cache_spec = self._downloader.cache.load('youtube-sigfuncs', func_id)
1239 if cache_spec is not None:
1240 return lambda s: ''.join(s[i] for i in cache_spec)
1242 if player_id not in self._code_cache:
1243 self._code_cache[player_id] = self._download_webpage(
1244 player_url, video_id,
1245 note='Downloading player ' + player_id,
1246 errnote='Download of %s failed' % player_url)
1247 code = self._code_cache[player_id]
1248 res = self._parse_sig_js(code)
1250 test_string = ''.join(map(compat_chr, range(len(example_sig))))
1251 cache_res = res(test_string)
1252 cache_spec = [ord(c) for c in cache_res]
1254 self._downloader.cache.store('youtube-sigfuncs', func_id, cache_spec)
1257 def _print_sig_code(self, func, example_sig):
1258 def gen_sig_code(idxs):
1259 def _genslice(start, end, step):
1260 starts = '' if start == 0 else str(start)
1261 ends = (':%d' % (end + step)) if end + step >= 0 else ':'
1262 steps = '' if step == 1 else (':%d' % step)
1263 return 's[%s%s%s]' % (starts, ends, steps)
1266 # Quelch pyflakes warnings - start will be set when step is set
1267 start = '(Never used)'
1268 for i, prev in zip(idxs[1:], idxs[:-1]):
1269 if step is not None:
1270 if i - prev == step:
1272 yield _genslice(start, prev, step)
1275 if i - prev in [-1, 1]:
1280 yield 's[%d]' % prev
1284 yield _genslice(start, i, step)
1286 test_string = ''.join(map(compat_chr, range(len(example_sig))))
1287 cache_res = func(test_string)
1288 cache_spec = [ord(c) for c in cache_res]
1289 expr_code = ' + '.join(gen_sig_code(cache_spec))
1290 signature_id_tuple = '(%s)' % (
1291 ', '.join(compat_str(len(p)) for p in example_sig.split('.')))
1292 code = ('if tuple(len(p) for p in s.split(\'.\')) == %s:\n'
1293 ' return %s\n') % (signature_id_tuple, expr_code)
1294 self.to_screen('Extracted signature function:\n' + code)
1296 def _parse_sig_js(self, jscode):
1297 funcname = self._search_regex(
1298 (r'\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
1299 r'\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
1300 r'\bm=(?P<sig>[a-zA-Z0-9$]{2})\(decodeURIComponent\(h\.s\)\)',
1301 r'\bc&&\(c=(?P<sig>[a-zA-Z0-9$]{2})\(decodeURIComponent\(c\)\)',
1302 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*\);[a-zA-Z0-9$]{2}\.[a-zA-Z0-9$]{2}\(a,\d+\)',
1303 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*\)',
1304 r'(?P<sig>[a-zA-Z0-9$]+)\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)',
1306 r'(["\'])signature\1\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
1307 r'\.sig\|\|(?P<sig>[a-zA-Z0-9$]+)\(',
1308 r'yt\.akamaized\.net/\)\s*\|\|\s*.*?\s*[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*(?:encodeURIComponent\s*\()?\s*(?P<sig>[a-zA-Z0-9$]+)\(',
1309 r'\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
1310 r'\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
1311 r'\bc\s*&&\s*a\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
1312 r'\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
1313 r'\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\('),
1314 jscode, 'Initial JS player signature function name', group='sig')
1316 jsi = JSInterpreter(jscode)
1317 initial_function = jsi.extract_function(funcname)
1318 return lambda s: initial_function([s])
1320 def _decrypt_signature(self, s, video_id, player_url):
1321 """Turn the encrypted s field into a working signature"""
1323 if player_url is None:
1324 raise ExtractorError('Cannot decrypt signature without player_url')
1326 if player_url.startswith('//'):
1327 player_url = 'https:' + player_url
1328 elif not re.match(r'https?://', player_url):
1329 player_url = compat_urlparse.urljoin(
1330 'https://www.youtube.com', player_url)
1332 player_id = (player_url, self._signature_cache_id(s))
1333 if player_id not in self._player_cache:
1334 func = self._extract_signature_function(
1335 video_id, player_url, s
1337 self._player_cache[player_id] = func
1338 func = self._player_cache[player_id]
1339 if self._downloader.params.get('youtube_print_sig_code'):
1340 self._print_sig_code(func, s)
1342 except Exception as e:
1343 tb = traceback.format_exc()
1344 raise ExtractorError(
1345 'Signature extraction failed: ' + tb, cause=e)
1347 def _mark_watched(self, video_id, player_response):
1348 playback_url = url_or_none(try_get(
1350 lambda x: x['playbackTracking']['videostatsPlaybackUrl']['baseUrl']))
1351 if not playback_url:
1353 parsed_playback_url = compat_urlparse.urlparse(playback_url)
1354 qs = compat_urlparse.parse_qs(parsed_playback_url.query)
1356 # cpn generation algorithm is reverse engineered from base.js.
1357 # In fact it works even with dummy cpn.
1358 CPN_ALPHABET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'
1359 cpn = ''.join((CPN_ALPHABET[random.randint(0, 256) & 63] for _ in range(0, 16)))
1365 playback_url = compat_urlparse.urlunparse(
1366 parsed_playback_url._replace(query=compat_urllib_parse_urlencode(qs, True)))
1368 self._download_webpage(
1369 playback_url, video_id, 'Marking watched',
1370 'Unable to mark watched', fatal=False)
1373 def _extract_urls(webpage):
1374 # Embedded YouTube player
1376 unescapeHTML(mobj.group('url'))
1377 for mobj in re.finditer(r'''(?x)
1387 (?P<url>(?:https?:)?//(?:www\.)?youtube(?:-nocookie)?\.com/
1388 (?:embed|v|p)/[0-9A-Za-z_-]{11}.*?)
1391 # lazyYT YouTube embed
1392 entries.extend(list(map(
1394 re.findall(r'class="lazyYT" data-youtube-id="([^"]+)"', webpage))))
1396 # Wordpress "YouTube Video Importer" plugin
1397 matches = re.findall(r'''(?x)<div[^>]+
1398 class=(?P<q1>[\'"])[^\'"]*\byvii_single_video_player\b[^\'"]*(?P=q1)[^>]+
1399 data-video_id=(?P<q2>[\'"])([^\'"]+)(?P=q2)''', webpage)
1400 entries.extend(m[-1] for m in matches)
1405 def _extract_url(webpage):
1406 urls = YoutubeIE._extract_urls(webpage)
1407 return urls[0] if urls else None
1410 def extract_id(cls, url):
1411 mobj = re.match(cls._VALID_URL, url, re.VERBOSE)
1413 raise ExtractorError('Invalid URL: %s' % url)
1414 video_id = mobj.group(2)
1417 def _extract_chapters_from_json(self, data, video_id, duration):
1418 chapters_list = try_get(
1420 lambda x: x['playerOverlays']
1421 ['playerOverlayRenderer']
1422 ['decoratedPlayerBarRenderer']
1423 ['decoratedPlayerBarRenderer']
1425 ['chapteredPlayerBarRenderer']
1428 if not chapters_list:
1431 def chapter_time(chapter):
1432 return float_or_none(
1435 lambda x: x['chapterRenderer']['timeRangeStartMillis'],
1439 for next_num, chapter in enumerate(chapters_list, start=1):
1440 start_time = chapter_time(chapter)
1441 if start_time is None:
1443 end_time = (chapter_time(chapters_list[next_num])
1444 if next_num < len(chapters_list) else duration)
1445 if end_time is None:
1448 chapter, lambda x: x['chapterRenderer']['title']['simpleText'],
1451 'start_time': start_time,
1452 'end_time': end_time,
1457 def _extract_yt_initial_variable(self, webpage, regex, video_id, name):
1458 return self._parse_json(self._search_regex(
1459 (r'%s\s*%s' % (regex, self._YT_INITIAL_BOUNDARY_RE),
1460 regex), webpage, name, default='{}'), video_id, fatal=False)
1462 def _real_extract(self, url):
1463 url, smuggled_data = unsmuggle_url(url, {})
1464 video_id = self._match_id(url)
1465 base_url = self.http_scheme() + '//www.youtube.com/'
1466 webpage_url = base_url + 'watch?v=' + video_id
1467 webpage = self._download_webpage(
1468 webpage_url + '&bpctr=9999999999&has_verified=1', video_id, fatal=False)
1470 player_response = None
1472 player_response = self._extract_yt_initial_variable(
1473 webpage, self._YT_INITIAL_PLAYER_RESPONSE_RE,
1474 video_id, 'initial player response')
1475 if not player_response:
1476 player_response = self._call_api(
1477 'player', {'videoId': video_id}, video_id)
1479 playability_status = player_response.get('playabilityStatus') or {}
1480 if playability_status.get('reason') == 'Sign in to confirm your age':
1481 pr = self._parse_json(try_get(compat_parse_qs(
1482 self._download_webpage(
1483 base_url + 'get_video_info', video_id,
1484 'Refetching age-gated info webpage',
1485 'unable to download video info webpage', query={
1486 'video_id': video_id,
1487 'eurl': 'https://youtube.googleapis.com/v/' + video_id,
1489 lambda x: x['player_response'][0],
1490 compat_str) or '{}', video_id)
1492 player_response = pr
1494 trailer_video_id = try_get(
1496 lambda x: x['errorScreen']['playerLegacyDesktopYpcTrailerRenderer']['trailerVideoId'],
1498 if trailer_video_id:
1499 return self.url_result(
1500 trailer_video_id, self.ie_key(), trailer_video_id)
1505 text = x.get('simpleText')
1506 if text and isinstance(text, compat_str):
1508 runs = x.get('runs')
1509 if not isinstance(runs, list):
1511 return ''.join([r['text'] for r in runs if isinstance(r.get('text'), compat_str)])
1514 lambda x: self._html_search_meta(x, webpage, default=None)) \
1515 if webpage else lambda x: None
1517 video_details = player_response.get('videoDetails') or {}
1518 microformat = try_get(
1520 lambda x: x['microformat']['playerMicroformatRenderer'],
1522 video_title = video_details.get('title') \
1523 or get_text(microformat.get('title')) \
1524 or search_meta(['og:title', 'twitter:title', 'title'])
1525 video_description = video_details.get('shortDescription')
1527 if not smuggled_data.get('force_singlefeed', False):
1528 if not self._downloader.params.get('noplaylist'):
1529 multifeed_metadata_list = try_get(
1531 lambda x: x['multicamera']['playerLegacyMulticameraRenderer']['metadataList'],
1533 if multifeed_metadata_list:
1536 for feed in multifeed_metadata_list.split(','):
1537 # Unquote should take place before split on comma (,) since textual
1538 # fields may contain comma as well (see
1539 # https://github.com/ytdl-org/youtube-dl/issues/8536)
1540 feed_data = compat_parse_qs(
1541 compat_urllib_parse_unquote_plus(feed))
1543 def feed_entry(name):
1545 feed_data, lambda x: x[name][0], compat_str)
1547 feed_id = feed_entry('id')
1550 feed_title = feed_entry('title')
1553 title += ' (%s)' % feed_title
1555 '_type': 'url_transparent',
1556 'ie_key': 'Youtube',
1558 base_url + 'watch?v=' + feed_data['id'][0],
1559 {'force_singlefeed': True}),
1562 feed_ids.append(feed_id)
1564 'Downloading multifeed video (%s) - add --no-playlist to just download video %s'
1565 % (', '.join(feed_ids), video_id))
1566 return self.playlist_result(
1567 entries, video_id, video_title, video_description)
1569 self.to_screen('Downloading just video %s because of --no-playlist' % video_id)
1575 q = qualities(['tiny', 'small', 'medium', 'large', 'hd720', 'hd1080', 'hd1440', 'hd2160', 'hd2880', 'highres'])
1576 streaming_data = player_response.get('streamingData') or {}
1577 streaming_formats = streaming_data.get('formats') or []
1578 streaming_formats.extend(streaming_data.get('adaptiveFormats') or [])
1579 for fmt in streaming_formats:
1580 if fmt.get('targetDurationSec') or fmt.get('drmFamilies'):
1583 itag = str_or_none(fmt.get('itag'))
1584 quality = fmt.get('quality')
1585 if itag and quality:
1586 itag_qualities[itag] = quality
1587 # FORMAT_STREAM_TYPE_OTF(otf=1) requires downloading the init fragment
1588 # (adding `&sq=0` to the URL) and parsing emsg box to determine the
1589 # number of fragment that would subsequently requested with (`&sq=N`)
1590 if fmt.get('type') == 'FORMAT_STREAM_TYPE_OTF':
1593 fmt_url = fmt.get('url')
1595 sc = compat_parse_qs(fmt.get('signatureCipher'))
1596 fmt_url = url_or_none(try_get(sc, lambda x: x['url'][0]))
1597 encrypted_sig = try_get(sc, lambda x: x['s'][0])
1598 if not (sc and fmt_url and encrypted_sig):
1603 player_url = self._search_regex(
1604 r'"(?:PLAYER_JS_URL|jsUrl)"\s*:\s*"([^"]+)"',
1605 webpage, 'player URL', fatal=False)
1608 signature = self._decrypt_signature(sc['s'][0], video_id, player_url)
1609 sp = try_get(sc, lambda x: x['sp'][0]) or 'signature'
1610 fmt_url += '&' + sp + '=' + signature
1614 tbr = float_or_none(
1615 fmt.get('averageBitrate') or fmt.get('bitrate'), 1000)
1617 'asr': int_or_none(fmt.get('audioSampleRate')),
1618 'filesize': int_or_none(fmt.get('contentLength')),
1620 'format_note': fmt.get('qualityLabel') or quality,
1621 'fps': int_or_none(fmt.get('fps')),
1622 'height': int_or_none(fmt.get('height')),
1623 'quality': q(quality),
1626 'width': fmt.get('width'),
1628 mimetype = fmt.get('mimeType')
1631 r'((?:[^/]+)/(?:[^;]+))(?:;\s*codecs="([^"]+)")?', mimetype)
1633 dct['ext'] = mimetype2ext(mobj.group(1))
1634 dct.update(parse_codecs(mobj.group(2)))
1635 no_audio = dct.get('acodec') == 'none'
1636 no_video = dct.get('vcodec') == 'none'
1641 if no_audio or no_video:
1642 dct['downloader_options'] = {
1643 # Youtube throttles chunks >~10M
1644 'http_chunk_size': 10485760,
1647 dct['container'] = dct['ext'] + '_dash'
1650 hls_manifest_url = streaming_data.get('hlsManifestUrl')
1651 if hls_manifest_url:
1652 for f in self._extract_m3u8_formats(
1653 hls_manifest_url, video_id, 'mp4', fatal=False):
1654 itag = self._search_regex(
1655 r'/itag/(\d+)', f['url'], 'itag', default=None)
1657 f['format_id'] = itag
1660 if self._downloader.params.get('youtube_include_dash_manifest', True):
1661 dash_manifest_url = streaming_data.get('dashManifestUrl')
1662 if dash_manifest_url:
1663 for f in self._extract_mpd_formats(
1664 dash_manifest_url, video_id, fatal=False):
1665 itag = f['format_id']
1668 if itag in itag_qualities:
1669 f['quality'] = q(itag_qualities[itag])
1670 filesize = int_or_none(self._search_regex(
1671 r'/clen/(\d+)', f.get('fragment_base_url')
1672 or f['url'], 'file size', default=None))
1674 f['filesize'] = filesize
1678 if streaming_data.get('licenseInfos'):
1679 raise ExtractorError(
1680 'This video is DRM protected.', expected=True)
1683 lambda x: x['errorScreen']['playerErrorMessageRenderer'],
1685 reason = get_text(pemr.get('reason')) or playability_status.get('reason')
1686 subreason = pemr.get('subreason')
1688 subreason = clean_html(get_text(subreason))
1689 if subreason == 'The uploader has not made this video available in your country.':
1690 countries = microformat.get('availableCountries')
1692 regions_allowed = search_meta('regionsAllowed')
1693 countries = regions_allowed.split(',') if regions_allowed else None
1694 self.raise_geo_restricted(
1695 subreason, countries)
1696 reason += '\n' + subreason
1698 raise ExtractorError(reason, expected=True)
1700 self._sort_formats(formats)
1702 keywords = video_details.get('keywords') or []
1703 if not keywords and webpage:
1705 unescapeHTML(m.group('content'))
1706 for m in re.finditer(self._meta_regex('og:video:tag'), webpage)]
1707 for keyword in keywords:
1708 if keyword.startswith('yt:stretch='):
1709 w, h = keyword.split('=')[1].split(':')
1710 w, h = int(w), int(h)
1714 if f.get('vcodec') != 'none':
1715 f['stretched_ratio'] = ratio
1718 for container in (video_details, microformat):
1719 for thumbnail in (try_get(
1721 lambda x: x['thumbnail']['thumbnails'], list) or []):
1722 thumbnail_url = thumbnail.get('url')
1723 if not thumbnail_url:
1726 'height': int_or_none(thumbnail.get('height')),
1727 'url': thumbnail_url,
1728 'width': int_or_none(thumbnail.get('width')),
1733 thumbnail = search_meta(['og:image', 'twitter:image'])
1735 thumbnails = [{'url': thumbnail}]
1737 category = microformat.get('category') or search_meta('genre')
1738 channel_id = video_details.get('channelId') \
1739 or microformat.get('externalChannelId') \
1740 or search_meta('channelId')
1741 duration = int_or_none(
1742 video_details.get('lengthSeconds')
1743 or microformat.get('lengthSeconds')) \
1744 or parse_duration(search_meta('duration'))
1745 is_live = video_details.get('isLive')
1746 owner_profile_url = microformat.get('ownerProfileUrl')
1750 'title': self._live_title(video_title) if is_live else video_title,
1752 'thumbnails': thumbnails,
1753 'description': video_description,
1754 'upload_date': unified_strdate(
1755 microformat.get('uploadDate')
1756 or search_meta('uploadDate')),
1757 'uploader': video_details['author'],
1758 'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id') if owner_profile_url else None,
1759 'uploader_url': owner_profile_url,
1760 'channel_id': channel_id,
1761 'channel_url': 'https://www.youtube.com/channel/' + channel_id if channel_id else None,
1762 'duration': duration,
1763 'view_count': int_or_none(
1764 video_details.get('viewCount')
1765 or microformat.get('viewCount')
1766 or search_meta('interactionCount')),
1767 'average_rating': float_or_none(video_details.get('averageRating')),
1768 'age_limit': 18 if (
1769 microformat.get('isFamilySafe') is False
1770 or search_meta('isFamilyFriendly') == 'false'
1771 or search_meta('og:restrictions:age') == '18+') else 0,
1772 'webpage_url': webpage_url,
1773 'categories': [category] if category else None,
1780 lambda x: x['captions']['playerCaptionsTracklistRenderer'], dict)
1782 def process_language(container, base_url, lang_code, query):
1784 for fmt in self._SUBTITLE_FORMATS:
1790 'url': update_url_query(base_url, query),
1792 container[lang_code] = lang_subs
1795 for caption_track in (pctr.get('captionTracks') or []):
1796 base_url = caption_track.get('baseUrl')
1799 if caption_track.get('kind') != 'asr':
1800 lang_code = caption_track.get('languageCode')
1804 subtitles, base_url, lang_code, {})
1806 automatic_captions = {}
1807 for translation_language in (pctr.get('translationLanguages') or []):
1808 translation_language_code = translation_language.get('languageCode')
1809 if not translation_language_code:
1812 automatic_captions, base_url, translation_language_code,
1813 {'tlang': translation_language_code})
1814 info['automatic_captions'] = automatic_captions
1815 info['subtitles'] = subtitles
1817 parsed_url = compat_urllib_parse_urlparse(url)
1818 for component in [parsed_url.fragment, parsed_url.query]:
1819 query = compat_parse_qs(component)
1820 for k, v in query.items():
1821 for d_k, s_ks in [('start', ('start', 't')), ('end', ('end',))]:
1823 if d_k not in info and k in s_ks:
1824 info[d_k] = parse_duration(query[k][0])
1826 if video_description:
1827 mobj = re.search(r'(?s)(?P<track>[^·\n]+)·(?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]+))?.+\nAuto-generated by YouTube\.\s*$', video_description)
1829 release_year = mobj.group('release_year')
1830 release_date = mobj.group('release_date')
1832 release_date = release_date.replace('-', '')
1833 if not release_year:
1834 release_year = release_date[:4]
1836 'album': mobj.group('album'.strip()),
1837 'artist': mobj.group('clean_artist') or ', '.join(a.strip() for a in mobj.group('artist').split('·')),
1838 'track': mobj.group('track').strip(),
1839 'release_date': release_date,
1840 'release_year': int_or_none(release_year),
1845 initial_data = self._extract_yt_initial_variable(
1846 webpage, self._YT_INITIAL_DATA_RE, video_id,
1848 if not initial_data:
1849 initial_data = self._call_api(
1850 'next', {'videoId': video_id}, video_id, fatal=False)
1853 chapters = self._extract_chapters_from_json(
1854 initial_data, video_id, duration)
1856 for engagment_pannel in (initial_data.get('engagementPanels') or []):
1858 engagment_pannel, lambda x: x['engagementPanelSectionListRenderer']['content']['macroMarkersListRenderer']['contents'],
1863 def chapter_time(mmlir):
1864 return parse_duration(
1865 get_text(mmlir.get('timeDescription')))
1868 for next_num, content in enumerate(contents, start=1):
1869 mmlir = content.get('macroMarkersListItemRenderer') or {}
1870 start_time = chapter_time(mmlir)
1871 end_time = chapter_time(try_get(
1872 contents, lambda x: x[next_num]['macroMarkersListItemRenderer'])) \
1873 if next_num < len(contents) else duration
1874 if start_time is None or end_time is None:
1877 'start_time': start_time,
1878 'end_time': end_time,
1879 'title': get_text(mmlir.get('title')),
1884 info['chapters'] = chapters
1888 lambda x: x['contents']['twoColumnWatchNextResults']['results']['results']['contents'],
1890 for content in contents:
1891 vpir = content.get('videoPrimaryInfoRenderer')
1893 stl = vpir.get('superTitleLink')
1898 lambda x: x['superTitleIcon']['iconType']) == 'LOCATION_PIN':
1899 info['location'] = stl
1901 mobj = re.search(r'(.+?)\s*S(\d+)\s*•\s*E(\d+)', stl)
1904 'series': mobj.group(1),
1905 'season_number': int(mobj.group(2)),
1906 'episode_number': int(mobj.group(3)),
1908 for tlb in (try_get(
1910 lambda x: x['videoActions']['menuRenderer']['topLevelButtons'],
1912 tbr = tlb.get('toggleButtonRenderer') or {}
1913 for getter, regex in [(
1914 lambda x: x['defaultText']['accessibility']['accessibilityData'],
1915 r'(?P<count>[\d,]+)\s*(?P<type>(?:dis)?like)'), ([
1916 lambda x: x['accessibility'],
1917 lambda x: x['accessibilityData']['accessibilityData'],
1918 ], r'(?P<type>(?:dis)?like) this video along with (?P<count>[\d,]+) other people')]:
1919 label = (try_get(tbr, getter, dict) or {}).get('label')
1921 mobj = re.match(regex, label)
1923 info[mobj.group('type') + '_count'] = str_to_int(mobj.group('count'))
1925 sbr_tooltip = try_get(
1926 vpir, lambda x: x['sentimentBar']['sentimentBarRenderer']['tooltip'])
1928 like_count, dislike_count = sbr_tooltip.split(' / ')
1930 'like_count': str_to_int(like_count),
1931 'dislike_count': str_to_int(dislike_count),
1933 vsir = content.get('videoSecondaryInfoRenderer')
1935 info['channel'] = get_text(try_get(
1937 lambda x: x['owner']['videoOwnerRenderer']['title'],
1941 lambda x: x['metadataRowContainer']['metadataRowContainerRenderer']['rows'],
1943 multiple_songs = False
1945 if try_get(row, lambda x: x['metadataRowRenderer']['hasDividerLine']) is True:
1946 multiple_songs = True
1949 mrr = row.get('metadataRowRenderer') or {}
1950 mrr_title = mrr.get('title')
1953 mrr_title = get_text(mrr['title'])
1954 mrr_contents_text = get_text(mrr['contents'][0])
1955 if mrr_title == 'License':
1956 info['license'] = mrr_contents_text
1957 elif not multiple_songs:
1958 if mrr_title == 'Album':
1959 info['album'] = mrr_contents_text
1960 elif mrr_title == 'Artist':
1961 info['artist'] = mrr_contents_text
1962 elif mrr_title == 'Song':
1963 info['track'] = mrr_contents_text
1965 for s_k, d_k in [('artist', 'creator'), ('track', 'alt_title')]:
1970 self.mark_watched(video_id, player_response)
1975 class YoutubeTabIE(YoutubeBaseInfoExtractor):
1976 IE_DESC = 'YouTube.com tab'
1977 _VALID_URL = r'''(?x)
1981 youtube(?:kids)?\.com|
1985 (?:channel|c|user|feed|hashtag)/|
1986 (?:playlist|watch)\?.*?\blist=|
1987 (?!(?:watch|embed|v|e)\b)
1991 IE_NAME = 'youtube:tab'
1994 # playlists, multipage
1995 'url': 'https://www.youtube.com/c/ИгорьКлейнер/playlists?view=1&flow=grid',
1996 'playlist_mincount': 94,
1998 'id': 'UCqj7Cz7revf5maW9g5pgNcg',
1999 'title': 'Игорь Клейнер - Playlists',
2000 'description': 'md5:be97ee0f14ee314f1f002cf187166ee2',
2003 # playlists, multipage, different order
2004 'url': 'https://www.youtube.com/user/igorkle1/playlists?view=1&sort=dd',
2005 'playlist_mincount': 94,
2007 'id': 'UCqj7Cz7revf5maW9g5pgNcg',
2008 'title': 'Игорь Клейнер - Playlists',
2009 'description': 'md5:be97ee0f14ee314f1f002cf187166ee2',
2012 # playlists, singlepage
2013 'url': 'https://www.youtube.com/user/ThirstForScience/playlists',
2014 'playlist_mincount': 4,
2016 'id': 'UCAEtajcuhQ6an9WEzY9LEMQ',
2017 'title': 'ThirstForScience - Playlists',
2018 'description': 'md5:609399d937ea957b0f53cbffb747a14c',
2021 'url': 'https://www.youtube.com/c/ChristophLaimer/playlists',
2022 'only_matching': True,
2024 # basic, single video playlist
2025 'url': 'https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc',
2027 'uploader_id': 'UCmlqkdCBesrv2Lak1mF_MxA',
2028 'uploader': 'Sergey M.',
2029 'id': 'PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc',
2030 'title': 'youtube-dl public playlist',
2032 'playlist_count': 1,
2035 'url': 'https://www.youtube.com/playlist?list=PL4lCao7KL_QFodcLWhDpGCYnngnHtQ-Xf',
2037 'uploader_id': 'UCmlqkdCBesrv2Lak1mF_MxA',
2038 'uploader': 'Sergey M.',
2039 'id': 'PL4lCao7KL_QFodcLWhDpGCYnngnHtQ-Xf',
2040 'title': 'youtube-dl empty playlist',
2042 'playlist_count': 0,
2045 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/featured',
2047 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
2048 'title': 'lex will - Home',
2049 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
2051 'playlist_mincount': 2,
2054 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/videos',
2056 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
2057 'title': 'lex will - Videos',
2058 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
2060 'playlist_mincount': 975,
2062 # Videos tab, sorted by popular
2063 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/videos?view=0&sort=p&flow=grid',
2065 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
2066 'title': 'lex will - Videos',
2067 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
2069 'playlist_mincount': 199,
2072 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/playlists',
2074 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
2075 'title': 'lex will - Playlists',
2076 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
2078 'playlist_mincount': 17,
2081 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/community',
2083 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
2084 'title': 'lex will - Community',
2085 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
2087 'playlist_mincount': 18,
2090 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/channels',
2092 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
2093 'title': 'lex will - Channels',
2094 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
2096 'playlist_mincount': 138,
2098 'url': 'https://invidio.us/channel/UCmlqkdCBesrv2Lak1mF_MxA',
2099 'only_matching': True,
2101 'url': 'https://www.youtubekids.com/channel/UCmlqkdCBesrv2Lak1mF_MxA',
2102 'only_matching': True,
2104 'url': 'https://music.youtube.com/channel/UCmlqkdCBesrv2Lak1mF_MxA',
2105 'only_matching': True,
2107 'note': 'Playlist with deleted videos (#651). As a bonus, the video #51 is also twice in this list.',
2108 'url': 'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC',
2110 'title': '29C3: Not my department',
2111 'id': 'PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC',
2112 'uploader': 'Christiaan008',
2113 'uploader_id': 'UCEPzS1rYsrkqzSLNp76nrcg',
2115 'playlist_count': 96,
2117 'note': 'Large playlist',
2118 'url': 'https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q',
2120 'title': 'Uploads from Cauchemar',
2121 'id': 'UUBABnxM4Ar9ten8Mdjj1j0Q',
2122 'uploader': 'Cauchemar',
2123 'uploader_id': 'UCBABnxM4Ar9ten8Mdjj1j0Q',
2125 'playlist_mincount': 1123,
2127 # even larger playlist, 8832 videos
2128 'url': 'http://www.youtube.com/user/NASAgovVideo/videos',
2129 'only_matching': True,
2131 'note': 'Buggy playlist: the webpage has a "Load more" button but it doesn\'t have more videos',
2132 'url': 'https://www.youtube.com/playlist?list=UUXw-G3eDE9trcvY2sBMM_aA',
2134 'title': 'Uploads from Interstellar Movie',
2135 'id': 'UUXw-G3eDE9trcvY2sBMM_aA',
2136 'uploader': 'Interstellar Movie',
2137 'uploader_id': 'UCXw-G3eDE9trcvY2sBMM_aA',
2139 'playlist_mincount': 21,
2141 # https://github.com/ytdl-org/youtube-dl/issues/21844
2142 'url': 'https://www.youtube.com/playlist?list=PLzH6n4zXuckpfMu_4Ff8E7Z1behQks5ba',
2144 'title': 'Data Analysis with Dr Mike Pound',
2145 'id': 'PLzH6n4zXuckpfMu_4Ff8E7Z1behQks5ba',
2146 'uploader_id': 'UC9-y-6csu5WGm29I7JiwpnA',
2147 'uploader': 'Computerphile',
2149 'playlist_mincount': 11,
2151 'url': 'https://invidio.us/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc',
2152 'only_matching': True,
2154 # Playlist URL that does not actually serve a playlist
2155 'url': 'https://www.youtube.com/watch?v=FqZTN594JQw&list=PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4',
2157 'id': 'FqZTN594JQw',
2159 'title': "Smiley's People 01 detective, Adventure Series, Action",
2160 'uploader': 'STREEM',
2161 'uploader_id': 'UCyPhqAZgwYWZfxElWVbVJng',
2162 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UCyPhqAZgwYWZfxElWVbVJng',
2163 'upload_date': '20150526',
2164 'license': 'Standard YouTube License',
2165 'description': 'md5:507cdcb5a49ac0da37a920ece610be80',
2166 'categories': ['People & Blogs'],
2170 'dislike_count': int,
2173 'skip_download': True,
2175 'skip': 'This video is not available.',
2176 'add_ie': [YoutubeIE.ie_key()],
2178 'url': 'https://www.youtubekids.com/watch?v=Agk7R8I8o5U&list=PUZ6jURNr1WQZCNHF0ao-c0g',
2179 'only_matching': True,
2181 'url': 'https://www.youtube.com/watch?v=MuAGGZNfUkU&list=RDMM',
2182 'only_matching': True,
2184 'url': 'https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ/live',
2186 'id': '9Auq9mYxFEE',
2188 'title': 'Watch Sky News live',
2189 'uploader': 'Sky News',
2190 'uploader_id': 'skynews',
2191 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/skynews',
2192 'upload_date': '20191102',
2193 'description': 'md5:78de4e1c2359d0ea3ed829678e38b662',
2194 'categories': ['News & Politics'],
2197 'dislike_count': int,
2200 'skip_download': True,
2203 'url': 'https://www.youtube.com/user/TheYoungTurks/live',
2205 'id': 'a48o2S1cPoo',
2207 'title': 'The Young Turks - Live Main Show',
2208 'uploader': 'The Young Turks',
2209 'uploader_id': 'TheYoungTurks',
2210 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/TheYoungTurks',
2211 'upload_date': '20150715',
2212 'license': 'Standard YouTube License',
2213 'description': 'md5:438179573adcdff3c97ebb1ee632b891',
2214 'categories': ['News & Politics'],
2215 'tags': ['Cenk Uygur (TV Program Creator)', 'The Young Turks (Award-Winning Work)', 'Talk Show (TV Genre)'],
2217 'dislike_count': int,
2220 'skip_download': True,
2222 'only_matching': True,
2224 'url': 'https://www.youtube.com/channel/UC1yBKRuGpC1tSM73A0ZjYjQ/live',
2225 'only_matching': True,
2227 'url': 'https://www.youtube.com/c/CommanderVideoHq/live',
2228 'only_matching': True,
2230 'url': 'https://www.youtube.com/feed/trending',
2231 'only_matching': True,
2234 'url': 'https://www.youtube.com/feed/library',
2235 'only_matching': True,
2238 'url': 'https://www.youtube.com/feed/history',
2239 'only_matching': True,
2242 'url': 'https://www.youtube.com/feed/subscriptions',
2243 'only_matching': True,
2246 'url': 'https://www.youtube.com/feed/watch_later',
2247 'only_matching': True,
2249 # no longer available?
2250 'url': 'https://www.youtube.com/feed/recommended',
2251 'only_matching': True,
2253 # inline playlist with not always working continuations
2254 'url': 'https://www.youtube.com/watch?v=UC6u0Tct-Fo&list=PL36D642111D65BE7C',
2255 'only_matching': True,
2257 'url': 'https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8',
2258 'only_matching': True,
2260 'url': 'https://www.youtube.com/course',
2261 'only_matching': True,
2263 'url': 'https://www.youtube.com/zsecurity',
2264 'only_matching': True,
2266 'url': 'http://www.youtube.com/NASAgovVideo/videos',
2267 'only_matching': True,
2269 'url': 'https://www.youtube.com/TheYoungTurks/live',
2270 'only_matching': True,
2272 'url': 'https://www.youtube.com/hashtag/cctv9',
2277 'playlist_mincount': 350,
2281 def suitable(cls, url):
2282 return False if YoutubeIE.suitable(url) else super(
2283 YoutubeTabIE, cls).suitable(url)
2285 def _extract_channel_id(self, webpage):
2286 channel_id = self._html_search_meta(
2287 'channelId', webpage, 'channel id', default=None)
2290 channel_url = self._html_search_meta(
2291 ('og:url', 'al:ios:url', 'al:android:url', 'al:web:url',
2292 'twitter:url', 'twitter:app:url:iphone', 'twitter:app:url:ipad',
2293 'twitter:app:url:googleplay'), webpage, 'channel url')
2294 return self._search_regex(
2295 r'https?://(?:www\.)?youtube\.com/channel/([^/?#&])+',
2296 channel_url, 'channel id')
2299 def _extract_grid_item_renderer(item):
2300 for item_kind in ('Playlist', 'Video', 'Channel'):
2301 renderer = item.get('grid%sRenderer' % item_kind)
2305 def _grid_entries(self, grid_renderer):
2306 for item in grid_renderer['items']:
2307 if not isinstance(item, dict):
2309 renderer = self._extract_grid_item_renderer(item)
2310 if not isinstance(renderer, dict):
2313 renderer, lambda x: x['title']['runs'][0]['text'], compat_str)
2315 playlist_id = renderer.get('playlistId')
2317 yield self.url_result(
2318 'https://www.youtube.com/playlist?list=%s' % playlist_id,
2319 ie=YoutubeTabIE.ie_key(), video_id=playlist_id,
2322 video_id = renderer.get('videoId')
2324 yield self._extract_video(renderer)
2326 channel_id = renderer.get('channelId')
2329 renderer, lambda x: x['title']['simpleText'], compat_str)
2330 yield self.url_result(
2331 'https://www.youtube.com/channel/%s' % channel_id,
2332 ie=YoutubeTabIE.ie_key(), video_title=title)
2334 def _shelf_entries_from_content(self, shelf_renderer):
2335 content = shelf_renderer.get('content')
2336 if not isinstance(content, dict):
2338 renderer = content.get('gridRenderer')
2340 # TODO: add support for nested playlists so each shelf is processed
2341 # as separate playlist
2342 # TODO: this includes only first N items
2343 for entry in self._grid_entries(renderer):
2345 renderer = content.get('horizontalListRenderer')
2350 def _shelf_entries(self, shelf_renderer, skip_channels=False):
2352 shelf_renderer, lambda x: x['endpoint']['commandMetadata']['webCommandMetadata']['url'],
2354 shelf_url = urljoin('https://www.youtube.com', ep)
2356 # Skipping links to another channels, note that checking for
2357 # endpoint.commandMetadata.webCommandMetadata.webPageTypwebPageType == WEB_PAGE_TYPE_CHANNEL
2359 if skip_channels and '/channels?' in shelf_url:
2362 shelf_renderer, lambda x: x['title']['runs'][0]['text'], compat_str)
2363 yield self.url_result(shelf_url, video_title=title)
2364 # Shelf may not contain shelf URL, fallback to extraction from content
2365 for entry in self._shelf_entries_from_content(shelf_renderer):
2368 def _playlist_entries(self, video_list_renderer):
2369 for content in video_list_renderer['contents']:
2370 if not isinstance(content, dict):
2372 renderer = content.get('playlistVideoRenderer') or content.get('playlistPanelVideoRenderer')
2373 if not isinstance(renderer, dict):
2375 video_id = renderer.get('videoId')
2378 yield self._extract_video(renderer)
2380 def _video_entry(self, video_renderer):
2381 video_id = video_renderer.get('videoId')
2383 return self._extract_video(video_renderer)
2385 def _post_thread_entries(self, post_thread_renderer):
2386 post_renderer = try_get(
2387 post_thread_renderer, lambda x: x['post']['backstagePostRenderer'], dict)
2388 if not post_renderer:
2391 video_renderer = try_get(
2392 post_renderer, lambda x: x['backstageAttachment']['videoRenderer'], dict)
2395 entry = self._video_entry(video_renderer)
2398 # inline video links
2399 runs = try_get(post_renderer, lambda x: x['contentText']['runs'], list) or []
2401 if not isinstance(run, dict):
2404 run, lambda x: x['navigationEndpoint']['urlEndpoint']['url'], compat_str)
2407 if not YoutubeIE.suitable(ep_url):
2409 ep_video_id = YoutubeIE._match_id(ep_url)
2410 if video_id == ep_video_id:
2412 yield self.url_result(ep_url, ie=YoutubeIE.ie_key(), video_id=video_id)
2414 def _post_thread_continuation_entries(self, post_thread_continuation):
2415 contents = post_thread_continuation.get('contents')
2416 if not isinstance(contents, list):
2418 for content in contents:
2419 renderer = content.get('backstagePostThreadRenderer')
2420 if not isinstance(renderer, dict):
2422 for entry in self._post_thread_entries(renderer):
2425 def _rich_grid_entries(self, contents):
2426 for content in contents:
2427 video_renderer = try_get(content, lambda x: x['richItemRenderer']['content']['videoRenderer'], dict)
2429 entry = self._video_entry(video_renderer)
2434 def _build_continuation_query(continuation, ctp=None):
2436 'ctoken': continuation,
2437 'continuation': continuation,
2444 def _extract_next_continuation_data(renderer):
2445 next_continuation = try_get(
2446 renderer, lambda x: x['continuations'][0]['nextContinuationData'], dict)
2447 if not next_continuation:
2449 continuation = next_continuation.get('continuation')
2450 if not continuation:
2452 ctp = next_continuation.get('clickTrackingParams')
2453 return YoutubeTabIE._build_continuation_query(continuation, ctp)
2456 def _extract_continuation(cls, renderer):
2457 next_continuation = cls._extract_next_continuation_data(renderer)
2458 if next_continuation:
2459 return next_continuation
2461 for key in ('contents', 'items'):
2462 contents.extend(try_get(renderer, lambda x: x[key], list) or [])
2463 for content in contents:
2464 if not isinstance(content, dict):
2466 continuation_ep = try_get(
2467 content, lambda x: x['continuationItemRenderer']['continuationEndpoint'],
2469 if not continuation_ep:
2471 continuation = try_get(
2472 continuation_ep, lambda x: x['continuationCommand']['token'], compat_str)
2473 if not continuation:
2475 ctp = continuation_ep.get('clickTrackingParams')
2476 return YoutubeTabIE._build_continuation_query(continuation, ctp)
2478 def _entries(self, tab, identity_token):
2479 tab_content = try_get(tab, lambda x: x['content'], dict)
2482 slr_renderer = try_get(tab_content, lambda x: x['sectionListRenderer'], dict)
2484 is_channels_tab = tab.get('title') == 'Channels'
2486 slr_contents = try_get(slr_renderer, lambda x: x['contents'], list) or []
2487 for slr_content in slr_contents:
2488 if not isinstance(slr_content, dict):
2490 is_renderer = try_get(slr_content, lambda x: x['itemSectionRenderer'], dict)
2493 isr_contents = try_get(is_renderer, lambda x: x['contents'], list) or []
2494 for isr_content in isr_contents:
2495 if not isinstance(isr_content, dict):
2497 renderer = isr_content.get('playlistVideoListRenderer')
2499 for entry in self._playlist_entries(renderer):
2501 continuation = self._extract_continuation(renderer)
2503 renderer = isr_content.get('gridRenderer')
2505 for entry in self._grid_entries(renderer):
2507 continuation = self._extract_continuation(renderer)
2509 renderer = isr_content.get('shelfRenderer')
2511 for entry in self._shelf_entries(renderer, not is_channels_tab):
2514 renderer = isr_content.get('backstagePostThreadRenderer')
2516 for entry in self._post_thread_entries(renderer):
2518 continuation = self._extract_continuation(renderer)
2520 renderer = isr_content.get('videoRenderer')
2522 entry = self._video_entry(renderer)
2526 if not continuation:
2527 continuation = self._extract_continuation(is_renderer)
2528 if not continuation:
2529 continuation = self._extract_continuation(slr_renderer)
2531 rich_grid_renderer = tab_content.get('richGridRenderer')
2532 if not rich_grid_renderer:
2534 for entry in self._rich_grid_entries(rich_grid_renderer.get('contents') or []):
2536 continuation = self._extract_continuation(rich_grid_renderer)
2539 'x-youtube-client-name': '1',
2540 'x-youtube-client-version': '2.20201112.04.01',
2541 'content-type': 'application/json',
2544 headers['x-youtube-identity-token'] = identity_token
2549 'clientName': 'WEB',
2550 'clientVersion': '2.20201021.03.00',
2555 for page_num in itertools.count(1):
2556 if not continuation:
2558 data['continuation'] = continuation['continuation']
2559 data['clickTracking'] = {
2560 'clickTrackingParams': continuation['itct']
2564 while count <= retries:
2566 # Downloading page may result in intermittent 5xx HTTP error
2567 # that is usually worked around with a retry
2568 response = self._download_json(
2569 'https://www.youtube.com/youtubei/v1/browse?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
2570 None, 'Downloading page %d%s' % (page_num, ' (retry #%d)' % count if count else ''),
2571 headers=headers, data=json.dumps(data).encode('utf8'))
2573 except ExtractorError as e:
2574 if isinstance(e.cause, compat_HTTPError) and e.cause.code in (500, 503):
2576 if count <= retries:
2582 continuation_contents = try_get(
2583 response, lambda x: x['continuationContents'], dict)
2584 if continuation_contents:
2585 continuation_renderer = continuation_contents.get('playlistVideoListContinuation')
2586 if continuation_renderer:
2587 for entry in self._playlist_entries(continuation_renderer):
2589 continuation = self._extract_continuation(continuation_renderer)
2591 continuation_renderer = continuation_contents.get('gridContinuation')
2592 if continuation_renderer:
2593 for entry in self._grid_entries(continuation_renderer):
2595 continuation = self._extract_continuation(continuation_renderer)
2597 continuation_renderer = continuation_contents.get('itemSectionContinuation')
2598 if continuation_renderer:
2599 for entry in self._post_thread_continuation_entries(continuation_renderer):
2601 continuation = self._extract_continuation(continuation_renderer)
2604 on_response_received = dict_get(response, ('onResponseReceivedActions', 'onResponseReceivedEndpoints'))
2605 continuation_items = try_get(
2606 on_response_received, lambda x: x[0]['appendContinuationItemsAction']['continuationItems'], list)
2607 if continuation_items:
2608 continuation_item = continuation_items[0]
2609 if not isinstance(continuation_item, dict):
2611 renderer = self._extract_grid_item_renderer(continuation_item)
2613 grid_renderer = {'items': continuation_items}
2614 for entry in self._grid_entries(grid_renderer):
2616 continuation = self._extract_continuation(grid_renderer)
2618 renderer = continuation_item.get('playlistVideoRenderer') or continuation_item.get('itemSectionRenderer')
2620 video_list_renderer = {'contents': continuation_items}
2621 for entry in self._playlist_entries(video_list_renderer):
2623 continuation = self._extract_continuation(video_list_renderer)
2625 renderer = continuation_item.get('backstagePostThreadRenderer')
2627 continuation_renderer = {'contents': continuation_items}
2628 for entry in self._post_thread_continuation_entries(continuation_renderer):
2630 continuation = self._extract_continuation(continuation_renderer)
2632 renderer = continuation_item.get('richItemRenderer')
2634 for entry in self._rich_grid_entries(continuation_items):
2636 continuation = self._extract_continuation({'contents': continuation_items})
2642 def _extract_selected_tab(tabs):
2644 if try_get(tab, lambda x: x['tabRenderer']['selected'], bool):
2645 return tab['tabRenderer']
2647 raise ExtractorError('Unable to find selected tab')
2650 def _extract_uploader(data):
2652 sidebar_renderer = try_get(
2653 data, lambda x: x['sidebar']['playlistSidebarRenderer']['items'], list)
2654 if sidebar_renderer:
2655 for item in sidebar_renderer:
2656 if not isinstance(item, dict):
2658 renderer = item.get('playlistSidebarSecondaryInfoRenderer')
2659 if not isinstance(renderer, dict):
2662 renderer, lambda x: x['videoOwner']['videoOwnerRenderer']['title']['runs'][0], dict)
2664 uploader['uploader'] = owner.get('text')
2665 uploader['uploader_id'] = try_get(
2666 owner, lambda x: x['navigationEndpoint']['browseEndpoint']['browseId'], compat_str)
2667 uploader['uploader_url'] = urljoin(
2668 'https://www.youtube.com/',
2669 try_get(owner, lambda x: x['navigationEndpoint']['browseEndpoint']['canonicalBaseUrl'], compat_str))
2673 def _extract_alert(data):
2675 for alert in try_get(data, lambda x: x['alerts'], list) or []:
2676 if not isinstance(alert, dict):
2678 alert_text = try_get(
2679 alert, lambda x: x['alertRenderer']['text'], dict)
2684 (lambda x: x['simpleText'], lambda x: x['runs'][0]['text']),
2688 return '\n'.join(alerts)
2690 def _extract_from_tabs(self, item_id, webpage, data, tabs, identity_token):
2691 selected_tab = self._extract_selected_tab(tabs)
2693 data, lambda x: x['metadata']['channelMetadataRenderer'], dict)
2694 playlist_id = item_id
2695 title = description = None
2697 channel_title = renderer.get('title') or item_id
2698 tab_title = selected_tab.get('title')
2699 title = channel_title or item_id
2701 title += ' - %s' % tab_title
2702 description = renderer.get('description')
2703 playlist_id = renderer.get('externalId')
2706 data, lambda x: x['metadata']['playlistMetadataRenderer'], dict)
2708 title = renderer.get('title')
2711 data, lambda x: x['header']['hashtagHeaderRenderer'], dict)
2713 title = try_get(renderer, lambda x: x['hashtag']['simpleText'])
2714 playlist = self.playlist_result(
2715 self._entries(selected_tab, identity_token),
2716 playlist_id=playlist_id, playlist_title=title,
2717 playlist_description=description)
2718 playlist.update(self._extract_uploader(data))
2721 def _extract_from_playlist(self, item_id, url, data, playlist):
2722 title = playlist.get('title') or try_get(
2723 data, lambda x: x['titleText']['simpleText'], compat_str)
2724 playlist_id = playlist.get('playlistId') or item_id
2725 # Inline playlist rendition continuation does not always work
2726 # at Youtube side, so delegating regular tab-based playlist URL
2727 # processing whenever possible.
2728 playlist_url = urljoin(url, try_get(
2729 playlist, lambda x: x['endpoint']['commandMetadata']['webCommandMetadata']['url'],
2731 if playlist_url and playlist_url != url:
2732 return self.url_result(
2733 playlist_url, ie=YoutubeTabIE.ie_key(), video_id=playlist_id,
2735 return self.playlist_result(
2736 self._playlist_entries(playlist), playlist_id=playlist_id,
2737 playlist_title=title)
2739 def _extract_identity_token(self, webpage, item_id):
2740 ytcfg = self._extract_ytcfg(item_id, webpage)
2742 token = try_get(ytcfg, lambda x: x['ID_TOKEN'], compat_str)
2745 return self._search_regex(
2746 r'\bID_TOKEN["\']\s*:\s*["\'](.+?)["\']', webpage,
2747 'identity token', default=None)
2749 def _real_extract(self, url):
2750 item_id = self._match_id(url)
2751 url = compat_urlparse.urlunparse(
2752 compat_urlparse.urlparse(url)._replace(netloc='www.youtube.com'))
2753 # Handle both video/playlist URLs
2754 qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
2755 video_id = qs.get('v', [None])[0]
2756 playlist_id = qs.get('list', [None])[0]
2757 if video_id and playlist_id:
2758 if self._downloader.params.get('noplaylist'):
2759 self.to_screen('Downloading just video %s because of --no-playlist' % video_id)
2760 return self.url_result(video_id, ie=YoutubeIE.ie_key(), video_id=video_id)
2761 self.to_screen('Downloading playlist %s - add --no-playlist to just download video %s' % (playlist_id, video_id))
2762 webpage = self._download_webpage(url, item_id)
2763 identity_token = self._extract_identity_token(webpage, item_id)
2764 data = self._extract_yt_initial_data(item_id, webpage)
2766 data, lambda x: x['contents']['twoColumnBrowseResultsRenderer']['tabs'], list)
2768 return self._extract_from_tabs(item_id, webpage, data, tabs, identity_token)
2770 data, lambda x: x['contents']['twoColumnWatchNextResults']['playlist']['playlist'], dict)
2772 return self._extract_from_playlist(item_id, url, data, playlist)
2773 # Fallback to video extraction if no playlist alike page is recognized.
2774 # First check for the current video then try the v attribute of URL query.
2776 data, lambda x: x['currentVideoEndpoint']['watchEndpoint']['videoId'],
2777 compat_str) or video_id
2779 return self.url_result(video_id, ie=YoutubeIE.ie_key(), video_id=video_id)
2780 # Capture and output alerts
2781 alert = self._extract_alert(data)
2783 raise ExtractorError(alert, expected=True)
2784 # Failed to recognize
2785 raise ExtractorError('Unable to recognize tab page')
2788 class YoutubePlaylistIE(InfoExtractor):
2789 IE_DESC = 'YouTube.com playlists'
2790 _VALID_URL = r'''(?x)(?:
2795 youtube(?:kids)?\.com|
2800 (?P<id>%(playlist_id)s)
2801 )''' % {'playlist_id': YoutubeBaseInfoExtractor._PLAYLIST_ID_RE}
2802 IE_NAME = 'youtube:playlist'
2804 'note': 'issue #673',
2805 'url': 'PLBB231211A4F62143',
2807 'title': '[OLD]Team Fortress 2 (Class-based LP)',
2808 'id': 'PLBB231211A4F62143',
2809 'uploader': 'Wickydoo',
2810 'uploader_id': 'UCKSpbfbl5kRQpTdL7kMc-1Q',
2812 'playlist_mincount': 29,
2814 'url': 'PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl',
2816 'title': 'YDL_safe_search',
2817 'id': 'PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl',
2819 'playlist_count': 2,
2820 'skip': 'This playlist is private',
2823 'url': 'https://www.youtube.com/embed/videoseries?list=PL6IaIsEjSbf96XFRuNccS_RuEXwNdsoEu',
2824 'playlist_count': 4,
2827 'id': 'PL6IaIsEjSbf96XFRuNccS_RuEXwNdsoEu',
2828 'uploader': 'milan',
2829 'uploader_id': 'UCEI1-PVPcYXjB73Hfelbmaw',
2832 'url': 'http://www.youtube.com/embed/_xDOZElKyNU?list=PLsyOSbh5bs16vubvKePAQ1x3PhKavfBIl',
2833 'playlist_mincount': 982,
2835 'title': '2018 Chinese New Singles (11/6 updated)',
2836 'id': 'PLsyOSbh5bs16vubvKePAQ1x3PhKavfBIl',
2838 'uploader_id': 'UC21nz3_MesPLqtDqwdvnoxA',
2841 'url': 'TLGGrESM50VT6acwMjAyMjAxNw',
2842 'only_matching': True,
2844 # music album playlist
2845 'url': 'OLAK5uy_m4xAFdmMC5rX3Ji3g93pQe3hqLZw_9LhM',
2846 'only_matching': True,
2850 def suitable(cls, url):
2851 return False if YoutubeTabIE.suitable(url) else super(
2852 YoutubePlaylistIE, cls).suitable(url)
2854 def _real_extract(self, url):
2855 playlist_id = self._match_id(url)
2856 qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
2858 qs = {'list': playlist_id}
2859 return self.url_result(
2860 update_url_query('https://www.youtube.com/playlist', qs),
2861 ie=YoutubeTabIE.ie_key(), video_id=playlist_id)
2864 class YoutubeYtBeIE(InfoExtractor):
2865 _VALID_URL = r'https?://youtu\.be/(?P<id>[0-9A-Za-z_-]{11})/*?.*?\blist=(?P<playlist_id>%(playlist_id)s)' % {'playlist_id': YoutubeBaseInfoExtractor._PLAYLIST_ID_RE}
2867 'url': 'https://youtu.be/yeWKywCrFtk?list=PL2qgrgXsNUG5ig9cat4ohreBjYLAPC0J5',
2869 'id': 'yeWKywCrFtk',
2871 'title': 'Small Scale Baler and Braiding Rugs',
2872 'uploader': 'Backus-Page House Museum',
2873 'uploader_id': 'backuspagemuseum',
2874 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/backuspagemuseum',
2875 'upload_date': '20161008',
2876 'description': 'md5:800c0c78d5eb128500bffd4f0b4f2e8a',
2877 'categories': ['Nonprofits & Activism'],
2880 'dislike_count': int,
2884 'skip_download': True,
2887 'url': 'https://youtu.be/uWyaPkt-VOI?list=PL9D9FC436B881BA21',
2888 'only_matching': True,
2891 def _real_extract(self, url):
2892 mobj = re.match(self._VALID_URL, url)
2893 video_id = mobj.group('id')
2894 playlist_id = mobj.group('playlist_id')
2895 return self.url_result(
2896 update_url_query('https://www.youtube.com/watch', {
2898 'list': playlist_id,
2899 'feature': 'youtu.be',
2900 }), ie=YoutubeTabIE.ie_key(), video_id=playlist_id)
2903 class YoutubeYtUserIE(InfoExtractor):
2904 _VALID_URL = r'ytuser:(?P<id>.+)'
2906 'url': 'ytuser:phihag',
2907 'only_matching': True,
2910 def _real_extract(self, url):
2911 user_id = self._match_id(url)
2912 return self.url_result(
2913 'https://www.youtube.com/user/%s' % user_id,
2914 ie=YoutubeTabIE.ie_key(), video_id=user_id)
2917 class YoutubeFavouritesIE(YoutubeBaseInfoExtractor):
2918 IE_NAME = 'youtube:favorites'
2919 IE_DESC = 'YouTube.com favourite videos, ":ytfav" for short (requires authentication)'
2920 _VALID_URL = r'https?://(?:www\.)?youtube\.com/my_favorites|:ytfav(?:ou?rites)?'
2921 _LOGIN_REQUIRED = True
2924 'only_matching': True,
2926 'url': ':ytfavorites',
2927 'only_matching': True,
2930 def _real_extract(self, url):
2931 return self.url_result(
2932 'https://www.youtube.com/playlist?list=LL',
2933 ie=YoutubeTabIE.ie_key())
2936 class YoutubeSearchIE(SearchInfoExtractor, YoutubeBaseInfoExtractor):
2937 IE_DESC = 'YouTube.com searches'
2938 # there doesn't appear to be a real limit, for example if you search for
2939 # 'python' you get more than 8.000.000 results
2940 _MAX_RESULTS = float('inf')
2941 IE_NAME = 'youtube:search'
2942 _SEARCH_KEY = 'ytsearch'
2943 _SEARCH_PARAMS = None
2946 def _entries(self, query, n):
2950 'clientName': 'WEB',
2951 'clientVersion': '2.20201021.03.00',
2956 if self._SEARCH_PARAMS:
2957 data['params'] = self._SEARCH_PARAMS
2959 for page_num in itertools.count(1):
2960 search = self._download_json(
2961 'https://www.youtube.com/youtubei/v1/search?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
2962 video_id='query "%s"' % query,
2963 note='Downloading page %s' % page_num,
2964 errnote='Unable to download API page', fatal=False,
2965 data=json.dumps(data).encode('utf8'),
2966 headers={'content-type': 'application/json'})
2969 slr_contents = try_get(
2971 (lambda x: x['contents']['twoColumnSearchResultsRenderer']['primaryContents']['sectionListRenderer']['contents'],
2972 lambda x: x['onResponseReceivedCommands'][0]['appendContinuationItemsAction']['continuationItems']),
2974 if not slr_contents:
2976 for slr_content in slr_contents:
2977 isr_contents = try_get(
2979 lambda x: x['itemSectionRenderer']['contents'],
2981 if not isr_contents:
2983 for content in isr_contents:
2984 if not isinstance(content, dict):
2986 video = content.get('videoRenderer')
2987 if not isinstance(video, dict):
2989 video_id = video.get('videoId')
2992 yield self._extract_video(video)
2998 lambda x: x[-1]['continuationItemRenderer']['continuationEndpoint']['continuationCommand']['token'],
3002 data['continuation'] = token
3004 def _get_n_results(self, query, n):
3005 """Get a specified number of results for a query"""
3006 return self.playlist_result(self._entries(query, n), query)
3009 class YoutubeSearchDateIE(YoutubeSearchIE):
3010 IE_NAME = YoutubeSearchIE.IE_NAME + ':date'
3011 _SEARCH_KEY = 'ytsearchdate'
3012 IE_DESC = 'YouTube.com searches, newest videos first'
3013 _SEARCH_PARAMS = 'CAI%3D'
3017 class YoutubeSearchURLIE(YoutubeSearchIE):
3018 IE_DESC = 'YouTube.com search URLs'
3019 IE_NAME = 'youtube:search_url'
3020 _VALID_URL = r'https?://(?:www\.)?youtube\.com/results\?(.*?&)?(?:search_query|q)=(?P<query>[^&]+)(?:[&]|$)'
3022 'url': 'https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video',
3023 'playlist_mincount': 5,
3025 'title': 'youtube-dl test video',
3028 'url': 'https://www.youtube.com/results?q=test&sp=EgQIBBgB',
3029 'only_matching': True,
3032 def _real_extract(self, url):
3033 mobj = re.match(self._VALID_URL, url)
3034 query = compat_urllib_parse_unquote_plus(mobj.group('query'))
3035 webpage = self._download_webpage(url, query)
3036 return self.playlist_result(self._process_page(webpage), playlist_title=query)
3040 class YoutubeFeedsInfoExtractor(YoutubeTabIE):
3042 Base class for feed extractors
3043 Subclasses must define the _FEED_NAME property.
3045 _LOGIN_REQUIRED = True
3049 return 'youtube:%s' % self._FEED_NAME
3051 def _real_initialize(self):
3054 def _real_extract(self, url):
3055 return self.url_result(
3056 'https://www.youtube.com/feed/%s' % self._FEED_NAME,
3057 ie=YoutubeTabIE.ie_key())
3060 class YoutubeWatchLaterIE(InfoExtractor):
3061 IE_NAME = 'youtube:watchlater'
3062 IE_DESC = 'Youtube watch later list, ":ytwatchlater" for short (requires authentication)'
3063 _VALID_URL = r':ytwatchlater'
3065 'url': ':ytwatchlater',
3066 'only_matching': True,
3069 def _real_extract(self, url):
3070 return self.url_result(
3071 'https://www.youtube.com/playlist?list=WL', ie=YoutubeTabIE.ie_key())
3074 class YoutubeRecommendedIE(YoutubeFeedsInfoExtractor):
3075 IE_DESC = 'YouTube.com recommended videos, ":ytrec" for short (requires authentication)'
3076 _VALID_URL = r':ytrec(?:ommended)?'
3077 _FEED_NAME = 'recommended'
3080 'only_matching': True,
3082 'url': ':ytrecommended',
3083 'only_matching': True,
3087 class YoutubeSubscriptionsIE(YoutubeFeedsInfoExtractor):
3088 IE_DESC = 'YouTube.com subscriptions feed, "ytsubs" keyword (requires authentication)'
3089 _VALID_URL = r':ytsubs(?:criptions)?'
3090 _FEED_NAME = 'subscriptions'
3093 'only_matching': True,
3095 'url': ':ytsubscriptions',
3096 'only_matching': True,
3100 class YoutubeHistoryIE(YoutubeFeedsInfoExtractor):
3101 IE_DESC = 'Youtube watch history, ":ythistory" for short (requires authentication)'
3102 _VALID_URL = r':ythistory'
3103 _FEED_NAME = 'history'
3105 'url': ':ythistory',
3106 'only_matching': True,
3110 class YoutubeTruncatedURLIE(InfoExtractor):
3111 IE_NAME = 'youtube:truncated_url'
3112 IE_DESC = False # Do not list
3113 _VALID_URL = r'''(?x)
3115 (?:\w+\.)?[yY][oO][uU][tT][uU][bB][eE](?:-nocookie)?\.com/
3118 annotation_id=annotation_[^&]+|
3124 attribution_link\?a=[^&]+
3130 'url': 'https://www.youtube.com/watch?annotation_id=annotation_3951667041',
3131 'only_matching': True,
3133 'url': 'https://www.youtube.com/watch?',
3134 'only_matching': True,
3136 'url': 'https://www.youtube.com/watch?x-yt-cl=84503534',
3137 'only_matching': True,
3139 'url': 'https://www.youtube.com/watch?feature=foo',
3140 'only_matching': True,
3142 'url': 'https://www.youtube.com/watch?hl=en-GB',
3143 'only_matching': True,
3145 'url': 'https://www.youtube.com/watch?t=2372',
3146 'only_matching': True,
3149 def _real_extract(self, url):
3150 raise ExtractorError(
3151 'Did you forget to quote the URL? Remember that & is a meta '
3152 'character in most shells, so you want to put the URL in quotes, '
3154 '"https://www.youtube.com/watch?feature=foo&v=BaW_jenozKc" '
3155 ' or simply youtube-dl BaW_jenozKc .',
3159 class YoutubeTruncatedIDIE(InfoExtractor):
3160 IE_NAME = 'youtube:truncated_id'
3161 IE_DESC = False # Do not list
3162 _VALID_URL = r'https?://(?:www\.)?youtube\.com/watch\?v=(?P<id>[0-9A-Za-z_-]{1,10})$'
3165 'url': 'https://www.youtube.com/watch?v=N_708QY7Ob',
3166 'only_matching': True,
3169 def _real_extract(self, url):
3170 video_id = self._match_id(url)
3171 raise ExtractorError(
3172 'Incomplete YouTube ID %s. URL %s looks truncated.' % (video_id, url),