20 from .common
import InfoExtractor
, SearchInfoExtractor
21 from .openload
import PhantomJSwrapper
22 from ..compat
import functools
23 from ..jsinterp
import JSInterpreter
67 # any clients starting with _ cannot be explicitly requested by the user
70 'INNERTUBE_API_KEY': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
71 'INNERTUBE_CONTEXT': {
74 'clientVersion': '2.20220801.00.00',
77 'INNERTUBE_CONTEXT_CLIENT_NAME': 1
80 'INNERTUBE_API_KEY': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
81 'INNERTUBE_CONTEXT': {
83 'clientName': 'WEB_EMBEDDED_PLAYER',
84 'clientVersion': '1.20220731.00.00',
87 'INNERTUBE_CONTEXT_CLIENT_NAME': 56
90 'INNERTUBE_API_KEY': 'AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30',
91 'INNERTUBE_HOST': 'music.youtube.com',
92 'INNERTUBE_CONTEXT': {
94 'clientName': 'WEB_REMIX',
95 'clientVersion': '1.20220727.01.00',
98 'INNERTUBE_CONTEXT_CLIENT_NAME': 67,
101 'INNERTUBE_API_KEY': 'AIzaSyBUPetSUmoZL-OhlxA7wSac5XinrygCqMo',
102 'INNERTUBE_CONTEXT': {
104 'clientName': 'WEB_CREATOR',
105 'clientVersion': '1.20220726.00.00',
108 'INNERTUBE_CONTEXT_CLIENT_NAME': 62,
111 'INNERTUBE_API_KEY': 'AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w',
112 'INNERTUBE_CONTEXT': {
114 'clientName': 'ANDROID',
115 'clientVersion': '17.31.35',
116 'androidSdkVersion': 30,
117 'userAgent': 'com.google.android.youtube/17.31.35 (Linux; U; Android 11) gzip'
120 'INNERTUBE_CONTEXT_CLIENT_NAME': 3,
121 'REQUIRE_JS_PLAYER': False
123 'android_embedded': {
124 'INNERTUBE_API_KEY': 'AIzaSyCjc_pVEDi4qsv5MtC2dMXzpIaDoRFLsxw',
125 'INNERTUBE_CONTEXT': {
127 'clientName': 'ANDROID_EMBEDDED_PLAYER',
128 'clientVersion': '17.31.35',
129 'androidSdkVersion': 30,
130 'userAgent': 'com.google.android.youtube/17.31.35 (Linux; U; Android 11) gzip'
133 'INNERTUBE_CONTEXT_CLIENT_NAME': 55,
134 'REQUIRE_JS_PLAYER': False
137 'INNERTUBE_API_KEY': 'AIzaSyAOghZGza2MQSZkY_zfZ370N-PUdXEo8AI',
138 'INNERTUBE_CONTEXT': {
140 'clientName': 'ANDROID_MUSIC',
141 'clientVersion': '5.16.51',
142 'androidSdkVersion': 30,
143 'userAgent': 'com.google.android.apps.youtube.music/5.16.51 (Linux; U; Android 11) gzip'
146 'INNERTUBE_CONTEXT_CLIENT_NAME': 21,
147 'REQUIRE_JS_PLAYER': False
150 'INNERTUBE_API_KEY': 'AIzaSyD_qjV8zaaUMehtLkrKFgVeSX_Iqbtyws8',
151 'INNERTUBE_CONTEXT': {
153 'clientName': 'ANDROID_CREATOR',
154 'clientVersion': '22.30.100',
155 'androidSdkVersion': 30,
156 'userAgent': 'com.google.android.apps.youtube.creator/22.30.100 (Linux; U; Android 11) gzip'
159 'INNERTUBE_CONTEXT_CLIENT_NAME': 14,
160 'REQUIRE_JS_PLAYER': False
162 # iOS clients have HLS live streams. Setting device model to get 60fps formats.
163 # See: https://github.com/TeamNewPipe/NewPipeExtractor/issues/680#issuecomment-1002724558
165 'INNERTUBE_API_KEY': 'AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc',
166 'INNERTUBE_CONTEXT': {
169 'clientVersion': '17.33.2',
170 'deviceModel': 'iPhone14,3',
171 'userAgent': 'com.google.ios.youtube/17.33.2 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)'
174 'INNERTUBE_CONTEXT_CLIENT_NAME': 5,
175 'REQUIRE_JS_PLAYER': False
178 'INNERTUBE_CONTEXT': {
180 'clientName': 'IOS_MESSAGES_EXTENSION',
181 'clientVersion': '17.33.2',
182 'deviceModel': 'iPhone14,3',
183 'userAgent': 'com.google.ios.youtube/17.33.2 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)'
186 'INNERTUBE_CONTEXT_CLIENT_NAME': 66,
187 'REQUIRE_JS_PLAYER': False
190 'INNERTUBE_API_KEY': 'AIzaSyBAETezhkwP0ZWA02RsqT1zu78Fpt0bC_s',
191 'INNERTUBE_CONTEXT': {
193 'clientName': 'IOS_MUSIC',
194 'clientVersion': '5.21',
195 'deviceModel': 'iPhone14,3',
196 'userAgent': 'com.google.ios.youtubemusic/5.21 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)'
199 'INNERTUBE_CONTEXT_CLIENT_NAME': 26,
200 'REQUIRE_JS_PLAYER': False
203 'INNERTUBE_CONTEXT': {
205 'clientName': 'IOS_CREATOR',
206 'clientVersion': '22.33.101',
207 'deviceModel': 'iPhone14,3',
208 'userAgent': 'com.google.ios.ytcreator/22.33.101 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)'
211 'INNERTUBE_CONTEXT_CLIENT_NAME': 15,
212 'REQUIRE_JS_PLAYER': False
214 # mweb has 'ultralow' formats
215 # See: https://github.com/yt-dlp/yt-dlp/pull/557
217 'INNERTUBE_API_KEY': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
218 'INNERTUBE_CONTEXT': {
220 'clientName': 'MWEB',
221 'clientVersion': '2.20220801.00.00',
224 'INNERTUBE_CONTEXT_CLIENT_NAME': 2
226 # This client can access age restricted videos (unless the uploader has disabled the 'allow embedding' option)
227 # See: https://github.com/zerodytrash/YouTube-Internal-Clients
229 'INNERTUBE_API_KEY': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
230 'INNERTUBE_CONTEXT': {
232 'clientName': 'TVHTML5_SIMPLY_EMBEDDED_PLAYER',
233 'clientVersion': '2.0',
236 'INNERTUBE_CONTEXT_CLIENT_NAME': 85
241 def _split_innertube_client(client_name
):
242 variant
, *base
= client_name
.rsplit('.', 1)
244 return variant
, base
[0], variant
245 base
, *variant
= client_name
.split('_', 1)
246 return client_name
, base
, variant
[0] if variant
else None
249 def build_innertube_clients():
251 'embedUrl': 'https://www.youtube.com/', # Can be any valid URL
253 BASE_CLIENTS
= ('android', 'web', 'tv', 'ios', 'mweb')
254 priority
= qualities(BASE_CLIENTS
[::-1])
256 for client
, ytcfg
in tuple(INNERTUBE_CLIENTS
.items()):
257 ytcfg
.setdefault('INNERTUBE_API_KEY', 'AIzaSyDCU8hByM-4DrUqRUYnGn-3llEO78bcxq8')
258 ytcfg
.setdefault('INNERTUBE_HOST', 'www.youtube.com')
259 ytcfg
.setdefault('REQUIRE_JS_PLAYER', True)
260 ytcfg
['INNERTUBE_CONTEXT']['client'].setdefault('hl', 'en')
262 _
, base_client
, variant
= _split_innertube_client(client
)
263 ytcfg
['priority'] = 10 * priority(base_client
)
266 INNERTUBE_CLIENTS
[f
'{client}_embedscreen'] = embedscreen
= copy
.deepcopy(ytcfg
)
267 embedscreen
['INNERTUBE_CONTEXT']['client']['clientScreen'] = 'EMBED'
268 embedscreen
['INNERTUBE_CONTEXT']['thirdParty'] = THIRD_PARTY
269 embedscreen
['priority'] -= 3
270 elif variant
== 'embedded':
271 ytcfg
['INNERTUBE_CONTEXT']['thirdParty'] = THIRD_PARTY
272 ytcfg
['priority'] -= 2
274 ytcfg
['priority'] -= 3
277 build_innertube_clients()
280 class BadgeType(enum
.Enum
):
281 AVAILABILITY_UNLISTED
= enum
.auto()
282 AVAILABILITY_PRIVATE
= enum
.auto()
283 AVAILABILITY_PUBLIC
= enum
.auto()
284 AVAILABILITY_PREMIUM
= enum
.auto()
285 AVAILABILITY_SUBSCRIPTION
= enum
.auto()
286 LIVE_NOW
= enum
.auto()
289 class YoutubeBaseInfoExtractor(InfoExtractor
):
290 """Provide base functions for Youtube extractors"""
293 r
'channel|c|user|playlist|watch|w|v|embed|e|watch_popup|clip|'
294 r
'shorts|movies|results|search|shared|hashtag|trending|explore|feed|feeds|'
295 r
'browse|oembed|get_video_info|iframe_api|s/player|source|'
296 r
'storefront|oops|index|account|t/terms|about|upload|signin|logout')
298 _PLAYLIST_ID_RE
= r
'(?:(?:PL|LL|EC|UU|FL|RD|UL|TL|PU|OLAK5uy_)[0-9A-Za-z-_]{10,}|RDMM|WL|LL|LM)'
300 # _NETRC_MACHINE = 'youtube'
302 # If True it will raise an error if no login info is provided
303 _LOGIN_REQUIRED
= False
306 # invidious-redirect websites
307 r
'(?:www\.)?redirect\.invidious\.io',
308 r
'(?:(?:www|dev)\.)?invidio\.us',
309 # Invidious instances taken from https://github.com/iv-org/documentation/blob/master/docs/instances.md
310 r
'(?:www\.)?invidious\.pussthecat\.org',
311 r
'(?:www\.)?invidious\.zee\.li',
312 r
'(?:www\.)?invidious\.ethibox\.fr',
313 r
'(?:www\.)?invidious\.3o7z6yfxhbw7n3za4rss6l434kmv55cgw2vuziwuigpwegswvwzqipyd\.onion',
314 r
'(?:www\.)?osbivz6guyeahrwp2lnwyjk2xos342h4ocsxyqrlaopqjuhwn2djiiyd\.onion',
315 r
'(?:www\.)?u2cvlit75owumwpy4dj2hsmvkq7nvrclkpht7xgyye2pyoxhpmclkrad\.onion',
316 # youtube-dl invidious instances list
317 r
'(?:(?:www|no)\.)?invidiou\.sh',
318 r
'(?:(?:www|fi)\.)?invidious\.snopyta\.org',
319 r
'(?:www\.)?invidious\.kabi\.tk',
320 r
'(?:www\.)?invidious\.mastodon\.host',
321 r
'(?:www\.)?invidious\.zapashcanon\.fr',
322 r
'(?:www\.)?(?:invidious(?:-us)?|piped)\.kavin\.rocks',
323 r
'(?:www\.)?invidious\.tinfoil-hat\.net',
324 r
'(?:www\.)?invidious\.himiko\.cloud',
325 r
'(?:www\.)?invidious\.reallyancient\.tech',
326 r
'(?:www\.)?invidious\.tube',
327 r
'(?:www\.)?invidiou\.site',
328 r
'(?:www\.)?invidious\.site',
329 r
'(?:www\.)?invidious\.xyz',
330 r
'(?:www\.)?invidious\.nixnet\.xyz',
331 r
'(?:www\.)?invidious\.048596\.xyz',
332 r
'(?:www\.)?invidious\.drycat\.fr',
333 r
'(?:www\.)?inv\.skyn3t\.in',
334 r
'(?:www\.)?tube\.poal\.co',
335 r
'(?:www\.)?tube\.connect\.cafe',
336 r
'(?:www\.)?vid\.wxzm\.sx',
337 r
'(?:www\.)?vid\.mint\.lgbt',
338 r
'(?:www\.)?vid\.puffyan\.us',
339 r
'(?:www\.)?yewtu\.be',
340 r
'(?:www\.)?yt\.elukerio\.org',
341 r
'(?:www\.)?yt\.lelux\.fi',
342 r
'(?:www\.)?invidious\.ggc-project\.de',
343 r
'(?:www\.)?yt\.maisputain\.ovh',
344 r
'(?:www\.)?ytprivate\.com',
345 r
'(?:www\.)?invidious\.13ad\.de',
346 r
'(?:www\.)?invidious\.toot\.koeln',
347 r
'(?:www\.)?invidious\.fdn\.fr',
348 r
'(?:www\.)?watch\.nettohikari\.com',
349 r
'(?:www\.)?invidious\.namazso\.eu',
350 r
'(?:www\.)?invidious\.silkky\.cloud',
351 r
'(?:www\.)?invidious\.exonip\.de',
352 r
'(?:www\.)?invidious\.riverside\.rocks',
353 r
'(?:www\.)?invidious\.blamefran\.net',
354 r
'(?:www\.)?invidious\.moomoo\.de',
355 r
'(?:www\.)?ytb\.trom\.tf',
356 r
'(?:www\.)?yt\.cyberhost\.uk',
357 r
'(?:www\.)?kgg2m7yk5aybusll\.onion',
358 r
'(?:www\.)?qklhadlycap4cnod\.onion',
359 r
'(?:www\.)?axqzx4s6s54s32yentfqojs3x5i7faxza6xo3ehd4bzzsg2ii4fv2iid\.onion',
360 r
'(?:www\.)?c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid\.onion',
361 r
'(?:www\.)?fz253lmuao3strwbfbmx46yu7acac2jz27iwtorgmbqlkurlclmancad\.onion',
362 r
'(?:www\.)?invidious\.l4qlywnpwqsluw65ts7md3khrivpirse744un3x7mlskqauz5pyuzgqd\.onion',
363 r
'(?:www\.)?owxfohz4kjyv25fvlqilyxast7inivgiktls3th44jhk3ej3i7ya\.b32\.i2p',
364 r
'(?:www\.)?4l2dgddgsrkf2ous66i6seeyi6etzfgrue332grh2n7madpwopotugyd\.onion',
365 r
'(?:www\.)?w6ijuptxiku4xpnnaetxvnkc5vqcdu7mgns2u77qefoixi63vbvnpnqd\.onion',
366 r
'(?:www\.)?kbjggqkzv65ivcqj6bumvp337z6264huv5kpkwuv6gu5yjiskvan7fad\.onion',
367 r
'(?:www\.)?grwp24hodrefzvjjuccrkw3mjq4tzhaaq32amf33dzpmuxe7ilepcmad\.onion',
368 r
'(?:www\.)?hpniueoejy4opn7bc4ftgazyqjoeqwlvh2uiku2xqku6zpoa4bf5ruid\.onion',
369 # piped instances from https://github.com/TeamPiped/Piped/wiki/Instances
370 r
'(?:www\.)?piped\.kavin\.rocks',
371 r
'(?:www\.)?piped\.silkky\.cloud',
372 r
'(?:www\.)?piped\.tokhmi\.xyz',
373 r
'(?:www\.)?piped\.moomoo\.me',
375 r
'(?:www\.)?piped\.syncpundit\.com',
376 r
'(?:www\.)?piped\.mha\.fi',
377 r
'(?:www\.)?piped\.mint\.lgbt',
378 r
'(?:www\.)?piped\.privacy\.com\.de',
381 # extracted from account/account_menu ep
382 # XXX: These are the supported YouTube UI and API languages,
383 # which is slightly different from languages supported for translation in YouTube studio
384 _SUPPORTED_LANG_CODES
= [
385 'af', 'az', 'id', 'ms', 'bs', 'ca', 'cs', 'da', 'de', 'et', 'en-IN', 'en-GB', 'en', 'es',
386 'es-419', 'es-US', 'eu', 'fil', 'fr', 'fr-CA', 'gl', 'hr', 'zu', 'is', 'it', 'sw', 'lv',
387 'lt', 'hu', 'nl', 'no', 'uz', 'pl', 'pt-PT', 'pt', 'ro', 'sq', 'sk', 'sl', 'sr-Latn', 'fi',
388 'sv', 'vi', 'tr', 'be', 'bg', 'ky', 'kk', 'mk', 'mn', 'ru', 'sr', 'uk', 'el', 'hy', 'iw',
389 'ur', 'ar', 'fa', 'ne', 'mr', 'hi', 'as', 'bn', 'pa', 'gu', 'or', 'ta', 'te', 'kn', 'ml',
390 'si', 'th', 'lo', 'my', 'ka', 'am', 'km', 'zh-CN', 'zh-TW', 'zh-HK', 'ja', 'ko'
393 @functools.cached_property
394 def _preferred_lang(self
):
396 Returns a language code supported by YouTube for the user preferred language.
397 Returns None if no preferred language set.
399 preferred_lang
= self
._configuration
_arg
('lang', ie_key
='Youtube', casesense
=True, default
=[''])[0]
400 if not preferred_lang
:
402 if preferred_lang
not in self
._SUPPORTED
_LANG
_CODES
:
403 raise ExtractorError(
404 f
'Unsupported language code: {preferred_lang}. Supported language codes (case-sensitive): {join_nonempty(*self._SUPPORTED_LANG_CODES, delim=", ")}.',
406 elif preferred_lang
!= 'en':
408 f
'Preferring "{preferred_lang}" translated fields. Note that some metadata extraction may fail or be incorrect.')
409 return preferred_lang
411 def _initialize_consent(self
):
412 cookies
= self
._get
_cookies
('https://www.youtube.com/')
413 if cookies
.get('__Secure-3PSID'):
416 consent
= cookies
.get('CONSENT')
418 if 'YES' in consent
.value
:
420 consent_id
= self
._search
_regex
(
421 r
'PENDING\+(\d+)', consent
.value
, 'consent', default
=None)
423 consent_id
= random
.randint(100, 999)
424 self
._set
_cookie
('.youtube.com', 'CONSENT', 'YES+cb.20210328-17-p0.en+FX+%s' % consent_id
)
426 def _initialize_pref(self
):
427 cookies
= self
._get
_cookies
('https://www.youtube.com/')
428 pref_cookie
= cookies
.get('PREF')
432 pref
= dict(urllib
.parse
.parse_qsl(pref_cookie
.value
))
434 self
.report_warning('Failed to parse user PREF cookie' + bug_reports_message())
435 pref
.update({'hl': self._preferred_lang or 'en', 'tz': 'UTC'}
)
436 self
._set
_cookie
('.youtube.com', name
='PREF', value
=urllib
.parse
.urlencode(pref
))
438 def _real_initialize(self
):
439 self
._initialize
_pref
()
440 self
._initialize
_consent
()
441 self
._check
_login
_required
()
443 def _check_login_required(self
):
444 if self
._LOGIN
_REQUIRED
and not self
._cookies
_passed
:
445 self
.raise_login_required('Login details are needed to download this content', method
='cookies')
447 _YT_INITIAL_DATA_RE
= r
'(?:window\s*\[\s*["\']ytInitialData
["\']\s*\]|ytInitialData)\s*='
448 _YT_INITIAL_PLAYER_RESPONSE_RE = r'ytInitialPlayerResponse\s*='
450 def _get_default_ytcfg(self, client='web'):
451 return copy.deepcopy(INNERTUBE_CLIENTS[client])
453 def _get_innertube_host(self, client='web'):
454 return INNERTUBE_CLIENTS[client]['INNERTUBE_HOST']
456 def _ytcfg_get_safe(self, ytcfg, getter, expected_type=None, default_client='web'):
457 # try_get but with fallback to default ytcfg client values when present
458 _func = lambda y: try_get(y, getter, expected_type)
459 return _func(ytcfg) or _func(self._get_default_ytcfg(default_client))
461 def _extract_client_name(self, ytcfg, default_client='web'):
462 return self._ytcfg_get_safe(
463 ytcfg, (lambda x: x['INNERTUBE_CLIENT_NAME'],
464 lambda x: x['INNERTUBE_CONTEXT']['client']['clientName']), str, default_client)
466 def _extract_client_version(self, ytcfg, default_client='web'):
467 return self._ytcfg_get_safe(
468 ytcfg, (lambda x: x['INNERTUBE_CLIENT_VERSION'],
469 lambda x: x['INNERTUBE_CONTEXT']['client']['clientVersion']), str, default_client)
471 def _select_api_hostname(self, req_api_hostname, default_client=None):
472 return (self._configuration_arg('innertube_host', [''], ie_key=YoutubeIE.ie_key())[0]
473 or req_api_hostname or self._get_innertube_host(default_client or 'web'))
475 def _extract_api_key(self, ytcfg=None, default_client='web'):
476 return self._ytcfg_get_safe(ytcfg, lambda x: x['INNERTUBE_API_KEY'], str, default_client)
478 def _extract_context(self, ytcfg=None, default_client='web'):
480 (ytcfg, self._get_default_ytcfg(default_client)), 'INNERTUBE_CONTEXT', expected_type=dict)
481 # Enforce language and tz for extraction
482 client_context = traverse_obj(context, 'client', expected_type=dict, default={})
483 client_context.update({'hl': self._preferred_lang or 'en', 'timeZone': 'UTC', 'utcOffsetMinutes': 0})
488 def _generate_sapisidhash_header(self, origin='https://www.youtube.com'):
489 time_now = round(time.time())
490 if self._SAPISID is None:
491 yt_cookies = self._get_cookies('https://www.youtube.com')
492 # Sometimes SAPISID cookie isn't present but __Secure-3PAPISID is.
493 # See: https://github.com/yt-dlp/yt-dlp/issues/393
494 sapisid_cookie = dict_get(
495 yt_cookies, ('__Secure-3PAPISID', 'SAPISID'))
496 if sapisid_cookie and sapisid_cookie.value:
497 self._SAPISID = sapisid_cookie.value
498 self.write_debug('Extracted SAPISID cookie')
499 # SAPISID cookie is required if not already present
500 if not yt_cookies.get('SAPISID'):
501 self.write_debug('Copying __Secure-3PAPISID cookie to SAPISID cookie')
503 '.youtube.com', 'SAPISID', self._SAPISID, secure=True, expire_time=time_now + 3600)
505 self._SAPISID = False
506 if not self._SAPISID:
508 # SAPISIDHASH algorithm from https://stackoverflow.com/a/32065323
509 sapisidhash = hashlib.sha1(
510 f'{time_now} {self._SAPISID} {origin}'.encode()).hexdigest()
511 return f'SAPISIDHASH {time_now}_{sapisidhash}'
513 def _call_api(self, ep, query, video_id, fatal=True, headers=None,
514 note='Downloading API JSON', errnote='Unable to download API page',
515 context=None, api_key=None, api_hostname=None, default_client='web'):
517 data = {'context': context} if context else {'context': self._extract_context(default_client=default_client)}
519 real_headers = self.generate_api_headers(default_client=default_client)
520 real_headers.update({'content-type': 'application/json'})
522 real_headers.update(headers)
523 api_key = (self._configuration_arg('innertube_key', [''], ie_key=YoutubeIE.ie_key(), casesense=True)[0]
524 or api_key or self._extract_api_key(default_client=default_client))
525 return self._download_json(
526 f'https://{self._select_api_hostname(api_hostname, default_client)}/youtubei/v1/{ep}',
527 video_id=video_id, fatal=fatal, note=note, errnote=errnote,
528 data=json.dumps(data).encode('utf8'), headers=real_headers,
529 query={'key': api_key, 'prettyPrint': 'false'})
531 def extract_yt_initial_data(self, item_id, webpage, fatal=True):
532 return self._search_json(self._YT_INITIAL_DATA_RE, webpage, 'yt initial data', item_id, fatal=fatal)
535 def _extract_session_index(*data):
537 Index of current account in account list.
538 See: https://github.com/yt-dlp/yt-dlp/pull/519
541 session_index = int_or_none(try_get(ytcfg, lambda x: x['SESSION_INDEX']))
542 if session_index is not None:
546 def _extract_identity_token(self, ytcfg=None, webpage=None):
548 token = try_get(ytcfg, lambda x: x['ID_TOKEN'], str)
552 return self._search_regex(
553 r'\bID_TOKEN["\']\s
*:\s
*["\'](.+?)["\']', webpage,
554 'identity token
', default=None, fatal=False)
557 def _extract_account_syncid(*args):
559 Extract syncId required to download private playlists of secondary channels
560 @params response and/or ytcfg
563 # ytcfg includes channel_syncid if on secondary channel
564 delegated_sid = try_get(data, lambda x: x['DELEGATED_SESSION_ID
'], str)
568 data, (lambda x: x['responseContext
']['mainAppWebResponseContext
']['datasyncId
'],
569 lambda x: x['DATASYNC_ID
']), str) or '').split('||
')
570 if len(sync_ids) >= 2 and sync_ids[1]:
571 # datasyncid is of the form "channel_syncid||user_syncid" for secondary channel
572 # and just "user_syncid||" for primary channel. We only want the channel_syncid
576 def _extract_visitor_data(*args):
578 Extracts visitorData from an API response or ytcfg
579 Appears to be used to track session state
582 args, [('VISITOR_DATA
', ('INNERTUBE_CONTEXT
', 'client
', 'visitorData
'), ('responseContext
', 'visitorData
'))],
585 @functools.cached_property
586 def is_authenticated(self):
587 return bool(self._generate_sapisidhash_header())
589 def extract_ytcfg(self, video_id, webpage):
592 return self._parse_json(
594 r'ytcfg\
.set\s
*\
(\s
*({.+?}
)\s
*\
)\s
*;', webpage, 'ytcfg
',
595 default='{}'), video_id, fatal=False) or {}
597 def generate_api_headers(
598 self
, *, ytcfg
=None, account_syncid
=None, session_index
=None,
599 visitor_data
=None, identity_token
=None, api_hostname
=None, default_client
='web'):
601 origin
= 'https://' + (self
._select
_api
_hostname
(api_hostname
, default_client
))
603 'X-YouTube-Client-Name': str(
604 self
._ytcfg
_get
_safe
(ytcfg
, lambda x
: x
['INNERTUBE_CONTEXT_CLIENT_NAME'], default_client
=default_client
)),
605 'X-YouTube-Client-Version': self
._extract
_client
_version
(ytcfg
, default_client
),
607 'X-Youtube-Identity-Token': identity_token
or self
._extract
_identity
_token
(ytcfg
),
608 'X-Goog-PageId': account_syncid
or self
._extract
_account
_syncid
(ytcfg
),
609 'X-Goog-Visitor-Id': visitor_data
or self
._extract
_visitor
_data
(ytcfg
),
610 'User-Agent': self
._ytcfg
_get
_safe
(ytcfg
, lambda x
: x
['INNERTUBE_CONTEXT']['client']['userAgent'], default_client
=default_client
)
612 if session_index
is None:
613 session_index
= self
._extract
_session
_index
(ytcfg
)
614 if account_syncid
or session_index
is not None:
615 headers
['X-Goog-AuthUser'] = session_index
if session_index
is not None else 0
617 auth
= self
._generate
_sapisidhash
_header
(origin
)
619 headers
['Authorization'] = auth
620 headers
['X-Origin'] = origin
621 return filter_dict(headers
)
623 def _download_ytcfg(self
, client
, video_id
):
625 'web': 'https://www.youtube.com',
626 'web_music': 'https://music.youtube.com',
627 'web_embedded': f
'https://www.youtube.com/embed/{video_id}?html5=1'
631 webpage
= self
._download
_webpage
(
632 url
, video_id
, fatal
=False, note
=f
'Downloading {client.replace("_", " ").strip()} client config')
633 return self
.extract_ytcfg(video_id
, webpage
) or {}
636 def _build_api_continuation_query(continuation
, ctp
=None):
638 'continuation': continuation
640 # TODO: Inconsistency with clickTrackingParams.
641 # Currently we have a fixed ctp contained within context (from ytcfg)
642 # and a ctp in root query for continuation.
644 query
['clickTracking'] = {'clickTrackingParams': ctp}
648 def _extract_next_continuation_data(cls
, renderer
):
649 next_continuation
= try_get(
650 renderer
, (lambda x
: x
['continuations'][0]['nextContinuationData'],
651 lambda x
: x
['continuation']['reloadContinuationData']), dict)
652 if not next_continuation
:
654 continuation
= next_continuation
.get('continuation')
657 ctp
= next_continuation
.get('clickTrackingParams')
658 return cls
._build
_api
_continuation
_query
(continuation
, ctp
)
661 def _extract_continuation_ep_data(cls
, continuation_ep
: dict):
662 if isinstance(continuation_ep
, dict):
663 continuation
= try_get(
664 continuation_ep
, lambda x
: x
['continuationCommand']['token'], str)
667 ctp
= continuation_ep
.get('clickTrackingParams')
668 return cls
._build
_api
_continuation
_query
(continuation
, ctp
)
671 def _extract_continuation(cls
, renderer
):
672 next_continuation
= cls
._extract
_next
_continuation
_data
(renderer
)
673 if next_continuation
:
674 return next_continuation
676 return traverse_obj(renderer
, (
677 ('contents', 'items', 'rows'), ..., 'continuationItemRenderer',
678 ('continuationEndpoint', ('button', 'buttonRenderer', 'command'))
679 ), get_all
=False, expected_type
=cls
._extract
_continuation
_ep
_data
)
682 def _extract_alerts(cls
, data
):
683 for alert_dict
in try_get(data
, lambda x
: x
['alerts'], list) or []:
684 if not isinstance(alert_dict
, dict):
686 for alert
in alert_dict
.values():
687 alert_type
= alert
.get('type')
690 message
= cls
._get
_text
(alert
, 'text')
692 yield alert_type
, message
694 def _report_alerts(self
, alerts
, expected
=True, fatal
=True, only_once
=False):
697 for alert_type
, alert_message
in alerts
:
698 if alert_type
.lower() == 'error' and fatal
:
699 errors
.append([alert_type
, alert_message
])
701 warnings
.append([alert_type
, alert_message
])
703 for alert_type
, alert_message
in (warnings
+ errors
[:-1]):
704 self
.report_warning(f
'YouTube said: {alert_type} - {alert_message}', only_once
=only_once
)
706 raise ExtractorError('YouTube said: %s' % errors
[-1][1], expected
=expected
)
708 def _extract_and_report_alerts(self
, data
, *args
, **kwargs
):
709 return self
._report
_alerts
(self
._extract
_alerts
(data
), *args
, **kwargs
)
711 def _extract_badges(self
, renderer
: dict):
713 'PRIVACY_UNLISTED': BadgeType
.AVAILABILITY_UNLISTED
,
714 'PRIVACY_PRIVATE': BadgeType
.AVAILABILITY_PRIVATE
,
715 'PRIVACY_PUBLIC': BadgeType
.AVAILABILITY_PUBLIC
719 'BADGE_STYLE_TYPE_MEMBERS_ONLY': BadgeType
.AVAILABILITY_SUBSCRIPTION
,
720 'BADGE_STYLE_TYPE_PREMIUM': BadgeType
.AVAILABILITY_PREMIUM
,
721 'BADGE_STYLE_TYPE_LIVE_NOW': BadgeType
.LIVE_NOW
725 'unlisted': BadgeType
.AVAILABILITY_UNLISTED
,
726 'private': BadgeType
.AVAILABILITY_PRIVATE
,
727 'members only': BadgeType
.AVAILABILITY_SUBSCRIPTION
,
728 'live': BadgeType
.LIVE_NOW
,
729 'premium': BadgeType
.AVAILABILITY_PREMIUM
733 for badge
in traverse_obj(renderer
, ('badges', ..., 'metadataBadgeRenderer'), default
=[]):
735 privacy_icon_map
.get(traverse_obj(badge
, ('icon', 'iconType'), expected_type
=str))
736 or badge_style_map
.get(traverse_obj(badge
, 'style'))
739 badges
.append({'type': badge_type}
)
742 # fallback, won't work in some languages
743 label
= traverse_obj(badge
, 'label', expected_type
=str, default
='')
744 for match
, label_badge_type
in label_map
.items():
745 if match
in label
.lower():
746 badges
.append({'type': badge_type}
)
752 def _has_badge(badges
, badge_type
):
753 return bool(traverse_obj(badges
, lambda _
, v
: v
['type'] == badge_type
))
756 def _get_text(data
, *path_list
, max_runs
=None):
757 for path
in path_list
or [None]:
761 obj
= traverse_obj(data
, path
, default
=[])
762 if not any(key
is ... or isinstance(key
, (list, tuple)) for key
in variadic(path
)):
765 text
= try_get(item
, lambda x
: x
['simpleText'], str)
768 runs
= try_get(item
, lambda x
: x
['runs'], list) or []
769 if not runs
and isinstance(item
, list):
772 runs
= runs
[:min(len(runs
), max_runs
or len(runs
))]
773 text
= ''.join(traverse_obj(runs
, (..., 'text'), expected_type
=str, default
=[]))
777 def _get_count(self
, data
, *path_list
):
778 count_text
= self
._get
_text
(data
, *path_list
) or ''
779 count
= parse_count(count_text
)
782 self
._search
_regex
(r
'^([\d,]+)', re
.sub(r
'\s', '', count_text
), 'count', default
=None))
786 def _extract_thumbnails(data
, *path_list
):
788 Extract thumbnails from thumbnails dict
789 @param path_list: path list to level that contains 'thumbnails' key
792 for path
in path_list
or [()]:
793 for thumbnail
in traverse_obj(data
, (*variadic(path
), 'thumbnails', ...), default
=[]):
794 thumbnail_url
= url_or_none(thumbnail
.get('url'))
795 if not thumbnail_url
:
797 # Sometimes youtube gives a wrong thumbnail URL. See:
798 # https://github.com/yt-dlp/yt-dlp/issues/233
799 # https://github.com/ytdl-org/youtube-dl/issues/28023
800 if 'maxresdefault' in thumbnail_url
:
801 thumbnail_url
= thumbnail_url
.split('?')[0]
803 'url': thumbnail_url
,
804 'height': int_or_none(thumbnail
.get('height')),
805 'width': int_or_none(thumbnail
.get('width')),
810 def extract_relative_time(relative_time_text
):
812 Extracts a relative time from string and converts to dt object
813 e.g. 'streamed 6 days ago', '5 seconds ago (edited)', 'updated today'
815 mobj
= re
.search(r
'(?P<start>today|yesterday|now)|(?P<time>\d+)\s*(?P<unit>microsecond|second|minute|hour|day|week|month|year)s?\s*ago', relative_time_text
)
817 start
= mobj
.group('start')
819 return datetime_from_str(start
)
821 return datetime_from_str('now-%s%s' % (mobj
.group('time'), mobj
.group('unit')))
825 def _parse_time_text(self
, text
):
828 dt
= self
.extract_relative_time(text
)
830 if isinstance(dt
, datetime
.datetime
):
831 timestamp
= calendar
.timegm(dt
.timetuple())
833 if timestamp
is None:
835 unified_timestamp(text
) or unified_timestamp(
837 (r
'([a-z]+\s*\d{1,2},?\s*20\d{2})', r
'(?:.+|^)(?:live|premieres|ed|ing)(?:\s*(?:on|for))?\s*(.+\d)'),
838 text
.lower(), 'time text', default
=None)))
840 if text
and timestamp
is None and self
._preferred
_lang
in (None, 'en'):
842 f
'Cannot parse localized time text "{text}"', only_once
=True)
845 def _extract_response(self
, item_id
, query
, note
='Downloading API JSON', headers
=None,
846 ytcfg
=None, check_get_keys
=None, ep
='browse', fatal
=True, api_hostname
=None,
847 default_client
='web'):
848 for retry
in self
.RetryManager():
850 response
= self
._call
_api
(
851 ep
=ep
, fatal
=True, headers
=headers
,
852 video_id
=item_id
, query
=query
, note
=note
,
853 context
=self
._extract
_context
(ytcfg
, default_client
),
854 api_key
=self
._extract
_api
_key
(ytcfg
, default_client
),
855 api_hostname
=api_hostname
, default_client
=default_client
)
856 except ExtractorError
as e
:
857 if not isinstance(e
.cause
, network_exceptions
):
858 return self
._error
_or
_warning
(e
, fatal
=fatal
)
859 elif not isinstance(e
.cause
, urllib
.error
.HTTPError
):
863 first_bytes
= e
.cause
.read(512)
864 if not is_html(first_bytes
):
867 self
._webpage
_read
_content
(e
.cause
, None, item_id
, prefix
=first_bytes
) or '{}', item_id
, fatal
=False),
868 lambda x
: x
['error']['message'], str)
870 self
._report
_alerts
([('ERROR', yt_error
)], fatal
=False)
871 # Downloading page may result in intermittent 5xx HTTP error
872 # Sometimes a 404 is also recieved. See: https://github.com/ytdl-org/youtube-dl/issues/28289
873 # We also want to catch all other network exceptions since errors in later pages can be troublesome
874 # See https://github.com/yt-dlp/yt-dlp/issues/507#issuecomment-880188210
875 if e
.cause
.code
not in (403, 429):
878 return self
._error
_or
_warning
(e
, fatal
=fatal
)
881 self
._extract
_and
_report
_alerts
(response
, only_once
=True)
882 except ExtractorError
as e
:
883 # YouTube servers may return errors we want to retry on in a 200 OK response
884 # See: https://github.com/yt-dlp/yt-dlp/issues/839
885 if 'unknown error' in e
.msg
.lower():
888 return self
._error
_or
_warning
(e
, fatal
=fatal
)
889 # Youtube sometimes sends incomplete data
890 # See: https://github.com/ytdl-org/youtube-dl/issues/28194
891 if not traverse_obj(response
, *variadic(check_get_keys
)):
892 retry
.error
= ExtractorError('Incomplete data received', expected
=True)
898 def is_music_url(url
):
899 return re
.match(r
'https?://music\.youtube\.com/', url
) is not None
901 def _extract_video(self
, renderer
):
902 video_id
= renderer
.get('videoId')
903 title
= self
._get
_text
(renderer
, 'title')
904 description
= self
._get
_text
(renderer
, 'descriptionSnippet')
905 duration
= parse_duration(self
._get
_text
(
906 renderer
, 'lengthText', ('thumbnailOverlays', ..., 'thumbnailOverlayTimeStatusRenderer', 'text')))
908 duration
= parse_duration(self
._search
_regex
(
909 r
'(?i)(ago)(?!.*\1)\s+(?P<duration>[a-z0-9 ,]+?)(?:\s+[\d,]+\s+views)?(?:\s+-\s+play\s+short)?$',
910 traverse_obj(renderer
, ('title', 'accessibility', 'accessibilityData', 'label'), default
='', expected_type
=str),
911 video_id
, default
=None, group
='duration'))
913 view_count
= self
._get
_count
(renderer
, 'viewCountText')
915 uploader
= self
._get
_text
(renderer
, 'ownerText', 'shortBylineText')
916 channel_id
= traverse_obj(
917 renderer
, ('shortBylineText', 'runs', ..., 'navigationEndpoint', 'browseEndpoint', 'browseId'),
918 expected_type
=str, get_all
=False)
919 time_text
= self
._get
_text
(renderer
, 'publishedTimeText') or ''
920 scheduled_timestamp
= str_to_int(traverse_obj(renderer
, ('upcomingEventData', 'startTime'), get_all
=False))
921 overlay_style
= traverse_obj(
922 renderer
, ('thumbnailOverlays', ..., 'thumbnailOverlayTimeStatusRenderer', 'style'),
923 get_all
=False, expected_type
=str)
924 badges
= self
._extract
_badges
(renderer
)
925 thumbnails
= self
._extract
_thumbnails
(renderer
, 'thumbnail')
926 navigation_url
= urljoin('https://www.youtube.com/', traverse_obj(
927 renderer
, ('navigationEndpoint', 'commandMetadata', 'webCommandMetadata', 'url'),
928 expected_type
=str)) or ''
929 url
= f
'https://www.youtube.com/watch?v={video_id}'
930 if overlay_style
== 'SHORTS' or '/shorts/' in navigation_url
:
931 url
= f
'https://www.youtube.com/shorts/{video_id}'
935 'ie_key': YoutubeIE
.ie_key(),
939 'description': description
,
940 'duration': duration
,
941 'view_count': view_count
,
942 'uploader': uploader
,
943 'channel_id': channel_id
,
944 'thumbnails': thumbnails
,
945 'upload_date': (strftime_or_none(self
._parse
_time
_text
(time_text
), '%Y%m%d')
946 if self
._configuration
_arg
('approximate_date', ie_key
='youtubetab')
948 'live_status': ('is_upcoming' if scheduled_timestamp
is not None
949 else 'was_live' if 'streamed' in time_text
.lower()
950 else 'is_live' if overlay_style
== 'LIVE' or self
._has
_badge
(badges
, BadgeType
.LIVE_NOW
)
952 'release_timestamp': scheduled_timestamp
,
954 'public' if self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PUBLIC
)
955 else self
._availability
(
956 is_private
=self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PRIVATE
) or None,
957 needs_premium
=self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PREMIUM
) or None,
958 needs_subscription
=self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_SUBSCRIPTION
) or None,
959 is_unlisted
=self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_UNLISTED
) or None)
963 class YoutubeIE(YoutubeBaseInfoExtractor
):
965 _VALID_URL
= r
"""(?x)^
967 (?:https?://|//) # http(s):// or protocol-independent URL
968 (?:(?:(?:(?:\w+\.)?[yY][oO][uU][tT][uU][bB][eE](?:-nocookie|kids)?\.com|
969 (?:www\.)?deturl\.com/www\.youtube\.com|
970 (?:www\.)?pwnyoutube\.com|
971 (?:www\.)?hooktube\.com|
972 (?:www\.)?yourepeat\.com|
975 youtube\.googleapis\.com)/ # the various hostnames, with wildcard subdomains
976 (?:.*?\#/)? # handle anchor (#/) redirect urls
977 (?: # the various things that can precede the ID:
978 (?:(?:v|embed|e|shorts)/(?!videoseries|live_stream)) # v/ or embed/ or e/ or shorts/
979 |(?: # or the v= param in all its forms
980 (?:(?:watch|movie)(?:_popup)?(?:\.php)?/?)? # preceding watch(_popup|.php) or nothing (like /?v=xxxx)
981 (?:\?|\#!?) # the params delimiter ? or # or #!
982 (?:.*?[&;])?? # any other preceding param (like /?s=tuff&v=xxxx or ?s=tuff&v=V36LpHqtcDY)
987 youtu\.be| # just youtu.be/xxxx
988 vid\.plus| # or vid.plus/xxxx
989 zwearz\.com/watch| # or zwearz.com/watch/xxxx
992 |(?:www\.)?cleanvideosearch\.com/media/action/yt/watch\?videoId=
994 )? # all until now is optional -> you can pass the naked ID
995 (?P<id>[0-9A-Za-z_-]{11}) # here is it! the YouTube video ID
996 (?(1).+)? # if we found the ID, everything can follow
998 'invidious': '|'.join(YoutubeBaseInfoExtractor
._INVIDIOUS
_SITES
),
1003 <(?:[0-9A-Za-z-]+?)?iframe[^>]+?src=|
1011 (?P
<url
>(?
:https?
:)?
//(?
:www\
.)?
youtube(?
:-nocookie
)?\
.com
/
1012 (?
:embed|v|p
)/[0-9A
-Za
-z_
-]{11}
.*?
)
1014 # https://wordpress.org/plugins/lazy-load-for-videos/
1016 <a\s
[^
>]*\bhref
="(?P<url>https://www\.youtube\.com/watch\?v=[0-9A-Za-z_-]{11})"
1017 \s
[^
>]*\bclass
="[^"]*\blazy
-load
-youtube
''',
1021 r'/s/player/(?P<id>[a-zA-Z0-9_-]{8,})/player',
1022 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$',
1023 r'\b(?P<id>vfl[a-zA-Z0-9_-]+)\b.*?\.js$',
1026 '5': {'ext': 'flv', 'width': 400, 'height': 240, 'acodec': 'mp3', 'abr': 64, 'vcodec': 'h263'},
1027 '6': {'ext': 'flv', 'width': 450, 'height': 270, 'acodec': 'mp3', 'abr': 64, 'vcodec': 'h263'},
1028 '13': {'ext': '3gp', 'acodec': 'aac', 'vcodec': 'mp4v'},
1029 '17': {'ext': '3gp', 'width': 176, 'height': 144, 'acodec': 'aac', 'abr': 24, 'vcodec': 'mp4v'},
1030 '18': {'ext': 'mp4', 'width': 640, 'height': 360, 'acodec': 'aac', 'abr': 96, 'vcodec': 'h264'},
1031 '22': {'ext': 'mp4', 'width': 1280, 'height': 720, 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264'},
1032 '34': {'ext': 'flv', 'width': 640, 'height': 360, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'},
1033 '35': {'ext': 'flv', 'width': 854, 'height': 480, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'},
1034 # itag 36 videos are either 320x180 (BaW_jenozKc) or 320x240 (__2ABJjxzNo), abr varies as well
1035 '36': {'ext': '3gp', 'width': 320, 'acodec': 'aac', 'vcodec': 'mp4v'},
1036 '37': {'ext': 'mp4', 'width': 1920, 'height': 1080, 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264'},
1037 '38': {'ext': 'mp4', 'width': 4096, 'height': 3072, 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264'},
1038 '43': {'ext': 'webm', 'width': 640, 'height': 360, 'acodec': 'vorbis', 'abr': 128, 'vcodec': 'vp8'},
1039 '44': {'ext': 'webm', 'width': 854, 'height': 480, 'acodec': 'vorbis', 'abr': 128, 'vcodec': 'vp8'},
1040 '45': {'ext': 'webm', 'width': 1280, 'height': 720, 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8'},
1041 '46': {'ext': 'webm', 'width': 1920, 'height': 1080, 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8'},
1042 '59': {'ext': 'mp4', 'width': 854, 'height': 480, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'},
1043 '78': {'ext': 'mp4', 'width': 854, 'height': 480, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'},
1047 '82': {'ext': 'mp4', 'height': 360, 'format_note': '3D', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -20},
1048 '83': {'ext': 'mp4', 'height': 480, 'format_note': '3D', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -20},
1049 '84': {'ext': 'mp4', 'height': 720, 'format_note': '3D', 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264', 'preference': -20},
1050 '85': {'ext': 'mp4', 'height': 1080, 'format_note': '3D', 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264', 'preference': -20},
1051 '100': {'ext': 'webm', 'height': 360, 'format_note': '3D', 'acodec': 'vorbis', 'abr': 128, 'vcodec': 'vp8', 'preference': -20},
1052 '101': {'ext': 'webm', 'height': 480, 'format_note': '3D', 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8', 'preference': -20},
1053 '102': {'ext': 'webm', 'height': 720, 'format_note': '3D', 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8', 'preference': -20},
1055 # Apple HTTP Live Streaming
1056 '91': {'ext': 'mp4', 'height': 144, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 48, 'vcodec': 'h264', 'preference': -10},
1057 '92': {'ext': 'mp4', 'height': 240, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 48, 'vcodec': 'h264', 'preference': -10},
1058 '93': {'ext': 'mp4', 'height': 360, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -10},
1059 '94': {'ext': 'mp4', 'height': 480, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -10},
1060 '95': {'ext': 'mp4', 'height': 720, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 256, 'vcodec': 'h264', 'preference': -10},
1061 '96': {'ext': 'mp4', 'height': 1080, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 256, 'vcodec': 'h264', 'preference': -10},
1062 '132': {'ext': 'mp4', 'height': 240, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 48, 'vcodec': 'h264', 'preference': -10},
1063 '151': {'ext': 'mp4', 'height': 72, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 24, 'vcodec': 'h264', 'preference': -10},
1066 '133': {'ext': 'mp4', 'height': 240, 'format_note': 'DASH video', 'vcodec': 'h264'},
1067 '134': {'ext': 'mp4', 'height': 360, 'format_note': 'DASH video', 'vcodec': 'h264'},
1068 '135': {'ext': 'mp4', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'h264'},
1069 '136': {'ext': 'mp4', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'h264'},
1070 '137': {'ext': 'mp4', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'h264'},
1071 '138': {'ext': 'mp4', 'format_note': 'DASH video', 'vcodec': 'h264'}, # Height can vary (https://github.com/ytdl-org/youtube-dl/issues/4559)
1072 '160': {'ext': 'mp4', 'height': 144, 'format_note': 'DASH video', 'vcodec': 'h264'},
1073 '212': {'ext': 'mp4', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'h264'},
1074 '264': {'ext': 'mp4', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'h264'},
1075 '298': {'ext': 'mp4', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'h264', 'fps': 60},
1076 '299': {'ext': 'mp4', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'h264', 'fps': 60},
1077 '266': {'ext': 'mp4', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'h264'},
1080 '139': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'abr': 48, 'container': 'm4a_dash'},
1081 '140': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'abr': 128, 'container': 'm4a_dash'},
1082 '141': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'abr': 256, 'container': 'm4a_dash'},
1083 '256': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'container': 'm4a_dash'},
1084 '258': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'container': 'm4a_dash'},
1085 '325': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'dtse', 'container': 'm4a_dash'},
1086 '328': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'ec-3', 'container': 'm4a_dash'},
1089 '167': {'ext': 'webm', 'height': 360, 'width': 640, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1090 '168': {'ext': 'webm', 'height': 480, 'width': 854, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1091 '169': {'ext': 'webm', 'height': 720, 'width': 1280, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1092 '170': {'ext': 'webm', 'height': 1080, 'width': 1920, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1093 '218': {'ext': 'webm', 'height': 480, 'width': 854, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1094 '219': {'ext': 'webm', 'height': 480, 'width': 854, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1095 '278': {'ext': 'webm', 'height': 144, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp9'},
1096 '242': {'ext': 'webm', 'height': 240, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1097 '243': {'ext': 'webm', 'height': 360, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1098 '244': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1099 '245': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1100 '246': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1101 '247': {'ext': 'webm', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1102 '248': {'ext': 'webm', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1103 '271': {'ext': 'webm', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1104 # itag 272 videos are either 3840x2160 (e.g. RtoitU2A-3E) or 7680x4320 (sLprVF6d7Ug)
1105 '272': {'ext': 'webm', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1106 '302': {'ext': 'webm', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60},
1107 '303': {'ext': 'webm', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60},
1108 '308': {'ext': 'webm', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60},
1109 '313': {'ext': 'webm', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1110 '315': {'ext': 'webm', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60},
1113 '171': {'ext': 'webm', 'acodec': 'vorbis', 'format_note': 'DASH audio', 'abr': 128},
1114 '172': {'ext': 'webm', 'acodec': 'vorbis', 'format_note': 'DASH audio', 'abr': 256},
1116 # Dash webm audio with opus inside
1117 '249': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 50},
1118 '250': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 70},
1119 '251': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 160},
1122 '_rtmp': {'protocol': 'rtmp'},
1124 # av01 video only formats sometimes served with "unknown" codecs
1125 '394': {'ext': 'mp4', 'height': 144, 'format_note': 'DASH video', 'vcodec': 'av01.0.00M.08'},
1126 '395': {'ext': 'mp4', 'height': 240, 'format_note': 'DASH video', 'vcodec': 'av01.0.00M.08'},
1127 '396': {'ext': 'mp4', 'height': 360, 'format_note': 'DASH video', 'vcodec': 'av01.0.01M.08'},
1128 '397': {'ext': 'mp4', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'av01.0.04M.08'},
1129 '398': {'ext': 'mp4', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'av01.0.05M.08'},
1130 '399': {'ext': 'mp4', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'av01.0.08M.08'},
1131 '400': {'ext': 'mp4', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'av01.0.12M.08'},
1132 '401': {'ext': 'mp4', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'av01.0.12M.08'},
1134 _SUBTITLE_FORMATS = ('json3', 'srv1', 'srv2', 'srv3', 'ttml', 'vtt')
1141 'url': 'https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9',
1143 'id': 'BaW_jenozKc',
1145 'title': 'youtube-dl test video "\'/\\ä↭𝕐',
1146 'uploader': 'Philipp Hagemeister',
1147 'uploader_id': 'phihag',
1148 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/phihag',
1149 'channel': 'Philipp Hagemeister',
1150 'channel_id': 'UCLqxVugv74EIW3VWh2NOa3Q',
1151 'channel_url': r're:https?://(?:www\.)?youtube\.com/channel/UCLqxVugv74EIW3VWh2NOa3Q',
1152 'upload_date': '20121002',
1153 'description': 'md5:8fb536f4877b8a7455c2ec23794dbc22',
1154 'categories': ['Science & Technology'],
1155 'tags': ['youtube-dl'],
1159 'availability': 'public',
1160 'playable_in_embed': True,
1161 'thumbnail': 'https://i.ytimg.com/vi/BaW_jenozKc/maxresdefault.jpg',
1162 'live_status': 'not_live',
1166 'comment_count': int,
1167 'channel_follower_count': int
1171 'url': '//www.YouTube.com/watch?v=yZIXLfi8CZQ',
1172 'note': 'Embed-only video (#1746)',
1174 'id': 'yZIXLfi8CZQ',
1176 'upload_date': '20120608',
1177 'title': 'Principal Sexually Assaults A Teacher - Episode 117 - 8th June 2012',
1178 'description': 'md5:09b78bd971f1e3e289601dfba15ca4f7',
1179 'uploader': 'SET India',
1180 'uploader_id': 'setindia',
1181 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/setindia',
1184 'skip': 'Private video',
1187 'url': 'https://www.youtube.com/watch?v=BaW_jenozKc&v=yZIXLfi8CZQ',
1188 'note': 'Use the first video ID in the URL',
1190 'id': 'BaW_jenozKc',
1192 'title': 'youtube-dl test video "\'/\\ä↭𝕐',
1193 'uploader': 'Philipp Hagemeister',
1194 'uploader_id': 'phihag',
1195 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/phihag',
1196 'channel': 'Philipp Hagemeister',
1197 'channel_id': 'UCLqxVugv74EIW3VWh2NOa3Q',
1198 'channel_url': r're:https?://(?:www\.)?youtube\.com/channel/UCLqxVugv74EIW3VWh2NOa3Q',
1199 'upload_date': '20121002',
1200 'description': 'md5:8fb536f4877b8a7455c2ec23794dbc22',
1201 'categories': ['Science & Technology'],
1202 'tags': ['youtube-dl'],
1206 'availability': 'public',
1207 'playable_in_embed': True,
1208 'thumbnail': 'https://i.ytimg.com/vi/BaW_jenozKc/maxresdefault.jpg',
1209 'live_status': 'not_live',
1211 'comment_count': int,
1212 'channel_follower_count': int
1215 'skip_download': True,
1219 'url': 'https://www.youtube.com/watch?v=a9LDPn-MO4I',
1220 'note': '256k DASH audio (format 141) via DASH manifest',
1222 'id': 'a9LDPn-MO4I',
1224 'upload_date': '20121002',
1225 'uploader_id': '8KVIDEO',
1226 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/8KVIDEO',
1228 'uploader': '8KVIDEO',
1229 'title': 'UHDTV TEST 8K VIDEO.mp4'
1232 'youtube_include_dash_manifest': True,
1235 'skip': 'format 141 not served anymore',
1237 # DASH manifest with encrypted signature
1239 'url': 'https://www.youtube.com/watch?v=IB3lcPjvWLA',
1241 'id': 'IB3lcPjvWLA',
1243 'title': 'Afrojack, Spree Wilson - The Spark (Official Music Video) ft. Spree Wilson',
1244 'description': 'md5:8f5e2b82460520b619ccac1f509d43bf',
1246 'uploader': 'AfrojackVEVO',
1247 'uploader_id': 'AfrojackVEVO',
1248 'upload_date': '20131011',
1251 'channel_id': 'UChuZAo1RKL85gev3Eal9_zg',
1252 'playable_in_embed': True,
1253 'channel_url': 'https://www.youtube.com/channel/UChuZAo1RKL85gev3Eal9_zg',
1255 'track': 'The Spark',
1256 'live_status': 'not_live',
1257 'thumbnail': 'https://i.ytimg.com/vi_webp/IB3lcPjvWLA/maxresdefault.webp',
1258 'channel': 'Afrojack',
1259 'uploader_url': 'http://www.youtube.com/user/AfrojackVEVO',
1261 'availability': 'public',
1262 'categories': ['Music'],
1264 'alt_title': 'The Spark',
1265 'channel_follower_count': int
1268 'youtube_include_dash_manifest': True,
1269 'format': '141/bestaudio[ext=m4a]',
1272 # Age-gate videos. See https://github.com/yt-dlp/yt-dlp/pull/575#issuecomment-888837000
1274 'note': 'Embed allowed age-gate video',
1275 'url': 'https://youtube.com/watch?v=HtVdAasjOgU',
1277 'id': 'HtVdAasjOgU',
1279 'title': 'The Witcher 3: Wild Hunt - The Sword Of Destiny Trailer',
1280 'description': r're:(?s).{100,}About the Game\n.*?The Witcher 3: Wild Hunt.{100,}',
1282 'uploader': 'The Witcher',
1283 'uploader_id': 'WitcherGame',
1284 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/WitcherGame',
1285 'upload_date': '20140605',
1287 'categories': ['Gaming'],
1288 'thumbnail': 'https://i.ytimg.com/vi_webp/HtVdAasjOgU/maxresdefault.webp',
1289 'availability': 'needs_auth',
1290 'channel_url': 'https://www.youtube.com/channel/UCzybXLxv08IApdjdN0mJhEg',
1292 'channel': 'The Witcher',
1293 'live_status': 'not_live',
1295 'channel_id': 'UCzybXLxv08IApdjdN0mJhEg',
1296 'playable_in_embed': True,
1298 'channel_follower_count': int
1302 'note': 'Age-gate video with embed allowed in public site',
1303 'url': 'https://youtube.com/watch?v=HsUATh_Nc2U',
1305 'id': 'HsUATh_Nc2U',
1307 'title': 'Godzilla 2 (Official Video)',
1308 'description': 'md5:bf77e03fcae5529475e500129b05668a',
1309 'upload_date': '20200408',
1310 'uploader_id': 'FlyingKitty900',
1311 'uploader': 'FlyingKitty',
1313 'availability': 'needs_auth',
1314 'channel_id': 'UCYQT13AtrJC0gsM1far_zJg',
1315 'uploader_url': 'http://www.youtube.com/user/FlyingKitty900',
1316 'channel': 'FlyingKitty',
1317 'channel_url': 'https://www.youtube.com/channel/UCYQT13AtrJC0gsM1far_zJg',
1319 'categories': ['Entertainment'],
1320 'live_status': 'not_live',
1321 'tags': ['Flyingkitty', 'godzilla 2'],
1322 'thumbnail': 'https://i.ytimg.com/vi/HsUATh_Nc2U/maxresdefault.jpg',
1325 'playable_in_embed': True,
1326 'channel_follower_count': int
1330 'note': 'Age-gate video embedable only with clientScreen=EMBED',
1331 'url': 'https://youtube.com/watch?v=Tq92D6wQ1mg',
1333 'id': 'Tq92D6wQ1mg',
1334 'title': '[MMD] Adios - EVERGLOW [+Motion DL]',
1336 'upload_date': '20191228',
1337 'uploader_id': 'UC1yoRdFoFJaCY-AGfD9W0wQ',
1338 'uploader': 'Projekt Melody',
1339 'description': 'md5:17eccca93a786d51bc67646756894066',
1342 'availability': 'needs_auth',
1343 'uploader_url': 'http://www.youtube.com/channel/UC1yoRdFoFJaCY-AGfD9W0wQ',
1344 'channel_id': 'UC1yoRdFoFJaCY-AGfD9W0wQ',
1346 'thumbnail': 'https://i.ytimg.com/vi_webp/Tq92D6wQ1mg/sddefault.webp',
1347 'channel': 'Projekt Melody',
1348 'live_status': 'not_live',
1349 'tags': ['mmd', 'dance', 'mikumikudance', 'kpop', 'vtuber'],
1350 'playable_in_embed': True,
1351 'categories': ['Entertainment'],
1353 'channel_url': 'https://www.youtube.com/channel/UC1yoRdFoFJaCY-AGfD9W0wQ',
1354 'comment_count': int,
1355 'channel_follower_count': int
1359 'note': 'Non-Agegated non-embeddable video',
1360 'url': 'https://youtube.com/watch?v=MeJVWBSsPAY',
1362 'id': 'MeJVWBSsPAY',
1364 'title': 'OOMPH! - Such Mich Find Mich (Lyrics)',
1365 'uploader': 'Herr Lurik',
1366 'uploader_id': 'st3in234',
1367 'description': 'Fan Video. Music & Lyrics by OOMPH!.',
1368 'upload_date': '20130730',
1369 'track': 'Such mich find mich',
1371 'tags': ['oomph', 'such mich find mich', 'lyrics', 'german industrial', 'musica industrial'],
1373 'playable_in_embed': False,
1374 'creator': 'OOMPH!',
1375 'thumbnail': 'https://i.ytimg.com/vi/MeJVWBSsPAY/sddefault.jpg',
1377 'alt_title': 'Such mich find mich',
1379 'channel': 'Herr Lurik',
1380 'channel_id': 'UCdR3RSDPqub28LjZx0v9-aA',
1381 'categories': ['Music'],
1382 'availability': 'public',
1383 'uploader_url': 'http://www.youtube.com/user/st3in234',
1384 'channel_url': 'https://www.youtube.com/channel/UCdR3RSDPqub28LjZx0v9-aA',
1385 'live_status': 'not_live',
1387 'channel_follower_count': int
1391 'note': 'Non-bypassable age-gated video',
1392 'url': 'https://youtube.com/watch?v=Cr381pDsSsA',
1393 'only_matching': True,
1395 # video_info is None (https://github.com/ytdl-org/youtube-dl/issues/4421)
1396 # YouTube Red ad is not captured for creator
1398 'url': '__2ABJjxzNo',
1400 'id': '__2ABJjxzNo',
1403 'upload_date': '20100430',
1404 'uploader_id': 'deadmau5',
1405 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/deadmau5',
1406 'creator': 'deadmau5',
1407 'description': 'md5:6cbcd3a92ce1bc676fc4d6ab4ace2336',
1408 'uploader': 'deadmau5',
1409 'title': 'Deadmau5 - Some Chords (HD)',
1410 'alt_title': 'Some Chords',
1411 'availability': 'public',
1413 'channel_id': 'UCYEK6xds6eo-3tr4xRdflmQ',
1415 'live_status': 'not_live',
1416 'channel': 'deadmau5',
1417 'thumbnail': 'https://i.ytimg.com/vi_webp/__2ABJjxzNo/maxresdefault.webp',
1419 'track': 'Some Chords',
1420 'artist': 'deadmau5',
1421 'playable_in_embed': True,
1423 'channel_url': 'https://www.youtube.com/channel/UCYEK6xds6eo-3tr4xRdflmQ',
1424 'categories': ['Music'],
1425 'album': 'Some Chords',
1426 'channel_follower_count': int
1428 'expected_warnings': [
1429 'DASH manifest missing',
1432 # Olympics (https://github.com/ytdl-org/youtube-dl/issues/4431)
1434 'url': 'lqQg6PlCWgI',
1436 'id': 'lqQg6PlCWgI',
1439 'upload_date': '20150827',
1440 'uploader_id': 'olympic',
1441 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/olympic',
1442 'description': 'md5:04bbbf3ccceb6795947572ca36f45904',
1443 'uploader': 'Olympics',
1444 'title': 'Hockey - Women - GER-AUS - London 2012 Olympic Games',
1446 'release_timestamp': 1343767800,
1447 'playable_in_embed': True,
1448 'categories': ['Sports'],
1449 'release_date': '20120731',
1450 'channel': 'Olympics',
1451 'tags': ['Hockey', '2012-07-31', '31 July 2012', 'Riverbank Arena', 'Session', 'Olympics', 'Olympic Games', 'London 2012', '2012 Summer Olympics', 'Summer Games'],
1452 'channel_id': 'UCTl3QQTvqHFjurroKxexy2Q',
1453 'thumbnail': 'https://i.ytimg.com/vi/lqQg6PlCWgI/maxresdefault.jpg',
1455 'availability': 'public',
1456 'live_status': 'was_live',
1458 'channel_url': 'https://www.youtube.com/channel/UCTl3QQTvqHFjurroKxexy2Q',
1459 'channel_follower_count': int
1462 'skip_download': 'requires avconv',
1467 'url': 'https://www.youtube.com/watch?v=_b-2C3KPAM0',
1469 'id': '_b-2C3KPAM0',
1471 'stretched_ratio': 16 / 9.,
1473 'upload_date': '20110310',
1474 'uploader_id': 'AllenMeow',
1475 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/AllenMeow',
1476 'description': 'made by Wacom from Korea | 字幕&加油添醋 by TY\'s Allen | 感謝heylisa00cavey1001同學熱情提供梗及翻譯',
1478 'title': '[A-made] 變態妍字幕版 太妍 我就是這樣的人',
1479 'playable_in_embed': True,
1483 'channel_url': 'https://www.youtube.com/channel/UCS-xxCmRaA6BFdmgDPA_BIw',
1484 'channel_id': 'UCS-xxCmRaA6BFdmgDPA_BIw',
1485 'thumbnail': 'https://i.ytimg.com/vi/_b-2C3KPAM0/maxresdefault.jpg',
1487 'categories': ['People & Blogs'],
1489 'live_status': 'not_live',
1490 'availability': 'unlisted',
1491 'comment_count': int,
1492 'channel_follower_count': int
1495 # url_encoded_fmt_stream_map is empty string
1497 'url': 'qEJwOuvDf7I',
1499 'id': 'qEJwOuvDf7I',
1501 'title': 'Обсуждение судебной практики по выборам 14 сентября 2014 года в Санкт-Петербурге',
1503 'upload_date': '20150404',
1504 'uploader_id': 'spbelect',
1505 'uploader': 'Наблюдатели Петербурга',
1508 'skip_download': 'requires avconv',
1510 'skip': 'This live event has ended.',
1512 # Extraction from multiple DASH manifests (https://github.com/ytdl-org/youtube-dl/pull/6097)
1514 'url': 'https://www.youtube.com/watch?v=FIl7x6_3R5Y',
1516 'id': 'FIl7x6_3R5Y',
1518 'title': 'md5:7b81415841e02ecd4313668cde88737a',
1519 'description': 'md5:116377fd2963b81ec4ce64b542173306',
1521 'upload_date': '20150625',
1522 'uploader_id': 'dorappi2000',
1523 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/dorappi2000',
1524 'uploader': 'dorappi2000',
1525 'formats': 'mincount:31',
1527 'skip': 'not actual anymore',
1529 # DASH manifest with segment_list
1531 'url': 'https://www.youtube.com/embed/CsmdDsKjzN8',
1532 'md5': '8ce563a1d667b599d21064e982ab9e31',
1534 'id': 'CsmdDsKjzN8',
1536 'upload_date': '20150501', # According to '<meta itemprop="datePublished"', but in other places it's 20150510
1537 'uploader': 'Airtek',
1538 'description': 'Retransmisión en directo de la XVIII media maratón de Zaragoza.',
1539 'uploader_id': 'UCzTzUmjXxxacNnL8I3m4LnQ',
1540 'title': 'Retransmisión XVIII Media maratón Zaragoza 2015',
1543 'youtube_include_dash_manifest': True,
1544 'format': '135', # bestvideo
1546 'skip': 'This live event has ended.',
1549 # Multifeed videos (multiple cameras), URL is for Main Camera
1550 'url': 'https://www.youtube.com/watch?v=jvGDaLqkpTg',
1552 'id': 'jvGDaLqkpTg',
1553 'title': 'Tom Clancy Free Weekend Rainbow Whatever',
1554 'description': 'md5:e03b909557865076822aa169218d6a5d',
1558 'id': 'jvGDaLqkpTg',
1560 'title': 'Tom Clancy Free Weekend Rainbow Whatever (Main Camera)',
1561 'description': 'md5:e03b909557865076822aa169218d6a5d',
1563 'upload_date': '20161111',
1564 'uploader': 'Team PGP',
1565 'uploader_id': 'UChORY56LMMETTuGjXaJXvLg',
1566 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UChORY56LMMETTuGjXaJXvLg',
1570 'id': '3AKt1R1aDnw',
1572 'title': 'Tom Clancy Free Weekend Rainbow Whatever (Camera 2)',
1573 'description': 'md5:e03b909557865076822aa169218d6a5d',
1575 'upload_date': '20161111',
1576 'uploader': 'Team PGP',
1577 'uploader_id': 'UChORY56LMMETTuGjXaJXvLg',
1578 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UChORY56LMMETTuGjXaJXvLg',
1582 'id': 'RtAMM00gpVc',
1584 'title': 'Tom Clancy Free Weekend Rainbow Whatever (Camera 3)',
1585 'description': 'md5:e03b909557865076822aa169218d6a5d',
1587 'upload_date': '20161111',
1588 'uploader': 'Team PGP',
1589 'uploader_id': 'UChORY56LMMETTuGjXaJXvLg',
1590 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UChORY56LMMETTuGjXaJXvLg',
1594 'id': '6N2fdlP3C5U',
1596 'title': 'Tom Clancy Free Weekend Rainbow Whatever (Camera 4)',
1597 'description': 'md5:e03b909557865076822aa169218d6a5d',
1599 'upload_date': '20161111',
1600 'uploader': 'Team PGP',
1601 'uploader_id': 'UChORY56LMMETTuGjXaJXvLg',
1602 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UChORY56LMMETTuGjXaJXvLg',
1606 'skip_download': True,
1608 'skip': 'Not multifeed anymore',
1611 # Multifeed video with comma in title (see https://github.com/ytdl-org/youtube-dl/issues/8536)
1612 'url': 'https://www.youtube.com/watch?v=gVfLd0zydlo',
1614 'id': 'gVfLd0zydlo',
1615 'title': 'DevConf.cz 2016 Day 2 Workshops 1 14:00 - 15:30',
1617 'playlist_count': 2,
1618 'skip': 'Not multifeed anymore',
1621 'url': 'https://vid.plus/FlRa-iH7PGw',
1622 'only_matching': True,
1625 'url': 'https://zwearz.com/watch/9lWxNJF-ufM/electra-woman-dyna-girl-official-trailer-grace-helbig.html',
1626 'only_matching': True,
1629 # Title with JS-like syntax "};" (see https://github.com/ytdl-org/youtube-dl/issues/7468)
1630 # Also tests cut-off URL expansion in video description (see
1631 # https://github.com/ytdl-org/youtube-dl/issues/1892,
1632 # https://github.com/ytdl-org/youtube-dl/issues/8164)
1633 'url': 'https://www.youtube.com/watch?v=lsguqyKfVQg',
1635 'id': 'lsguqyKfVQg',
1637 'title': '{dark walk}; Loki/AC/Dishonored; collab w/Elflover21',
1638 'alt_title': 'Dark Walk',
1639 'description': 'md5:8085699c11dc3f597ce0410b0dcbb34a',
1641 'upload_date': '20151119',
1642 'uploader_id': 'IronSoulElf',
1643 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/IronSoulElf',
1644 'uploader': 'IronSoulElf',
1645 'creator': 'Todd Haberman;\nDaniel Law Heath and Aaron Kaplan',
1646 'track': 'Dark Walk',
1647 'artist': 'Todd Haberman;\nDaniel Law Heath and Aaron Kaplan',
1648 'album': 'Position Music - Production Music Vol. 143 - Dark Walk',
1649 'thumbnail': 'https://i.ytimg.com/vi_webp/lsguqyKfVQg/maxresdefault.webp',
1650 'categories': ['Film & Animation'],
1652 'live_status': 'not_live',
1653 'channel_url': 'https://www.youtube.com/channel/UCTSRgz5jylBvFt_S7wnsqLQ',
1654 'channel_id': 'UCTSRgz5jylBvFt_S7wnsqLQ',
1656 'availability': 'public',
1657 'channel': 'IronSoulElf',
1658 'playable_in_embed': True,
1661 'channel_follower_count': int
1664 'skip_download': True,
1668 # Tags with '};' (see https://github.com/ytdl-org/youtube-dl/issues/7468)
1669 'url': 'https://www.youtube.com/watch?v=Ms7iBXnlUO8',
1670 'only_matching': True,
1673 # Video with yt:stretch=17:0
1674 'url': 'https://www.youtube.com/watch?v=Q39EVAstoRM',
1676 'id': 'Q39EVAstoRM',
1678 'title': 'Clash Of Clans#14 Dicas De Ataque Para CV 4',
1679 'description': 'md5:ee18a25c350637c8faff806845bddee9',
1680 'upload_date': '20151107',
1681 'uploader_id': 'UCCr7TALkRbo3EtFzETQF1LA',
1682 'uploader': 'CH GAMER DROID',
1685 'skip_download': True,
1687 'skip': 'This video does not exist.',
1690 # Video with incomplete 'yt:stretch=16:'
1691 'url': 'https://www.youtube.com/watch?v=FRhJzUSJbGI',
1692 'only_matching': True,
1695 # Video licensed under Creative Commons
1696 'url': 'https://www.youtube.com/watch?v=M4gD1WSo5mA',
1698 'id': 'M4gD1WSo5mA',
1700 'title': 'md5:e41008789470fc2533a3252216f1c1d1',
1701 'description': 'md5:a677553cf0840649b731a3024aeff4cc',
1703 'upload_date': '20150128',
1704 'uploader_id': 'BerkmanCenter',
1705 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/BerkmanCenter',
1706 'uploader': 'The Berkman Klein Center for Internet & Society',
1707 'license': 'Creative Commons Attribution license (reuse allowed)',
1708 'channel_id': 'UCuLGmD72gJDBwmLw06X58SA',
1709 'channel_url': 'https://www.youtube.com/channel/UCuLGmD72gJDBwmLw06X58SA',
1712 'tags': ['Copyright (Legal Subject)', 'Law (Industry)', 'William W. Fisher (Author)'],
1713 'channel': 'The Berkman Klein Center for Internet & Society',
1714 'availability': 'public',
1716 'categories': ['Education'],
1717 'thumbnail': 'https://i.ytimg.com/vi_webp/M4gD1WSo5mA/maxresdefault.webp',
1718 'live_status': 'not_live',
1719 'playable_in_embed': True,
1720 'comment_count': int,
1721 'channel_follower_count': int
1724 'skip_download': True,
1728 # Channel-like uploader_url
1729 'url': 'https://www.youtube.com/watch?v=eQcmzGIKrzg',
1731 'id': 'eQcmzGIKrzg',
1733 'title': 'Democratic Socialism and Foreign Policy | Bernie Sanders',
1734 'description': 'md5:13a2503d7b5904ef4b223aa101628f39',
1736 'upload_date': '20151120',
1737 'uploader': 'Bernie Sanders',
1738 'uploader_id': 'UCH1dpzjCEiGAt8CXkryhkZg',
1739 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UCH1dpzjCEiGAt8CXkryhkZg',
1740 'license': 'Creative Commons Attribution license (reuse allowed)',
1741 'playable_in_embed': True,
1744 'channel_id': 'UCH1dpzjCEiGAt8CXkryhkZg',
1746 'availability': 'public',
1747 'categories': ['News & Politics'],
1748 'channel': 'Bernie Sanders',
1749 'thumbnail': 'https://i.ytimg.com/vi_webp/eQcmzGIKrzg/maxresdefault.webp',
1751 'live_status': 'not_live',
1752 'channel_url': 'https://www.youtube.com/channel/UCH1dpzjCEiGAt8CXkryhkZg',
1753 'comment_count': int,
1754 'channel_follower_count': int
1757 'skip_download': True,
1761 'url': 'https://www.youtube.com/watch?feature=player_embedded&amp;v=V36LpHqtcDY',
1762 'only_matching': True,
1765 # YouTube Red paid video (https://github.com/ytdl-org/youtube-dl/issues/10059)
1766 'url': 'https://www.youtube.com/watch?v=i1Ko8UG-Tdo',
1767 'only_matching': True,
1770 # Rental video preview
1771 'url': 'https://www.youtube.com/watch?v=yYr8q0y5Jfg',
1773 'id': 'uGpuVWrhIzE',
1775 'title': 'Piku - Trailer',
1776 'description': 'md5:c36bd60c3fd6f1954086c083c72092eb',
1777 'upload_date': '20150811',
1778 'uploader': 'FlixMatrix',
1779 'uploader_id': 'FlixMatrixKaravan',
1780 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/FlixMatrixKaravan',
1781 'license': 'Standard YouTube License',
1784 'skip_download': True,
1786 'skip': 'This video is not available.',
1789 # YouTube Red video with episode data
1790 'url': 'https://www.youtube.com/watch?v=iqKdEhx-dD4',
1792 'id': 'iqKdEhx-dD4',
1794 'title': 'Isolation - Mind Field (Ep 1)',
1795 'description': 'md5:f540112edec5d09fc8cc752d3d4ba3cd',
1797 'upload_date': '20170118',
1798 'uploader': 'Vsauce',
1799 'uploader_id': 'Vsauce',
1800 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/Vsauce',
1801 'series': 'Mind Field',
1803 'episode_number': 1,
1804 'thumbnail': 'https://i.ytimg.com/vi_webp/iqKdEhx-dD4/maxresdefault.webp',
1807 'availability': 'public',
1809 'channel': 'Vsauce',
1810 'episode': 'Episode 1',
1811 'categories': ['Entertainment'],
1812 'season': 'Season 1',
1813 'channel_id': 'UC6nSFpj9HTCZ5t-N3Rm3-HA',
1814 'channel_url': 'https://www.youtube.com/channel/UC6nSFpj9HTCZ5t-N3Rm3-HA',
1816 'playable_in_embed': True,
1817 'live_status': 'not_live',
1818 'channel_follower_count': int
1821 'skip_download': True,
1823 'expected_warnings': [
1824 'Skipping DASH manifest',
1828 # The following content has been identified by the YouTube community
1829 # as inappropriate or offensive to some audiences.
1830 'url': 'https://www.youtube.com/watch?v=6SJNVb0GnPI',
1832 'id': '6SJNVb0GnPI',
1834 'title': 'Race Differences in Intelligence',
1835 'description': 'md5:5d161533167390427a1f8ee89a1fc6f1',
1837 'upload_date': '20140124',
1838 'uploader': 'New Century Foundation',
1839 'uploader_id': 'UCEJYpZGqgUob0zVVEaLhvVg',
1840 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UCEJYpZGqgUob0zVVEaLhvVg',
1843 'skip_download': True,
1845 'skip': 'This video has been removed for violating YouTube\'s policy on hate speech.',
1849 'url': '1t24XAntNCY',
1850 'only_matching': True,
1853 # geo restricted to JP
1854 'url': 'sJL6WA-aGkQ',
1855 'only_matching': True,
1858 'url': 'https://invidio.us/watch?v=BaW_jenozKc',
1859 'only_matching': True,
1862 'url': 'https://redirect.invidious.io/watch?v=BaW_jenozKc',
1863 'only_matching': True,
1866 # from https://nitter.pussthecat.org/YouTube/status/1360363141947944964#m
1867 'url': 'https://redirect.invidious.io/Yh0AhrY9GjA',
1868 'only_matching': True,
1872 'url': 'https://www.youtube.com/watch?v=s7_qI6_mIXc',
1873 'only_matching': True,
1876 # Video with unsupported adaptive stream type formats
1877 'url': 'https://www.youtube.com/watch?v=Z4Vy8R84T1U',
1879 'id': 'Z4Vy8R84T1U',
1881 'title': 'saman SMAN 53 Jakarta(Sancety) opening COFFEE4th at SMAN 53 Jakarta',
1882 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
1884 'upload_date': '20130923',
1885 'uploader': 'Amelia Putri Harwita',
1886 'uploader_id': 'UCpOxM49HJxmC1qCalXyB3_Q',
1887 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UCpOxM49HJxmC1qCalXyB3_Q',
1888 'formats': 'maxcount:10',
1891 'skip_download': True,
1892 'youtube_include_dash_manifest': False,
1894 'skip': 'not actual anymore',
1897 # Youtube Music Auto-generated description
1898 'url': 'https://music.youtube.com/watch?v=MgNrAu2pzNs',
1900 'id': 'MgNrAu2pzNs',
1902 'title': 'Voyeur Girl',
1903 'description': 'md5:7ae382a65843d6df2685993e90a8628f',
1904 'upload_date': '20190312',
1905 'uploader': 'Stephen - Topic',
1906 'uploader_id': 'UC-pWHpBjdGG69N9mM2auIAA',
1907 'artist': 'Stephen',
1908 'track': 'Voyeur Girl',
1909 'album': 'it\'s too much love to know my dear',
1910 'release_date': '20190313',
1911 'release_year': 2019,
1912 'alt_title': 'Voyeur Girl',
1914 'uploader_url': 'http://www.youtube.com/channel/UC-pWHpBjdGG69N9mM2auIAA',
1915 'playable_in_embed': True,
1917 'categories': ['Music'],
1918 'channel_url': 'https://www.youtube.com/channel/UC-pWHpBjdGG69N9mM2auIAA',
1919 'channel': 'Stephen',
1920 'availability': 'public',
1921 'creator': 'Stephen',
1923 'thumbnail': 'https://i.ytimg.com/vi_webp/MgNrAu2pzNs/maxresdefault.webp',
1925 'channel_id': 'UC-pWHpBjdGG69N9mM2auIAA',
1927 'live_status': 'not_live',
1928 'channel_follower_count': int
1931 'skip_download': True,
1935 'url': 'https://www.youtubekids.com/watch?v=3b8nCWDgZ6Q',
1936 'only_matching': True,
1939 # invalid -> valid video id redirection
1940 'url': 'DJztXj2GPfl',
1942 'id': 'DJztXj2GPfk',
1944 'title': 'Panjabi MC - Mundian To Bach Ke (The Dictator Soundtrack)',
1945 'description': 'md5:bf577a41da97918e94fa9798d9228825',
1946 'upload_date': '20090125',
1947 'uploader': 'Prochorowka',
1948 'uploader_id': 'Prochorowka',
1949 'uploader_url': r're:https?://(?:www\.)?youtube\.com/user/Prochorowka',
1950 'artist': 'Panjabi MC',
1951 'track': 'Beware of the Boys (Mundian to Bach Ke) - Motivo Hi-Lectro Remix',
1952 'album': 'Beware of the Boys (Mundian To Bach Ke)',
1955 'skip_download': True,
1957 'skip': 'Video unavailable',
1960 # empty description results in an empty string
1961 'url': 'https://www.youtube.com/watch?v=x41yOUIvK2k',
1963 'id': 'x41yOUIvK2k',
1965 'title': 'IMG 3456',
1967 'upload_date': '20170613',
1968 'uploader_id': 'ElevageOrVert',
1969 'uploader': 'ElevageOrVert',
1971 'thumbnail': 'https://i.ytimg.com/vi_webp/x41yOUIvK2k/maxresdefault.webp',
1972 'uploader_url': 'http://www.youtube.com/user/ElevageOrVert',
1974 'channel_id': 'UCo03ZQPBW5U4UC3regpt1nw',
1976 'channel_url': 'https://www.youtube.com/channel/UCo03ZQPBW5U4UC3regpt1nw',
1977 'availability': 'public',
1979 'categories': ['Pets & Animals'],
1981 'playable_in_embed': True,
1982 'live_status': 'not_live',
1983 'channel': 'ElevageOrVert',
1984 'channel_follower_count': int
1987 'skip_download': True,
1991 # with '};' inside yt initial data (see [1])
1992 # see [2] for an example with '};' inside ytInitialPlayerResponse
1993 # 1. https://github.com/ytdl-org/youtube-dl/issues/27093
1994 # 2. https://github.com/ytdl-org/youtube-dl/issues/27216
1995 'url': 'https://www.youtube.com/watch?v=CHqg6qOn4no',
1997 'id': 'CHqg6qOn4no',
1999 'title': 'Part 77 Sort a list of simple types in c#',
2000 'description': 'md5:b8746fa52e10cdbf47997903f13b20dc',
2001 'upload_date': '20130831',
2002 'uploader_id': 'kudvenkat',
2003 'uploader': 'kudvenkat',
2004 'channel_id': 'UCCTVrRB5KpIiK6V2GGVsR1Q',
2006 'uploader_url': 'http://www.youtube.com/user/kudvenkat',
2007 'channel_url': 'https://www.youtube.com/channel/UCCTVrRB5KpIiK6V2GGVsR1Q',
2008 'live_status': 'not_live',
2009 'categories': ['Education'],
2010 'availability': 'public',
2011 'thumbnail': 'https://i.ytimg.com/vi/CHqg6qOn4no/sddefault.jpg',
2013 'playable_in_embed': True,
2017 'channel': 'kudvenkat',
2018 'comment_count': int,
2019 'channel_follower_count': int
2022 'skip_download': True,
2026 # another example of '};' in ytInitialData
2027 'url': 'https://www.youtube.com/watch?v=gVfgbahppCY',
2028 'only_matching': True,
2031 'url': 'https://www.youtube.com/watch_popup?v=63RmMXCd_bQ',
2032 'only_matching': True,
2035 # https://github.com/ytdl-org/youtube-dl/pull/28094
2036 'url': 'OtqTfy26tG0',
2038 'id': 'OtqTfy26tG0',
2040 'title': 'Burn Out',
2041 'description': 'md5:8d07b84dcbcbfb34bc12a56d968b6131',
2042 'upload_date': '20141120',
2043 'uploader': 'The Cinematic Orchestra - Topic',
2044 'uploader_id': 'UCIzsJBIyo8hhpFm1NK0uLgw',
2045 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UCIzsJBIyo8hhpFm1NK0uLgw',
2046 'artist': 'The Cinematic Orchestra',
2047 'track': 'Burn Out',
2048 'album': 'Every Day',
2050 'live_status': 'not_live',
2051 'alt_title': 'Burn Out',
2055 'channel_url': 'https://www.youtube.com/channel/UCIzsJBIyo8hhpFm1NK0uLgw',
2056 'creator': 'The Cinematic Orchestra',
2057 'channel': 'The Cinematic Orchestra',
2058 'tags': ['The Cinematic Orchestra', 'Every Day', 'Burn Out'],
2059 'channel_id': 'UCIzsJBIyo8hhpFm1NK0uLgw',
2060 'availability': 'public',
2061 'thumbnail': 'https://i.ytimg.com/vi/OtqTfy26tG0/maxresdefault.jpg',
2062 'categories': ['Music'],
2063 'playable_in_embed': True,
2064 'channel_follower_count': int
2067 'skip_download': True,
2071 # controversial video, only works with bpctr when authenticated with cookies
2072 'url': 'https://www.youtube.com/watch?v=nGC3D_FkCmg',
2073 'only_matching': True,
2076 # controversial video, requires bpctr/contentCheckOk
2077 'url': 'https://www.youtube.com/watch?v=SZJvDhaSDnc',
2079 'id': 'SZJvDhaSDnc',
2081 'title': 'San Diego teen commits suicide after bullying over embarrassing video',
2082 'channel_id': 'UC-SJ6nODDmufqBzPBwCvYvQ',
2083 'uploader': 'CBS Mornings',
2084 'uploader_id': 'CBSThisMorning',
2085 'upload_date': '20140716',
2086 'description': 'md5:acde3a73d3f133fc97e837a9f76b53b7',
2088 'categories': ['News & Politics'],
2089 'uploader_url': 'http://www.youtube.com/user/CBSThisMorning',
2091 'channel': 'CBS Mornings',
2092 'tags': ['suicide', 'bullying', 'video', 'cbs', 'news'],
2093 'thumbnail': 'https://i.ytimg.com/vi/SZJvDhaSDnc/hqdefault.jpg',
2095 'availability': 'needs_auth',
2096 'channel_url': 'https://www.youtube.com/channel/UC-SJ6nODDmufqBzPBwCvYvQ',
2098 'live_status': 'not_live',
2099 'playable_in_embed': True,
2100 'channel_follower_count': int
2104 # restricted location, https://github.com/ytdl-org/youtube-dl/issues/28685
2105 'url': 'cBvYw8_A0vQ',
2107 'id': 'cBvYw8_A0vQ',
2109 'title': '4K Ueno Okachimachi Street Scenes 上野御徒町歩き',
2110 'description': 'md5:ea770e474b7cd6722b4c95b833c03630',
2111 'upload_date': '20201120',
2112 'uploader': 'Walk around Japan',
2113 'uploader_id': 'UC3o_t8PzBmXf5S9b7GLx1Mw',
2114 'uploader_url': r're:https?://(?:www\.)?youtube\.com/channel/UC3o_t8PzBmXf5S9b7GLx1Mw',
2116 'categories': ['Travel & Events'],
2117 'channel_id': 'UC3o_t8PzBmXf5S9b7GLx1Mw',
2119 'channel': 'Walk around Japan',
2120 'tags': ['Ueno Tokyo', 'Okachimachi Tokyo', 'Ameyoko Street', 'Tokyo attraction', 'Travel in Tokyo'],
2121 'thumbnail': 'https://i.ytimg.com/vi_webp/cBvYw8_A0vQ/hqdefault.webp',
2123 'availability': 'public',
2124 'channel_url': 'https://www.youtube.com/channel/UC3o_t8PzBmXf5S9b7GLx1Mw',
2125 'live_status': 'not_live',
2126 'playable_in_embed': True,
2127 'channel_follower_count': int
2130 'skip_download': True,
2133 # Has multiple audio streams
2134 'url': 'WaOKSUlf4TM',
2135 'only_matching': True
2137 # Requires Premium: has format 141 when requested using YTM url
2138 'url': 'https://music.youtube.com/watch?v=XclachpHxis',
2139 'only_matching': True
2141 # multiple subtitles with same lang_code
2142 'url': 'https://www.youtube.com/watch?v=wsQiKKfKxug',
2143 'only_matching': True,
2145 # Force use android client fallback
2146 'url': 'https://www.youtube.com/watch?v=YOelRv7fMxY',
2148 'id': 'YOelRv7fMxY',
2149 'title': 'DIGGING A SECRET TUNNEL Part 1',
2151 'upload_date': '20210624',
2152 'channel_id': 'UCp68_FLety0O-n9QU6phsgw',
2153 'uploader': 'colinfurze',
2154 'uploader_id': 'colinfurze',
2155 'channel_url': r're:https?://(?:www\.)?youtube\.com/channel/UCp68_FLety0O-n9QU6phsgw',
2156 'description': 'md5:5d5991195d599b56cd0c4148907eec50',
2158 'categories': ['Entertainment'],
2159 'uploader_url': 'http://www.youtube.com/user/colinfurze',
2161 'channel': 'colinfurze',
2162 'tags': ['Colin', 'furze', 'Terry', 'tunnel', 'underground', 'bunker'],
2163 'thumbnail': 'https://i.ytimg.com/vi/YOelRv7fMxY/maxresdefault.jpg',
2165 'availability': 'public',
2167 'live_status': 'not_live',
2168 'playable_in_embed': True,
2169 'channel_follower_count': int
2172 'format': '17', # 3gp format available on android
2173 'extractor_args': {'youtube': {'player_client': ['android']}},
2177 # Skip download of additional client configs (remix client config in this case)
2178 'url': 'https://music.youtube.com/watch?v=MgNrAu2pzNs',
2179 'only_matching': True,
2181 'extractor_args': {'youtube': {'player_skip': ['configs']}},
2185 'url': 'https://www.youtube.com/shorts/BGQWPY4IigY',
2186 'only_matching': True,
2188 'note': 'Storyboards',
2189 'url': 'https://www.youtube.com/watch?v=5KLPxDtMqe8',
2191 'id': '5KLPxDtMqe8',
2194 'title': 'Your Brain is Plastic',
2195 'uploader_id': 'scishow',
2196 'description': 'md5:89cd86034bdb5466cd87c6ba206cd2bc',
2197 'upload_date': '20140324',
2198 'uploader': 'SciShow',
2200 'channel_id': 'UCZYTClx2T1of7BRZ86-8fow',
2201 'channel_url': 'https://www.youtube.com/channel/UCZYTClx2T1of7BRZ86-8fow',
2203 'thumbnail': 'https://i.ytimg.com/vi/5KLPxDtMqe8/maxresdefault.jpg',
2204 'playable_in_embed': True,
2206 'uploader_url': 'http://www.youtube.com/user/scishow',
2207 'availability': 'public',
2208 'channel': 'SciShow',
2209 'live_status': 'not_live',
2211 'categories': ['Education'],
2213 'channel_follower_count': int
2214 }, 'params': {'format': 'mhtml', 'skip_download': True}
2216 # Ensure video upload_date is in UTC timezone (video was uploaded 1641170939)
2217 'url': 'https://www.youtube.com/watch?v=2NUZ8W2llS4',
2219 'id': '2NUZ8W2llS4',
2221 'title': 'The NP that test your phone performance 🙂',
2222 'description': 'md5:144494b24d4f9dfacb97c1bbef5de84d',
2223 'uploader': 'Leon Nguyen',
2224 'uploader_id': 'VNSXIII',
2225 'uploader_url': 'http://www.youtube.com/user/VNSXIII',
2226 'channel_id': 'UCRqNBSOHgilHfAczlUmlWHA',
2227 'channel_url': 'https://www.youtube.com/channel/UCRqNBSOHgilHfAczlUmlWHA',
2231 'categories': ['Gaming'],
2233 'playable_in_embed': True,
2234 'live_status': 'not_live',
2235 'upload_date': '20220103',
2237 'availability': 'public',
2238 'channel': 'Leon Nguyen',
2239 'thumbnail': 'https://i.ytimg.com/vi_webp/2NUZ8W2llS4/maxresdefault.webp',
2240 'comment_count': int,
2241 'channel_follower_count': int
2244 # Same video as above, but with --compat-opt no-youtube-prefer-utc-upload-date
2245 'url': 'https://www.youtube.com/watch?v=2NUZ8W2llS4',
2247 'id': '2NUZ8W2llS4',
2249 'title': 'The NP that test your phone performance 🙂',
2250 'description': 'md5:144494b24d4f9dfacb97c1bbef5de84d',
2251 'uploader': 'Leon Nguyen',
2252 'uploader_id': 'VNSXIII',
2253 'uploader_url': 'http://www.youtube.com/user/VNSXIII',
2254 'channel_id': 'UCRqNBSOHgilHfAczlUmlWHA',
2255 'channel_url': 'https://www.youtube.com/channel/UCRqNBSOHgilHfAczlUmlWHA',
2259 'categories': ['Gaming'],
2261 'playable_in_embed': True,
2262 'live_status': 'not_live',
2263 'upload_date': '20220102',
2265 'availability': 'public',
2266 'channel': 'Leon Nguyen',
2267 'thumbnail': 'https://i.ytimg.com/vi_webp/2NUZ8W2llS4/maxresdefault.webp',
2268 'comment_count': int,
2269 'channel_follower_count': int
2271 'params': {'compat_opts': ['no-youtube-prefer-utc-upload-date']}
2273 # date text is premiered video, ensure upload date in UTC (published 1641172509)
2274 'url': 'https://www.youtube.com/watch?v=mzZzzBU6lrM',
2276 'id': 'mzZzzBU6lrM',
2278 'title': 'I Met GeorgeNotFound In Real Life...',
2279 'description': 'md5:cca98a355c7184e750f711f3a1b22c84',
2280 'uploader': 'Quackity',
2281 'uploader_id': 'QuackityHQ',
2282 'uploader_url': 'http://www.youtube.com/user/QuackityHQ',
2283 'channel_id': 'UC_8NknAFiyhOUaZqHR3lq3Q',
2284 'channel_url': 'https://www.youtube.com/channel/UC_8NknAFiyhOUaZqHR3lq3Q',
2288 'categories': ['Entertainment'],
2290 'playable_in_embed': True,
2291 'live_status': 'not_live',
2292 'release_timestamp': 1641172509,
2293 'release_date': '20220103',
2294 'upload_date': '20220103',
2296 'availability': 'public',
2297 'channel': 'Quackity',
2298 'thumbnail': 'https://i.ytimg.com/vi/mzZzzBU6lrM/maxresdefault.jpg',
2299 'channel_follower_count': int
2302 { # continuous livestream. Microformat upload date should be preferred.
2303 # Upload date was 2021-06-19 (not UTC), while stream start is 2021-11-27
2304 'url': 'https://www.youtube.com/watch?v=kgx4WGK0oNU',
2306 'id': 'kgx4WGK0oNU',
2307 'title': r're:jazz\/lofi hip hop radio🌱chill beats to relax\/study to \[LIVE 24\/7\] \d{4}-\d{2}-\d{2} \d{2}:\d{2}',
2309 'channel_id': 'UC84whx2xxsiA1gXHXXqKGOA',
2310 'availability': 'public',
2312 'release_timestamp': 1637975704,
2313 'upload_date': '20210619',
2314 'channel_url': 'https://www.youtube.com/channel/UC84whx2xxsiA1gXHXXqKGOA',
2315 'live_status': 'is_live',
2316 'thumbnail': 'https://i.ytimg.com/vi/kgx4WGK0oNU/maxresdefault.jpg',
2317 'uploader': '阿鲍Abao',
2318 'uploader_url': 'http://www.youtube.com/channel/UC84whx2xxsiA1gXHXXqKGOA',
2319 'channel': 'Abao in Tokyo',
2320 'channel_follower_count': int,
2321 'release_date': '20211127',
2323 'categories': ['People & Blogs'],
2325 'uploader_id': 'UC84whx2xxsiA1gXHXXqKGOA',
2327 'playable_in_embed': True,
2328 'description': 'md5:2ef1d002cad520f65825346e2084e49d',
2330 'params': {'skip_download': True}
2332 # Story. Requires specific player params to work.
2333 'url': 'https://www.youtube.com/watch?v=vv8qTUWmulI',
2335 'id': 'vv8qTUWmulI',
2337 'availability': 'unlisted',
2339 'channel_id': 'UCzIZ8HrzDgc-pNQDUG6avBA',
2340 'upload_date': '20220526',
2341 'categories': ['Education'],
2343 'channel': 'IT\'S HISTORY',
2345 'uploader_id': 'BlastfromthePast',
2347 'uploader': 'IT\'S HISTORY',
2348 'playable_in_embed': True,
2350 'live_status': 'not_live',
2352 'thumbnail': 'https://i.ytimg.com/vi_webp/vv8qTUWmulI/maxresdefault.webp',
2353 'uploader_url': 'http://www.youtube.com/user/BlastfromthePast',
2354 'channel_url': 'https://www.youtube.com/channel/UCzIZ8HrzDgc-pNQDUG6avBA',
2356 'skip': 'stories get removed after some period of time',
2358 'url': 'https://www.youtube.com/watch?v=tjjjtzRLHvA',
2360 'id': 'tjjjtzRLHvA',
2362 'title': 'ハッシュタグ無し };if window.ytcsi',
2363 'upload_date': '20220323',
2365 'availability': 'unlisted',
2366 'channel': 'nao20010128nao',
2367 'thumbnail': 'https://i.ytimg.com/vi_webp/tjjjtzRLHvA/maxresdefault.webp',
2369 'uploader': 'nao20010128nao',
2370 'uploader_id': 'nao20010128nao',
2371 'categories': ['Music'],
2374 'channel_url': 'https://www.youtube.com/channel/UCdqltm_7iv1Vs6kp6Syke5A',
2375 'channel_id': 'UCdqltm_7iv1Vs6kp6Syke5A',
2376 'live_status': 'not_live',
2377 'playable_in_embed': True,
2378 'channel_follower_count': int,
2381 'uploader_url': 'http://www.youtube.com/user/nao20010128nao',
2384 # Prefer primary title+description language metadata by default
2385 # Do not prefer translated description if primary is empty
2386 'url': 'https://www.youtube.com/watch?v=el3E4MbxRqQ',
2388 'id': 'el3E4MbxRqQ',
2390 'title': 'dlp test video 2 - primary sv no desc',
2392 'channel': 'cole-dlp-test-acc',
2395 'channel_url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
2397 'playable_in_embed': True,
2398 'availability': 'unlisted',
2399 'thumbnail': 'https://i.ytimg.com/vi_webp/el3E4MbxRqQ/maxresdefault.webp',
2402 'uploader_id': 'UCiu-3thuViMebBjw_5nWYrA',
2403 'uploader_url': 'http://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
2404 'live_status': 'not_live',
2405 'upload_date': '20220908',
2406 'categories': ['People & Blogs'],
2407 'uploader': 'cole-dlp-test-acc',
2408 'channel_id': 'UCiu-3thuViMebBjw_5nWYrA',
2410 'params': {'skip_download': True}
2412 # Extractor argument: prefer translated title+description
2413 'url': 'https://www.youtube.com/watch?v=gHKT4uU8Zng',
2415 'id': 'gHKT4uU8Zng',
2417 'channel': 'cole-dlp-test-acc',
2420 'live_status': 'not_live',
2421 'channel_id': 'UCiu-3thuViMebBjw_5nWYrA',
2422 'upload_date': '20220728',
2423 'uploader_id': 'UCiu-3thuViMebBjw_5nWYrA',
2425 'categories': ['People & Blogs'],
2426 'thumbnail': 'https://i.ytimg.com/vi_webp/gHKT4uU8Zng/maxresdefault.webp',
2427 'title': 'dlp test video title translated (fr)',
2428 'availability': 'public',
2429 'uploader': 'cole-dlp-test-acc',
2431 'description': 'dlp test video description translated (fr)',
2432 'playable_in_embed': True,
2433 'channel_url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
2434 'uploader_url': 'http://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
2436 'params': {'skip_download': True, 'extractor_args': {'youtube': {'lang': ['fr']}}},
2437 'expected_warnings': [r'Preferring "fr" translated fields'],
2439 'note': '6 channel audio',
2440 'url': 'https://www.youtube.com/watch?v=zgdo7-RRjgo',
2441 'only_matching': True,
2446 # YouTube <object> embed
2448 'url': 'http://www.improbable.com/2017/04/03/untrained-modern-youths-and-ancient-masters-in-selfie-portraits/',
2449 'md5': '873c81d308b979f0e23ee7e620b312a3',
2451 'id': 'msN87y-iEx0',
2453 'title': 'Feynman: Mirrors FUN TO IMAGINE 6',
2454 'upload_date': '20080526',
2455 'description': 'md5:873c81d308b979f0e23ee7e620b312a3',
2456 'uploader': 'Christopher Sykes',
2457 'uploader_id': 'ChristopherJSykes',
2459 'tags': ['feynman', 'mirror', 'science', 'physics', 'imagination', 'fun', 'cool', 'puzzle'],
2460 'channel_id': 'UCCeo--lls1vna5YJABWAcVA',
2461 'playable_in_embed': True,
2462 'thumbnail': 'https://i.ytimg.com/vi/msN87y-iEx0/hqdefault.jpg',
2464 'comment_count': int,
2465 'channel': 'Christopher Sykes',
2466 'live_status': 'not_live',
2467 'channel_url': 'https://www.youtube.com/channel/UCCeo--lls1vna5YJABWAcVA',
2468 'availability': 'public',
2471 'categories': ['Science & Technology'],
2472 'channel_follower_count': int,
2473 'uploader_url': 'http://www.youtube.com/user/ChristopherJSykes',
2476 'skip_download': True,
2482 def suitable(cls, url):
2483 from ..utils import parse_qs
2486 if qs.get('list', [None])[0]:
2488 return super().suitable(url)
2490 def __init__(self, *args, **kwargs):
2491 super().__init__(*args, **kwargs)
2492 self._code_cache = {}
2493 self._player_cache = {}
2495 def _prepare_live_from_start_formats(self, formats, video_id, live_start_time, url, webpage_url, smuggled_data):
2496 lock = threading.Lock()
2499 start_time = time.time()
2500 formats = [f for f in formats if f.get('is_from_start')]
2502 def refetch_manifest(format_id, delay):
2503 nonlocal formats, start_time, is_live
2504 if time.time() <= start_time + delay:
2507 _, _, prs, player_url = self._download_player_responses(url, smuggled_data, video_id, webpage_url)
2508 video_details = traverse_obj(
2509 prs, (..., 'videoDetails'), expected_type=dict, default=[])
2510 microformats = traverse_obj(
2511 prs, (..., 'microformat', 'playerMicroformatRenderer'),
2512 expected_type=dict, default=[])
2513 _, is_live, _, formats, _ = self._list_formats(video_id, microformats, video_details, prs, player_url)
2514 start_time = time.time()
2516 def mpd_feed(format_id, delay):
2518 @returns (manifest_url, manifest_stream_number, is_live) or None
2521 refetch_manifest(format_id, delay)
2523 f = next((f for f in formats if f['format_id'] == format_id), None)
2526 self.to_screen(f'{video_id}: Video is no longer live')
2528 self.report_warning(
2529 f'Cannot find refreshed manifest for format {format_id}{bug_reports_message()}')
2531 return f['manifest_url'], f['manifest_stream_number'], is_live
2535 f['protocol'] = 'http_dash_segments_generator'
2536 f['fragments'] = functools.partial(
2537 self._live_dash_fragments, f['format_id'], live_start_time, mpd_feed)
2539 def _live_dash_fragments(self, format_id, live_start_time, mpd_feed, ctx):
2540 FETCH_SPAN, MAX_DURATION = 5, 432000
2542 mpd_url, stream_number, is_live = None, None, True
2545 download_start_time = ctx.get('start') or time.time()
2547 lack_early_segments = download_start_time - (live_start_time or download_start_time) > MAX_DURATION
2548 if lack_early_segments:
2549 self.report_warning(bug_reports_message(
2550 'Starting download from the last 120 hours of the live stream since '
2551 'YouTube does not have data before that. If you think this is wrong,'), only_once=True)
2552 lack_early_segments = True
2554 known_idx, no_fragment_score, last_segment_url = begin_index, 0, None
2555 fragments, fragment_base_url = None, None
2557 def _extract_sequence_from_mpd(refresh_sequence, immediate):
2558 nonlocal mpd_url, stream_number, is_live, no_fragment_score, fragments, fragment_base_url
2559 # Obtain from MPD's maximum seq value
2560 old_mpd_url = mpd_url
2561 last_error = ctx.pop('last_error', None)
2562 expire_fast = immediate or last_error and isinstance(last_error, urllib.error.HTTPError) and last_error.code == 403
2563 mpd_url, stream_number, is_live = (mpd_feed(format_id, 5 if expire_fast else 18000)
2564 or (mpd_url, stream_number, False))
2565 if not refresh_sequence:
2566 if expire_fast and not is_live:
2567 return False, last_seq
2568 elif old_mpd_url == mpd_url:
2569 return True, last_seq
2571 fmts, _ = self._extract_mpd_formats_and_subtitles(
2572 mpd_url, None, note=False, errnote=False, fatal=False)
2573 except ExtractorError:
2576 no_fragment_score += 2
2577 return False, last_seq
2578 fmt_info = next(x for x in fmts if x['manifest_stream_number'] == stream_number)
2579 fragments = fmt_info['fragments']
2580 fragment_base_url = fmt_info['fragment_base_url']
2581 assert fragment_base_url
2583 _last_seq = int(re.search(r'(?:/|^)sq/(\d+)', fragments[-1]['path']).group(1))
2584 return True, _last_seq
2587 fetch_time = time.time()
2588 if no_fragment_score > 30:
2590 if last_segment_url:
2591 # Obtain from "X-Head-Seqnum" header value from each segment
2593 urlh = self._request_webpage(
2594 last_segment_url, None, note=False, errnote=False, fatal=False)
2595 except ExtractorError:
2597 last_seq = try_get(urlh, lambda x: int_or_none(x.headers['X-Head-Seqnum']))
2598 if last_seq is None:
2599 no_fragment_score += 2
2600 last_segment_url = None
2603 should_continue, last_seq = _extract_sequence_from_mpd(True, no_fragment_score > 15)
2604 no_fragment_score += 2
2605 if not should_continue:
2608 if known_idx > last_seq:
2609 last_segment_url = None
2614 if begin_index < 0 and known_idx < 0:
2615 # skip from the start when it's negative value
2616 known_idx = last_seq + begin_index
2617 if lack_early_segments:
2618 known_idx = max(known_idx, last_seq - int(MAX_DURATION // fragments[-1]['duration']))
2620 for idx in range(known_idx, last_seq):
2621 # do not update sequence here or you'll get skipped some part of it
2622 should_continue, _ = _extract_sequence_from_mpd(False, False)
2623 if not should_continue:
2625 raise ExtractorError('breaking out of outer loop')
2626 last_segment_url = urljoin(fragment_base_url, 'sq/%d' % idx)
2628 'url': last_segment_url,
2629 'fragment_count': last_seq,
2631 if known_idx == last_seq:
2632 no_fragment_score += 5
2634 no_fragment_score = 0
2635 known_idx = last_seq
2636 except ExtractorError:
2639 time.sleep(max(0, FETCH_SPAN + fetch_time - time.time()))
2641 def _extract_player_url(self, *ytcfgs, webpage=None):
2642 player_url = traverse_obj(
2643 ytcfgs, (..., 'PLAYER_JS_URL'), (..., 'WEB_PLAYER_CONTEXT_CONFIGS', ..., 'jsUrl'),
2644 get_all=False, expected_type=str)
2647 return urljoin('https://www.youtube.com', player_url)
2649 def _download_player_url(self, video_id, fatal=False):
2650 res = self._download_webpage(
2651 'https://www.youtube.com/iframe_api',
2652 note='Downloading iframe API JS', video_id=video_id, fatal=fatal)
2654 player_version = self._search_regex(
2655 r'player\\?/([0-9a-fA-F]{8})\\?/', res, 'player version', fatal=fatal)
2657 return f'https://www.youtube.com/s/player/{player_version}/player_ias.vflset/en_US/base.js'
2659 def _signature_cache_id(self, example_sig):
2660 """ Return a string representation of a signature """
2661 return '.'.join(str(len(part)) for part in example_sig.split('.'))
2664 def _extract_player_info(cls, player_url):
2665 for player_re in cls._PLAYER_INFO_RE:
2666 id_m = re.search(player_re, player_url)
2670 raise ExtractorError('Cannot identify player %r' % player_url)
2671 return id_m.group('id')
2673 def _load_player(self, video_id, player_url, fatal=True):
2674 player_id = self._extract_player_info(player_url)
2675 if player_id not in self._code_cache:
2676 code = self._download_webpage(
2677 player_url, video_id, fatal=fatal,
2678 note='Downloading player ' + player_id,
2679 errnote='Download of %s failed' % player_url)
2681 self._code_cache[player_id] = code
2682 return self._code_cache.get(player_id)
2684 def _extract_signature_function(self, video_id, player_url, example_sig):
2685 player_id = self._extract_player_info(player_url)
2687 # Read from filesystem cache
2688 func_id = f'js_{player_id}_{self._signature_cache_id(example_sig)}'
2689 assert os.path.basename(func_id) == func_id
2691 self.write_debug(f'Extracting signature function {func_id}')
2692 cache_spec, code = self.cache.load('youtube-sigfuncs', func_id), None
2695 code = self._load_player(video_id, player_url)
2697 res = self._parse_sig_js(code)
2698 test_string = ''.join(map(chr, range(len(example_sig))))
2699 cache_spec = [ord(c) for c in res(test_string)]
2700 self.cache.store('youtube-sigfuncs', func_id, cache_spec)
2702 return lambda s: ''.join(s[i] for i in cache_spec)
2704 def _print_sig_code(self, func, example_sig):
2705 if not self.get_param('youtube_print_sig_code'):
2708 def gen_sig_code(idxs):
2709 def _genslice(start, end, step):
2710 starts = '' if start == 0 else str(start)
2711 ends = (':%d' % (end + step)) if end + step >= 0 else ':'
2712 steps = '' if step == 1 else (':%d' % step)
2713 return f's[{starts}{ends}{steps}]'
2716 # Quelch pyflakes warnings - start will be set when step is set
2717 start = '(Never used)'
2718 for i, prev in zip(idxs[1:], idxs[:-1]):
2719 if step is not None:
2720 if i - prev == step:
2722 yield _genslice(start, prev, step)
2725 if i - prev in [-1, 1]:
2730 yield 's[%d]' % prev
2734 yield _genslice(start, i, step)
2736 test_string = ''.join(map(chr, range(len(example_sig))))
2737 cache_res = func(test_string)
2738 cache_spec = [ord(c) for c in cache_res]
2739 expr_code = ' + '.join(gen_sig_code(cache_spec))
2740 signature_id_tuple = '(%s)' % (
2741 ', '.join(str(len(p)) for p in example_sig.split('.')))
2742 code = ('if tuple(len(p) for p in s.split(\'.\')) == %s:\n'
2743 ' return %s\n') % (signature_id_tuple, expr_code)
2744 self.to_screen('Extracted signature function:\n' + code)
2746 def _parse_sig_js(self, jscode):
2747 funcname = self._search_regex(
2748 (r'\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
2749 r'\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
2750 r'\bm=(?P<sig>[a-zA-Z0-9$]{2,})\(decodeURIComponent\(h\.s\)\)',
2751 r'\bc&&\(c=(?P<sig>[a-zA-Z0-9$]{2,})\(decodeURIComponent\(c\)\)',
2752 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+\)',
2753 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*\)',
2754 r'(?P<sig>[a-zA-Z0-9$]+)\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)',
2756 r'(["\'])signature\1\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
2757 r'\.sig\|\|(?P<sig>[a-zA-Z0-9$]+)\(',
2758 r'yt\.akamaized\.net/\)\s*\|\|\s*.*?\s*[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*(?:encodeURIComponent\s*\()?\s*(?P<sig>[a-zA-Z0-9$]+)\(',
2759 r'\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
2760 r'\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
2761 r'\bc\s*&&\s*a\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
2762 r'\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
2763 r'\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\('),
2764 jscode, 'Initial JS player signature function name', group='sig')
2766 jsi = JSInterpreter(jscode)
2767 initial_function = jsi.extract_function(funcname)
2768 return lambda s: initial_function([s])
2770 def _cached(self, func, *cache_id):
2771 def inner(*args, **kwargs):
2772 if cache_id not in self._player_cache:
2774 self._player_cache[cache_id] = func(*args, **kwargs)
2775 except ExtractorError as e:
2776 self._player_cache[cache_id] = e
2777 except Exception as e:
2778 self._player_cache[cache_id] = ExtractorError(traceback.format_exc(), cause=e)
2780 ret = self._player_cache[cache_id]
2781 if isinstance(ret, Exception):
2786 def _decrypt_signature(self, s, video_id, player_url):
2787 """Turn the encrypted s field into a working signature"""
2788 extract_sig = self._cached(
2789 self._extract_signature_function, 'sig', player_url, self._signature_cache_id(s))
2790 func = extract_sig(video_id, player_url, s)
2791 self._print_sig_code(func, s)
2794 def _decrypt_nsig(self, s, video_id, player_url):
2795 """Turn the encrypted n field into a working signature"""
2796 if player_url is None:
2797 raise ExtractorError('Cannot decrypt nsig without player_url')
2798 player_url = urljoin('https://www.youtube.com', player_url)
2801 jsi, player_id, func_code = self._extract_n_function_code(video_id, player_url)
2802 except ExtractorError as e:
2803 raise ExtractorError('Unable to extract nsig function code', cause=e)
2804 if self.get_param('youtube_print_sig_code'):
2805 self.to_screen(f'Extracted nsig function from {player_id}:\n{func_code[1]}\n')
2808 extract_nsig = self._cached(self._extract_n_function_from_code, 'nsig func', player_url)
2809 ret = extract_nsig(jsi, func_code)(s)
2810 except JSInterpreter.Exception as e:
2812 jsi = PhantomJSwrapper(self, timeout=5000)
2813 except ExtractorError:
2815 self.report_warning(
2816 f'Native nsig extraction failed: Trying with PhantomJS\n'
2817 f' n = {s} ; player = {player_url}', video_id)
2820 args, func_body = func_code
2822 f'console.log(function({", ".join(args)}) {{ {func_body} }}({s!r}));',
2823 video_id=video_id, note='Executing signature code').strip()
2825 self.write_debug(f'Decrypted nsig {s} => {ret}')
2828 def _extract_n_function_name(self, jscode):
2829 funcname, idx = self._search_regex(
2830 r'\.get\("n"\)\)&&\(b=(?P<nfunc>[a-zA-Z0-9$]+)(?:\[(?P<idx>\d+)\])?\([a-zA-Z0-9]\)',
2831 jscode, 'Initial JS player n function name', group=('nfunc', 'idx'))
2835 return json.loads(js_to_json(self._search_regex(
2836 rf'var {re.escape(funcname)}\s*=\s*(\[.+?\]);', jscode,
2837 f'Initial JS player n function list ({funcname}.{idx})')))[int(idx)]
2839 def _extract_n_function_code(self, video_id, player_url):
2840 player_id = self._extract_player_info(player_url)
2841 func_code = self.cache.load('youtube-nsig', player_id, min_ver='2022.09.1')
2842 jscode = func_code or self._load_player(video_id, player_url)
2843 jsi = JSInterpreter(jscode)
2846 return jsi, player_id, func_code
2848 func_name = self._extract_n_function_name(jscode)
2851 func_code = self._search_regex(
2852 r'''(?xs
)%s\s
*=\s
*function\s
*\
((?P
<var
>[\w$
]+)\
)\s
*
2853 # NB: The end of the regex is intentionally kept strict
2854 {(?P<code>.+?}\s
*return\
[\w$
]+.join\
(""\
))};''' % func_name,
2855 jscode, 'nsig function', group=('var', 'code'), default=None)
2857 func_code = ([func_code[0]], func_code[1])
2859 self.write_debug('Extracting nsig function with jsinterp')
2860 func_code = jsi.extract_function_code(func_name)
2862 self.cache.store('youtube-nsig', player_id, func_code)
2863 return jsi, player_id, func_code
2865 def _extract_n_function_from_code(self, jsi, func_code):
2866 func = jsi.extract_function_from_code(*func_code)
2868 def extract_nsig(s):
2871 except JSInterpreter.Exception:
2873 except Exception as e:
2874 raise JSInterpreter.Exception(traceback.format_exc(), cause=e)
2876 if ret.startswith('enhanced_except_'):
2877 raise JSInterpreter.Exception('Signature function returned an exception')
2882 def _extract_signature_timestamp(self, video_id, player_url, ytcfg=None, fatal=False):
2884 Extract signatureTimestamp (sts)
2885 Required to tell API what sig/player version is in use.
2888 if isinstance(ytcfg, dict):
2889 sts = int_or_none(ytcfg.get('STS'))
2892 # Attempt to extract from player
2893 if player_url is None:
2894 error_msg = 'Cannot extract signature timestamp without player_url.'
2896 raise ExtractorError(error_msg)
2897 self.report_warning(error_msg)
2899 code = self._load_player(video_id, player_url, fatal=fatal)
2901 sts = int_or_none(self._search_regex(
2902 r'(?:signatureTimestamp|sts)\s*:\s*(?P<sts>[0-9]{5})', code,
2903 'JS player signature timestamp', group='sts', fatal=fatal))
2906 def _mark_watched(self, video_id, player_responses):
2907 for is_full, key in enumerate(('videostatsPlaybackUrl', 'videostatsWatchtimeUrl')):
2908 label = 'fully ' if is_full else ''
2909 url = get_first(player_responses, ('playbackTracking', key, 'baseUrl'),
2910 expected_type=url_or_none)
2912 self.report_warning(f'Unable to mark {label}watched')
2914 parsed_url = urllib.parse.urlparse(url)
2915 qs = urllib.parse.parse_qs(parsed_url.query)
2917 # cpn generation algorithm is reverse engineered from base.js.
2918 # In fact it works even with dummy cpn.
2919 CPN_ALPHABET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'
2920 cpn = ''.join(CPN_ALPHABET[random.randint(0, 256) & 63] for _ in range(0, 16))
2922 # # more consistent results setting it to right before the end
2923 video_length = [str(float((qs.get('len') or ['1.5'])[0]) - 1)]
2928 'cmt': video_length,
2929 'el': 'detailpage', # otherwise defaults to "shorts"
2933 # these seem to mark watchtime "history" in the real world
2934 # they're required, so send in a single value
2940 url = urllib.parse.urlunparse(
2941 parsed_url._replace(query=urllib.parse.urlencode(qs, True)))
2943 self._download_webpage(
2944 url, video_id, f'Marking {label}watched',
2945 'Unable to mark watched', fatal=False)
2948 def _extract_from_webpage(cls, url, webpage):
2949 # Invidious Instances
2950 # https://github.com/yt-dlp/yt-dlp/issues/195
2951 # https://github.com/iv-org/invidious/pull/1730
2953 r'<link rel="alternate" href="(?P<url>https://www\.youtube\.com/watch\?v=[0-9A-Za-z_-]{11})"',
2956 yield cls.url_result(mobj.group('url'), cls)
2957 raise cls.StopExtraction()
2959 yield from super()._extract_from_webpage(url, webpage)
2961 # lazyYT YouTube embed
2962 for id_ in re.findall(r'class="lazyYT" data-youtube-id="([^"]+)"', webpage):
2963 yield cls.url_result(unescapeHTML(id_), cls, id_)
2965 # Wordpress "YouTube Video Importer" plugin
2966 for m in re.findall(r'''(?x
)<div
[^
>]+
2967 class=(?P
<q1
>[\'"])[^\'"]*\byvii
_single
_video
_player
\b[^
\'"]*(?P=q1)[^>]+
2968 data-video_id=(?P<q2>[\'"])([^
\'"]+)(?P=q2)''', webpage):
2969 yield cls.url_result(m[-1], cls, m[-1])
2972 def extract_id(cls, url):
2973 video_id = cls.get_temp_id(url)
2975 raise ExtractorError(f'Invalid URL: {url}')
2978 def _extract_chapters_from_json(self, data, duration):
2979 chapter_list = traverse_obj(
2981 'playerOverlays', 'playerOverlayRenderer', 'decoratedPlayerBarRenderer',
2982 'decoratedPlayerBarRenderer', 'playerBar', 'chapteredPlayerBarRenderer', 'chapters'
2983 ), expected_type=list)
2985 return self._extract_chapters(
2987 chapter_time=lambda chapter: float_or_none(
2988 traverse_obj(chapter, ('chapterRenderer', 'timeRangeStartMillis')), scale=1000),
2989 chapter_title=lambda chapter: traverse_obj(
2990 chapter, ('chapterRenderer', 'title', 'simpleText'), expected_type=str),
2993 def _extract_chapters_from_engagement_panel(self, data, duration):
2994 content_list = traverse_obj(
2996 ('engagementPanels', ..., 'engagementPanelSectionListRenderer', 'content', 'macroMarkersListRenderer', 'contents'),
2997 expected_type=list, default=[])
2998 chapter_time = lambda chapter: parse_duration(self._get_text(chapter, 'timeDescription'))
2999 chapter_title = lambda chapter: self._get_text(chapter, 'title')
3001 return next(filter(None, (
3002 self._extract_chapters(traverse_obj(contents, (..., 'macroMarkersListItemRenderer')),
3003 chapter_time, chapter_title, duration)
3004 for contents in content_list)), [])
3006 def _extract_chapters_from_description(self, description, duration):
3007 return self._extract_chapters(
3008 re.findall(r'(?m)^((?:\d+:)?\d{1,2}:\d{2})\b\W*\s(.+?)\s*$', description or ''),
3009 chapter_time=lambda x: parse_duration(x[0]), chapter_title=lambda x: x[1],
3010 duration=duration, strict=False)
3012 def _extract_chapters(self, chapter_list, chapter_time, chapter_title, duration, strict=True):
3016 'start_time': chapter_time(chapter),
3017 'title': chapter_title(chapter),
3018 } for chapter in chapter_list or []]
3020 chapter_list.sort(key=lambda c: c['start_time'] or 0)
3022 chapters = [{'start_time': 0}]
3023 for idx, chapter in enumerate(chapter_list):
3024 if chapter['start_time'] is None:
3025 self.report_warning(f'Incomplete chapter {idx}')
3026 elif chapters[-1]['start_time'] <= chapter['start_time'] <= duration:
3027 chapters.append(chapter)
3028 elif chapter not in chapters:
3029 self.report_warning(
3030 f'Invalid start time ({chapter["start_time"]} < {chapters[-1]["start_time"]}) for chapter "{chapter["title"]}
"')
3033 def _extract_comment(self, comment_renderer, parent=None):
3034 comment_id = comment_renderer.get('commentId')
3038 text = self._get_text(comment_renderer, 'contentText')
3040 # Timestamp is an estimate calculated from the current time and time_text
3041 time_text = self._get_text(comment_renderer, 'publishedTimeText') or ''
3042 timestamp = self._parse_time_text(time_text)
3044 author = self._get_text(comment_renderer, 'authorText')
3045 author_id = try_get(comment_renderer,
3046 lambda x: x['authorEndpoint']['browseEndpoint']['browseId'], str)
3048 votes = parse_count(try_get(comment_renderer, (lambda x: x['voteCount']['simpleText'],
3049 lambda x: x['likeCount']), str)) or 0
3050 author_thumbnail = try_get(comment_renderer,
3051 lambda x: x['authorThumbnail']['thumbnails'][-1]['url'], str)
3053 author_is_uploader = try_get(comment_renderer, lambda x: x['authorIsChannelOwner'], bool)
3054 is_favorited = 'creatorHeart' in (try_get(
3055 comment_renderer, lambda x: x['actionButtons']['commentActionButtonsRenderer'], dict) or {})
3059 'timestamp': timestamp,
3060 'time_text': time_text,
3061 'like_count': votes,
3062 'is_favorited': is_favorited,
3064 'author_id': author_id,
3065 'author_thumbnail': author_thumbnail,
3066 'author_is_uploader': author_is_uploader,
3067 'parent': parent or 'root'
3070 def _comment_entries(self, root_continuation_data, ytcfg, video_id, parent=None, tracker=None):
3072 get_single_config_arg = lambda c: self._configuration_arg(c, [''])[0]
3074 def extract_header(contents):
3075 _continuation = None
3076 for content in contents:
3077 comments_header_renderer = traverse_obj(content, 'commentsHeaderRenderer')
3078 expected_comment_count = self._get_count(
3079 comments_header_renderer, 'countText', 'commentsCount')
3081 if expected_comment_count:
3082 tracker['est_total'] = expected_comment_count
3083 self.to_screen(f'Downloading ~{expected_comment_count} comments')
3084 comment_sort_index = int(get_single_config_arg('comment_sort') != 'top') # 1 = new, 0 = top
3086 sort_menu_item = try_get(
3087 comments_header_renderer,
3088 lambda x: x['sortMenu']['sortFilterSubMenuRenderer']['subMenuItems'][comment_sort_index], dict) or {}
3089 sort_continuation_ep = sort_menu_item.get('serviceEndpoint') or {}
3091 _continuation = self._extract_continuation_ep_data(sort_continuation_ep) or self._extract_continuation(sort_menu_item)
3092 if not _continuation:
3095 sort_text = str_or_none(sort_menu_item.get('title'))
3097 sort_text = 'top comments' if comment_sort_index == 0 else 'newest first'
3098 self.to_screen('Sorting comments by %s' % sort_text.lower())
3100 return _continuation
3102 def extract_thread(contents):
3104 tracker['current_page_thread'] = 0
3105 for content in contents:
3106 if not parent and tracker['total_parent_comments'] >= max_parents:
3108 comment_thread_renderer = try_get(content, lambda x: x['commentThreadRenderer'])
3109 comment_renderer = get_first(
3110 (comment_thread_renderer, content), [['commentRenderer', ('comment', 'commentRenderer')]],
3111 expected_type=dict, default={})
3113 comment = self._extract_comment(comment_renderer, parent)
3117 tracker['running_total'] += 1
3118 tracker['total_reply_comments' if parent else 'total_parent_comments'] += 1
3121 # Attempt to get the replies
3122 comment_replies_renderer = try_get(
3123 comment_thread_renderer, lambda x: x['replies']['commentRepliesRenderer'], dict)
3125 if comment_replies_renderer:
3126 tracker['current_page_thread'] += 1
3127 comment_entries_iter = self._comment_entries(
3128 comment_replies_renderer, ytcfg, video_id,
3129 parent=comment.get('id'), tracker=tracker)
3130 yield from itertools.islice(comment_entries_iter, min(
3131 max_replies_per_thread, max(0, max_replies - tracker['total_reply_comments'])))
3133 # Keeps track of counts across recursive calls
3138 current_page_thread=0,
3139 total_parent_comments=0,
3140 total_reply_comments=0)
3143 # YouTube comments have a max depth of 2
3144 max_depth = int_or_none(get_single_config_arg('max_comment_depth'))
3146 self._downloader.deprecated_feature('[youtube] max_comment_depth extractor argument is deprecated. '
3147 'Set max replies in the max-comments extractor argument instead')
3148 if max_depth == 1 and parent:
3151 max_comments, max_parents, max_replies, max_replies_per_thread, *_ = map(
3152 lambda p: int_or_none(p, default=sys.maxsize), self._configuration_arg('max_comments', ) + [''] * 4)
3154 continuation = self._extract_continuation(root_continuation_data)
3157 is_forced_continuation = False
3158 is_first_continuation = parent is None
3159 if is_first_continuation and not continuation:
3160 # Sometimes you can get comments by generating the continuation yourself,
3161 # even if YouTube initially reports them being disabled - e.g. stories comments.
3162 # Note: if the comment section is actually disabled, YouTube may return a response with
3163 # required check_get_keys missing. So we will disable that check initially in this case.
3164 continuation = self._build_api_continuation_query(self._generate_comment_continuation(video_id))
3165 is_forced_continuation = True
3167 for page_num in itertools.count(0):
3168 if not continuation:
3170 headers = self.generate_api_headers(ytcfg=ytcfg, visitor_data=self._extract_visitor_data(response))
3171 comment_prog_str = f"({tracker['running_total']}
/{tracker['est_total']}
)"
3173 if is_first_continuation:
3174 note_prefix = 'Downloading comment section API JSON'
3176 note_prefix = ' Downloading comment API JSON reply thread %d %s' % (
3177 tracker['current_page_thread'], comment_prog_str)
3179 note_prefix = '%sDownloading comment%s API JSON page %d %s' % (
3180 ' ' if parent else '', ' replies' if parent else '',
3181 page_num, comment_prog_str)
3183 response = self._extract_response(
3184 item_id=None, query=continuation,
3185 ep='next', ytcfg=ytcfg, headers=headers, note=note_prefix,
3186 check_get_keys='onResponseReceivedEndpoints' if not is_forced_continuation else None)
3187 is_forced_continuation = False
3188 continuation_contents = traverse_obj(
3189 response, 'onResponseReceivedEndpoints', expected_type=list, default=[])
3192 for continuation_section in continuation_contents:
3193 continuation_items = traverse_obj(
3194 continuation_section,
3195 (('reloadContinuationItemsCommand', 'appendContinuationItemsAction'), 'continuationItems'),
3196 get_all=False, expected_type=list) or []
3197 if is_first_continuation:
3198 continuation = extract_header(continuation_items)
3199 is_first_continuation = False
3204 for entry in extract_thread(continuation_items):
3208 continuation = self._extract_continuation({'contents': continuation_items})
3212 message = self._get_text(root_continuation_data, ('contents', ..., 'messageRenderer', 'text'), max_runs=1)
3213 if message and not parent and tracker['running_total'] == 0:
3214 self.report_warning(f'Youtube said: {message}', video_id=video_id, only_once=True)
3217 def _generate_comment_continuation(video_id):
3219 Generates initial comment section continuation token from given video id
3221 token = f'\x12\r\x12\x0b{video_id}\x18\x062\'"\x11"\x0b{video_id}0\x00x\x020\x00B\x10comments-section'
3222 return base64.b64encode(token.encode()).decode()
3224 def _get_comments(self, ytcfg, video_id, contents, webpage):
3225 """Entry for comment extraction"""
3226 def _real_comment_extract(contents):
3228 item for item in traverse_obj(contents, (..., 'itemSectionRenderer'), default={})
3229 if item.get('sectionIdentifier') == 'comment-item-section'), None)
3230 yield from self._comment_entries(renderer, ytcfg, video_id)
3232 max_comments = int_or_none(self._configuration_arg('max_comments', [''])[0])
3233 return itertools.islice(_real_comment_extract(contents), 0, max_comments)
3236 def _get_checkok_params():
3237 return {'contentCheckOk': True, 'racyCheckOk': True}
3240 def _generate_player_context(cls, sts=None):
3242 'html5Preference': 'HTML5_PREF_WANTS',
3245 context['signatureTimestamp'] = sts
3247 'playbackContext': {
3248 'contentPlaybackContext': context
3250 **cls._get_checkok_params()
3254 def _is_agegated(player_response):
3255 if traverse_obj(player_response, ('playabilityStatus', 'desktopLegacyAgeGateReason')):
3258 reasons = traverse_obj(player_response, ('playabilityStatus', ('status', 'reason')), default=[])
3259 AGE_GATE_REASONS = (
3260 'confirm your age', 'age-restricted', 'inappropriate', # reason
3261 'age_verification_required', 'age_check_required', # status
3263 return any(expected in reason for expected in AGE_GATE_REASONS for reason in reasons)
3266 def _is_unplayable(player_response):
3267 return traverse_obj(player_response, ('playabilityStatus', 'status')) == 'UNPLAYABLE'
3269 _STORY_PLAYER_PARAMS = '8AEB'
3271 def _extract_player_response(self, client, video_id, master_ytcfg, player_ytcfg, player_url, initial_pr, smuggled_data):
3273 session_index = self._extract_session_index(player_ytcfg, master_ytcfg)
3274 syncid = self._extract_account_syncid(player_ytcfg, master_ytcfg, initial_pr)
3275 sts = self._extract_signature_timestamp(video_id, player_url, master_ytcfg, fatal=False) if player_url else None
3276 headers = self.generate_api_headers(
3277 ytcfg=player_ytcfg, account_syncid=syncid, session_index=session_index, default_client=client)
3280 'videoId': video_id,
3282 if smuggled_data.get('is_story') or _split_innertube_client(client)[0] == 'android':
3283 yt_query['params'] = self._STORY_PLAYER_PARAMS
3285 yt_query.update(self._generate_player_context(sts))
3286 return self._extract_response(
3287 item_id=video_id, ep='player', query=yt_query,
3288 ytcfg=player_ytcfg, headers=headers, fatal=True,
3289 default_client=client,
3290 note='Downloading %s player API JSON' % client.replace('_', ' ').strip()
3293 def _get_requested_clients(self, url, smuggled_data):
3294 requested_clients = []
3295 default = ['android', 'web']
3296 allowed_clients = sorted(
3297 (client for client in INNERTUBE_CLIENTS.keys() if client[:1] != '_'),
3298 key=lambda client: INNERTUBE_CLIENTS[client]['priority'], reverse=True)
3299 for client in self._configuration_arg('player_client'):
3300 if client in allowed_clients:
3301 requested_clients.append(client)
3302 elif client == 'default':
3303 requested_clients.extend(default)
3304 elif client == 'all':
3305 requested_clients.extend(allowed_clients)
3307 self.report_warning(f'Skipping unsupported client {client}')
3308 if not requested_clients:
3309 requested_clients = default
3311 if smuggled_data.get('is_music_url') or self.is_music_url(url):
3312 requested_clients.extend(
3313 f'{client}_music' for client in requested_clients if f'{client}_music' in INNERTUBE_CLIENTS)
3315 return orderedSet(requested_clients)
3317 def _extract_player_responses(self, clients, video_id, webpage, master_ytcfg, smuggled_data):
3320 initial_pr = self._search_json(
3321 self._YT_INITIAL_PLAYER_RESPONSE_RE, webpage, 'initial player response', video_id, fatal=False)
3323 all_clients = set(clients)
3324 clients = clients[::-1]
3327 def append_client(*client_names):
3328 """ Append the first client name that exists but not already used """
3329 for client_name in client_names:
3330 actual_client = _split_innertube_client(client_name)[0]
3331 if actual_client in INNERTUBE_CLIENTS:
3332 if actual_client not in all_clients:
3333 clients.append(client_name)
3334 all_clients.add(actual_client)
3337 # Android player_response does not have microFormats which are needed for
3338 # extraction of some data. So we return the initial_pr with formats
3339 # stripped out even if not requested by the user
3340 # See: https://github.com/yt-dlp/yt-dlp/issues/501
3342 pr = dict(initial_pr)
3343 pr['streamingData'] = None
3347 tried_iframe_fallback = False
3350 client, base_client, variant = _split_innertube_client(clients.pop())
3351 player_ytcfg = master_ytcfg if client == 'web' else {}
3352 if 'configs' not in self._configuration_arg('player_skip') and client != 'web':
3353 player_ytcfg = self._download_ytcfg(client, video_id) or player_ytcfg
3355 player_url = player_url or self._extract_player_url(master_ytcfg, player_ytcfg, webpage=webpage)
3356 require_js_player = self._get_default_ytcfg(client).get('REQUIRE_JS_PLAYER')
3357 if 'js' in self._configuration_arg('player_skip'):
3358 require_js_player = False
3361 if not player_url and not tried_iframe_fallback and require_js_player:
3362 player_url = self._download_player_url(video_id)
3363 tried_iframe_fallback = True
3366 pr = initial_pr if client == 'web' and initial_pr else self._extract_player_response(
3367 client, video_id, player_ytcfg or master_ytcfg, player_ytcfg, player_url if require_js_player else None, initial_pr, smuggled_data)
3368 except ExtractorError as e:
3370 self.report_warning(last_error)
3375 # YouTube may return a different video player response than expected.
3376 # See: https://github.com/TeamNewPipe/NewPipe/issues/8713
3377 pr_video_id = traverse_obj(pr, ('videoDetails', 'videoId'))
3378 if pr_video_id and pr_video_id != video_id:
3379 self.report_warning(
3380 f'Skipping player response from {client} client (got player response for video "{pr_video_id}
" instead of "{video_id}
")' + bug_reports_message())
3384 # creator clients can bypass AGE_VERIFICATION_REQUIRED if logged in
3385 if variant == 'embedded' and self._is_unplayable(pr) and self.is_authenticated:
3386 append_client(f'{base_client}_creator')
3387 elif self._is_agegated(pr):
3388 if variant == 'tv_embedded':
3389 append_client(f'{base_client}_embedded')
3391 append_client(f'tv_embedded.{base_client}', f'{base_client}_embedded')
3396 self.report_warning(last_error)
3397 return prs, player_url
3399 def _extract_formats_and_subtitles(self, streaming_data, video_id, player_url, is_live, duration):
3400 itags, stream_ids = {}, []
3401 itag_qualities, res_qualities = {}, {0: None}
3403 # Normally tiny is the smallest video-only formats. But
3404 # audio-only formats with unknown quality may get tagged as tiny
3406 'audio_quality_ultralow', 'audio_quality_low', 'audio_quality_medium', 'audio_quality_high', # Audio only formats
3407 'small', 'medium', 'large', 'hd720', 'hd1080', 'hd1440', 'hd2160', 'hd2880', 'highres'
3409 streaming_formats = traverse_obj(streaming_data, (..., ('formats', 'adaptiveFormats'), ...), default=[])
3411 for fmt in streaming_formats:
3412 if fmt.get('targetDurationSec'):
3415 itag = str_or_none(fmt.get('itag'))
3416 audio_track = fmt.get('audioTrack') or {}
3417 stream_id = '%s.%s' % (itag or '', audio_track.get('id', ''))
3418 if stream_id in stream_ids:
3421 quality = fmt.get('quality')
3422 height = int_or_none(fmt.get('height'))
3423 if quality == 'tiny' or not quality:
3424 quality = fmt.get('audioQuality', '').lower() or quality
3425 # The 3gp format (17) in android client has a quality of "small
",
3426 # but is actually worse than other formats
3431 itag_qualities[itag] = quality
3433 res_qualities[height] = quality
3434 # FORMAT_STREAM_TYPE_OTF(otf=1) requires downloading the init fragment
3435 # (adding `&sq=0` to the URL) and parsing emsg box to determine the
3436 # number of fragment that would subsequently requested with (`&sq=N`)
3437 if fmt.get('type') == 'FORMAT_STREAM_TYPE_OTF':
3440 fmt_url = fmt.get('url')
3442 sc = urllib.parse.parse_qs(fmt.get('signatureCipher'))
3443 fmt_url = url_or_none(try_get(sc, lambda x: x['url'][0]))
3444 encrypted_sig = try_get(sc, lambda x: x['s'][0])
3445 if not all((sc, fmt_url, player_url, encrypted_sig)):
3448 fmt_url += '&%s=%s' % (
3449 traverse_obj(sc, ('sp', -1)) or 'signature',
3450 self._decrypt_signature(encrypted_sig, video_id, player_url)
3452 except ExtractorError as e:
3453 self.report_warning('Signature extraction failed: Some formats may be missing',
3454 video_id=video_id, only_once=True)
3455 self.write_debug(e, only_once=True)
3458 query = parse_qs(fmt_url)
3462 decrypt_nsig = self._cached(self._decrypt_nsig, 'nsig', query['n'][0])
3463 fmt_url = update_url_query(fmt_url, {
3464 'n': decrypt_nsig(query['n'][0], video_id, player_url)
3466 except ExtractorError as e:
3468 if isinstance(e, JSInterpreter.Exception):
3469 phantomjs_hint = (f' Install {self._downloader._format_err("PhantomJS", self._downloader.Styles.EMPHASIS)} '
3470 f'to workaround the issue. {PhantomJSwrapper.INSTALL_HINT}\n')
3472 self.report_warning(
3473 f'nsig extraction failed: You may experience throttling for some formats\n{phantomjs_hint}'
3474 f' n = {query["n"][0]} ; player = {player_url}', video_id=video_id, only_once=True)
3475 self.write_debug(e, only_once=True)
3477 self.report_warning(
3478 'Cannot decrypt nsig without player_url: You may experience throttling for some formats',
3479 video_id=video_id, only_once=True)
3483 itags[itag] = 'https'
3484 stream_ids.append(stream_id)
3486 tbr = float_or_none(fmt.get('averageBitrate') or fmt.get('bitrate'), 1000)
3487 language_preference = (
3488 10 if audio_track.get('audioIsDefault') and 10
3489 else -10 if 'descriptive' in (audio_track.get('displayName') or '').lower() and -10
3491 # Some formats may have much smaller duration than others (possibly damaged during encoding)
3492 # E.g. 2-nOtRESiUc Ref: https://github.com/yt-dlp/yt-dlp/issues/2823
3493 # Make sure to avoid false positives with small duration differences.
3494 # E.g. __2ABJjxzNo, ySuUZEjARPY
3495 is_damaged = try_get(fmt, lambda x: float(x['approxDurationMs']) / duration < 500)
3497 self.report_warning(
3498 f'{video_id}: Some formats are possibly damaged. They will be deprioritized', only_once=True)
3500 'asr': int_or_none(fmt.get('audioSampleRate')),
3501 'filesize': int_or_none(fmt.get('contentLength')),
3503 'format_note': join_nonempty(
3504 '%s%s' % (audio_track.get('displayName') or '',
3505 ' (default)' if language_preference > 0 else ''),
3506 fmt.get('qualityLabel') or quality.replace('audio_quality_', ''),
3507 try_get(fmt, lambda x: x['projectionType'].replace('RECTANGULAR', '').lower()),
3508 try_get(fmt, lambda x: x['spatialAudioType'].replace('SPATIAL_AUDIO_TYPE_', '').lower()),
3509 throttled and 'THROTTLED', is_damaged and 'DAMAGED', delim=', '),
3510 # Format 22 is likely to be damaged. See https://github.com/yt-dlp/yt-dlp/issues/3372
3511 'source_preference': -10 if throttled else -5 if itag == '22' else -1,
3512 'fps': int_or_none(fmt.get('fps')) or None,
3513 'audio_channels': fmt.get('audioChannels'),
3515 'quality': q(quality),
3516 'has_drm': bool(fmt.get('drmFamilies')),
3519 'width': int_or_none(fmt.get('width')),
3520 'language': join_nonempty(audio_track.get('id', '').split('.')[0],
3521 'desc' if language_preference < -1 else ''),
3522 'language_preference': language_preference,
3523 # Strictly de-prioritize damaged and 3gp formats
3524 'preference': -10 if is_damaged else -2 if itag == '17' else None,
3526 mime_mobj = re.match(
3527 r'((?:[^/]+)/(?:[^;]+))(?:;\s*codecs="([^
"]+)")?
', fmt.get('mimeType
') or '')
3529 dct['ext
'] = mimetype2ext(mime_mobj.group(1))
3530 dct.update(parse_codecs(mime_mobj.group(2)))
3531 no_audio = dct.get('acodec
') == 'none
'
3532 no_video = dct.get('vcodec
') == 'none
'
3537 if no_audio or no_video:
3538 dct['downloader_options
'] = {
3539 # Youtube throttles chunks >~10M
3540 'http_chunk_size
': 10485760,
3543 dct['container
'] = dct['ext
'] + '_dash
'
3546 live_from_start = is_live and self.get_param('live_from_start
')
3547 skip_manifests = self._configuration_arg('skip
')
3548 if not self.get_param('youtube_include_hls_manifest
', True):
3549 skip_manifests.append('hls
')
3550 if not self.get_param('youtube_include_dash_manifest
', True):
3551 skip_manifests.append('dash
')
3552 get_dash = 'dash
' not in skip_manifests and (
3553 not is_live or live_from_start or self._configuration_arg('include_live_dash
'))
3554 get_hls = not live_from_start and 'hls
' not in skip_manifests
3556 def process_manifest_format(f, proto, itag):
3558 if itags[itag] == proto or f'{itag}
-{proto}
' in itags:
3560 itag = f'{itag}
-{proto}
'
3562 f['format_id
'] = itag
3565 f['quality
'] = q(itag_qualities.get(try_get(f, lambda f: f['format_id
'].split('-')[0]), -1))
3566 if f['quality
'] == -1 and f.get('height
'):
3567 f['quality
'] = q(res_qualities[min(res_qualities, key=lambda x: abs(x - f['height
']))])
3571 for sd in streaming_data:
3572 hls_manifest_url = get_hls and sd.get('hlsManifestUrl
')
3573 if hls_manifest_url:
3574 fmts, subs = self._extract_m3u8_formats_and_subtitles(hls_manifest_url, video_id, 'mp4
', fatal=False, live=is_live)
3575 subtitles = self._merge_subtitles(subs, subtitles)
3577 if process_manifest_format(f, 'hls
', self._search_regex(
3578 r'/itag
/(\d
+)', f['url
'], 'itag
', default=None)):
3581 dash_manifest_url = get_dash and sd.get('dashManifestUrl
')
3582 if dash_manifest_url:
3583 formats, subs = self._extract_mpd_formats_and_subtitles(dash_manifest_url, video_id, fatal=False)
3584 subtitles = self._merge_subtitles(subs, subtitles) # Prioritize HLS subs over DASH
3586 if process_manifest_format(f, 'dash
', f['format_id
']):
3587 f['filesize
'] = int_or_none(self._search_regex(
3588 r'/clen
/(\d
+)', f.get('fragment_base_url
') or f['url
'], 'file size
', default=None))
3590 f['is_from_start
'] = True
3595 def _extract_storyboard(self, player_responses, duration):
3597 player_responses, ('storyboards
', 'playerStoryboardSpecRenderer
', 'spec
'), default='').split('|
')[::-1]
3598 base_url = url_or_none(urljoin('https
://i
.ytimg
.com
/', spec.pop() or None))
3602 for i, args in enumerate(spec):
3603 args = args.split('#')
3604 counts
= list(map(int_or_none
, args
[:5]))
3605 if len(args
) != 8 or not all(counts
):
3606 self
.report_warning(f
'Malformed storyboard {i}: {"#".join(args)}{bug_reports_message()}')
3608 width
, height
, frame_count
, cols
, rows
= counts
3611 url
= base_url
.replace('$L', str(L
- i
)).replace('$N', N
) + f
'&sigh={sigh}'
3612 fragment_count
= frame_count
/ (cols
* rows
)
3613 fragment_duration
= duration
/ fragment_count
3615 'format_id': f
'sb{i}',
3616 'format_note': 'storyboard',
3618 'protocol': 'mhtml',
3624 'fps': frame_count
/ duration
,
3628 'url': url
.replace('$M', str(j
)),
3629 'duration': min(fragment_duration
, duration
- (j
* fragment_duration
)),
3630 } for j
in range(math
.ceil(fragment_count
))],
3633 def _download_player_responses(self
, url
, smuggled_data
, video_id
, webpage_url
):
3635 if 'webpage' not in self
._configuration
_arg
('player_skip'):
3636 query
= {'bpctr': '9999999999', 'has_verified': '1'}
3637 if smuggled_data
.get('is_story'):
3638 query
['pp'] = self
._STORY
_PLAYER
_PARAMS
3639 webpage
= self
._download
_webpage
(
3640 webpage_url
, video_id
, fatal
=False, query
=query
)
3642 master_ytcfg
= self
.extract_ytcfg(video_id
, webpage
) or self
._get
_default
_ytcfg
()
3644 player_responses
, player_url
= self
._extract
_player
_responses
(
3645 self
._get
_requested
_clients
(url
, smuggled_data
),
3646 video_id
, webpage
, master_ytcfg
, smuggled_data
)
3648 return webpage
, master_ytcfg
, player_responses
, player_url
3650 def _list_formats(self
, video_id
, microformats
, video_details
, player_responses
, player_url
, duration
=None):
3651 live_broadcast_details
= traverse_obj(microformats
, (..., 'liveBroadcastDetails'))
3652 is_live
= get_first(video_details
, 'isLive')
3654 is_live
= get_first(live_broadcast_details
, 'isLiveNow')
3656 streaming_data
= traverse_obj(player_responses
, (..., 'streamingData'), default
=[])
3657 *formats
, subtitles
= self
._extract
_formats
_and
_subtitles
(streaming_data
, video_id
, player_url
, is_live
, duration
)
3659 return live_broadcast_details
, is_live
, streaming_data
, formats
, subtitles
3661 def _real_extract(self
, url
):
3662 url
, smuggled_data
= unsmuggle_url(url
, {})
3663 video_id
= self
._match
_id
(url
)
3665 base_url
= self
.http_scheme() + '//www.youtube.com/'
3666 webpage_url
= base_url
+ 'watch?v=' + video_id
3668 webpage
, master_ytcfg
, player_responses
, player_url
= self
._download
_player
_responses
(url
, smuggled_data
, video_id
, webpage_url
)
3670 playability_statuses
= traverse_obj(
3671 player_responses
, (..., 'playabilityStatus'), expected_type
=dict, default
=[])
3673 trailer_video_id
= get_first(
3674 playability_statuses
,
3675 ('errorScreen', 'playerLegacyDesktopYpcTrailerRenderer', 'trailerVideoId'),
3677 if trailer_video_id
:
3678 return self
.url_result(
3679 trailer_video_id
, self
.ie_key(), trailer_video_id
)
3681 search_meta
= ((lambda x
: self
._html
_search
_meta
(x
, webpage
, default
=None))
3682 if webpage
else (lambda x
: None))
3684 video_details
= traverse_obj(
3685 player_responses
, (..., 'videoDetails'), expected_type
=dict, default
=[])
3686 microformats
= traverse_obj(
3687 player_responses
, (..., 'microformat', 'playerMicroformatRenderer'),
3688 expected_type
=dict, default
=[])
3690 translated_title
= self
._get
_text
(microformats
, (..., 'title'))
3691 video_title
= (self
._preferred
_lang
and translated_title
3692 or get_first(video_details
, 'title') # primary
3694 or search_meta(['og:title', 'twitter:title', 'title']))
3695 translated_description
= self
._get
_text
(microformats
, (..., 'description'))
3696 original_description
= get_first(video_details
, 'shortDescription')
3697 video_description
= (
3698 self
._preferred
_lang
and translated_description
3699 # If original description is blank, it will be an empty string.
3700 # Do not prefer translated description in this case.
3701 or original_description
if original_description
is not None else translated_description
)
3703 multifeed_metadata_list
= get_first(
3705 ('multicamera', 'playerLegacyMulticameraRenderer', 'metadataList'),
3707 if multifeed_metadata_list
and not smuggled_data
.get('force_singlefeed'):
3708 if self
.get_param('noplaylist'):
3709 self
.to_screen('Downloading just video %s because of --no-playlist' % video_id
)
3713 for feed
in multifeed_metadata_list
.split(','):
3714 # Unquote should take place before split on comma (,) since textual
3715 # fields may contain comma as well (see
3716 # https://github.com/ytdl-org/youtube-dl/issues/8536)
3717 feed_data
= urllib
.parse
.parse_qs(
3718 urllib
.parse
.unquote_plus(feed
))
3720 def feed_entry(name
):
3722 feed_data
, lambda x
: x
[name
][0], str)
3724 feed_id
= feed_entry('id')
3727 feed_title
= feed_entry('title')
3730 title
+= ' (%s)' % feed_title
3732 '_type': 'url_transparent',
3733 'ie_key': 'Youtube',
3735 '%swatch?v=%s' % (base_url
, feed_data
['id'][0]),
3736 {'force_singlefeed': True}
),
3739 feed_ids
.append(feed_id
)
3741 'Downloading multifeed video (%s) - add --no-playlist to just download video %s'
3742 % (', '.join(feed_ids
), video_id
))
3743 return self
.playlist_result(
3744 entries
, video_id
, video_title
, video_description
)
3746 duration
= int_or_none(
3747 get_first(video_details
, 'lengthSeconds')
3748 or get_first(microformats
, 'lengthSeconds')
3749 or parse_duration(search_meta('duration'))) or None
3751 live_broadcast_details
, is_live
, streaming_data
, formats
, automatic_captions
= \
3752 self
._list
_formats
(video_id
, microformats
, video_details
, player_responses
, player_url
)
3755 if not self
.get_param('allow_unplayable_formats') and traverse_obj(streaming_data
, (..., 'licenseInfos')):
3756 self
.report_drm(video_id
)
3758 playability_statuses
,
3759 ('errorScreen', 'playerErrorMessageRenderer'), expected_type
=dict) or {}
3760 reason
= self
._get
_text
(pemr
, 'reason') or get_first(playability_statuses
, 'reason')
3761 subreason
= clean_html(self
._get
_text
(pemr
, 'subreason') or '')
3763 if subreason
== 'The uploader has not made this video available in your country.':
3764 countries
= get_first(microformats
, 'availableCountries')
3766 regions_allowed
= search_meta('regionsAllowed')
3767 countries
= regions_allowed
.split(',') if regions_allowed
else None
3768 self
.raise_geo_restricted(subreason
, countries
, metadata_available
=True)
3769 reason
+= f
'. {subreason}'
3771 self
.raise_no_formats(reason
, expected
=True)
3773 keywords
= get_first(video_details
, 'keywords', expected_type
=list) or []
3774 if not keywords
and webpage
:
3776 unescapeHTML(m
.group('content'))
3777 for m
in re
.finditer(self
._meta
_regex
('og:video:tag'), webpage
)]
3778 for keyword
in keywords
:
3779 if keyword
.startswith('yt:stretch='):
3780 mobj
= re
.search(r
'(\d+)\s*:\s*(\d+)', keyword
)
3782 # NB: float is intentional for forcing float division
3783 w
, h
= (float(v
) for v
in mobj
.groups())
3787 if f
.get('vcodec') != 'none':
3788 f
['stretched_ratio'] = ratio
3790 thumbnails
= self
._extract
_thumbnails
((video_details
, microformats
), (..., ..., 'thumbnail'))
3791 thumbnail_url
= search_meta(['og:image', 'twitter:image'])
3794 'url': thumbnail_url
,
3796 original_thumbnails
= thumbnails
.copy()
3798 # The best resolution thumbnails sometimes does not appear in the webpage
3799 # See: https://github.com/yt-dlp/yt-dlp/issues/340
3800 # List of possible thumbnails - Ref: <https://stackoverflow.com/a/20542029>
3802 # While the *1,*2,*3 thumbnails are just below their corresponding "*default" variants
3803 # in resolution, these are not the custom thumbnail. So de-prioritize them
3804 'maxresdefault', 'hq720', 'sddefault', 'hqdefault', '0', 'mqdefault', 'default',
3805 'sd1', 'sd2', 'sd3', 'hq1', 'hq2', 'hq3', 'mq1', 'mq2', 'mq3', '1', '2', '3'
3807 n_thumbnail_names
= len(thumbnail_names
)
3809 'url': 'https://i.ytimg.com/vi{webp}/{video_id}/{name}{live}.{ext}'.format(
3810 video_id
=video_id
, name
=name
, ext
=ext
,
3811 webp
='_webp' if ext
== 'webp' else '', live
='_live' if is_live
else ''),
3812 } for name
in thumbnail_names
for ext
in ('webp', 'jpg'))
3813 for thumb
in thumbnails
:
3814 i
= next((i
for i
, t
in enumerate(thumbnail_names
) if f
'/{video_id}/{t}' in thumb
['url']), n_thumbnail_names
)
3815 thumb
['preference'] = (0 if '.webp' in thumb
['url'] else -1) - (2 * i
)
3816 self
._remove
_duplicate
_formats
(thumbnails
)
3817 self
._downloader
._sort
_thumbnails
(original_thumbnails
)
3819 category
= get_first(microformats
, 'category') or search_meta('genre')
3820 channel_id
= str_or_none(
3821 get_first(video_details
, 'channelId')
3822 or get_first(microformats
, 'externalChannelId')
3823 or search_meta('channelId'))
3824 owner_profile_url
= get_first(microformats
, 'ownerProfileUrl')
3826 live_content
= get_first(video_details
, 'isLiveContent')
3827 is_upcoming
= get_first(video_details
, 'isUpcoming')
3829 if is_upcoming
or live_content
is False:
3831 if is_upcoming
is None and (live_content
or is_live
):
3833 live_start_time
= parse_iso8601(get_first(live_broadcast_details
, 'startTimestamp'))
3834 live_end_time
= parse_iso8601(get_first(live_broadcast_details
, 'endTimestamp'))
3835 if not duration
and live_end_time
and live_start_time
:
3836 duration
= live_end_time
- live_start_time
3838 if is_live
and self
.get_param('live_from_start'):
3839 self
._prepare
_live
_from
_start
_formats
(formats
, video_id
, live_start_time
, url
, webpage_url
, smuggled_data
)
3841 formats
.extend(self
._extract
_storyboard
(player_responses
, duration
))
3843 # source_preference is lower for throttled/potentially damaged formats
3844 self
._sort
_formats
(formats
, (
3845 'quality', 'res', 'fps', 'hdr:12', 'source', 'vcodec:vp9.2', 'channels', 'acodec', 'lang', 'proto'))
3849 'title': video_title
,
3851 'thumbnails': thumbnails
,
3852 # The best thumbnail that we are sure exists. Prevents unnecessary
3853 # URL checking if user don't care about getting the best possible thumbnail
3854 'thumbnail': traverse_obj(original_thumbnails
, (-1, 'url')),
3855 'description': video_description
,
3856 'uploader': get_first(video_details
, 'author'),
3857 'uploader_id': self
._search
_regex
(r
'/(?:channel|user)/([^/?&#]+)', owner_profile_url
, 'uploader id') if owner_profile_url
else None,
3858 'uploader_url': owner_profile_url
,
3859 'channel_id': channel_id
,
3860 'channel_url': format_field(channel_id
, None, 'https://www.youtube.com/channel/%s'),
3861 'duration': duration
,
3862 'view_count': int_or_none(
3863 get_first((video_details
, microformats
), (..., 'viewCount'))
3864 or search_meta('interactionCount')),
3865 'average_rating': float_or_none(get_first(video_details
, 'averageRating')),
3866 'age_limit': 18 if (
3867 get_first(microformats
, 'isFamilySafe') is False
3868 or search_meta('isFamilyFriendly') == 'false'
3869 or search_meta('og:restrictions:age') == '18+') else 0,
3870 'webpage_url': webpage_url
,
3871 'categories': [category
] if category
else None,
3873 'playable_in_embed': get_first(playability_statuses
, 'playableInEmbed'),
3875 'was_live': (False if is_live
or is_upcoming
or live_content
is False
3876 else None if is_live
is None or is_upcoming
is None
3878 'live_status': 'is_upcoming' if is_upcoming
else None, # rest will be set by YoutubeDL
3879 'release_timestamp': live_start_time
,
3882 if get_first(video_details
, 'isPostLiveDvr'):
3883 self
.write_debug('Video is in Post-Live Manifestless mode')
3884 info
['live_status'] = 'post_live'
3885 if (duration
or 0) > 4 * 3600:
3886 self
.report_warning(
3887 'The livestream has not finished processing. Only 4 hours of the video can be currently downloaded. '
3888 'This is a known issue and patches are welcome')
3891 pctr
= traverse_obj(player_responses
, (..., 'captions', 'playerCaptionsTracklistRenderer'), expected_type
=dict)
3893 def get_lang_code(track
):
3894 return (remove_start(track
.get('vssId') or '', '.').replace('.', '-')
3895 or track
.get('languageCode'))
3897 # Converted into dicts to remove duplicates
3899 get_lang_code(sub
): sub
3900 for sub
in traverse_obj(pctr
, (..., 'captionTracks', ...), default
=[])}
3901 translation_languages
= {
3902 lang
.get('languageCode'): self
._get
_text
(lang
.get('languageName'), max_runs
=1)
3903 for lang
in traverse_obj(pctr
, (..., 'translationLanguages', ...), default
=[])}
3905 def process_language(container
, base_url
, lang_code
, sub_name
, query
):
3906 lang_subs
= container
.setdefault(lang_code
, [])
3907 for fmt
in self
._SUBTITLE
_FORMATS
:
3913 'url': urljoin('https://www.youtube.com', update_url_query(base_url
, query
)),
3917 # NB: Constructing the full subtitle dictionary is slow
3918 get_translated_subs
= 'translated_subs' not in self
._configuration
_arg
('skip') and (
3919 self
.get_param('writeautomaticsub', False) or self
.get_param('listsubtitles'))
3920 for lang_code
, caption_track
in captions
.items():
3921 base_url
= caption_track
.get('baseUrl')
3922 orig_lang
= parse_qs(base_url
).get('lang', [None])[-1]
3925 lang_name
= self
._get
_text
(caption_track
, 'name', max_runs
=1)
3926 if caption_track
.get('kind') != 'asr':
3930 subtitles
, base_url
, lang_code
, lang_name
, {})
3931 if not caption_track
.get('isTranslatable'):
3933 for trans_code
, trans_name
in translation_languages
.items():
3936 orig_trans_code
= trans_code
3937 if caption_track
.get('kind') != 'asr':
3938 if not get_translated_subs
:
3940 trans_code
+= f
'-{lang_code}'
3941 trans_name
+= format_field(lang_name
, None, ' from %s')
3942 # Add an "-orig" label to the original language so that it can be distinguished.
3943 # The subs are returned without "-orig" as well for compatibility
3944 if lang_code
== f
'a-{orig_trans_code}':
3946 automatic_captions
, base_url
, f
'{trans_code}-orig', f
'{trans_name} (Original)', {})
3947 # Setting tlang=lang returns damaged subtitles.
3948 process_language(automatic_captions
, base_url
, trans_code
, trans_name
,
3949 {} if orig_lang == orig_trans_code else {'tlang': trans_code}
)
3951 info
['automatic_captions'] = automatic_captions
3952 info
['subtitles'] = subtitles
3954 parsed_url
= urllib
.parse
.urlparse(url
)
3955 for component
in [parsed_url
.fragment
, parsed_url
.query
]:
3956 query
= urllib
.parse
.parse_qs(component
)
3957 for k
, v
in query
.items():
3958 for d_k
, s_ks
in [('start', ('start', 't')), ('end', ('end',))]:
3960 if d_k
not in info
and k
in s_ks
:
3961 info
[d_k
] = parse_duration(query
[k
][0])
3963 # Youtube Music Auto-generated description
3964 if video_description
:
3967 (?P<track>[^·\n]+)·(?P<artist>[^\n]+)\n+
3969 (?:.+?℗\s*(?P<release_year>\d{4})(?!\d))?
3970 (?:.+?Released on\s*:\s*(?P<release_date>\d{4}-\d{2}-\d{2}))?
3971 (.+?\nArtist\s*:\s*(?P<clean_artist>[^\n]+))?
3972 .+\nAuto-generated\ by\ YouTube\.\s*$
3973 ''', video_description
)
3975 release_year
= mobj
.group('release_year')
3976 release_date
= mobj
.group('release_date')
3978 release_date
= release_date
.replace('-', '')
3979 if not release_year
:
3980 release_year
= release_date
[:4]
3982 'album': mobj
.group('album'.strip()),
3983 'artist': mobj
.group('clean_artist') or ', '.join(a
.strip() for a
in mobj
.group('artist').split('·')),
3984 'track': mobj
.group('track').strip(),
3985 'release_date': release_date
,
3986 'release_year': int_or_none(release_year
),
3991 initial_data
= self
.extract_yt_initial_data(video_id
, webpage
, fatal
=False)
3992 if not initial_data
:
3993 query
= {'videoId': video_id}
3994 query
.update(self
._get
_checkok
_params
())
3995 initial_data
= self
._extract
_response
(
3996 item_id
=video_id
, ep
='next', fatal
=False,
3997 ytcfg
=master_ytcfg
, query
=query
,
3998 headers
=self
.generate_api_headers(ytcfg
=master_ytcfg
),
3999 note
='Downloading initial data API JSON')
4001 info
['comment_count'] = traverse_obj(initial_data
, (
4002 'contents', 'twoColumnWatchNextResults', 'results', 'results', 'contents', ..., 'itemSectionRenderer',
4003 'contents', ..., 'commentsEntryPointHeaderRenderer', 'commentCount', 'simpleText'
4005 'engagementPanels', lambda _
, v
: v
['engagementPanelSectionListRenderer']['panelIdentifier'] == 'comment-item-section',
4006 'engagementPanelSectionListRenderer', 'header', 'engagementPanelTitleHeaderRenderer', 'contextualInfo', 'runs', ..., 'text'
4007 ), expected_type
=int_or_none
, get_all
=False)
4009 try: # This will error if there is no livechat
4010 initial_data
['contents']['twoColumnWatchNextResults']['conversationBar']['liveChatRenderer']['continuations'][0]['reloadContinuationData']['continuation']
4011 except (KeyError, IndexError, TypeError):
4014 info
.setdefault('subtitles', {})['live_chat'] = [{
4015 # url is needed to set cookies
4016 'url': f
'https://www.youtube.com/watch?v={video_id}&bpctr=9999999999&has_verified=1',
4017 'video_id': video_id
,
4019 'protocol': 'youtube_live_chat' if is_live
or is_upcoming
else 'youtube_live_chat_replay',
4023 info
['chapters'] = (
4024 self
._extract
_chapters
_from
_json
(initial_data
, duration
)
4025 or self
._extract
_chapters
_from
_engagement
_panel
(initial_data
, duration
)
4026 or self
._extract
_chapters
_from
_description
(video_description
, duration
)
4029 contents
= traverse_obj(
4030 initial_data
, ('contents', 'twoColumnWatchNextResults', 'results', 'results', 'contents'),
4031 expected_type
=list, default
=[])
4033 vpir
= get_first(contents
, 'videoPrimaryInfoRenderer')
4035 stl
= vpir
.get('superTitleLink')
4037 stl
= self
._get
_text
(stl
)
4040 lambda x
: x
['superTitleIcon']['iconType']) == 'LOCATION_PIN':
4041 info
['location'] = stl
4043 mobj
= re
.search(r
'(.+?)\s*S(\d+)\s*•?\s*E(\d+)', stl
)
4046 'series': mobj
.group(1),
4047 'season_number': int(mobj
.group(2)),
4048 'episode_number': int(mobj
.group(3)),
4050 for tlb
in (try_get(
4052 lambda x
: x
['videoActions']['menuRenderer']['topLevelButtons'],
4056 tlb
, 'toggleButtonRenderer',
4057 ('segmentedLikeDislikeButtonRenderer', ..., 'toggleButtonRenderer'),
4060 for getter
, regex
in [(
4061 lambda x
: x
['defaultText']['accessibility']['accessibilityData'],
4062 r
'(?P<count>[\d,]+)\s*(?P<type>(?:dis)?like)'), ([
4063 lambda x
: x
['accessibility'],
4064 lambda x
: x
['accessibilityData']['accessibilityData'],
4065 ], r
'(?P<type>(?:dis)?like) this video along with (?P<count>[\d,]+) other people')]:
4066 label
= (try_get(tbr
, getter
, dict) or {}).get('label')
4068 mobj
= re
.match(regex
, label
)
4070 info
[mobj
.group('type') + '_count'] = str_to_int(mobj
.group('count'))
4072 sbr_tooltip
= try_get(
4073 vpir
, lambda x
: x
['sentimentBar']['sentimentBarRenderer']['tooltip'])
4075 like_count
, dislike_count
= sbr_tooltip
.split(' / ')
4077 'like_count': str_to_int(like_count
),
4078 'dislike_count': str_to_int(dislike_count
),
4080 vsir
= get_first(contents
, 'videoSecondaryInfoRenderer')
4082 vor
= traverse_obj(vsir
, ('owner', 'videoOwnerRenderer'))
4084 'channel': self
._get
_text
(vor
, 'title'),
4085 'channel_follower_count': self
._get
_count
(vor
, 'subscriberCountText')})
4089 lambda x
: x
['metadataRowContainer']['metadataRowContainerRenderer']['rows'],
4091 multiple_songs
= False
4093 if try_get(row
, lambda x
: x
['metadataRowRenderer']['hasDividerLine']) is True:
4094 multiple_songs
= True
4097 mrr
= row
.get('metadataRowRenderer') or {}
4098 mrr_title
= mrr
.get('title')
4101 mrr_title
= self
._get
_text
(mrr
, 'title')
4102 mrr_contents_text
= self
._get
_text
(mrr
, ('contents', 0))
4103 if mrr_title
== 'License':
4104 info
['license'] = mrr_contents_text
4105 elif not multiple_songs
:
4106 if mrr_title
== 'Album':
4107 info
['album'] = mrr_contents_text
4108 elif mrr_title
== 'Artist':
4109 info
['artist'] = mrr_contents_text
4110 elif mrr_title
== 'Song':
4111 info
['track'] = mrr_contents_text
4114 'channel': 'uploader',
4115 'channel_id': 'uploader_id',
4116 'channel_url': 'uploader_url',
4119 # The upload date for scheduled, live and past live streams / premieres in microformats
4120 # may be different from the stream date. Although not in UTC, we will prefer it in this case.
4121 # See: https://github.com/yt-dlp/yt-dlp/pull/2223#issuecomment-1008485139
4123 unified_strdate(get_first(microformats
, 'uploadDate'))
4124 or unified_strdate(search_meta('uploadDate')))
4125 if not upload_date
or (
4126 not info
.get('is_live')
4127 and not info
.get('was_live')
4128 and info
.get('live_status') != 'is_upcoming'
4129 and 'no-youtube-prefer-utc-upload-date' not in self
.get_param('compat_opts', [])
4131 upload_date
= strftime_or_none(
4132 self
._parse
_time
_text
(self
._get
_text
(vpir
, 'dateText')), '%Y%m%d') or upload_date
4133 info
['upload_date'] = upload_date
4135 for to
, frm
in fallbacks
.items():
4136 if not info
.get(to
):
4137 info
[to
] = info
.get(frm
)
4139 for s_k
, d_k
in [('artist', 'creator'), ('track', 'alt_title')]:
4144 badges
= self
._extract
_badges
(traverse_obj(contents
, (..., 'videoPrimaryInfoRenderer'), get_all
=False))
4146 is_private
= (self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PRIVATE
)
4147 or get_first(video_details
, 'isPrivate', expected_type
=bool))
4149 info
['availability'] = (
4150 'public' if self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PUBLIC
)
4151 else self
._availability
(
4152 is_private
=is_private
,
4154 self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PREMIUM
)
4155 or False if initial_data
and is_private
is not None else None),
4156 needs_subscription
=(
4157 self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_SUBSCRIPTION
)
4158 or False if initial_data
and is_private
is not None else None),
4159 needs_auth
=info
['age_limit'] >= 18,
4160 is_unlisted
=None if is_private
is None else (
4161 self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_UNLISTED
)
4162 or get_first(microformats
, 'isUnlisted', expected_type
=bool))))
4164 info
['__post_extractor'] = self
.extract_comments(master_ytcfg
, video_id
, contents
, webpage
)
4166 self
.mark_watched(video_id
, player_responses
)
4171 class YoutubeTabBaseInfoExtractor(YoutubeBaseInfoExtractor
):
4174 def passthrough_smuggled_data(func
):
4175 def _smuggle(entries
, smuggled_data
):
4176 for entry
in entries
:
4177 # TODO: Convert URL to music.youtube instead.
4178 # Do we need to passthrough any other smuggled_data?
4179 entry
['url'] = smuggle_url(entry
['url'], smuggled_data
)
4182 @functools.wraps(func
)
4183 def wrapper(self
, url
):
4184 url
, smuggled_data
= unsmuggle_url(url
, {})
4185 if self
.is_music_url(url
):
4186 smuggled_data
['is_music_url'] = True
4187 info_dict
= func(self
, url
, smuggled_data
)
4188 if smuggled_data
and info_dict
.get('entries'):
4189 info_dict
['entries'] = _smuggle(info_dict
['entries'], smuggled_data
)
4193 def _extract_channel_id(self
, webpage
):
4194 channel_id
= self
._html
_search
_meta
(
4195 'channelId', webpage
, 'channel id', default
=None)
4198 channel_url
= self
._html
_search
_meta
(
4199 ('og:url', 'al:ios:url', 'al:android:url', 'al:web:url',
4200 'twitter:url', 'twitter:app:url:iphone', 'twitter:app:url:ipad',
4201 'twitter:app:url:googleplay'), webpage
, 'channel url')
4202 return self
._search
_regex
(
4203 r
'https?://(?:www\.)?youtube\.com/channel/([^/?#&])+',
4204 channel_url
, 'channel id')
4207 def _extract_basic_item_renderer(item
):
4208 # Modified from _extract_grid_item_renderer
4209 known_basic_renderers
= (
4210 'playlistRenderer', 'videoRenderer', 'channelRenderer', 'showRenderer', 'reelItemRenderer'
4212 for key
, renderer
in item
.items():
4213 if not isinstance(renderer
, dict):
4215 elif key
in known_basic_renderers
:
4217 elif key
.startswith('grid') and key
.endswith('Renderer'):
4220 def _grid_entries(self
, grid_renderer
):
4221 for item
in grid_renderer
['items']:
4222 if not isinstance(item
, dict):
4224 renderer
= self
._extract
_basic
_item
_renderer
(item
)
4225 if not isinstance(renderer
, dict):
4227 title
= self
._get
_text
(renderer
, 'title')
4230 playlist_id
= renderer
.get('playlistId')
4232 yield self
.url_result(
4233 'https://www.youtube.com/playlist?list=%s' % playlist_id
,
4234 ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
,
4238 video_id
= renderer
.get('videoId')
4240 yield self
._extract
_video
(renderer
)
4243 channel_id
= renderer
.get('channelId')
4245 yield self
.url_result(
4246 'https://www.youtube.com/channel/%s' % channel_id
,
4247 ie
=YoutubeTabIE
.ie_key(), video_title
=title
)
4249 # generic endpoint URL support
4250 ep_url
= urljoin('https://www.youtube.com/', try_get(
4251 renderer
, lambda x
: x
['navigationEndpoint']['commandMetadata']['webCommandMetadata']['url'],
4254 for ie
in (YoutubeTabIE
, YoutubePlaylistIE
, YoutubeIE
):
4255 if ie
.suitable(ep_url
):
4256 yield self
.url_result(
4257 ep_url
, ie
=ie
.ie_key(), video_id
=ie
._match
_id
(ep_url
), video_title
=title
)
4260 def _music_reponsive_list_entry(self
, renderer
):
4261 video_id
= traverse_obj(renderer
, ('playlistItemData', 'videoId'))
4263 return self
.url_result(f
'https://music.youtube.com/watch?v={video_id}',
4264 ie
=YoutubeIE
.ie_key(), video_id
=video_id
)
4265 playlist_id
= traverse_obj(renderer
, ('navigationEndpoint', 'watchEndpoint', 'playlistId'))
4267 video_id
= traverse_obj(renderer
, ('navigationEndpoint', 'watchEndpoint', 'videoId'))
4269 return self
.url_result(f
'https://music.youtube.com/watch?v={video_id}&list={playlist_id}',
4270 ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
)
4271 return self
.url_result(f
'https://music.youtube.com/playlist?list={playlist_id}',
4272 ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
)
4273 browse_id
= traverse_obj(renderer
, ('navigationEndpoint', 'browseEndpoint', 'browseId'))
4275 return self
.url_result(f
'https://music.youtube.com/browse/{browse_id}',
4276 ie
=YoutubeTabIE
.ie_key(), video_id
=browse_id
)
4278 def _shelf_entries_from_content(self
, shelf_renderer
):
4279 content
= shelf_renderer
.get('content')
4280 if not isinstance(content
, dict):
4282 renderer
= content
.get('gridRenderer') or content
.get('expandedShelfContentsRenderer')
4284 # TODO: add support for nested playlists so each shelf is processed
4285 # as separate playlist
4286 # TODO: this includes only first N items
4287 yield from self
._grid
_entries
(renderer
)
4288 renderer
= content
.get('horizontalListRenderer')
4293 def _shelf_entries(self
, shelf_renderer
, skip_channels
=False):
4295 shelf_renderer
, lambda x
: x
['endpoint']['commandMetadata']['webCommandMetadata']['url'],
4297 shelf_url
= urljoin('https://www.youtube.com', ep
)
4299 # Skipping links to another channels, note that checking for
4300 # endpoint.commandMetadata.webCommandMetadata.webPageTypwebPageType == WEB_PAGE_TYPE_CHANNEL
4302 if skip_channels
and '/channels?' in shelf_url
:
4304 title
= self
._get
_text
(shelf_renderer
, 'title')
4305 yield self
.url_result(shelf_url
, video_title
=title
)
4306 # Shelf may not contain shelf URL, fallback to extraction from content
4307 yield from self
._shelf
_entries
_from
_content
(shelf_renderer
)
4309 def _playlist_entries(self
, video_list_renderer
):
4310 for content
in video_list_renderer
['contents']:
4311 if not isinstance(content
, dict):
4313 renderer
= content
.get('playlistVideoRenderer') or content
.get('playlistPanelVideoRenderer')
4314 if not isinstance(renderer
, dict):
4316 video_id
= renderer
.get('videoId')
4319 yield self
._extract
_video
(renderer
)
4321 def _rich_entries(self
, rich_grid_renderer
):
4322 renderer
= traverse_obj(
4323 rich_grid_renderer
, ('content', ('videoRenderer', 'reelItemRenderer')), get_all
=False) or {}
4324 video_id
= renderer
.get('videoId')
4327 yield self
._extract
_video
(renderer
)
4329 def _video_entry(self
, video_renderer
):
4330 video_id
= video_renderer
.get('videoId')
4332 return self
._extract
_video
(video_renderer
)
4334 def _hashtag_tile_entry(self
, hashtag_tile_renderer
):
4335 url
= urljoin('https://youtube.com', traverse_obj(
4336 hashtag_tile_renderer
, ('onTapCommand', 'commandMetadata', 'webCommandMetadata', 'url')))
4338 return self
.url_result(
4339 url
, ie
=YoutubeTabIE
.ie_key(), title
=self
._get
_text
(hashtag_tile_renderer
, 'hashtag'))
4341 def _post_thread_entries(self
, post_thread_renderer
):
4342 post_renderer
= try_get(
4343 post_thread_renderer
, lambda x
: x
['post']['backstagePostRenderer'], dict)
4344 if not post_renderer
:
4347 video_renderer
= try_get(
4348 post_renderer
, lambda x
: x
['backstageAttachment']['videoRenderer'], dict) or {}
4349 video_id
= video_renderer
.get('videoId')
4351 entry
= self
._extract
_video
(video_renderer
)
4354 # playlist attachment
4355 playlist_id
= try_get(
4356 post_renderer
, lambda x
: x
['backstageAttachment']['playlistRenderer']['playlistId'], str)
4358 yield self
.url_result(
4359 'https://www.youtube.com/playlist?list=%s' % playlist_id
,
4360 ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
)
4361 # inline video links
4362 runs
= try_get(post_renderer
, lambda x
: x
['contentText']['runs'], list) or []
4364 if not isinstance(run
, dict):
4367 run
, lambda x
: x
['navigationEndpoint']['urlEndpoint']['url'], str)
4370 if not YoutubeIE
.suitable(ep_url
):
4372 ep_video_id
= YoutubeIE
._match
_id
(ep_url
)
4373 if video_id
== ep_video_id
:
4375 yield self
.url_result(ep_url
, ie
=YoutubeIE
.ie_key(), video_id
=ep_video_id
)
4377 def _post_thread_continuation_entries(self
, post_thread_continuation
):
4378 contents
= post_thread_continuation
.get('contents')
4379 if not isinstance(contents
, list):
4381 for content
in contents
:
4382 renderer
= content
.get('backstagePostThreadRenderer')
4383 if isinstance(renderer
, dict):
4384 yield from self
._post
_thread
_entries
(renderer
)
4386 renderer
= content
.get('videoRenderer')
4387 if isinstance(renderer
, dict):
4388 yield self
._video
_entry
(renderer
)
4391 def _rich_grid_entries(self, contents):
4392 for content in contents:
4393 video_renderer = try_get(content, lambda x: x['richItemRenderer']['content']['videoRenderer'], dict)
4395 entry = self._video_entry(video_renderer)
4400 def _report_history_entries(self
, renderer
):
4401 for url
in traverse_obj(renderer
, (
4402 'rows', ..., 'reportHistoryTableRowRenderer', 'cells', ...,
4403 'reportHistoryTableCellRenderer', 'cell', 'reportHistoryTableTextCellRenderer', 'text', 'runs', ...,
4404 'navigationEndpoint', 'commandMetadata', 'webCommandMetadata', 'url')):
4405 yield self
.url_result(urljoin('https://www.youtube.com', url
), YoutubeIE
)
4407 def _extract_entries(self
, parent_renderer
, continuation_list
):
4408 # continuation_list is modified in-place with continuation_list = [continuation_token]
4409 continuation_list
[:] = [None]
4410 contents
= try_get(parent_renderer
, lambda x
: x
['contents'], list) or []
4411 for content
in contents
:
4412 if not isinstance(content
, dict):
4414 is_renderer
= traverse_obj(
4415 content
, 'itemSectionRenderer', 'musicShelfRenderer', 'musicShelfContinuation',
4418 if content
.get('richItemRenderer'):
4419 for entry
in self
._rich
_entries
(content
['richItemRenderer']):
4421 continuation_list
[0] = self
._extract
_continuation
(parent_renderer
)
4422 elif content
.get('reportHistorySectionRenderer'): # https://www.youtube.com/reporthistory
4423 table
= traverse_obj(content
, ('reportHistorySectionRenderer', 'table', 'tableRenderer'))
4424 yield from self
._report
_history
_entries
(table
)
4425 continuation_list
[0] = self
._extract
_continuation
(table
)
4428 isr_contents
= try_get(is_renderer
, lambda x
: x
['contents'], list) or []
4429 for isr_content
in isr_contents
:
4430 if not isinstance(isr_content
, dict):
4434 'playlistVideoListRenderer': self
._playlist
_entries
,
4435 'gridRenderer': self
._grid
_entries
,
4436 'reelShelfRenderer': self
._grid
_entries
,
4437 'shelfRenderer': self
._shelf
_entries
,
4438 'musicResponsiveListItemRenderer': lambda x
: [self
._music
_reponsive
_list
_entry
(x
)],
4439 'backstagePostThreadRenderer': self
._post
_thread
_entries
,
4440 'videoRenderer': lambda x
: [self
._video
_entry
(x
)],
4441 'playlistRenderer': lambda x
: self
._grid
_entries
({'items': [{'playlistRenderer': x}
]}),
4442 'channelRenderer': lambda x
: self
._grid
_entries
({'items': [{'channelRenderer': x}
]}),
4443 'hashtagTileRenderer': lambda x
: [self
._hashtag
_tile
_entry
(x
)]
4445 for key
, renderer
in isr_content
.items():
4446 if key
not in known_renderers
:
4448 for entry
in known_renderers
[key
](renderer
):
4451 continuation_list
[0] = self
._extract
_continuation
(renderer
)
4454 if not continuation_list
[0]:
4455 continuation_list
[0] = self
._extract
_continuation
(is_renderer
)
4457 if not continuation_list
[0]:
4458 continuation_list
[0] = self
._extract
_continuation
(parent_renderer
)
4460 def _entries(self
, tab
, item_id
, ytcfg
, account_syncid
, visitor_data
):
4461 continuation_list
= [None]
4462 extract_entries
= lambda x
: self
._extract
_entries
(x
, continuation_list
)
4463 tab_content
= try_get(tab
, lambda x
: x
['content'], dict)
4467 try_get(tab_content
, lambda x
: x
['sectionListRenderer'], dict)
4468 or try_get(tab_content
, lambda x
: x
['richGridRenderer'], dict) or {})
4469 yield from extract_entries(parent_renderer
)
4470 continuation
= continuation_list
[0]
4472 for page_num
in itertools
.count(1):
4473 if not continuation
:
4475 headers
= self
.generate_api_headers(
4476 ytcfg
=ytcfg
, account_syncid
=account_syncid
, visitor_data
=visitor_data
)
4477 response
= self
._extract
_response
(
4478 item_id
=f
'{item_id} page {page_num}',
4479 query
=continuation
, headers
=headers
, ytcfg
=ytcfg
,
4480 check_get_keys
=('continuationContents', 'onResponseReceivedActions', 'onResponseReceivedEndpoints'))
4484 # Extracting updated visitor data is required to prevent an infinite extraction loop in some cases
4485 # See: https://github.com/ytdl-org/youtube-dl/issues/28702
4486 visitor_data
= self
._extract
_visitor
_data
(response
) or visitor_data
4489 'videoRenderer': (self
._grid
_entries
, 'items'), # for membership tab
4490 'gridPlaylistRenderer': (self
._grid
_entries
, 'items'),
4491 'gridVideoRenderer': (self
._grid
_entries
, 'items'),
4492 'gridChannelRenderer': (self
._grid
_entries
, 'items'),
4493 'playlistVideoRenderer': (self
._playlist
_entries
, 'contents'),
4494 'itemSectionRenderer': (extract_entries
, 'contents'), # for feeds
4495 'richItemRenderer': (extract_entries
, 'contents'), # for hashtag
4496 'backstagePostThreadRenderer': (self
._post
_thread
_continuation
_entries
, 'contents'),
4497 'reportHistoryTableRowRenderer': (self
._report
_history
_entries
, 'rows'),
4498 'playlistVideoListContinuation': (self
._playlist
_entries
, None),
4499 'gridContinuation': (self
._grid
_entries
, None),
4500 'itemSectionContinuation': (self
._post
_thread
_continuation
_entries
, None),
4501 'sectionListContinuation': (extract_entries
, None), # for feeds
4504 continuation_items
= traverse_obj(response
, (
4505 ('onResponseReceivedActions', 'onResponseReceivedEndpoints'), ...,
4506 'appendContinuationItemsAction', 'continuationItems'
4507 ), 'continuationContents', get_all
=False)
4508 continuation_item
= traverse_obj(continuation_items
, 0, None, expected_type
=dict, default
={})
4510 video_items_renderer
= None
4511 for key
in continuation_item
.keys():
4512 if key
not in known_renderers
:
4514 func
, parent_key
= known_renderers
[key
]
4515 video_items_renderer
= {parent_key: continuation_items}
if parent_key
else continuation_items
4516 continuation_list
= [None]
4517 yield from func(video_items_renderer
)
4518 continuation
= continuation_list
[0] or self
._extract
_continuation
(video_items_renderer
)
4520 if not video_items_renderer
:
4524 def _extract_selected_tab(tabs
, fatal
=True):
4526 renderer
= dict_get(tab
, ('tabRenderer', 'expandableTabRenderer')) or {}
4527 if renderer
.get('selected') is True:
4531 raise ExtractorError('Unable to find selected tab')
4533 def _extract_uploader(self
, data
):
4535 renderer
= self
._extract
_sidebar
_info
_renderer
(data
, 'playlistSidebarSecondaryInfoRenderer') or {}
4537 renderer
, lambda x
: x
['videoOwner']['videoOwnerRenderer']['title']['runs'][0], dict)
4539 owner_text
= owner
.get('text')
4540 uploader
['uploader'] = self
._search
_regex
(
4541 r
'^by (.+) and \d+ others?$', owner_text
, 'uploader', default
=owner_text
)
4542 uploader
['uploader_id'] = try_get(
4543 owner
, lambda x
: x
['navigationEndpoint']['browseEndpoint']['browseId'], str)
4544 uploader
['uploader_url'] = urljoin(
4545 'https://www.youtube.com/',
4546 try_get(owner
, lambda x
: x
['navigationEndpoint']['browseEndpoint']['canonicalBaseUrl'], str))
4547 return filter_dict(uploader
)
4549 def _extract_from_tabs(self
, item_id
, ytcfg
, data
, tabs
):
4550 playlist_id
= title
= description
= channel_url
= channel_name
= channel_id
= None
4553 selected_tab
= self
._extract
_selected
_tab
(tabs
)
4554 primary_sidebar_renderer
= self
._extract
_sidebar
_info
_renderer
(data
, 'playlistSidebarPrimaryInfoRenderer')
4556 data
, lambda x
: x
['metadata']['channelMetadataRenderer'], dict)
4558 channel_name
= renderer
.get('title')
4559 channel_url
= renderer
.get('channelUrl')
4560 channel_id
= renderer
.get('externalId')
4563 data
, lambda x
: x
['metadata']['playlistMetadataRenderer'], dict)
4566 title
= renderer
.get('title')
4567 description
= renderer
.get('description', '')
4568 playlist_id
= channel_id
4569 tags
= renderer
.get('keywords', '').split()
4571 # We can get the uncropped banner/avatar by replacing the crop params with '=s0'
4572 # See: https://github.com/yt-dlp/yt-dlp/issues/2237#issuecomment-1013694714
4573 def _get_uncropped(url
):
4574 return url_or_none((url
or '').split('=')[0] + '=s0')
4576 avatar_thumbnails
= self
._extract
_thumbnails
(renderer
, 'avatar')
4577 if avatar_thumbnails
:
4578 uncropped_avatar
= _get_uncropped(avatar_thumbnails
[0]['url'])
4579 if uncropped_avatar
:
4580 avatar_thumbnails
.append({
4581 'url': uncropped_avatar
,
4582 'id': 'avatar_uncropped',
4586 channel_banners
= self
._extract
_thumbnails
(
4587 data
, ('header', ..., ['banner', 'mobileBanner', 'tvBanner']))
4588 for banner
in channel_banners
:
4589 banner
['preference'] = -10
4592 uncropped_banner
= _get_uncropped(channel_banners
[0]['url'])
4593 if uncropped_banner
:
4594 channel_banners
.append({
4595 'url': uncropped_banner
,
4596 'id': 'banner_uncropped',
4600 primary_thumbnails
= self
._extract
_thumbnails
(
4601 primary_sidebar_renderer
, ('thumbnailRenderer', ('playlistVideoThumbnailRenderer', 'playlistCustomThumbnailRenderer'), 'thumbnail'))
4603 if playlist_id
is None:
4604 playlist_id
= item_id
4606 playlist_stats
= traverse_obj(primary_sidebar_renderer
, 'stats')
4607 last_updated_unix
= self
._parse
_time
_text
(self
._get
_text
(playlist_stats
, 2))
4609 title
= self
._get
_text
(data
, ('header', 'hashtagHeaderRenderer', 'hashtag')) or playlist_id
4610 title
+= format_field(selected_tab
, 'title', ' - %s')
4611 title
+= format_field(selected_tab
, 'expandedText', ' - %s')
4614 'playlist_id': playlist_id
,
4615 'playlist_title': title
,
4616 'playlist_description': description
,
4617 'uploader': channel_name
,
4618 'uploader_id': channel_id
,
4619 'uploader_url': channel_url
,
4620 'thumbnails': primary_thumbnails
+ avatar_thumbnails
+ channel_banners
,
4622 'view_count': self
._get
_count
(playlist_stats
, 1),
4623 'availability': self
._extract
_availability
(data
),
4624 'modified_date': strftime_or_none(last_updated_unix
, '%Y%m%d'),
4625 'playlist_count': self
._get
_count
(playlist_stats
, 0),
4626 'channel_follower_count': self
._get
_count
(data
, ('header', ..., 'subscriberCountText')),
4629 metadata
.update(self
._extract
_uploader
(data
))
4631 'channel': metadata
['uploader'],
4632 'channel_id': metadata
['uploader_id'],
4633 'channel_url': metadata
['uploader_url']})
4634 return self
.playlist_result(
4636 selected_tab
, playlist_id
, ytcfg
,
4637 self
._extract
_account
_syncid
(ytcfg
, data
),
4638 self
._extract
_visitor
_data
(data
, ytcfg
)),
4641 def _extract_inline_playlist(self
, playlist
, playlist_id
, data
, ytcfg
):
4642 first_id
= last_id
= response
= None
4643 for page_num
in itertools
.count(1):
4644 videos
= list(self
._playlist
_entries
(playlist
))
4647 start
= next((i
for i
, v
in enumerate(videos
) if v
['id'] == last_id
), -1) + 1
4648 if start
>= len(videos
):
4650 yield from videos
[start
:]
4651 first_id
= first_id
or videos
[0]['id']
4652 last_id
= videos
[-1]['id']
4653 watch_endpoint
= try_get(
4654 playlist
, lambda x
: x
['contents'][-1]['playlistPanelVideoRenderer']['navigationEndpoint']['watchEndpoint'])
4655 headers
= self
.generate_api_headers(
4656 ytcfg
=ytcfg
, account_syncid
=self
._extract
_account
_syncid
(ytcfg
, data
),
4657 visitor_data
=self
._extract
_visitor
_data
(response
, data
, ytcfg
))
4659 'playlistId': playlist_id
,
4660 'videoId': watch_endpoint
.get('videoId') or last_id
,
4661 'index': watch_endpoint
.get('index') or len(videos
),
4662 'params': watch_endpoint
.get('params') or 'OAE%3D'
4664 response
= self
._extract
_response
(
4665 item_id
='%s page %d' % (playlist_id
, page_num
),
4666 query
=query
, ep
='next', headers
=headers
, ytcfg
=ytcfg
,
4667 check_get_keys
='contents'
4670 response
, lambda x
: x
['contents']['twoColumnWatchNextResults']['playlist']['playlist'], dict)
4672 def _extract_from_playlist(self
, item_id
, url
, data
, playlist
, ytcfg
):
4673 title
= playlist
.get('title') or try_get(
4674 data
, lambda x
: x
['titleText']['simpleText'], str)
4675 playlist_id
= playlist
.get('playlistId') or item_id
4677 # Delegating everything except mix playlists to regular tab-based playlist URL
4678 playlist_url
= urljoin(url
, try_get(
4679 playlist
, lambda x
: x
['endpoint']['commandMetadata']['webCommandMetadata']['url'],
4682 # Some playlists are unviewable but YouTube still provides a link to the (broken) playlist page [1]
4683 # [1] MLCT, RLTDwFCb4jeqaKWnciAYM-ZVHg
4684 is_known_unviewable
= re
.fullmatch(r
'MLCT|RLTD[\w-]{22}', playlist_id
)
4686 if playlist_url
and playlist_url
!= url
and not is_known_unviewable
:
4687 return self
.url_result(
4688 playlist_url
, ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
,
4691 return self
.playlist_result(
4692 self
._extract
_inline
_playlist
(playlist
, playlist_id
, data
, ytcfg
),
4693 playlist_id
=playlist_id
, playlist_title
=title
)
4695 def _extract_availability(self
, data
):
4697 Gets the availability of a given playlist/tab.
4698 Note: Unless YouTube tells us explicitly, we do not assume it is public
4699 @param data: response
4701 renderer
= self
._extract
_sidebar
_info
_renderer
(data
, 'playlistSidebarPrimaryInfoRenderer') or {}
4703 player_header_privacy
= traverse_obj(
4704 data
, ('header', 'playlistHeaderRenderer', 'privacy'), expected_type
=str)
4706 badges
= self
._extract
_badges
(renderer
)
4708 # Personal playlists, when authenticated, have a dropdown visibility selector instead of a badge
4709 privacy_setting_icon
= traverse_obj(
4711 'privacyForm', 'dropdownFormFieldRenderer', 'dropdown', 'dropdownRenderer', 'entries',
4712 lambda _
, v
: v
['privacyDropdownItemRenderer']['isSelected'], 'privacyDropdownItemRenderer', 'icon', 'iconType'),
4713 get_all
=False, expected_type
=str)
4717 self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PUBLIC
)
4718 or player_header_privacy
== 'PUBLIC'
4719 or privacy_setting_icon
== 'PRIVACY_PUBLIC')
4720 else self
._availability
(
4722 self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PRIVATE
)
4723 or player_header_privacy
== 'PRIVATE' if player_header_privacy
is not None
4724 else privacy_setting_icon
== 'PRIVACY_PRIVATE' if privacy_setting_icon
is not None else None),
4726 self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_UNLISTED
)
4727 or player_header_privacy
== 'UNLISTED' if player_header_privacy
is not None
4728 else privacy_setting_icon
== 'PRIVACY_UNLISTED' if privacy_setting_icon
is not None else None),
4729 needs_subscription
=self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_SUBSCRIPTION
) or None,
4730 needs_premium
=self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PREMIUM
) or None,
4734 def _extract_sidebar_info_renderer(data
, info_renderer
, expected_type
=dict):
4735 sidebar_renderer
= try_get(
4736 data
, lambda x
: x
['sidebar']['playlistSidebarRenderer']['items'], list) or []
4737 for item
in sidebar_renderer
:
4738 renderer
= try_get(item
, lambda x
: x
[info_renderer
], expected_type
)
4742 def _reload_with_unavailable_videos(self
, item_id
, data
, ytcfg
):
4744 Get playlist with unavailable videos if the 'show unavailable videos' button exists.
4746 browse_id
= params
= None
4747 renderer
= self
._extract
_sidebar
_info
_renderer
(data
, 'playlistSidebarPrimaryInfoRenderer')
4750 menu_renderer
= try_get(
4751 renderer
, lambda x
: x
['menu']['menuRenderer']['items'], list) or []
4752 for menu_item
in menu_renderer
:
4753 if not isinstance(menu_item
, dict):
4755 nav_item_renderer
= menu_item
.get('menuNavigationItemRenderer')
4757 nav_item_renderer
, lambda x
: x
['text']['simpleText'], str)
4758 if not text
or text
.lower() != 'show unavailable videos':
4760 browse_endpoint
= try_get(
4761 nav_item_renderer
, lambda x
: x
['navigationEndpoint']['browseEndpoint'], dict) or {}
4762 browse_id
= browse_endpoint
.get('browseId')
4763 params
= browse_endpoint
.get('params')
4766 headers
= self
.generate_api_headers(
4767 ytcfg
=ytcfg
, account_syncid
=self
._extract
_account
_syncid
(ytcfg
, data
),
4768 visitor_data
=self
._extract
_visitor
_data
(data
, ytcfg
))
4770 'params': params
or 'wgYCCAA=',
4771 'browseId': browse_id
or 'VL%s' % item_id
4773 return self
._extract
_response
(
4774 item_id
=item_id
, headers
=headers
, query
=query
,
4775 check_get_keys
='contents', fatal
=False, ytcfg
=ytcfg
,
4776 note
='Downloading API JSON with unavailable videos')
4778 @functools.cached_property
4779 def skip_webpage(self
):
4780 return 'webpage' in self
._configuration
_arg
('skip', ie_key
=YoutubeTabIE
.ie_key())
4782 def _extract_webpage(self
, url
, item_id
, fatal
=True):
4783 webpage
, data
= None, None
4784 for retry
in self
.RetryManager(fatal
=fatal
):
4786 webpage
= self
._download
_webpage
(url
, item_id
, note
='Downloading webpage')
4787 data
= self
.extract_yt_initial_data(item_id
, webpage
or '', fatal
=fatal
) or {}
4788 except ExtractorError
as e
:
4789 if isinstance(e
.cause
, network_exceptions
):
4790 if not isinstance(e
.cause
, urllib
.error
.HTTPError
) or e
.cause
.code
not in (403, 429):
4793 self
._error
_or
_warning
(e
, fatal
=fatal
)
4797 self
._extract
_and
_report
_alerts
(data
)
4798 except ExtractorError
as e
:
4799 self
._error
_or
_warning
(e
, fatal
=fatal
)
4802 # Sometimes youtube returns a webpage with incomplete ytInitialData
4803 # See: https://github.com/yt-dlp/yt-dlp/issues/116
4804 if not traverse_obj(data
, 'contents', 'currentVideoEndpoint', 'onResponseReceivedActions'):
4805 retry
.error
= ExtractorError('Incomplete yt initial data received')
4808 return webpage
, data
4810 def _report_playlist_authcheck(self
, ytcfg
, fatal
=True):
4811 """Use if failed to extract ytcfg (and data) from initial webpage"""
4812 if not ytcfg
and self
.is_authenticated
:
4813 msg
= 'Playlists that require authentication may not extract correctly without a successful webpage download'
4814 if 'authcheck' not in self
._configuration
_arg
('skip', ie_key
=YoutubeTabIE
.ie_key()) and fatal
:
4815 raise ExtractorError(
4816 f
'{msg}. If you are not downloading private content, or '
4817 'your cookies are only for the first account and channel,'
4818 ' pass "--extractor-args youtubetab:skip=authcheck" to skip this check',
4820 self
.report_warning(msg
, only_once
=True)
4822 def _extract_data(self
, url
, item_id
, ytcfg
=None, fatal
=True, webpage_fatal
=False, default_client
='web'):
4824 if not self
.skip_webpage
:
4825 webpage
, data
= self
._extract
_webpage
(url
, item_id
, fatal
=webpage_fatal
)
4826 ytcfg
= ytcfg
or self
.extract_ytcfg(item_id
, webpage
)
4827 # Reject webpage data if redirected to home page without explicitly requesting
4828 selected_tab
= self
._extract
_selected
_tab
(traverse_obj(
4829 data
, ('contents', 'twoColumnBrowseResultsRenderer', 'tabs'), expected_type
=list, default
=[]), fatal
=False) or {}
4830 if (url
!= 'https://www.youtube.com/feed/recommended'
4831 and selected_tab
.get('tabIdentifier') == 'FEwhat_to_watch' # Home page
4832 and 'no-youtube-channel-redirect' not in self
.get_param('compat_opts', [])):
4833 msg
= 'The channel/playlist does not exist and the URL redirected to youtube.com home page'
4835 raise ExtractorError(msg
, expected
=True)
4836 self
.report_warning(msg
, only_once
=True)
4838 self
._report
_playlist
_authcheck
(ytcfg
, fatal
=fatal
)
4839 data
= self
._extract
_tab
_endpoint
(url
, item_id
, ytcfg
, fatal
=fatal
, default_client
=default_client
)
4842 def _extract_tab_endpoint(self
, url
, item_id
, ytcfg
=None, fatal
=True, default_client
='web'):
4843 headers
= self
.generate_api_headers(ytcfg
=ytcfg
, default_client
=default_client
)
4844 resolve_response
= self
._extract
_response
(
4845 item_id
=item_id
, query
={'url': url}
, check_get_keys
='endpoint', headers
=headers
, ytcfg
=ytcfg
, fatal
=fatal
,
4846 ep
='navigation/resolve_url', note
='Downloading API parameters API JSON', default_client
=default_client
)
4847 endpoints
= {'browseEndpoint': 'browse', 'watchEndpoint': 'next'}
4848 for ep_key
, ep
in endpoints
.items():
4849 params
= try_get(resolve_response
, lambda x
: x
['endpoint'][ep_key
], dict)
4851 return self
._extract
_response
(
4852 item_id
=item_id
, query
=params
, ep
=ep
, headers
=headers
,
4853 ytcfg
=ytcfg
, fatal
=fatal
, default_client
=default_client
,
4854 check_get_keys
=('contents', 'currentVideoEndpoint', 'onResponseReceivedActions'))
4855 err_note
= 'Failed to resolve url (does the playlist exist?)'
4857 raise ExtractorError(err_note
, expected
=True)
4858 self
.report_warning(err_note
, item_id
)
4860 _SEARCH_PARAMS
= None
4862 def _search_results(self
, query
, params
=NO_DEFAULT
, default_client
='web'):
4863 data
= {'query': query}
4864 if params
is NO_DEFAULT
:
4865 params
= self
._SEARCH
_PARAMS
4867 data
['params'] = params
4870 ('contents', 'twoColumnSearchResultsRenderer', 'primaryContents', 'sectionListRenderer', 'contents'),
4871 ('onResponseReceivedCommands', 0, 'appendContinuationItemsAction', 'continuationItems'),
4873 ('contents', 'tabbedSearchResultsRenderer', 'tabs', 0, 'tabRenderer', 'content', 'sectionListRenderer', 'contents'),
4874 ('continuationContents', ),
4876 display_id
= f
'query "{query}"'
4877 check_get_keys
= tuple({keys[0] for keys in content_keys}
)
4878 ytcfg
= self
._download
_ytcfg
(default_client
, display_id
) if not self
.skip_webpage
else {}
4879 self
._report
_playlist
_authcheck
(ytcfg
, fatal
=False)
4881 continuation_list
= [None]
4883 for page_num
in itertools
.count(1):
4884 data
.update(continuation_list
[0] or {})
4885 headers
= self
.generate_api_headers(
4886 ytcfg
=ytcfg
, visitor_data
=self
._extract
_visitor
_data
(search
), default_client
=default_client
)
4887 search
= self
._extract
_response
(
4888 item_id
=f
'{display_id} page {page_num}', ep
='search', query
=data
,
4889 default_client
=default_client
, check_get_keys
=check_get_keys
, ytcfg
=ytcfg
, headers
=headers
)
4890 slr_contents
= traverse_obj(search
, *content_keys
)
4891 yield from self
._extract
_entries
({'contents': list(variadic(slr_contents))}
, continuation_list
)
4892 if not continuation_list
[0]:
4896 class YoutubeTabIE(YoutubeTabBaseInfoExtractor
):
4897 IE_DESC
= 'YouTube Tabs'
4898 _VALID_URL
= r
'''(?x:
4902 youtube(?:kids)?\.com|
4906 (?P<channel_type>channel|c|user|browse)/|
4909 (?:playlist|watch)\?.*?\blist=
4911 (?!(?:%(reserved_names)s)\b) # Direct URLs
4915 'reserved_names': YoutubeBaseInfoExtractor
._RESERVED
_NAMES
,
4916 'invidious': '|'.join(YoutubeBaseInfoExtractor
._INVIDIOUS
_SITES
),
4918 IE_NAME
= 'youtube:tab'
4921 'note': 'playlists, multipage',
4922 'url': 'https://www.youtube.com/c/ИгорьКлейнер/playlists?view=1&flow=grid',
4923 'playlist_mincount': 94,
4925 'id': 'UCqj7Cz7revf5maW9g5pgNcg',
4926 'title': 'Igor Kleiner - Playlists',
4927 'description': 'md5:be97ee0f14ee314f1f002cf187166ee2',
4928 'uploader': 'Igor Kleiner',
4929 'uploader_id': 'UCqj7Cz7revf5maW9g5pgNcg',
4930 'channel': 'Igor Kleiner',
4931 'channel_id': 'UCqj7Cz7revf5maW9g5pgNcg',
4932 'tags': ['"критическое', 'мышление"', '"наука', 'просто"', 'математика', '"анализ', 'данных"'],
4933 'channel_url': 'https://www.youtube.com/channel/UCqj7Cz7revf5maW9g5pgNcg',
4934 'uploader_url': 'https://www.youtube.com/channel/UCqj7Cz7revf5maW9g5pgNcg',
4935 'channel_follower_count': int
4938 'note': 'playlists, multipage, different order',
4939 'url': 'https://www.youtube.com/user/igorkle1/playlists?view=1&sort=dd',
4940 'playlist_mincount': 94,
4942 'id': 'UCqj7Cz7revf5maW9g5pgNcg',
4943 'title': 'Igor Kleiner - Playlists',
4944 'description': 'md5:be97ee0f14ee314f1f002cf187166ee2',
4945 'uploader_id': 'UCqj7Cz7revf5maW9g5pgNcg',
4946 'uploader': 'Igor Kleiner',
4947 'uploader_url': 'https://www.youtube.com/channel/UCqj7Cz7revf5maW9g5pgNcg',
4948 'tags': ['"критическое', 'мышление"', '"наука', 'просто"', 'математика', '"анализ', 'данных"'],
4949 'channel_id': 'UCqj7Cz7revf5maW9g5pgNcg',
4950 'channel': 'Igor Kleiner',
4951 'channel_url': 'https://www.youtube.com/channel/UCqj7Cz7revf5maW9g5pgNcg',
4952 'channel_follower_count': int
4955 'note': 'playlists, series',
4956 'url': 'https://www.youtube.com/c/3blue1brown/playlists?view=50&sort=dd&shelf_id=3',
4957 'playlist_mincount': 5,
4959 'id': 'UCYO_jab_esuFRV4b17AJtAw',
4960 'title': '3Blue1Brown - Playlists',
4961 'description': 'md5:e1384e8a133307dd10edee76e875d62f',
4962 'uploader_id': 'UCYO_jab_esuFRV4b17AJtAw',
4963 'uploader': '3Blue1Brown',
4964 'channel_url': 'https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw',
4965 'uploader_url': 'https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw',
4966 'channel': '3Blue1Brown',
4967 'channel_id': 'UCYO_jab_esuFRV4b17AJtAw',
4968 'tags': ['Mathematics'],
4969 'channel_follower_count': int
4972 'note': 'playlists, singlepage',
4973 'url': 'https://www.youtube.com/user/ThirstForScience/playlists',
4974 'playlist_mincount': 4,
4976 'id': 'UCAEtajcuhQ6an9WEzY9LEMQ',
4977 'title': 'ThirstForScience - Playlists',
4978 'description': 'md5:609399d937ea957b0f53cbffb747a14c',
4979 'uploader': 'ThirstForScience',
4980 'uploader_id': 'UCAEtajcuhQ6an9WEzY9LEMQ',
4981 'uploader_url': 'https://www.youtube.com/channel/UCAEtajcuhQ6an9WEzY9LEMQ',
4982 'channel_url': 'https://www.youtube.com/channel/UCAEtajcuhQ6an9WEzY9LEMQ',
4983 'channel_id': 'UCAEtajcuhQ6an9WEzY9LEMQ',
4985 'channel': 'ThirstForScience',
4986 'channel_follower_count': int
4989 'url': 'https://www.youtube.com/c/ChristophLaimer/playlists',
4990 'only_matching': True,
4992 'note': 'basic, single video playlist',
4993 'url': 'https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc',
4995 'uploader_id': 'UCmlqkdCBesrv2Lak1mF_MxA',
4996 'uploader': 'Sergey M.',
4997 'id': 'PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc',
4998 'title': 'youtube-dl public playlist',
5002 'modified_date': '20201130',
5003 'channel': 'Sergey M.',
5004 'channel_id': 'UCmlqkdCBesrv2Lak1mF_MxA',
5005 'uploader_url': 'https://www.youtube.com/channel/UCmlqkdCBesrv2Lak1mF_MxA',
5006 'channel_url': 'https://www.youtube.com/channel/UCmlqkdCBesrv2Lak1mF_MxA',
5007 'availability': 'public',
5009 'playlist_count': 1,
5011 'note': 'empty playlist',
5012 'url': 'https://www.youtube.com/playlist?list=PL4lCao7KL_QFodcLWhDpGCYnngnHtQ-Xf',
5014 'uploader_id': 'UCmlqkdCBesrv2Lak1mF_MxA',
5015 'uploader': 'Sergey M.',
5016 'id': 'PL4lCao7KL_QFodcLWhDpGCYnngnHtQ-Xf',
5017 'title': 'youtube-dl empty playlist',
5019 'channel': 'Sergey M.',
5021 'modified_date': '20160902',
5022 'channel_id': 'UCmlqkdCBesrv2Lak1mF_MxA',
5023 'channel_url': 'https://www.youtube.com/channel/UCmlqkdCBesrv2Lak1mF_MxA',
5024 'uploader_url': 'https://www.youtube.com/channel/UCmlqkdCBesrv2Lak1mF_MxA',
5025 'availability': 'public',
5027 'playlist_count': 0,
5030 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/featured',
5032 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5033 'title': 'lex will - Home',
5034 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
5035 'uploader': 'lex will',
5036 'uploader_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5037 'channel': 'lex will',
5038 'tags': ['bible', 'history', 'prophesy'],
5039 'uploader_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5040 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5041 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5042 'channel_follower_count': int
5044 'playlist_mincount': 2,
5046 'note': 'Videos tab',
5047 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/videos',
5049 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5050 'title': 'lex will - Videos',
5051 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
5052 'uploader': 'lex will',
5053 'uploader_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5054 'tags': ['bible', 'history', 'prophesy'],
5055 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5056 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5057 'uploader_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5058 'channel': 'lex will',
5059 'channel_follower_count': int
5061 'playlist_mincount': 975,
5063 'note': 'Videos tab, sorted by popular',
5064 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/videos?view=0&sort=p&flow=grid',
5066 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5067 'title': 'lex will - Videos',
5068 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
5069 'uploader': 'lex will',
5070 'uploader_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5071 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5072 'uploader_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5073 'channel': 'lex will',
5074 'tags': ['bible', 'history', 'prophesy'],
5075 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5076 'channel_follower_count': int
5078 'playlist_mincount': 199,
5080 'note': 'Playlists tab',
5081 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/playlists',
5083 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5084 'title': 'lex will - Playlists',
5085 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
5086 'uploader': 'lex will',
5087 'uploader_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5088 'uploader_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5089 'channel': 'lex will',
5090 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5091 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5092 'tags': ['bible', 'history', 'prophesy'],
5093 'channel_follower_count': int
5095 'playlist_mincount': 17,
5097 'note': 'Community tab',
5098 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/community',
5100 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5101 'title': 'lex will - Community',
5102 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
5103 'uploader': 'lex will',
5104 'uploader_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5105 'uploader_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5106 'channel': 'lex will',
5107 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5108 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5109 'tags': ['bible', 'history', 'prophesy'],
5110 'channel_follower_count': int
5112 'playlist_mincount': 18,
5114 'note': 'Channels tab',
5115 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/channels',
5117 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5118 'title': 'lex will - Channels',
5119 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
5120 'uploader': 'lex will',
5121 'uploader_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5122 'uploader_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5123 'channel': 'lex will',
5124 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5125 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5126 'tags': ['bible', 'history', 'prophesy'],
5127 'channel_follower_count': int
5129 'playlist_mincount': 12,
5131 'note': 'Search tab',
5132 'url': 'https://www.youtube.com/c/3blue1brown/search?query=linear%20algebra',
5133 'playlist_mincount': 40,
5135 'id': 'UCYO_jab_esuFRV4b17AJtAw',
5136 'title': '3Blue1Brown - Search - linear algebra',
5137 'description': 'md5:e1384e8a133307dd10edee76e875d62f',
5138 'uploader': '3Blue1Brown',
5139 'uploader_id': 'UCYO_jab_esuFRV4b17AJtAw',
5140 'channel_url': 'https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw',
5141 'uploader_url': 'https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw',
5142 'tags': ['Mathematics'],
5143 'channel': '3Blue1Brown',
5144 'channel_id': 'UCYO_jab_esuFRV4b17AJtAw',
5145 'channel_follower_count': int
5148 'url': 'https://invidio.us/channel/UCmlqkdCBesrv2Lak1mF_MxA',
5149 'only_matching': True,
5151 'url': 'https://www.youtubekids.com/channel/UCmlqkdCBesrv2Lak1mF_MxA',
5152 'only_matching': True,
5154 'url': 'https://music.youtube.com/channel/UCmlqkdCBesrv2Lak1mF_MxA',
5155 'only_matching': True,
5157 'note': 'Playlist with deleted videos (#651). As a bonus, the video #51 is also twice in this list.',
5158 'url': 'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC',
5160 'title': '29C3: Not my department',
5161 'id': 'PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC',
5162 'uploader': 'Christiaan008',
5163 'uploader_id': 'UCEPzS1rYsrkqzSLNp76nrcg',
5164 'description': 'md5:a14dc1a8ef8307a9807fe136a0660268',
5166 'uploader_url': 'https://www.youtube.com/c/ChRiStIaAn008',
5168 'modified_date': '20150605',
5169 'channel_id': 'UCEPzS1rYsrkqzSLNp76nrcg',
5170 'channel_url': 'https://www.youtube.com/c/ChRiStIaAn008',
5171 'channel': 'Christiaan008',
5172 'availability': 'public',
5174 'playlist_count': 96,
5176 'note': 'Large playlist',
5177 'url': 'https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q',
5179 'title': 'Uploads from Cauchemar',
5180 'id': 'UUBABnxM4Ar9ten8Mdjj1j0Q',
5181 'uploader': 'Cauchemar',
5182 'uploader_id': 'UCBABnxM4Ar9ten8Mdjj1j0Q',
5183 'channel_url': 'https://www.youtube.com/c/Cauchemar89',
5185 'modified_date': r
're:\d{8}',
5186 'channel': 'Cauchemar',
5187 'uploader_url': 'https://www.youtube.com/c/Cauchemar89',
5190 'channel_id': 'UCBABnxM4Ar9ten8Mdjj1j0Q',
5191 'availability': 'public',
5193 'playlist_mincount': 1123,
5194 'expected_warnings': [r
'[Uu]navailable videos (are|will be) hidden'],
5196 'note': 'even larger playlist, 8832 videos',
5197 'url': 'http://www.youtube.com/user/NASAgovVideo/videos',
5198 'only_matching': True,
5200 'note': 'Buggy playlist: the webpage has a "Load more" button but it doesn\'t have more videos',
5201 'url': 'https://www.youtube.com/playlist?list=UUXw-G3eDE9trcvY2sBMM_aA',
5203 'title': 'Uploads from Interstellar Movie',
5204 'id': 'UUXw-G3eDE9trcvY2sBMM_aA',
5205 'uploader': 'Interstellar Movie',
5206 'uploader_id': 'UCXw-G3eDE9trcvY2sBMM_aA',
5207 'uploader_url': 'https://www.youtube.com/c/InterstellarMovie',
5210 'channel_id': 'UCXw-G3eDE9trcvY2sBMM_aA',
5211 'channel_url': 'https://www.youtube.com/c/InterstellarMovie',
5212 'channel': 'Interstellar Movie',
5214 'modified_date': r
're:\d{8}',
5215 'availability': 'public',
5217 'playlist_mincount': 21,
5219 'note': 'Playlist with "show unavailable videos" button',
5220 'url': 'https://www.youtube.com/playlist?list=UUTYLiWFZy8xtPwxFwX9rV7Q',
5222 'title': 'Uploads from Phim Siêu Nhân Nhật Bản',
5223 'id': 'UUTYLiWFZy8xtPwxFwX9rV7Q',
5224 'uploader': 'Phim Siêu Nhân Nhật Bản',
5225 'uploader_id': 'UCTYLiWFZy8xtPwxFwX9rV7Q',
5227 'channel': 'Phim Siêu Nhân Nhật Bản',
5229 'uploader_url': 'https://www.youtube.com/channel/UCTYLiWFZy8xtPwxFwX9rV7Q',
5231 'channel_url': 'https://www.youtube.com/channel/UCTYLiWFZy8xtPwxFwX9rV7Q',
5232 'channel_id': 'UCTYLiWFZy8xtPwxFwX9rV7Q',
5233 'modified_date': r
're:\d{8}',
5234 'availability': 'public',
5236 'playlist_mincount': 200,
5237 'expected_warnings': [r
'[Uu]navailable videos (are|will be) hidden'],
5239 'note': 'Playlist with unavailable videos in page 7',
5240 'url': 'https://www.youtube.com/playlist?list=UU8l9frL61Yl5KFOl87nIm2w',
5242 'title': 'Uploads from BlankTV',
5243 'id': 'UU8l9frL61Yl5KFOl87nIm2w',
5244 'uploader': 'BlankTV',
5245 'uploader_id': 'UC8l9frL61Yl5KFOl87nIm2w',
5246 'channel': 'BlankTV',
5247 'channel_url': 'https://www.youtube.com/c/blanktv',
5248 'channel_id': 'UC8l9frL61Yl5KFOl87nIm2w',
5251 'uploader_url': 'https://www.youtube.com/c/blanktv',
5252 'modified_date': r
're:\d{8}',
5254 'availability': 'public',
5256 'playlist_mincount': 1000,
5257 'expected_warnings': [r
'[Uu]navailable videos (are|will be) hidden'],
5259 'note': 'https://github.com/ytdl-org/youtube-dl/issues/21844',
5260 'url': 'https://www.youtube.com/playlist?list=PLzH6n4zXuckpfMu_4Ff8E7Z1behQks5ba',
5262 'title': 'Data Analysis with Dr Mike Pound',
5263 'id': 'PLzH6n4zXuckpfMu_4Ff8E7Z1behQks5ba',
5264 'uploader_id': 'UC9-y-6csu5WGm29I7JiwpnA',
5265 'uploader': 'Computerphile',
5266 'description': 'md5:7f567c574d13d3f8c0954d9ffee4e487',
5267 'uploader_url': 'https://www.youtube.com/user/Computerphile',
5270 'channel_id': 'UC9-y-6csu5WGm29I7JiwpnA',
5271 'channel_url': 'https://www.youtube.com/user/Computerphile',
5272 'channel': 'Computerphile',
5273 'availability': 'public',
5275 'playlist_mincount': 11,
5277 'url': 'https://invidio.us/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc',
5278 'only_matching': True,
5280 'note': 'Playlist URL that does not actually serve a playlist',
5281 'url': 'https://www.youtube.com/watch?v=FqZTN594JQw&list=PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4',
5283 'id': 'FqZTN594JQw',
5285 'title': "Smiley's People 01 detective, Adventure Series, Action",
5286 'uploader': 'STREEM',
5287 'uploader_id': 'UCyPhqAZgwYWZfxElWVbVJng',
5288 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/channel/UCyPhqAZgwYWZfxElWVbVJng',
5289 'upload_date': '20150526',
5290 'license': 'Standard YouTube License',
5291 'description': 'md5:507cdcb5a49ac0da37a920ece610be80',
5292 'categories': ['People & Blogs'],
5298 'skip_download': True,
5300 'skip': 'This video is not available.',
5301 'add_ie': [YoutubeIE
.ie_key()],
5303 'url': 'https://www.youtubekids.com/watch?v=Agk7R8I8o5U&list=PUZ6jURNr1WQZCNHF0ao-c0g',
5304 'only_matching': True,
5306 'url': 'https://www.youtube.com/watch?v=MuAGGZNfUkU&list=RDMM',
5307 'only_matching': True,
5309 'url': 'https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ/live',
5311 'id': 'Wq15eF5vCbI', # This will keep changing
5314 'uploader': 'Sky News',
5315 'uploader_id': 'skynews',
5316 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/skynews',
5317 'upload_date': r
're:\d{8}',
5319 'categories': ['News & Politics'],
5322 'release_timestamp': 1642502819,
5323 'channel': 'Sky News',
5324 'channel_id': 'UCoMdktPbSTixAyNGwb-UYkQ',
5327 'thumbnail': 'https://i.ytimg.com/vi/GgL890LIznQ/maxresdefault_live.jpg',
5328 'playable_in_embed': True,
5329 'release_date': '20220118',
5330 'availability': 'public',
5331 'live_status': 'is_live',
5332 'channel_url': 'https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ',
5333 'channel_follower_count': int
5336 'skip_download': True,
5338 'expected_warnings': ['Ignoring subtitle tracks found in '],
5340 'url': 'https://www.youtube.com/user/TheYoungTurks/live',
5342 'id': 'a48o2S1cPoo',
5344 'title': 'The Young Turks - Live Main Show',
5345 'uploader': 'The Young Turks',
5346 'uploader_id': 'TheYoungTurks',
5347 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/TheYoungTurks',
5348 'upload_date': '20150715',
5349 'license': 'Standard YouTube License',
5350 'description': 'md5:438179573adcdff3c97ebb1ee632b891',
5351 'categories': ['News & Politics'],
5352 'tags': ['Cenk Uygur (TV Program Creator)', 'The Young Turks (Award-Winning Work)', 'Talk Show (TV Genre)'],
5356 'skip_download': True,
5358 'only_matching': True,
5360 'url': 'https://www.youtube.com/channel/UC1yBKRuGpC1tSM73A0ZjYjQ/live',
5361 'only_matching': True,
5363 'url': 'https://www.youtube.com/c/CommanderVideoHq/live',
5364 'only_matching': True,
5366 'note': 'A channel that is not live. Should raise error',
5367 'url': 'https://www.youtube.com/user/numberphile/live',
5368 'only_matching': True,
5370 'url': 'https://www.youtube.com/feed/trending',
5371 'only_matching': True,
5373 'url': 'https://www.youtube.com/feed/library',
5374 'only_matching': True,
5376 'url': 'https://www.youtube.com/feed/history',
5377 'only_matching': True,
5379 'url': 'https://www.youtube.com/feed/subscriptions',
5380 'only_matching': True,
5382 'url': 'https://www.youtube.com/feed/watch_later',
5383 'only_matching': True,
5385 'note': 'Recommended - redirects to home page.',
5386 'url': 'https://www.youtube.com/feed/recommended',
5387 'only_matching': True,
5389 'note': 'inline playlist with not always working continuations',
5390 'url': 'https://www.youtube.com/watch?v=UC6u0Tct-Fo&list=PL36D642111D65BE7C',
5391 'only_matching': True,
5393 'url': 'https://www.youtube.com/course',
5394 'only_matching': True,
5396 'url': 'https://www.youtube.com/zsecurity',
5397 'only_matching': True,
5399 'url': 'http://www.youtube.com/NASAgovVideo/videos',
5400 'only_matching': True,
5402 'url': 'https://www.youtube.com/TheYoungTurks/live',
5403 'only_matching': True,
5405 'url': 'https://www.youtube.com/hashtag/cctv9',
5411 'playlist_mincount': 350,
5413 'url': 'https://www.youtube.com/watch?list=PLW4dVinRY435CBE_JD3t-0SRXKfnZHS1P&feature=youtu.be&v=M9cJMXmQ_ZU',
5414 'only_matching': True,
5416 'note': 'Requires Premium: should request additional YTM-info webpage (and have format 141) for videos in playlist',
5417 'url': 'https://music.youtube.com/playlist?list=PLRBp0Fe2GpgmgoscNFLxNyBVSFVdYmFkq',
5418 'only_matching': True
5420 'note': '/browse/ should redirect to /channel/',
5421 'url': 'https://music.youtube.com/browse/UC1a8OFewdjuLq6KlF8M_8Ng',
5422 'only_matching': True
5424 'note': 'VLPL, should redirect to playlist?list=PL...',
5425 'url': 'https://music.youtube.com/browse/VLPLRBp0Fe2GpgmgoscNFLxNyBVSFVdYmFkq',
5427 'id': 'PLRBp0Fe2GpgmgoscNFLxNyBVSFVdYmFkq',
5428 'uploader': 'NoCopyrightSounds',
5429 'description': 'Providing you with copyright free / safe music for gaming, live streaming, studying and more!',
5430 'uploader_id': 'UC_aEa8K-EOJ3D6gOs7HcyNg',
5431 'title': 'NCS : All Releases 💿',
5432 'uploader_url': 'https://www.youtube.com/c/NoCopyrightSounds',
5433 'channel_url': 'https://www.youtube.com/c/NoCopyrightSounds',
5434 'modified_date': r
're:\d{8}',
5436 'channel_id': 'UC_aEa8K-EOJ3D6gOs7HcyNg',
5438 'channel': 'NoCopyrightSounds',
5439 'availability': 'public',
5441 'playlist_mincount': 166,
5442 'expected_warnings': [r
'[Uu]navailable videos (are|will be) hidden'],
5444 'note': 'Topic, should redirect to playlist?list=UU...',
5445 'url': 'https://music.youtube.com/browse/UC9ALqqC4aIeG5iDs7i90Bfw',
5447 'id': 'UU9ALqqC4aIeG5iDs7i90Bfw',
5448 'uploader_id': 'UC9ALqqC4aIeG5iDs7i90Bfw',
5449 'title': 'Uploads from Royalty Free Music - Topic',
5450 'uploader': 'Royalty Free Music - Topic',
5452 'channel_id': 'UC9ALqqC4aIeG5iDs7i90Bfw',
5453 'channel': 'Royalty Free Music - Topic',
5455 'channel_url': 'https://www.youtube.com/channel/UC9ALqqC4aIeG5iDs7i90Bfw',
5456 'channel_url': 'https://www.youtube.com/channel/UC9ALqqC4aIeG5iDs7i90Bfw',
5457 'modified_date': r
're:\d{8}',
5458 'uploader_url': 'https://www.youtube.com/channel/UC9ALqqC4aIeG5iDs7i90Bfw',
5460 'availability': 'public',
5462 'expected_warnings': [
5463 'The URL does not have a videos tab',
5464 r
'[Uu]navailable videos (are|will be) hidden',
5466 'playlist_mincount': 101,
5468 'note': 'Topic without a UU playlist',
5469 'url': 'https://www.youtube.com/channel/UCtFRv9O2AHqOZjjynzrv-xg',
5471 'id': 'UCtFRv9O2AHqOZjjynzrv-xg',
5472 'title': 'UCtFRv9O2AHqOZjjynzrv-xg',
5475 'expected_warnings': [
5476 'the playlist redirect gave error',
5478 'playlist_mincount': 9,
5480 'note': 'Youtube music Album',
5481 'url': 'https://music.youtube.com/browse/MPREb_gTAcphH99wE',
5483 'id': 'OLAK5uy_l1m0thk3g31NmIIz_vMIbWtyv7eZixlH0',
5484 'title': 'Album - Royalty Free Music Library V2 (50 Songs)',
5488 'availability': 'unlisted',
5489 'modified_date': r
're:\d{8}',
5491 'playlist_count': 50,
5493 'note': 'unlisted single video playlist',
5494 'url': 'https://www.youtube.com/playlist?list=PLwL24UFy54GrB3s2KMMfjZscDi1x5Dajf',
5496 'uploader_id': 'UC9zHu_mHU96r19o-wV5Qs1Q',
5497 'uploader': 'colethedj',
5498 'id': 'PLwL24UFy54GrB3s2KMMfjZscDi1x5Dajf',
5499 'title': 'yt-dlp unlisted playlist test',
5500 'availability': 'unlisted',
5502 'modified_date': '20220418',
5503 'channel': 'colethedj',
5506 'uploader_url': 'https://www.youtube.com/channel/UC9zHu_mHU96r19o-wV5Qs1Q',
5507 'channel_id': 'UC9zHu_mHU96r19o-wV5Qs1Q',
5508 'channel_url': 'https://www.youtube.com/channel/UC9zHu_mHU96r19o-wV5Qs1Q',
5510 'playlist_count': 1,
5512 'note': 'API Fallback: Recommended - redirects to home page. Requires visitorData',
5513 'url': 'https://www.youtube.com/feed/recommended',
5515 'id': 'recommended',
5516 'title': 'recommended',
5519 'playlist_mincount': 50,
5521 'skip_download': True,
5522 'extractor_args': {'youtubetab': {'skip': ['webpage']}
}
5525 'note': 'API Fallback: /videos tab, sorted by oldest first',
5526 'url': 'https://www.youtube.com/user/theCodyReeder/videos?view=0&sort=da&flow=grid',
5528 'id': 'UCu6mSoMNzHQiBIOCkHUa2Aw',
5529 'title': 'Cody\'sLab - Videos',
5530 'description': 'md5:d083b7c2f0c67ee7a6c74c3e9b4243fa',
5531 'uploader': 'Cody\'sLab',
5532 'uploader_id': 'UCu6mSoMNzHQiBIOCkHUa2Aw',
5533 'channel': 'Cody\'sLab',
5534 'channel_id': 'UCu6mSoMNzHQiBIOCkHUa2Aw',
5536 'channel_url': 'https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw',
5537 'uploader_url': 'https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw',
5538 'channel_follower_count': int
5540 'playlist_mincount': 650,
5542 'skip_download': True,
5543 'extractor_args': {'youtubetab': {'skip': ['webpage']}
}
5546 'note': 'API Fallback: Topic, should redirect to playlist?list=UU...',
5547 'url': 'https://music.youtube.com/browse/UC9ALqqC4aIeG5iDs7i90Bfw',
5549 'id': 'UU9ALqqC4aIeG5iDs7i90Bfw',
5550 'uploader_id': 'UC9ALqqC4aIeG5iDs7i90Bfw',
5551 'title': 'Uploads from Royalty Free Music - Topic',
5552 'uploader': 'Royalty Free Music - Topic',
5553 'modified_date': r
're:\d{8}',
5554 'channel_id': 'UC9ALqqC4aIeG5iDs7i90Bfw',
5556 'channel_url': 'https://www.youtube.com/channel/UC9ALqqC4aIeG5iDs7i90Bfw',
5558 'channel': 'Royalty Free Music - Topic',
5560 'uploader_url': 'https://www.youtube.com/channel/UC9ALqqC4aIeG5iDs7i90Bfw',
5561 'availability': 'public',
5563 'expected_warnings': [
5564 'does not have a videos tab',
5565 r
'[Uu]navailable videos (are|will be) hidden',
5567 'playlist_mincount': 101,
5569 'skip_download': True,
5570 'extractor_args': {'youtubetab': {'skip': ['webpage']}
}
5573 'note': 'non-standard redirect to regional channel',
5574 'url': 'https://www.youtube.com/channel/UCwVVpHQ2Cs9iGJfpdFngePQ',
5575 'only_matching': True
5577 'note': 'collaborative playlist (uploader name in the form "by <uploader> and x other(s)")',
5578 'url': 'https://www.youtube.com/playlist?list=PLx-_-Kk4c89oOHEDQAojOXzEzemXxoqx6',
5580 'id': 'PLx-_-Kk4c89oOHEDQAojOXzEzemXxoqx6',
5581 'modified_date': '20220407',
5582 'channel_url': 'https://www.youtube.com/channel/UCKcqXmCcyqnhgpA5P0oHH_Q',
5584 'uploader_id': 'UCKcqXmCcyqnhgpA5P0oHH_Q',
5585 'uploader': 'pukkandan',
5586 'availability': 'unlisted',
5587 'channel_id': 'UCKcqXmCcyqnhgpA5P0oHH_Q',
5588 'channel': 'pukkandan',
5589 'description': 'Test for collaborative playlist',
5590 'title': 'yt-dlp test - collaborative playlist',
5592 'uploader_url': 'https://www.youtube.com/channel/UCKcqXmCcyqnhgpA5P0oHH_Q',
5594 'playlist_mincount': 2
5596 'note': 'translated tab name',
5597 'url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA/playlists',
5599 'id': 'UCiu-3thuViMebBjw_5nWYrA',
5601 'uploader_id': 'UCiu-3thuViMebBjw_5nWYrA',
5602 'channel_url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
5604 'title': 'cole-dlp-test-acc - 再生リスト',
5605 'uploader_url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
5606 'uploader': 'cole-dlp-test-acc',
5607 'channel_id': 'UCiu-3thuViMebBjw_5nWYrA',
5608 'channel': 'cole-dlp-test-acc',
5610 'playlist_mincount': 1,
5611 'params': {'extractor_args': {'youtube': {'lang': ['ja']}
}},
5612 'expected_warnings': ['Preferring "ja"'],
5614 # XXX: this should really check flat playlist entries, but the test suite doesn't support that
5615 'note': 'preferred lang set with playlist with translated video titles',
5616 'url': 'https://www.youtube.com/playlist?list=PLt5yu3-wZAlQAaPZ5Z-rJoTdbT-45Q7c0',
5618 'id': 'PLt5yu3-wZAlQAaPZ5Z-rJoTdbT-45Q7c0',
5621 'channel_url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
5622 'uploader': 'cole-dlp-test-acc',
5623 'uploader_id': 'UCiu-3thuViMebBjw_5nWYrA',
5624 'channel': 'cole-dlp-test-acc',
5625 'channel_id': 'UCiu-3thuViMebBjw_5nWYrA',
5626 'description': 'test',
5627 'uploader_url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
5628 'title': 'dlp test playlist',
5629 'availability': 'public',
5631 'playlist_mincount': 1,
5632 'params': {'extractor_args': {'youtube': {'lang': ['ja']}
}},
5633 'expected_warnings': ['Preferring "ja"'],
5635 # shorts audio pivot for 2GtVksBMYFM.
5636 'url': 'https://www.youtube.com/feed/sfv_audio_pivot?bp=8gUrCikSJwoLMkd0VmtzQk1ZRk0SCzJHdFZrc0JNWUZNGgsyR3RWa3NCTVlGTQ==',
5638 'id': 'sfv_audio_pivot',
5639 'title': 'sfv_audio_pivot',
5642 'playlist_mincount': 50,
5647 def suitable(cls
, url
):
5648 return False if YoutubeIE
.suitable(url
) else super().suitable(url
)
5650 _URL_RE
= re
.compile(rf
'(?P<pre>{_VALID_URL})(?(not_channel)|(?P<tab>/\w+))?(?P<post>.*)$')
5652 @YoutubeTabBaseInfoExtractor.passthrough_smuggled_data
5653 def _real_extract(self
, url
, smuggled_data
):
5654 item_id
= self
._match
_id
(url
)
5655 url
= urllib
.parse
.urlunparse(
5656 urllib
.parse
.urlparse(url
)._replace
(netloc
='www.youtube.com'))
5657 compat_opts
= self
.get_param('compat_opts', [])
5660 mobj
= self
._URL
_RE
.match(url
).groupdict()
5661 mobj
.update((k
, '') for k
, v
in mobj
.items() if v
is None)
5664 mobj
, redirect_warning
= get_mobj(url
), None
5665 # Youtube returns incomplete data if tabname is not lower case
5666 pre
, tab
, post
, is_channel
= mobj
['pre'], mobj
['tab'].lower(), mobj
['post'], not mobj
['not_channel']
5668 if smuggled_data
.get('is_music_url'):
5669 if item_id
[:2] == 'VL': # Youtube music VL channels have an equivalent playlist
5670 item_id
= item_id
[2:]
5671 pre
, tab
, post
, is_channel
= f
'https://www.youtube.com/playlist?list={item_id}', '', '', False
5672 elif item_id
[:2] == 'MP': # Resolve albums (/[channel/browse]/MP...) to their equivalent playlist
5673 mdata
= self
._extract
_tab
_endpoint
(
5674 f
'https://music.youtube.com/channel/{item_id}', item_id
, default_client
='web_music')
5675 murl
= traverse_obj(mdata
, ('microformat', 'microformatDataRenderer', 'urlCanonical'),
5676 get_all
=False, expected_type
=str)
5678 raise ExtractorError('Failed to resolve album to playlist')
5679 return self
.url_result(murl
, ie
=YoutubeTabIE
.ie_key())
5680 elif mobj
['channel_type'] == 'browse': # Youtube music /browse/ should be changed to /channel/
5681 pre
= f
'https://www.youtube.com/channel/{item_id}'
5683 original_tab_name
= tab
5684 if is_channel
and not tab
and 'no-youtube-channel-redirect' not in compat_opts
:
5685 # Home URLs should redirect to /videos/
5686 redirect_warning
= ('A channel/user page was given. All the channel\'s videos will be downloaded. '
5687 'To download only the videos in the home page, add a "/featured" to the URL')
5690 url
= ''.join((pre
, tab
, post
))
5691 mobj
= get_mobj(url
)
5693 # Handle both video/playlist URLs
5695 video_id
, playlist_id
= (qs
.get(key
, [None])[0] for key
in ('v', 'list'))
5697 if not video_id
and mobj
['not_channel'].startswith('watch'):
5699 # If there is neither video or playlist ids, youtube redirects to home page, which is undesirable
5700 raise ExtractorError('Unable to recognize tab page')
5701 # Common mistake: https://www.youtube.com/watch?list=playlist_id
5702 self
.report_warning(f
'A video URL was given without video ID. Trying to download playlist {playlist_id}')
5703 url
= f
'https://www.youtube.com/playlist?list={playlist_id}'
5704 mobj
= get_mobj(url
)
5706 if video_id
and playlist_id
:
5707 if self
.get_param('noplaylist'):
5708 self
.to_screen(f
'Downloading just video {video_id} because of --no-playlist')
5709 return self
.url_result(f
'https://www.youtube.com/watch?v={video_id}',
5710 ie
=YoutubeIE
.ie_key(), video_id
=video_id
)
5711 self
.to_screen(f
'Downloading playlist {playlist_id}; add --no-playlist to just download video {video_id}')
5713 data
, ytcfg
= self
._extract
_data
(url
, item_id
)
5715 # YouTube may provide a non-standard redirect to the regional channel
5716 # See: https://github.com/yt-dlp/yt-dlp/issues/2694
5717 redirect_url
= traverse_obj(
5718 data
, ('onResponseReceivedActions', ..., 'navigateAction', 'endpoint', 'commandMetadata', 'webCommandMetadata', 'url'), get_all
=False)
5719 if redirect_url
and 'no-youtube-channel-redirect' not in compat_opts
:
5720 redirect_url
= ''.join((
5721 urljoin('https://www.youtube.com', redirect_url
), mobj
['tab'], mobj
['post']))
5722 self
.to_screen(f
'This playlist is likely not available in your region. Following redirect to regional playlist {redirect_url}')
5723 return self
.url_result(redirect_url
, ie
=YoutubeTabIE
.ie_key())
5725 tabs
= traverse_obj(data
, ('contents', 'twoColumnBrowseResultsRenderer', 'tabs'), expected_type
=list)
5727 selected_tab
= self
._extract
_selected
_tab
(tabs
)
5728 selected_tab_url
= urljoin(
5729 url
, traverse_obj(selected_tab
, ('endpoint', 'commandMetadata', 'webCommandMetadata', 'url')))
5730 translated_tab_name
= selected_tab
.get('title', '').lower()
5732 # Prefer tab name from tab url as it is always in en,
5733 # but only when preferred lang is set as it may not extract reliably in all cases.
5734 selected_tab_name
= (self
._preferred
_lang
in (None, 'en') and translated_tab_name
5735 or selected_tab_url
and get_mobj(selected_tab_url
)['tab'][1:] # primary
5736 or translated_tab_name
)
5738 if selected_tab_name
== 'home':
5739 selected_tab_name
= 'featured'
5740 requested_tab_name
= mobj
['tab'][1:]
5742 if 'no-youtube-channel-redirect' not in compat_opts
:
5743 if requested_tab_name
== 'live': # Live tab should have redirected to the video
5744 raise UserNotLive(video_id
=mobj
['id'])
5745 if requested_tab_name
not in ('', selected_tab_name
):
5746 redirect_warning
= f
'The channel does not have a {requested_tab_name} tab'
5747 if not original_tab_name
:
5748 if item_id
[:2] == 'UC':
5749 # Topic channels don't have /videos. Use the equivalent playlist instead
5750 pl_id
= f
'UU{item_id[2:]}'
5751 pl_url
= f
'https://www.youtube.com/playlist?list={pl_id}'
5753 data
, ytcfg
= self
._extract
_data
(pl_url
, pl_id
, ytcfg
=ytcfg
, fatal
=True, webpage_fatal
=True)
5754 except ExtractorError
:
5755 redirect_warning
+= ' and the playlist redirect gave error'
5757 item_id
, url
, selected_tab_name
= pl_id
, pl_url
, requested_tab_name
5758 redirect_warning
+= f
'. Redirecting to playlist {pl_id} instead'
5759 if selected_tab_name
and selected_tab_name
!= requested_tab_name
:
5760 redirect_warning
+= f
'. {selected_tab_name} tab is being downloaded instead'
5762 raise ExtractorError(redirect_warning
, expected
=True)
5764 if redirect_warning
:
5765 self
.to_screen(redirect_warning
)
5766 self
.write_debug(f
'Final URL: {url}')
5768 # YouTube sometimes provides a button to reload playlist with unavailable videos.
5769 if 'no-youtube-unavailable-videos' not in compat_opts
:
5770 data
= self
._reload
_with
_unavailable
_videos
(item_id
, data
, ytcfg
) or data
5771 self
._extract
_and
_report
_alerts
(data
, only_once
=True)
5772 tabs
= traverse_obj(data
, ('contents', 'twoColumnBrowseResultsRenderer', 'tabs'), expected_type
=list)
5774 return self
._extract
_from
_tabs
(item_id
, ytcfg
, data
, tabs
)
5776 playlist
= traverse_obj(
5777 data
, ('contents', 'twoColumnWatchNextResults', 'playlist', 'playlist'), expected_type
=dict)
5779 return self
._extract
_from
_playlist
(item_id
, url
, data
, playlist
, ytcfg
)
5781 video_id
= traverse_obj(
5782 data
, ('currentVideoEndpoint', 'watchEndpoint', 'videoId'), expected_type
=str) or video_id
5784 if mobj
['tab'] != '/live': # live tab is expected to redirect to video
5785 self
.report_warning(f
'Unable to recognize playlist. Downloading just video {video_id}')
5786 return self
.url_result(f
'https://www.youtube.com/watch?v={video_id}',
5787 ie
=YoutubeIE
.ie_key(), video_id
=video_id
)
5789 raise ExtractorError('Unable to recognize tab page')
5792 class YoutubePlaylistIE(InfoExtractor
):
5793 IE_DESC
= 'YouTube playlists'
5794 _VALID_URL
= r
'''(?x)(?:
5799 youtube(?:kids)?\.com|
5804 (?P<id>%(playlist_id)s)
5806 'playlist_id': YoutubeBaseInfoExtractor
._PLAYLIST
_ID
_RE
,
5807 'invidious': '|'.join(YoutubeBaseInfoExtractor
._INVIDIOUS
_SITES
),
5809 IE_NAME
= 'youtube:playlist'
5811 'note': 'issue #673',
5812 'url': 'PLBB231211A4F62143',
5814 'title': '[OLD]Team Fortress 2 (Class-based LP)',
5815 'id': 'PLBB231211A4F62143',
5816 'uploader': 'Wickman',
5817 'uploader_id': 'UCKSpbfbl5kRQpTdL7kMc-1Q',
5818 'description': 'md5:8fa6f52abb47a9552002fa3ddfc57fc2',
5820 'uploader_url': 'https://www.youtube.com/user/Wickydoo',
5821 'modified_date': r
're:\d{8}',
5822 'channel_id': 'UCKSpbfbl5kRQpTdL7kMc-1Q',
5823 'channel': 'Wickman',
5825 'channel_url': 'https://www.youtube.com/user/Wickydoo',
5827 'playlist_mincount': 29,
5829 'url': 'PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl',
5831 'title': 'YDL_safe_search',
5832 'id': 'PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl',
5834 'playlist_count': 2,
5835 'skip': 'This playlist is private',
5838 'url': 'https://www.youtube.com/embed/videoseries?list=PL6IaIsEjSbf96XFRuNccS_RuEXwNdsoEu',
5839 'playlist_count': 4,
5842 'id': 'PL6IaIsEjSbf96XFRuNccS_RuEXwNdsoEu',
5843 'uploader': 'milan',
5844 'uploader_id': 'UCEI1-PVPcYXjB73Hfelbmaw',
5846 'channel_url': 'https://www.youtube.com/channel/UCEI1-PVPcYXjB73Hfelbmaw',
5848 'modified_date': '20140919',
5851 'channel_id': 'UCEI1-PVPcYXjB73Hfelbmaw',
5852 'uploader_url': 'https://www.youtube.com/channel/UCEI1-PVPcYXjB73Hfelbmaw',
5853 'availability': 'public',
5855 'expected_warnings': [r
'[Uu]navailable videos (are|will be) hidden'],
5857 'url': 'http://www.youtube.com/embed/_xDOZElKyNU?list=PLsyOSbh5bs16vubvKePAQ1x3PhKavfBIl',
5858 'playlist_mincount': 455,
5860 'title': '2018 Chinese New Singles (11/6 updated)',
5861 'id': 'PLsyOSbh5bs16vubvKePAQ1x3PhKavfBIl',
5863 'uploader_id': 'UC21nz3_MesPLqtDqwdvnoxA',
5864 'description': 'md5:da521864744d60a198e3a88af4db0d9d',
5867 'channel_url': 'https://www.youtube.com/c/愛低音的國王',
5869 'uploader_url': 'https://www.youtube.com/c/愛低音的國王',
5870 'channel_id': 'UC21nz3_MesPLqtDqwdvnoxA',
5871 'modified_date': r
're:\d{8}',
5872 'availability': 'public',
5874 'expected_warnings': [r
'[Uu]navailable videos (are|will be) hidden'],
5876 'url': 'TLGGrESM50VT6acwMjAyMjAxNw',
5877 'only_matching': True,
5879 # music album playlist
5880 'url': 'OLAK5uy_m4xAFdmMC5rX3Ji3g93pQe3hqLZw_9LhM',
5881 'only_matching': True,
5885 def suitable(cls
, url
):
5886 if YoutubeTabIE
.suitable(url
):
5888 from ..utils
import parse_qs
5890 if qs
.get('v', [None])[0]:
5892 return super().suitable(url
)
5894 def _real_extract(self
, url
):
5895 playlist_id
= self
._match
_id
(url
)
5896 is_music_url
= YoutubeBaseInfoExtractor
.is_music_url(url
)
5897 url
= update_url_query(
5898 'https://www.youtube.com/playlist',
5899 parse_qs(url
) or {'list': playlist_id}
)
5901 url
= smuggle_url(url
, {'is_music_url': True}
)
5902 return self
.url_result(url
, ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
)
5905 class YoutubeYtBeIE(InfoExtractor
):
5906 IE_DESC
= 'youtu.be'
5907 _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}
5909 'url': 'https://youtu.be/yeWKywCrFtk?list=PL2qgrgXsNUG5ig9cat4ohreBjYLAPC0J5',
5911 'id': 'yeWKywCrFtk',
5913 'title': 'Small Scale Baler and Braiding Rugs',
5914 'uploader': 'Backus-Page House Museum',
5915 'uploader_id': 'backuspagemuseum',
5916 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/user/backuspagemuseum',
5917 'upload_date': '20161008',
5918 'description': 'md5:800c0c78d5eb128500bffd4f0b4f2e8a',
5919 'categories': ['Nonprofits & Activism'],
5923 'playable_in_embed': True,
5924 'thumbnail': 'https://i.ytimg.com/vi_webp/yeWKywCrFtk/maxresdefault.webp',
5925 'channel': 'Backus-Page House Museum',
5926 'channel_id': 'UCEfMCQ9bs3tjvjy1s451zaw',
5927 'live_status': 'not_live',
5929 'channel_url': 'https://www.youtube.com/channel/UCEfMCQ9bs3tjvjy1s451zaw',
5930 'availability': 'public',
5932 'comment_count': int,
5933 'channel_follower_count': int
5937 'skip_download': True,
5940 'url': 'https://youtu.be/uWyaPkt-VOI?list=PL9D9FC436B881BA21',
5941 'only_matching': True,
5944 def _real_extract(self
, url
):
5945 mobj
= self
._match
_valid
_url
(url
)
5946 video_id
= mobj
.group('id')
5947 playlist_id
= mobj
.group('playlist_id')
5948 return self
.url_result(
5949 update_url_query('https://www.youtube.com/watch', {
5951 'list': playlist_id
,
5952 'feature': 'youtu.be',
5953 }), ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
)
5956 class YoutubeLivestreamEmbedIE(InfoExtractor
):
5957 IE_DESC
= 'YouTube livestream embeds'
5958 _VALID_URL
= r
'https?://(?:\w+\.)?youtube\.com/embed/live_stream/?\?(?:[^#]+&)?channel=(?P<id>[^&#]+)'
5960 'url': 'https://www.youtube.com/embed/live_stream?channel=UC2_KI6RB__jGdlnK6dvFEZA',
5961 'only_matching': True,
5964 def _real_extract(self
, url
):
5965 channel_id
= self
._match
_id
(url
)
5966 return self
.url_result(
5967 f
'https://www.youtube.com/channel/{channel_id}/live',
5968 ie
=YoutubeTabIE
.ie_key(), video_id
=channel_id
)
5971 class YoutubeYtUserIE(InfoExtractor
):
5972 IE_DESC
= 'YouTube user videos; "ytuser:" prefix'
5973 IE_NAME
= 'youtube:user'
5974 _VALID_URL
= r
'ytuser:(?P<id>.+)'
5976 'url': 'ytuser:phihag',
5977 'only_matching': True,
5980 def _real_extract(self
, url
):
5981 user_id
= self
._match
_id
(url
)
5982 return self
.url_result(
5983 'https://www.youtube.com/user/%s/videos' % user_id
,
5984 ie
=YoutubeTabIE
.ie_key(), video_id
=user_id
)
5987 class YoutubeFavouritesIE(YoutubeBaseInfoExtractor
):
5988 IE_NAME
= 'youtube:favorites'
5989 IE_DESC
= 'YouTube liked videos; ":ytfav" keyword (requires cookies)'
5990 _VALID_URL
= r
':ytfav(?:ou?rite)?s?'
5991 _LOGIN_REQUIRED
= True
5994 'only_matching': True,
5996 'url': ':ytfavorites',
5997 'only_matching': True,
6000 def _real_extract(self
, url
):
6001 return self
.url_result(
6002 'https://www.youtube.com/playlist?list=LL',
6003 ie
=YoutubeTabIE
.ie_key())
6006 class YoutubeNotificationsIE(YoutubeTabBaseInfoExtractor
):
6007 IE_NAME
= 'youtube:notif'
6008 IE_DESC
= 'YouTube notifications; ":ytnotif" keyword (requires cookies)'
6009 _VALID_URL
= r
':ytnotif(?:ication)?s?'
6010 _LOGIN_REQUIRED
= True
6013 'only_matching': True,
6015 'url': ':ytnotifications',
6016 'only_matching': True,
6019 def _extract_notification_menu(self
, response
, continuation_list
):
6020 notification_list
= traverse_obj(
6022 ('actions', 0, 'openPopupAction', 'popup', 'multiPageMenuRenderer', 'sections', 0, 'multiPageMenuNotificationSectionRenderer', 'items'),
6023 ('actions', 0, 'appendContinuationItemsAction', 'continuationItems'),
6024 expected_type
=list) or []
6025 continuation_list
[0] = None
6026 for item
in notification_list
:
6027 entry
= self
._extract
_notification
_renderer
(item
.get('notificationRenderer'))
6030 continuation
= item
.get('continuationItemRenderer')
6032 continuation_list
[0] = continuation
6034 def _extract_notification_renderer(self
, notification
):
6035 video_id
= traverse_obj(
6036 notification
, ('navigationEndpoint', 'watchEndpoint', 'videoId'), expected_type
=str)
6037 url
= f
'https://www.youtube.com/watch?v={video_id}'
6040 browse_ep
= traverse_obj(
6041 notification
, ('navigationEndpoint', 'browseEndpoint'), expected_type
=dict)
6042 channel_id
= traverse_obj(browse_ep
, 'browseId', expected_type
=str)
6043 post_id
= self
._search
_regex
(
6044 r
'/post/(.+)', traverse_obj(browse_ep
, 'canonicalBaseUrl', expected_type
=str),
6045 'post id', default
=None)
6046 if not channel_id
or not post_id
:
6048 # The direct /post url redirects to this in the browser
6049 url
= f
'https://www.youtube.com/channel/{channel_id}/community?lb={post_id}'
6051 channel
= traverse_obj(
6052 notification
, ('contextualMenu', 'menuRenderer', 'items', 1, 'menuServiceItemRenderer', 'text', 'runs', 1, 'text'),
6054 notification_title
= self
._get
_text
(notification
, 'shortMessage')
6055 if notification_title
:
6056 notification_title
= notification_title
.replace('\xad', '') # remove soft hyphens
6057 # TODO: handle recommended videos
6058 title
= self
._search
_regex
(
6059 rf
'{re.escape(channel or "")}[^:]+: (.+)', notification_title
,
6060 'video title', default
=None)
6061 upload_date
= (strftime_or_none(self
._parse
_time
_text
(self
._get
_text
(notification
, 'sentTimeText')), '%Y%m%d')
6062 if self
._configuration
_arg
('approximate_date', ie_key
=YoutubeTabIE
.ie_key())
6067 'ie_key': (YoutubeIE
if video_id
else YoutubeTabIE
).ie_key(),
6068 'video_id': video_id
,
6070 'channel_id': channel_id
,
6072 'thumbnails': self
._extract
_thumbnails
(notification
, 'videoThumbnail'),
6073 'upload_date': upload_date
,
6076 def _notification_menu_entries(self
, ytcfg
):
6077 continuation_list
= [None]
6079 for page
in itertools
.count(1):
6080 ctoken
= traverse_obj(
6081 continuation_list
, (0, 'continuationEndpoint', 'getNotificationMenuEndpoint', 'ctoken'), expected_type
=str)
6082 response
= self
._extract
_response
(
6083 item_id
=f
'page {page}', query
={'ctoken': ctoken}
if ctoken
else {}, ytcfg
=ytcfg
,
6084 ep
='notification/get_notification_menu', check_get_keys
='actions',
6085 headers
=self
.generate_api_headers(ytcfg
=ytcfg
, visitor_data
=self
._extract
_visitor
_data
(response
)))
6086 yield from self
._extract
_notification
_menu
(response
, continuation_list
)
6087 if not continuation_list
[0]:
6090 def _real_extract(self
, url
):
6091 display_id
= 'notifications'
6092 ytcfg
= self
._download
_ytcfg
('web', display_id
) if not self
.skip_webpage
else {}
6093 self
._report
_playlist
_authcheck
(ytcfg
)
6094 return self
.playlist_result(self
._notification
_menu
_entries
(ytcfg
), display_id
, display_id
)
6097 class YoutubeSearchIE(YoutubeTabBaseInfoExtractor
, SearchInfoExtractor
):
6098 IE_DESC
= 'YouTube search'
6099 IE_NAME
= 'youtube:search'
6100 _SEARCH_KEY
= 'ytsearch'
6101 _SEARCH_PARAMS
= 'EgIQAQ%3D%3D' # Videos only
6103 'url': 'ytsearch5:youtube-dl test video',
6104 'playlist_count': 5,
6106 'id': 'youtube-dl test video',
6107 'title': 'youtube-dl test video',
6112 class YoutubeSearchDateIE(YoutubeTabBaseInfoExtractor
, SearchInfoExtractor
):
6113 IE_NAME
= YoutubeSearchIE
.IE_NAME
+ ':date'
6114 _SEARCH_KEY
= 'ytsearchdate'
6115 IE_DESC
= 'YouTube search, newest videos first'
6116 _SEARCH_PARAMS
= 'CAISAhAB' # Videos only, sorted by date
6118 'url': 'ytsearchdate5:youtube-dl test video',
6119 'playlist_count': 5,
6121 'id': 'youtube-dl test video',
6122 'title': 'youtube-dl test video',
6127 class YoutubeSearchURLIE(YoutubeTabBaseInfoExtractor
):
6128 IE_DESC
= 'YouTube search URLs with sorting and filter support'
6129 IE_NAME
= YoutubeSearchIE
.IE_NAME
+ '_url'
6130 _VALID_URL
= r
'https?://(?:www\.)?youtube\.com/(?:results|search)\?([^#]+&)?(?:search_query|q)=(?:[^&]+)(?:[&#]|$)'
6132 'url': 'https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video',
6133 'playlist_mincount': 5,
6135 'id': 'youtube-dl test video',
6136 'title': 'youtube-dl test video',
6139 'url': 'https://www.youtube.com/results?search_query=python&sp=EgIQAg%253D%253D',
6140 'playlist_mincount': 5,
6146 'url': 'https://www.youtube.com/results?search_query=%23cats',
6147 'playlist_mincount': 1,
6151 # The test suite does not have support for nested playlists
6153 # 'url': r're:https://(www\.)?youtube\.com/hashtag/cats',
6158 'url': 'https://www.youtube.com/results?q=test&sp=EgQIBBgB',
6159 'only_matching': True,
6162 def _real_extract(self
, url
):
6164 query
= (qs
.get('search_query') or qs
.get('q'))[0]
6165 return self
.playlist_result(self
._search
_results
(query
, qs
.get('sp', (None,))[0]), query
, query
)
6168 class YoutubeMusicSearchURLIE(YoutubeTabBaseInfoExtractor
):
6169 IE_DESC
= 'YouTube music search URLs with selectable sections, e.g. #songs'
6170 IE_NAME
= 'youtube:music:search_url'
6171 _VALID_URL
= r
'https?://music\.youtube\.com/search\?([^#]+&)?(?:search_query|q)=(?:[^&]+)(?:[&#]|$)'
6173 'url': 'https://music.youtube.com/search?q=royalty+free+music',
6174 'playlist_count': 16,
6176 'id': 'royalty free music',
6177 'title': 'royalty free music',
6180 'url': 'https://music.youtube.com/search?q=royalty+free+music&sp=EgWKAQIIAWoKEAoQAxAEEAkQBQ%3D%3D',
6181 'playlist_mincount': 30,
6183 'id': 'royalty free music - songs',
6184 'title': 'royalty free music - songs',
6186 'params': {'extract_flat': 'in_playlist'}
6188 'url': 'https://music.youtube.com/search?q=royalty+free+music#community+playlists',
6189 'playlist_mincount': 30,
6191 'id': 'royalty free music - community playlists',
6192 'title': 'royalty free music - community playlists',
6194 'params': {'extract_flat': 'in_playlist'}
6198 'albums': 'EgWKAQIYAWoKEAoQAxAEEAkQBQ==',
6199 'artists': 'EgWKAQIgAWoKEAoQAxAEEAkQBQ==',
6200 'community playlists': 'EgeKAQQoAEABagoQChADEAQQCRAF',
6201 'featured playlists': 'EgeKAQQoADgBagwQAxAJEAQQDhAKEAU==',
6202 'songs': 'EgWKAQIIAWoKEAoQAxAEEAkQBQ==',
6203 'videos': 'EgWKAQIQAWoKEAoQAxAEEAkQBQ==',
6206 def _real_extract(self
, url
):
6208 query
= (qs
.get('search_query') or qs
.get('q'))[0]
6209 params
= qs
.get('sp', (None,))[0]
6211 section
= next((k
for k
, v
in self
._SECTIONS
.items() if v
== params
), params
)
6213 section
= urllib
.parse
.unquote_plus((url
.split('#') + [''])[1]).lower()
6214 params
= self
._SECTIONS
.get(section
)
6217 title
= join_nonempty(query
, section
, delim
=' - ')
6218 return self
.playlist_result(self
._search
_results
(query
, params
, default_client
='web_music'), title
, title
)
6221 class YoutubeFeedsInfoExtractor(InfoExtractor
):
6223 Base class for feed extractors
6224 Subclasses must re-define the _FEED_NAME property.
6226 _LOGIN_REQUIRED
= True
6227 _FEED_NAME
= 'feeds'
6229 def _real_initialize(self
):
6230 YoutubeBaseInfoExtractor
._check
_login
_required
(self
)
6234 return f
'youtube:{self._FEED_NAME}'
6236 def _real_extract(self
, url
):
6237 return self
.url_result(
6238 f
'https://www.youtube.com/feed/{self._FEED_NAME}', ie
=YoutubeTabIE
.ie_key())
6241 class YoutubeWatchLaterIE(InfoExtractor
):
6242 IE_NAME
= 'youtube:watchlater'
6243 IE_DESC
= 'Youtube watch later list; ":ytwatchlater" keyword (requires cookies)'
6244 _VALID_URL
= r
':ytwatchlater'
6246 'url': ':ytwatchlater',
6247 'only_matching': True,
6250 def _real_extract(self
, url
):
6251 return self
.url_result(
6252 'https://www.youtube.com/playlist?list=WL', ie
=YoutubeTabIE
.ie_key())
6255 class YoutubeRecommendedIE(YoutubeFeedsInfoExtractor
):
6256 IE_DESC
= 'YouTube recommended videos; ":ytrec" keyword'
6257 _VALID_URL
= r
'https?://(?:www\.)?youtube\.com/?(?:[?#]|$)|:ytrec(?:ommended)?'
6258 _FEED_NAME
= 'recommended'
6259 _LOGIN_REQUIRED
= False
6262 'only_matching': True,
6264 'url': ':ytrecommended',
6265 'only_matching': True,
6267 'url': 'https://youtube.com',
6268 'only_matching': True,
6272 class YoutubeSubscriptionsIE(YoutubeFeedsInfoExtractor
):
6273 IE_DESC
= 'YouTube subscriptions feed; ":ytsubs" keyword (requires cookies)'
6274 _VALID_URL
= r
':ytsub(?:scription)?s?'
6275 _FEED_NAME
= 'subscriptions'
6278 'only_matching': True,
6280 'url': ':ytsubscriptions',
6281 'only_matching': True,
6285 class YoutubeHistoryIE(YoutubeFeedsInfoExtractor
):
6286 IE_DESC
= 'Youtube watch history; ":ythis" keyword (requires cookies)'
6287 _VALID_URL
= r
':ythis(?:tory)?'
6288 _FEED_NAME
= 'history'
6290 'url': ':ythistory',
6291 'only_matching': True,
6295 class YoutubeStoriesIE(InfoExtractor
):
6296 IE_DESC
= 'YouTube channel stories; "ytstories:" prefix'
6297 IE_NAME
= 'youtube:stories'
6298 _VALID_URL
= r
'ytstories:UC(?P<id>[A-Za-z0-9_-]{21}[AQgw])$'
6300 'url': 'ytstories:UCwFCb4jeqaKWnciAYM-ZVHg',
6301 'only_matching': True,
6304 def _real_extract(self
, url
):
6305 playlist_id
= f
'RLTD{self._match_id(url)}'
6306 return self
.url_result(
6307 smuggle_url(f
'https://www.youtube.com/playlist?list={playlist_id}&playnext=1', {'is_story': True}
),
6308 ie
=YoutubeTabIE
, video_id
=playlist_id
)
6311 class YoutubeShortsAudioPivotIE(InfoExtractor
):
6312 IE_DESC
= 'YouTube Shorts audio pivot (Shorts using audio of a given video)'
6313 IE_NAME
= 'youtube:shorts:pivot:audio'
6314 _VALID_URL
= r
'https?://(?:www\.)?youtube\.com/source/(?P<id>[\w-]{11})/shorts'
6316 'url': 'https://www.youtube.com/source/Lyj-MZSAA9o/shorts',
6317 'only_matching': True,
6321 def _generate_audio_pivot_params(video_id
):
6323 Generates sfv_audio_pivot browse params for this video id
6325 pb_params
= b
'\xf2\x05+\n)\x12\'\n\x0b%b\x12\x0b%b\x1a\x0b%b' % ((video_id
.encode(),) * 3)
6326 return urllib
.parse
.quote(base64
.b64encode(pb_params
).decode())
6328 def _real_extract(self
, url
):
6329 video_id
= self
._match
_id
(url
)
6330 return self
.url_result(
6331 f
'https://www.youtube.com/feed/sfv_audio_pivot?bp={self._generate_audio_pivot_params(video_id)}',
6335 class YoutubeTruncatedURLIE(InfoExtractor
):
6336 IE_NAME
= 'youtube:truncated_url'
6337 IE_DESC
= False # Do not list
6338 _VALID_URL
= r
'''(?x)
6340 (?:\w+\.)?[yY][oO][uU][tT][uU][bB][eE](?:-nocookie)?\.com/
6343 annotation_id=annotation_[^&]+|
6349 attribution_link\?a=[^&]+
6355 'url': 'https://www.youtube.com/watch?annotation_id=annotation_3951667041',
6356 'only_matching': True,
6358 'url': 'https://www.youtube.com/watch?',
6359 'only_matching': True,
6361 'url': 'https://www.youtube.com/watch?x-yt-cl=84503534',
6362 'only_matching': True,
6364 'url': 'https://www.youtube.com/watch?feature=foo',
6365 'only_matching': True,
6367 'url': 'https://www.youtube.com/watch?hl=en-GB',
6368 'only_matching': True,
6370 'url': 'https://www.youtube.com/watch?t=2372',
6371 'only_matching': True,
6374 def _real_extract(self
, url
):
6375 raise ExtractorError(
6376 'Did you forget to quote the URL? Remember that & is a meta '
6377 'character in most shells, so you want to put the URL in quotes, '
6379 '"https://www.youtube.com/watch?feature=foo&v=BaW_jenozKc" '
6380 ' or simply youtube-dl BaW_jenozKc .',
6384 class YoutubeClipIE(YoutubeTabBaseInfoExtractor
):
6385 IE_NAME
= 'youtube:clip'
6386 _VALID_URL
= r
'https?://(?:www\.)?youtube\.com/clip/(?P<id>[^/?#]+)'
6388 # FIXME: Other metadata should be extracted from the clip, not from the base video
6389 'url': 'https://www.youtube.com/clip/UgytZKpehg-hEMBSn3F4AaABCQ',
6391 'id': 'UgytZKpehg-hEMBSn3F4AaABCQ',
6393 'section_start': 29.0,
6394 'section_end': 39.7,
6397 'availability': 'public',
6398 'categories': ['Gaming'],
6399 'channel': 'Scott The Woz',
6400 'channel_id': 'UC4rqhyiTs7XyuODcECvuiiQ',
6401 'channel_url': 'https://www.youtube.com/channel/UC4rqhyiTs7XyuODcECvuiiQ',
6402 'description': 'md5:7a4517a17ea9b4bd98996399d8bb36e7',
6404 'playable_in_embed': True,
6406 'thumbnail': 'https://i.ytimg.com/vi_webp/ScPX26pdQik/maxresdefault.webp',
6407 'title': 'Mobile Games on Console - Scott The Woz',
6408 'upload_date': '20210920',
6409 'uploader': 'Scott The Woz',
6410 'uploader_id': 'scottthewoz',
6411 'uploader_url': 'http://www.youtube.com/user/scottthewoz',
6413 'live_status': 'not_live',
6414 'channel_follower_count': int
6418 def _real_extract(self
, url
):
6419 clip_id
= self
._match
_id
(url
)
6420 _
, data
= self
._extract
_webpage
(url
, clip_id
)
6422 video_id
= traverse_obj(data
, ('currentVideoEndpoint', 'watchEndpoint', 'videoId'))
6424 raise ExtractorError('Unable to find video ID')
6426 clip_data
= traverse_obj(data
, (
6427 'engagementPanels', ..., 'engagementPanelSectionListRenderer', 'content', 'clipSectionRenderer',
6428 'contents', ..., 'clipAttributionRenderer', 'onScrubExit', 'commandExecutorCommand', 'commands', ...,
6429 'openPopupAction', 'popup', 'notificationActionRenderer', 'actionButton', 'buttonRenderer', 'command',
6430 'commandExecutorCommand', 'commands', ..., 'loopCommand'), get_all
=False)
6433 '_type': 'url_transparent',
6434 'url': f
'https://www.youtube.com/watch?v={video_id}',
6435 'ie_key': YoutubeIE
.ie_key(),
6437 'section_start': int(clip_data
['startTimeMs']) / 1000,
6438 'section_end': int(clip_data
['endTimeMs']) / 1000,
6442 class YoutubeTruncatedIDIE(InfoExtractor
):
6443 IE_NAME
= 'youtube:truncated_id'
6444 IE_DESC
= False # Do not list
6445 _VALID_URL
= r
'https?://(?:www\.)?youtube\.com/watch\?v=(?P<id>[0-9A-Za-z_-]{1,10})$'
6448 'url': 'https://www.youtube.com/watch?v=N_708QY7Ob',
6449 'only_matching': True,
6452 def _real_extract(self
, url
):
6453 video_id
= self
._match
_id
(url
)
6454 raise ExtractorError(
6455 f
'Incomplete YouTube ID {video_id}. URL {url} looks truncated.',