21 from .common
import InfoExtractor
, SearchInfoExtractor
22 from .openload
import PhantomJSwrapper
23 from ..compat
import functools
24 from ..jsinterp
import JSInterpreter
25 from ..networking
.exceptions
import HTTPError
, network_exceptions
71 STREAMING_DATA_CLIENT_NAME
= '__yt_dlp_client'
72 # any clients starting with _ cannot be explicitly requested by the user
75 'INNERTUBE_API_KEY': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
76 'INNERTUBE_CONTEXT': {
79 'clientVersion': '2.20220801.00.00',
82 'INNERTUBE_CONTEXT_CLIENT_NAME': 1
85 'INNERTUBE_API_KEY': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
86 'INNERTUBE_CONTEXT': {
88 'clientName': 'WEB_EMBEDDED_PLAYER',
89 'clientVersion': '1.20220731.00.00',
92 'INNERTUBE_CONTEXT_CLIENT_NAME': 56
95 'INNERTUBE_API_KEY': 'AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30',
96 'INNERTUBE_HOST': 'music.youtube.com',
97 'INNERTUBE_CONTEXT': {
99 'clientName': 'WEB_REMIX',
100 'clientVersion': '1.20220727.01.00',
103 'INNERTUBE_CONTEXT_CLIENT_NAME': 67,
106 'INNERTUBE_API_KEY': 'AIzaSyBUPetSUmoZL-OhlxA7wSac5XinrygCqMo',
107 'INNERTUBE_CONTEXT': {
109 'clientName': 'WEB_CREATOR',
110 'clientVersion': '1.20220726.00.00',
113 'INNERTUBE_CONTEXT_CLIENT_NAME': 62,
116 'INNERTUBE_API_KEY': 'AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w',
117 'INNERTUBE_CONTEXT': {
119 'clientName': 'ANDROID',
120 'clientVersion': '19.09.37',
121 'androidSdkVersion': 30,
122 'userAgent': 'com.google.android.youtube/19.09.37 (Linux; U; Android 11) gzip'
125 'INNERTUBE_CONTEXT_CLIENT_NAME': 3,
126 'REQUIRE_JS_PLAYER': False
128 'android_embedded': {
129 'INNERTUBE_API_KEY': 'AIzaSyCjc_pVEDi4qsv5MtC2dMXzpIaDoRFLsxw',
130 'INNERTUBE_CONTEXT': {
132 'clientName': 'ANDROID_EMBEDDED_PLAYER',
133 'clientVersion': '19.09.37',
134 'androidSdkVersion': 30,
135 'userAgent': 'com.google.android.youtube/19.09.37 (Linux; U; Android 11) gzip'
138 'INNERTUBE_CONTEXT_CLIENT_NAME': 55,
139 'REQUIRE_JS_PLAYER': False
142 'INNERTUBE_API_KEY': 'AIzaSyAOghZGza2MQSZkY_zfZ370N-PUdXEo8AI',
143 'INNERTUBE_CONTEXT': {
145 'clientName': 'ANDROID_MUSIC',
146 'clientVersion': '6.42.52',
147 'androidSdkVersion': 30,
148 'userAgent': 'com.google.android.apps.youtube.music/6.42.52 (Linux; U; Android 11) gzip'
151 'INNERTUBE_CONTEXT_CLIENT_NAME': 21,
152 'REQUIRE_JS_PLAYER': False
155 'INNERTUBE_API_KEY': 'AIzaSyD_qjV8zaaUMehtLkrKFgVeSX_Iqbtyws8',
156 'INNERTUBE_CONTEXT': {
158 'clientName': 'ANDROID_CREATOR',
159 'clientVersion': '22.30.100',
160 'androidSdkVersion': 30,
161 'userAgent': 'com.google.android.apps.youtube.creator/22.30.100 (Linux; U; Android 11) gzip'
164 'INNERTUBE_CONTEXT_CLIENT_NAME': 14,
165 'REQUIRE_JS_PLAYER': False
167 # iOS clients have HLS live streams. Setting device model to get 60fps formats.
168 # See: https://github.com/TeamNewPipe/NewPipeExtractor/issues/680#issuecomment-1002724558
170 'INNERTUBE_API_KEY': 'AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc',
171 'INNERTUBE_CONTEXT': {
174 'clientVersion': '19.09.3',
175 'deviceModel': 'iPhone14,3',
176 'userAgent': 'com.google.ios.youtube/19.09.3 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)'
179 'INNERTUBE_CONTEXT_CLIENT_NAME': 5,
180 'REQUIRE_JS_PLAYER': False
183 'INNERTUBE_CONTEXT': {
185 'clientName': 'IOS_MESSAGES_EXTENSION',
186 'clientVersion': '19.09.3',
187 'deviceModel': 'iPhone14,3',
188 'userAgent': 'com.google.ios.youtube/19.09.3 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)'
191 'INNERTUBE_CONTEXT_CLIENT_NAME': 66,
192 'REQUIRE_JS_PLAYER': False
195 'INNERTUBE_API_KEY': 'AIzaSyBAETezhkwP0ZWA02RsqT1zu78Fpt0bC_s',
196 'INNERTUBE_CONTEXT': {
198 'clientName': 'IOS_MUSIC',
199 'clientVersion': '6.33.3',
200 'deviceModel': 'iPhone14,3',
201 'userAgent': 'com.google.ios.youtubemusic/6.33.3 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)'
204 'INNERTUBE_CONTEXT_CLIENT_NAME': 26,
205 'REQUIRE_JS_PLAYER': False
208 'INNERTUBE_CONTEXT': {
210 'clientName': 'IOS_CREATOR',
211 'clientVersion': '22.33.101',
212 'deviceModel': 'iPhone14,3',
213 'userAgent': 'com.google.ios.ytcreator/22.33.101 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)'
216 'INNERTUBE_CONTEXT_CLIENT_NAME': 15,
217 'REQUIRE_JS_PLAYER': False
219 # mweb has 'ultralow' formats
220 # See: https://github.com/yt-dlp/yt-dlp/pull/557
222 'INNERTUBE_API_KEY': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
223 'INNERTUBE_CONTEXT': {
225 'clientName': 'MWEB',
226 'clientVersion': '2.20220801.00.00',
229 'INNERTUBE_CONTEXT_CLIENT_NAME': 2
231 # This client can access age restricted videos (unless the uploader has disabled the 'allow embedding' option)
232 # See: https://github.com/zerodytrash/YouTube-Internal-Clients
234 'INNERTUBE_API_KEY': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
235 'INNERTUBE_CONTEXT': {
237 'clientName': 'TVHTML5_SIMPLY_EMBEDDED_PLAYER',
238 'clientVersion': '2.0',
241 'INNERTUBE_CONTEXT_CLIENT_NAME': 85
246 def _split_innertube_client(client_name
):
247 variant
, *base
= client_name
.rsplit('.', 1)
249 return variant
, base
[0], variant
250 base
, *variant
= client_name
.split('_', 1)
251 return client_name
, base
, variant
[0] if variant
else None
254 def short_client_name(client_name
):
255 main
, *parts
= _split_innertube_client(client_name
)[0].replace('embedscreen', 'e_s').split('_')
256 return join_nonempty(main
[:4], ''.join(x
[0] for x
in parts
)).upper()
259 def build_innertube_clients():
261 'embedUrl': 'https://www.youtube.com/', # Can be any valid URL
263 BASE_CLIENTS
= ('ios', 'android', 'web', 'tv', 'mweb')
264 priority
= qualities(BASE_CLIENTS
[::-1])
266 for client
, ytcfg
in tuple(INNERTUBE_CLIENTS
.items()):
267 ytcfg
.setdefault('INNERTUBE_API_KEY', 'AIzaSyDCU8hByM-4DrUqRUYnGn-3llEO78bcxq8')
268 ytcfg
.setdefault('INNERTUBE_HOST', 'www.youtube.com')
269 ytcfg
.setdefault('REQUIRE_JS_PLAYER', True)
270 ytcfg
['INNERTUBE_CONTEXT']['client'].setdefault('hl', 'en')
272 _
, base_client
, variant
= _split_innertube_client(client
)
273 ytcfg
['priority'] = 10 * priority(base_client
)
276 INNERTUBE_CLIENTS
[f
'{client}_embedscreen'] = embedscreen
= copy
.deepcopy(ytcfg
)
277 embedscreen
['INNERTUBE_CONTEXT']['client']['clientScreen'] = 'EMBED'
278 embedscreen
['INNERTUBE_CONTEXT']['thirdParty'] = THIRD_PARTY
279 embedscreen
['priority'] -= 3
280 elif variant
== 'embedded':
281 ytcfg
['INNERTUBE_CONTEXT']['thirdParty'] = THIRD_PARTY
282 ytcfg
['priority'] -= 2
284 ytcfg
['priority'] -= 3
287 build_innertube_clients()
290 class BadgeType(enum
.Enum
):
291 AVAILABILITY_UNLISTED
= enum
.auto()
292 AVAILABILITY_PRIVATE
= enum
.auto()
293 AVAILABILITY_PUBLIC
= enum
.auto()
294 AVAILABILITY_PREMIUM
= enum
.auto()
295 AVAILABILITY_SUBSCRIPTION
= enum
.auto()
296 LIVE_NOW
= enum
.auto()
297 VERIFIED
= enum
.auto()
300 class YoutubeBaseInfoExtractor(InfoExtractor
):
301 """Provide base functions for Youtube extractors"""
304 r
'channel|c|user|playlist|watch|w|v|embed|e|live|watch_popup|clip|'
305 r
'shorts|movies|results|search|shared|hashtag|trending|explore|feed|feeds|'
306 r
'browse|oembed|get_video_info|iframe_api|s/player|source|'
307 r
'storefront|oops|index|account|t/terms|about|upload|signin|logout')
309 _PLAYLIST_ID_RE
= r
'(?:(?:PL|LL|EC|UU|FL|RD|UL|TL|PU|OLAK5uy_)[0-9A-Za-z-_]{10,}|RDMM|WL|LL|LM)'
311 # _NETRC_MACHINE = 'youtube'
313 # If True it will raise an error if no login info is provided
314 _LOGIN_REQUIRED
= False
317 # invidious-redirect websites
318 r
'(?:www\.)?redirect\.invidious\.io',
319 r
'(?:(?:www|dev)\.)?invidio\.us',
320 # Invidious instances taken from https://github.com/iv-org/documentation/blob/master/docs/instances.md
321 r
'(?:www\.)?invidious\.pussthecat\.org',
322 r
'(?:www\.)?invidious\.zee\.li',
323 r
'(?:www\.)?invidious\.ethibox\.fr',
324 r
'(?:www\.)?iv\.ggtyler\.dev',
325 r
'(?:www\.)?inv\.vern\.i2p',
326 r
'(?:www\.)?am74vkcrjp2d5v36lcdqgsj2m6x36tbrkhsruoegwfcizzabnfgf5zyd\.onion',
327 r
'(?:www\.)?inv\.riverside\.rocks',
328 r
'(?:www\.)?invidious\.silur\.me',
329 r
'(?:www\.)?inv\.bp\.projectsegfau\.lt',
330 r
'(?:www\.)?invidious\.g4c3eya4clenolymqbpgwz3q3tawoxw56yhzk4vugqrl6dtu3ejvhjid\.onion',
331 r
'(?:www\.)?invidious\.slipfox\.xyz',
332 r
'(?:www\.)?invidious\.esmail5pdn24shtvieloeedh7ehz3nrwcdivnfhfcedl7gf4kwddhkqd\.onion',
333 r
'(?:www\.)?inv\.vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad\.onion',
334 r
'(?:www\.)?invidious\.tiekoetter\.com',
335 r
'(?:www\.)?iv\.odysfvr23q5wgt7i456o5t3trw2cw5dgn56vbjfbq2m7xsc5vqbqpcyd\.onion',
336 r
'(?:www\.)?invidious\.nerdvpn\.de',
337 r
'(?:www\.)?invidious\.weblibre\.org',
338 r
'(?:www\.)?inv\.odyssey346\.dev',
339 r
'(?:www\.)?invidious\.dhusch\.de',
340 r
'(?:www\.)?iv\.melmac\.space',
341 r
'(?:www\.)?watch\.thekitty\.zone',
342 r
'(?:www\.)?invidious\.privacydev\.net',
343 r
'(?:www\.)?ng27owmagn5amdm7l5s3rsqxwscl5ynppnis5dqcasogkyxcfqn7psid\.onion',
344 r
'(?:www\.)?invidious\.drivet\.xyz',
345 r
'(?:www\.)?vid\.priv\.au',
346 r
'(?:www\.)?euxxcnhsynwmfidvhjf6uzptsmh4dipkmgdmcmxxuo7tunp3ad2jrwyd\.onion',
347 r
'(?:www\.)?inv\.vern\.cc',
348 r
'(?:www\.)?invidious\.esmailelbob\.xyz',
349 r
'(?:www\.)?invidious\.sethforprivacy\.com',
350 r
'(?:www\.)?yt\.oelrichsgarcia\.de',
351 r
'(?:www\.)?yt\.artemislena\.eu',
352 r
'(?:www\.)?invidious\.flokinet\.to',
353 r
'(?:www\.)?invidious\.baczek\.me',
354 r
'(?:www\.)?y\.com\.sb',
355 r
'(?:www\.)?invidious\.epicsite\.xyz',
356 r
'(?:www\.)?invidious\.lidarshield\.cloud',
357 r
'(?:www\.)?yt\.funami\.tech',
358 r
'(?:www\.)?invidious\.3o7z6yfxhbw7n3za4rss6l434kmv55cgw2vuziwuigpwegswvwzqipyd\.onion',
359 r
'(?:www\.)?osbivz6guyeahrwp2lnwyjk2xos342h4ocsxyqrlaopqjuhwn2djiiyd\.onion',
360 r
'(?:www\.)?u2cvlit75owumwpy4dj2hsmvkq7nvrclkpht7xgyye2pyoxhpmclkrad\.onion',
361 # youtube-dl invidious instances list
362 r
'(?:(?:www|no)\.)?invidiou\.sh',
363 r
'(?:(?:www|fi)\.)?invidious\.snopyta\.org',
364 r
'(?:www\.)?invidious\.kabi\.tk',
365 r
'(?:www\.)?invidious\.mastodon\.host',
366 r
'(?:www\.)?invidious\.zapashcanon\.fr',
367 r
'(?:www\.)?(?:invidious(?:-us)?|piped)\.kavin\.rocks',
368 r
'(?:www\.)?invidious\.tinfoil-hat\.net',
369 r
'(?:www\.)?invidious\.himiko\.cloud',
370 r
'(?:www\.)?invidious\.reallyancient\.tech',
371 r
'(?:www\.)?invidious\.tube',
372 r
'(?:www\.)?invidiou\.site',
373 r
'(?:www\.)?invidious\.site',
374 r
'(?:www\.)?invidious\.xyz',
375 r
'(?:www\.)?invidious\.nixnet\.xyz',
376 r
'(?:www\.)?invidious\.048596\.xyz',
377 r
'(?:www\.)?invidious\.drycat\.fr',
378 r
'(?:www\.)?inv\.skyn3t\.in',
379 r
'(?:www\.)?tube\.poal\.co',
380 r
'(?:www\.)?tube\.connect\.cafe',
381 r
'(?:www\.)?vid\.wxzm\.sx',
382 r
'(?:www\.)?vid\.mint\.lgbt',
383 r
'(?:www\.)?vid\.puffyan\.us',
384 r
'(?:www\.)?yewtu\.be',
385 r
'(?:www\.)?yt\.elukerio\.org',
386 r
'(?:www\.)?yt\.lelux\.fi',
387 r
'(?:www\.)?invidious\.ggc-project\.de',
388 r
'(?:www\.)?yt\.maisputain\.ovh',
389 r
'(?:www\.)?ytprivate\.com',
390 r
'(?:www\.)?invidious\.13ad\.de',
391 r
'(?:www\.)?invidious\.toot\.koeln',
392 r
'(?:www\.)?invidious\.fdn\.fr',
393 r
'(?:www\.)?watch\.nettohikari\.com',
394 r
'(?:www\.)?invidious\.namazso\.eu',
395 r
'(?:www\.)?invidious\.silkky\.cloud',
396 r
'(?:www\.)?invidious\.exonip\.de',
397 r
'(?:www\.)?invidious\.riverside\.rocks',
398 r
'(?:www\.)?invidious\.blamefran\.net',
399 r
'(?:www\.)?invidious\.moomoo\.de',
400 r
'(?:www\.)?ytb\.trom\.tf',
401 r
'(?:www\.)?yt\.cyberhost\.uk',
402 r
'(?:www\.)?kgg2m7yk5aybusll\.onion',
403 r
'(?:www\.)?qklhadlycap4cnod\.onion',
404 r
'(?:www\.)?axqzx4s6s54s32yentfqojs3x5i7faxza6xo3ehd4bzzsg2ii4fv2iid\.onion',
405 r
'(?:www\.)?c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid\.onion',
406 r
'(?:www\.)?fz253lmuao3strwbfbmx46yu7acac2jz27iwtorgmbqlkurlclmancad\.onion',
407 r
'(?:www\.)?invidious\.l4qlywnpwqsluw65ts7md3khrivpirse744un3x7mlskqauz5pyuzgqd\.onion',
408 r
'(?:www\.)?owxfohz4kjyv25fvlqilyxast7inivgiktls3th44jhk3ej3i7ya\.b32\.i2p',
409 r
'(?:www\.)?4l2dgddgsrkf2ous66i6seeyi6etzfgrue332grh2n7madpwopotugyd\.onion',
410 r
'(?:www\.)?w6ijuptxiku4xpnnaetxvnkc5vqcdu7mgns2u77qefoixi63vbvnpnqd\.onion',
411 r
'(?:www\.)?kbjggqkzv65ivcqj6bumvp337z6264huv5kpkwuv6gu5yjiskvan7fad\.onion',
412 r
'(?:www\.)?grwp24hodrefzvjjuccrkw3mjq4tzhaaq32amf33dzpmuxe7ilepcmad\.onion',
413 r
'(?:www\.)?hpniueoejy4opn7bc4ftgazyqjoeqwlvh2uiku2xqku6zpoa4bf5ruid\.onion',
414 # piped instances from https://github.com/TeamPiped/Piped/wiki/Instances
415 r
'(?:www\.)?piped\.kavin\.rocks',
416 r
'(?:www\.)?piped\.tokhmi\.xyz',
417 r
'(?:www\.)?piped\.syncpundit\.io',
418 r
'(?:www\.)?piped\.mha\.fi',
419 r
'(?:www\.)?watch\.whatever\.social',
420 r
'(?:www\.)?piped\.garudalinux\.org',
421 r
'(?:www\.)?piped\.rivo\.lol',
422 r
'(?:www\.)?piped-libre\.kavin\.rocks',
423 r
'(?:www\.)?yt\.jae\.fi',
424 r
'(?:www\.)?piped\.mint\.lgbt',
426 r
'(?:www\.)?piped\.esmailelbob\.xyz',
427 r
'(?:www\.)?piped\.projectsegfau\.lt',
428 r
'(?:www\.)?piped\.privacydev\.net',
429 r
'(?:www\.)?piped\.palveluntarjoaja\.eu',
430 r
'(?:www\.)?piped\.smnz\.de',
431 r
'(?:www\.)?piped\.adminforge\.de',
432 r
'(?:www\.)?watch\.whatevertinfoil\.de',
433 r
'(?:www\.)?piped\.qdi\.fi',
434 r
'(?:(?:www|cf)\.)?piped\.video',
435 r
'(?:www\.)?piped\.aeong\.one',
436 r
'(?:www\.)?piped\.moomoo\.me',
437 r
'(?:www\.)?piped\.chauvet\.pro',
438 r
'(?:www\.)?watch\.leptons\.xyz',
439 r
'(?:www\.)?pd\.vern\.cc',
440 r
'(?:www\.)?piped\.hostux\.net',
441 r
'(?:www\.)?piped\.lunar\.icu',
442 # Hyperpipe instances from https://hyperpipe.codeberg.page/
443 r
'(?:www\.)?hyperpipe\.surge\.sh',
444 r
'(?:www\.)?hyperpipe\.esmailelbob\.xyz',
445 r
'(?:www\.)?listen\.whatever\.social',
446 r
'(?:www\.)?music\.adminforge\.de',
449 # extracted from account/account_menu ep
450 # XXX: These are the supported YouTube UI and API languages,
451 # which is slightly different from languages supported for translation in YouTube studio
452 _SUPPORTED_LANG_CODES
= [
453 'af', 'az', 'id', 'ms', 'bs', 'ca', 'cs', 'da', 'de', 'et', 'en-IN', 'en-GB', 'en', 'es',
454 'es-419', 'es-US', 'eu', 'fil', 'fr', 'fr-CA', 'gl', 'hr', 'zu', 'is', 'it', 'sw', 'lv',
455 'lt', 'hu', 'nl', 'no', 'uz', 'pl', 'pt-PT', 'pt', 'ro', 'sq', 'sk', 'sl', 'sr-Latn', 'fi',
456 'sv', 'vi', 'tr', 'be', 'bg', 'ky', 'kk', 'mk', 'mn', 'ru', 'sr', 'uk', 'el', 'hy', 'iw',
457 'ur', 'ar', 'fa', 'ne', 'mr', 'hi', 'as', 'bn', 'pa', 'gu', 'or', 'ta', 'te', 'kn', 'ml',
458 'si', 'th', 'lo', 'my', 'ka', 'am', 'km', 'zh-CN', 'zh-TW', 'zh-HK', 'ja', 'ko'
461 _IGNORED_WARNINGS
= {'Unavailable videos will be hidden during playback'}
463 _YT_HANDLE_RE
= r
'@[\w.-]{3,30}' # https://support.google.com/youtube/answer/11585688?hl=en
464 _YT_CHANNEL_UCID_RE
= r
'UC[\w-]{22}'
466 def ucid_or_none(self
, ucid
):
467 return self
._search
_regex
(rf
'^({self._YT_CHANNEL_UCID_RE})$', ucid
, 'UC-id', default
=None)
469 def handle_or_none(self
, handle
):
470 return self
._search
_regex
(rf
'^({self._YT_HANDLE_RE})$', handle
, '@-handle', default
=None)
472 def handle_from_url(self
, url
):
473 return self
._search
_regex
(rf
'^(?:https?://(?:www\.)?youtube\.com)?/({self._YT_HANDLE_RE})',
474 url
, 'channel handle', default
=None)
476 def ucid_from_url(self
, url
):
477 return self
._search
_regex
(rf
'^(?:https?://(?:www\.)?youtube\.com)?/({self._YT_CHANNEL_UCID_RE})',
478 url
, 'channel id', default
=None)
480 @functools.cached_property
481 def _preferred_lang(self
):
483 Returns a language code supported by YouTube for the user preferred language.
484 Returns None if no preferred language set.
486 preferred_lang
= self
._configuration
_arg
('lang', ie_key
='Youtube', casesense
=True, default
=[''])[0]
487 if not preferred_lang
:
489 if preferred_lang
not in self
._SUPPORTED
_LANG
_CODES
:
490 raise ExtractorError(
491 f
'Unsupported language code: {preferred_lang}. Supported language codes (case-sensitive): {join_nonempty(*self._SUPPORTED_LANG_CODES, delim=", ")}.',
493 elif preferred_lang
!= 'en':
495 f
'Preferring "{preferred_lang}" translated fields. Note that some metadata extraction may fail or be incorrect.')
496 return preferred_lang
498 def _initialize_consent(self
):
499 cookies
= self
._get
_cookies
('https://www.youtube.com/')
500 if cookies
.get('__Secure-3PSID'):
502 socs
= cookies
.get('SOCS')
503 if socs
and not socs
.value
.startswith('CAA'): # not consented
505 self
._set
_cookie
('.youtube.com', 'SOCS', 'CAI', secure
=True) # accept all (required for mixes)
507 def _initialize_pref(self
):
508 cookies
= self
._get
_cookies
('https://www.youtube.com/')
509 pref_cookie
= cookies
.get('PREF')
513 pref
= dict(urllib
.parse
.parse_qsl(pref_cookie
.value
))
515 self
.report_warning('Failed to parse user PREF cookie' + bug_reports_message())
516 pref
.update({'hl': self._preferred_lang or 'en', 'tz': 'UTC'}
)
517 self
._set
_cookie
('.youtube.com', name
='PREF', value
=urllib
.parse
.urlencode(pref
))
519 def _real_initialize(self
):
520 self
._initialize
_pref
()
521 self
._initialize
_consent
()
522 self
._check
_login
_required
()
524 def _check_login_required(self
):
525 if self
._LOGIN
_REQUIRED
and not self
._cookies
_passed
:
526 self
.raise_login_required('Login details are needed to download this content', method
='cookies')
528 _YT_INITIAL_DATA_RE
= r
'(?:window\s*\[\s*["\']ytInitialData
["\']\s*\]|ytInitialData)\s*='
529 _YT_INITIAL_PLAYER_RESPONSE_RE = r'ytInitialPlayerResponse\s*='
531 def _get_default_ytcfg(self, client='web'):
532 return copy.deepcopy(INNERTUBE_CLIENTS[client])
534 def _get_innertube_host(self, client='web'):
535 return INNERTUBE_CLIENTS[client]['INNERTUBE_HOST']
537 def _ytcfg_get_safe(self, ytcfg, getter, expected_type=None, default_client='web'):
538 # try_get but with fallback to default ytcfg client values when present
539 _func = lambda y: try_get(y, getter, expected_type)
540 return _func(ytcfg) or _func(self._get_default_ytcfg(default_client))
542 def _extract_client_name(self, ytcfg, default_client='web'):
543 return self._ytcfg_get_safe(
544 ytcfg, (lambda x: x['INNERTUBE_CLIENT_NAME'],
545 lambda x: x['INNERTUBE_CONTEXT']['client']['clientName']), str, default_client)
547 def _extract_client_version(self, ytcfg, default_client='web'):
548 return self._ytcfg_get_safe(
549 ytcfg, (lambda x: x['INNERTUBE_CLIENT_VERSION'],
550 lambda x: x['INNERTUBE_CONTEXT']['client']['clientVersion']), str, default_client)
552 def _select_api_hostname(self, req_api_hostname, default_client=None):
553 return (self._configuration_arg('innertube_host', [''], ie_key=YoutubeIE.ie_key())[0]
554 or req_api_hostname or self._get_innertube_host(default_client or 'web'))
556 def _extract_api_key(self, ytcfg=None, default_client='web'):
557 return self._ytcfg_get_safe(ytcfg, lambda x: x['INNERTUBE_API_KEY'], str, default_client)
559 def _extract_context(self, ytcfg=None, default_client='web'):
561 (ytcfg, self._get_default_ytcfg(default_client)), 'INNERTUBE_CONTEXT', expected_type=dict)
562 # Enforce language and tz for extraction
563 client_context = traverse_obj(context, 'client', expected_type=dict, default={})
564 client_context.update({'hl': self._preferred_lang or 'en', 'timeZone': 'UTC', 'utcOffsetMinutes': 0})
569 def _generate_sapisidhash_header(self, origin='https://www.youtube.com'):
570 time_now = round(time.time())
571 if self._SAPISID is None:
572 yt_cookies = self._get_cookies('https://www.youtube.com')
573 # Sometimes SAPISID cookie isn't present but __Secure-3PAPISID is.
574 # See: https://github.com/yt-dlp/yt-dlp/issues/393
575 sapisid_cookie = dict_get(
576 yt_cookies, ('__Secure-3PAPISID', 'SAPISID'))
577 if sapisid_cookie and sapisid_cookie.value:
578 self._SAPISID = sapisid_cookie.value
579 self.write_debug('Extracted SAPISID cookie')
580 # SAPISID cookie is required if not already present
581 if not yt_cookies.get('SAPISID'):
582 self.write_debug('Copying __Secure-3PAPISID cookie to SAPISID cookie')
584 '.youtube.com', 'SAPISID', self._SAPISID, secure=True, expire_time=time_now + 3600)
586 self._SAPISID = False
587 if not self._SAPISID:
589 # SAPISIDHASH algorithm from https://stackoverflow.com/a/32065323
590 sapisidhash = hashlib.sha1(
591 f'{time_now} {self._SAPISID} {origin}'.encode()).hexdigest()
592 return f'SAPISIDHASH {time_now}_{sapisidhash}'
594 def _call_api(self, ep, query, video_id, fatal=True, headers=None,
595 note='Downloading API JSON', errnote='Unable to download API page',
596 context=None, api_key=None, api_hostname=None, default_client='web'):
598 data = {'context': context} if context else {'context': self._extract_context(default_client=default_client)}
600 real_headers = self.generate_api_headers(default_client=default_client)
601 real_headers.update({'content-type': 'application/json'})
603 real_headers.update(headers)
604 api_key = (self._configuration_arg('innertube_key', [''], ie_key=YoutubeIE.ie_key(), casesense=True)[0]
605 or api_key or self._extract_api_key(default_client=default_client))
606 return self._download_json(
607 f'https://{self._select_api_hostname(api_hostname, default_client)}/youtubei/v1/{ep}',
608 video_id=video_id, fatal=fatal, note=note, errnote=errnote,
609 data=json.dumps(data).encode('utf8'), headers=real_headers,
610 query={'key': api_key, 'prettyPrint': 'false'})
612 def extract_yt_initial_data(self, item_id, webpage, fatal=True):
613 return self._search_json(self._YT_INITIAL_DATA_RE, webpage, 'yt initial data', item_id, fatal=fatal)
616 def _extract_session_index(*data):
618 Index of current account in account list.
619 See: https://github.com/yt-dlp/yt-dlp/pull/519
622 session_index = int_or_none(try_get(ytcfg, lambda x: x['SESSION_INDEX']))
623 if session_index is not None:
627 def _extract_identity_token(self, ytcfg=None, webpage=None):
629 token = try_get(ytcfg, lambda x: x['ID_TOKEN'], str)
633 return self._search_regex(
634 r'\bID_TOKEN["\']\s
*:\s
*["\'](.+?)["\']', webpage,
635 'identity token
', default=None, fatal=False)
638 def _extract_account_syncid(*args):
640 Extract syncId required to download private playlists of secondary channels
641 @params response and/or ytcfg
644 # ytcfg includes channel_syncid if on secondary channel
645 delegated_sid = try_get(data, lambda x: x['DELEGATED_SESSION_ID
'], str)
649 data, (lambda x: x['responseContext
']['mainAppWebResponseContext
']['datasyncId
'],
650 lambda x: x['DATASYNC_ID
']), str) or '').split('||
')
651 if len(sync_ids) >= 2 and sync_ids[1]:
652 # datasyncid is of the form "channel_syncid||user_syncid" for secondary channel
653 # and just "user_syncid||" for primary channel. We only want the channel_syncid
657 def _extract_visitor_data(*args):
659 Extracts visitorData from an API response or ytcfg
660 Appears to be used to track session state
663 args, [('VISITOR_DATA
', ('INNERTUBE_CONTEXT
', 'client
', 'visitorData
'), ('responseContext
', 'visitorData
'))],
666 @functools.cached_property
667 def is_authenticated(self):
668 return bool(self._generate_sapisidhash_header())
670 def extract_ytcfg(self, video_id, webpage):
673 return self._parse_json(
675 r'ytcfg\
.set\s
*\
(\s
*({.+?}
)\s
*\
)\s
*;', webpage, 'ytcfg
',
676 default='{}'), video_id, fatal=False) or {}
678 def generate_api_headers(
679 self
, *, ytcfg
=None, account_syncid
=None, session_index
=None,
680 visitor_data
=None, identity_token
=None, api_hostname
=None, default_client
='web'):
682 origin
= 'https://' + (self
._select
_api
_hostname
(api_hostname
, default_client
))
684 'X-YouTube-Client-Name': str(
685 self
._ytcfg
_get
_safe
(ytcfg
, lambda x
: x
['INNERTUBE_CONTEXT_CLIENT_NAME'], default_client
=default_client
)),
686 'X-YouTube-Client-Version': self
._extract
_client
_version
(ytcfg
, default_client
),
688 'X-Youtube-Identity-Token': identity_token
or self
._extract
_identity
_token
(ytcfg
),
689 'X-Goog-PageId': account_syncid
or self
._extract
_account
_syncid
(ytcfg
),
690 'X-Goog-Visitor-Id': visitor_data
or self
._extract
_visitor
_data
(ytcfg
),
691 'User-Agent': self
._ytcfg
_get
_safe
(ytcfg
, lambda x
: x
['INNERTUBE_CONTEXT']['client']['userAgent'], default_client
=default_client
)
693 if session_index
is None:
694 session_index
= self
._extract
_session
_index
(ytcfg
)
695 if account_syncid
or session_index
is not None:
696 headers
['X-Goog-AuthUser'] = session_index
if session_index
is not None else 0
698 auth
= self
._generate
_sapisidhash
_header
(origin
)
700 headers
['Authorization'] = auth
701 headers
['X-Origin'] = origin
702 return filter_dict(headers
)
704 def _download_ytcfg(self
, client
, video_id
):
706 'web': 'https://www.youtube.com',
707 'web_music': 'https://music.youtube.com',
708 'web_embedded': f
'https://www.youtube.com/embed/{video_id}?html5=1'
712 webpage
= self
._download
_webpage
(
713 url
, video_id
, fatal
=False, note
=f
'Downloading {client.replace("_", " ").strip()} client config')
714 return self
.extract_ytcfg(video_id
, webpage
) or {}
717 def _build_api_continuation_query(continuation
, ctp
=None):
719 'continuation': continuation
721 # TODO: Inconsistency with clickTrackingParams.
722 # Currently we have a fixed ctp contained within context (from ytcfg)
723 # and a ctp in root query for continuation.
725 query
['clickTracking'] = {'clickTrackingParams': ctp}
729 def _extract_next_continuation_data(cls
, renderer
):
730 next_continuation
= try_get(
731 renderer
, (lambda x
: x
['continuations'][0]['nextContinuationData'],
732 lambda x
: x
['continuation']['reloadContinuationData']), dict)
733 if not next_continuation
:
735 continuation
= next_continuation
.get('continuation')
738 ctp
= next_continuation
.get('clickTrackingParams')
739 return cls
._build
_api
_continuation
_query
(continuation
, ctp
)
742 def _extract_continuation_ep_data(cls
, continuation_ep
: dict):
743 if isinstance(continuation_ep
, dict):
744 continuation
= try_get(
745 continuation_ep
, lambda x
: x
['continuationCommand']['token'], str)
748 ctp
= continuation_ep
.get('clickTrackingParams')
749 return cls
._build
_api
_continuation
_query
(continuation
, ctp
)
752 def _extract_continuation(cls
, renderer
):
753 next_continuation
= cls
._extract
_next
_continuation
_data
(renderer
)
754 if next_continuation
:
755 return next_continuation
757 return traverse_obj(renderer
, (
758 ('contents', 'items', 'rows'), ..., 'continuationItemRenderer',
759 ('continuationEndpoint', ('button', 'buttonRenderer', 'command'))
760 ), get_all
=False, expected_type
=cls
._extract
_continuation
_ep
_data
)
763 def _extract_alerts(cls
, data
):
764 for alert_dict
in try_get(data
, lambda x
: x
['alerts'], list) or []:
765 if not isinstance(alert_dict
, dict):
767 for alert
in alert_dict
.values():
768 alert_type
= alert
.get('type')
771 message
= cls
._get
_text
(alert
, 'text')
773 yield alert_type
, message
775 def _report_alerts(self
, alerts
, expected
=True, fatal
=True, only_once
=False):
776 errors
, warnings
= [], []
777 for alert_type
, alert_message
in alerts
:
778 if alert_type
.lower() == 'error' and fatal
:
779 errors
.append([alert_type
, alert_message
])
780 elif alert_message
not in self
._IGNORED
_WARNINGS
:
781 warnings
.append([alert_type
, alert_message
])
783 for alert_type
, alert_message
in (warnings
+ errors
[:-1]):
784 self
.report_warning(f
'YouTube said: {alert_type} - {alert_message}', only_once
=only_once
)
786 raise ExtractorError('YouTube said: %s' % errors
[-1][1], expected
=expected
)
788 def _extract_and_report_alerts(self
, data
, *args
, **kwargs
):
789 return self
._report
_alerts
(self
._extract
_alerts
(data
), *args
, **kwargs
)
791 def _extract_badges(self
, badge_list
: list):
793 Extract known BadgeType's from a list of badge renderers.
794 @returns [{'type': BadgeType}]
797 'PRIVACY_UNLISTED': BadgeType
.AVAILABILITY_UNLISTED
,
798 'PRIVACY_PRIVATE': BadgeType
.AVAILABILITY_PRIVATE
,
799 'PRIVACY_PUBLIC': BadgeType
.AVAILABILITY_PUBLIC
,
800 'CHECK_CIRCLE_THICK': BadgeType
.VERIFIED
,
801 'OFFICIAL_ARTIST_BADGE': BadgeType
.VERIFIED
,
802 'CHECK': BadgeType
.VERIFIED
,
806 'BADGE_STYLE_TYPE_MEMBERS_ONLY': BadgeType
.AVAILABILITY_SUBSCRIPTION
,
807 'BADGE_STYLE_TYPE_PREMIUM': BadgeType
.AVAILABILITY_PREMIUM
,
808 'BADGE_STYLE_TYPE_LIVE_NOW': BadgeType
.LIVE_NOW
,
809 'BADGE_STYLE_TYPE_VERIFIED': BadgeType
.VERIFIED
,
810 'BADGE_STYLE_TYPE_VERIFIED_ARTIST': BadgeType
.VERIFIED
,
814 'unlisted': BadgeType
.AVAILABILITY_UNLISTED
,
815 'private': BadgeType
.AVAILABILITY_PRIVATE
,
816 'members only': BadgeType
.AVAILABILITY_SUBSCRIPTION
,
817 'live': BadgeType
.LIVE_NOW
,
818 'premium': BadgeType
.AVAILABILITY_PREMIUM
,
819 'verified': BadgeType
.VERIFIED
,
820 'official artist channel': BadgeType
.VERIFIED
,
824 for badge
in traverse_obj(badge_list
, (..., lambda key
, _
: re
.search(r
'[bB]adgeRenderer$', key
))):
826 icon_type_map
.get(traverse_obj(badge
, ('icon', 'iconType'), expected_type
=str))
827 or badge_style_map
.get(traverse_obj(badge
, 'style'))
830 badges
.append({'type': badge_type}
)
833 # fallback, won't work in some languages
834 label
= traverse_obj(
835 badge
, 'label', ('accessibilityData', 'label'), 'tooltip', 'iconTooltip', get_all
=False, expected_type
=str, default
='')
836 for match
, label_badge_type
in label_map
.items():
837 if match
in label
.lower():
838 badges
.append({'type': label_badge_type}
)
844 def _has_badge(badges
, badge_type
):
845 return bool(traverse_obj(badges
, lambda _
, v
: v
['type'] == badge_type
))
848 def _get_text(data
, *path_list
, max_runs
=None):
849 for path
in path_list
or [None]:
853 obj
= traverse_obj(data
, path
, default
=[])
854 if not any(key
is ... or isinstance(key
, (list, tuple)) for key
in variadic(path
)):
857 text
= try_get(item
, lambda x
: x
['simpleText'], str)
860 runs
= try_get(item
, lambda x
: x
['runs'], list) or []
861 if not runs
and isinstance(item
, list):
864 runs
= runs
[:min(len(runs
), max_runs
or len(runs
))]
865 text
= ''.join(traverse_obj(runs
, (..., 'text'), expected_type
=str))
869 def _get_count(self
, data
, *path_list
):
870 count_text
= self
._get
_text
(data
, *path_list
) or ''
871 count
= parse_count(count_text
)
874 self
._search
_regex
(r
'^([\d,]+)', re
.sub(r
'\s', '', count_text
), 'count', default
=None))
878 def _extract_thumbnails(data
, *path_list
):
880 Extract thumbnails from thumbnails dict
881 @param path_list: path list to level that contains 'thumbnails' key
884 for path
in path_list
or [()]:
885 for thumbnail
in traverse_obj(data
, (*variadic(path
), 'thumbnails', ...)):
886 thumbnail_url
= url_or_none(thumbnail
.get('url'))
887 if not thumbnail_url
:
889 # Sometimes youtube gives a wrong thumbnail URL. See:
890 # https://github.com/yt-dlp/yt-dlp/issues/233
891 # https://github.com/ytdl-org/youtube-dl/issues/28023
892 if 'maxresdefault' in thumbnail_url
:
893 thumbnail_url
= thumbnail_url
.split('?')[0]
895 'url': thumbnail_url
,
896 'height': int_or_none(thumbnail
.get('height')),
897 'width': int_or_none(thumbnail
.get('width')),
902 def extract_relative_time(relative_time_text
):
904 Extracts a relative time from string and converts to dt object
905 e.g. 'streamed 6 days ago', '5 seconds ago (edited)', 'updated today', '8 yr ago'
908 # XXX: this could be moved to a general function in utils/_utils.py
909 # The relative time text strings are roughly the same as what
910 # Javascript's Intl.RelativeTimeFormat function generates.
911 # See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat
913 r
'(?P<start>today|yesterday|now)|(?P<time>\d+)\s*(?P<unit>sec(?:ond)?|s|min(?:ute)?|h(?:our|r)?|d(?:ay)?|w(?:eek|k)?|mo(?:nth)?|y(?:ear|r)?)s?\s*ago',
916 start
= mobj
.group('start')
918 return datetime_from_str(start
)
920 return datetime_from_str('now-%s%s' % (mobj
.group('time'), mobj
.group('unit')))
924 def _parse_time_text(self
, text
):
927 dt_
= self
.extract_relative_time(text
)
929 if isinstance(dt_
, dt
.datetime
):
930 timestamp
= calendar
.timegm(dt_
.timetuple())
932 if timestamp
is None:
934 unified_timestamp(text
) or unified_timestamp(
936 (r
'([a-z]+\s*\d{1,2},?\s*20\d{2})', r
'(?:.+|^)(?:live|premieres|ed|ing)(?:\s*(?:on|for))?\s*(.+\d)'),
937 text
.lower(), 'time text', default
=None)))
939 if text
and timestamp
is None and self
._preferred
_lang
in (None, 'en'):
941 f
'Cannot parse localized time text "{text}"', only_once
=True)
944 def _extract_response(self
, item_id
, query
, note
='Downloading API JSON', headers
=None,
945 ytcfg
=None, check_get_keys
=None, ep
='browse', fatal
=True, api_hostname
=None,
946 default_client
='web'):
947 raise_for_incomplete
= bool(self
._configuration
_arg
('raise_incomplete_data', ie_key
=YoutubeIE
))
948 # Incomplete Data should be a warning by default when retries are exhausted, while other errors should be fatal.
949 icd_retries
= iter(self
.RetryManager(fatal
=raise_for_incomplete
))
950 icd_rm
= next(icd_retries
)
951 main_retries
= iter(self
.RetryManager())
952 main_rm
= next(main_retries
)
953 # Manual retry loop for multiple RetryManagers
954 # The proper RetryManager MUST be advanced after an error
955 # and its result MUST be checked if the manager is non fatal
958 response
= self
._call
_api
(
959 ep
=ep
, fatal
=True, headers
=headers
,
960 video_id
=item_id
, query
=query
, note
=note
,
961 context
=self
._extract
_context
(ytcfg
, default_client
),
962 api_key
=self
._extract
_api
_key
(ytcfg
, default_client
),
963 api_hostname
=api_hostname
, default_client
=default_client
)
964 except ExtractorError
as e
:
965 if not isinstance(e
.cause
, network_exceptions
):
966 return self
._error
_or
_warning
(e
, fatal
=fatal
)
967 elif not isinstance(e
.cause
, HTTPError
):
972 first_bytes
= e
.cause
.response
.read(512)
973 if not is_html(first_bytes
):
976 self
._webpage
_read
_content
(e
.cause
.response
, None, item_id
, prefix
=first_bytes
) or '{}', item_id
, fatal
=False),
977 lambda x
: x
['error']['message'], str)
979 self
._report
_alerts
([('ERROR', yt_error
)], fatal
=False)
980 # Downloading page may result in intermittent 5xx HTTP error
981 # Sometimes a 404 is also received. See: https://github.com/ytdl-org/youtube-dl/issues/28289
982 # We also want to catch all other network exceptions since errors in later pages can be troublesome
983 # See https://github.com/yt-dlp/yt-dlp/issues/507#issuecomment-880188210
984 if e
.cause
.status
not in (403, 429):
988 return self
._error
_or
_warning
(e
, fatal
=fatal
)
991 self
._extract
_and
_report
_alerts
(response
, only_once
=True)
992 except ExtractorError
as e
:
993 # YouTube's servers may return errors we want to retry on in a 200 OK response
994 # See: https://github.com/yt-dlp/yt-dlp/issues/839
995 if 'unknown error' in e
.msg
.lower():
999 return self
._error
_or
_warning
(e
, fatal
=fatal
)
1000 # Youtube sometimes sends incomplete data
1001 # See: https://github.com/ytdl-org/youtube-dl/issues/28194
1002 if not traverse_obj(response
, *variadic(check_get_keys
)):
1003 icd_rm
.error
= ExtractorError('Incomplete data received', expected
=True)
1004 should_retry
= next(icd_retries
, None)
1005 if not should_retry
:
1012 def is_music_url(url
):
1013 return re
.match(r
'(https?://)?music\.youtube\.com/', url
) is not None
1015 def _extract_video(self
, renderer
):
1016 video_id
= renderer
.get('videoId')
1018 reel_header_renderer
= traverse_obj(renderer
, (
1019 'navigationEndpoint', 'reelWatchEndpoint', 'overlay', 'reelPlayerOverlayRenderer',
1020 'reelPlayerHeaderSupportedRenderers', 'reelPlayerHeaderRenderer'))
1022 title
= self
._get
_text
(renderer
, 'title', 'headline') or self
._get
_text
(reel_header_renderer
, 'reelTitleText')
1023 description
= self
._get
_text
(renderer
, 'descriptionSnippet')
1025 duration
= int_or_none(renderer
.get('lengthSeconds'))
1026 if duration
is None:
1027 duration
= parse_duration(self
._get
_text
(
1028 renderer
, 'lengthText', ('thumbnailOverlays', ..., 'thumbnailOverlayTimeStatusRenderer', 'text')))
1029 if duration
is None:
1030 # XXX: should write a parser to be more general to support more cases (e.g. shorts in shorts tab)
1031 duration
= parse_duration(self
._search
_regex
(
1032 r
'(?i)(ago)(?!.*\1)\s+(?P<duration>[a-z0-9 ,]+?)(?:\s+[\d,]+\s+views)?(?:\s+-\s+play\s+short)?$',
1033 traverse_obj(renderer
, ('title', 'accessibility', 'accessibilityData', 'label'), default
='', expected_type
=str),
1034 video_id
, default
=None, group
='duration'))
1036 channel_id
= traverse_obj(
1037 renderer
, ('shortBylineText', 'runs', ..., 'navigationEndpoint', 'browseEndpoint', 'browseId'),
1038 expected_type
=str, get_all
=False)
1040 channel_id
= traverse_obj(reel_header_renderer
, ('channelNavigationEndpoint', 'browseEndpoint', 'browseId'))
1042 channel_id
= self
.ucid_or_none(channel_id
)
1044 overlay_style
= traverse_obj(
1045 renderer
, ('thumbnailOverlays', ..., 'thumbnailOverlayTimeStatusRenderer', 'style'),
1046 get_all
=False, expected_type
=str)
1047 badges
= self
._extract
_badges
(traverse_obj(renderer
, 'badges'))
1048 owner_badges
= self
._extract
_badges
(traverse_obj(renderer
, 'ownerBadges'))
1049 navigation_url
= urljoin('https://www.youtube.com/', traverse_obj(
1050 renderer
, ('navigationEndpoint', 'commandMetadata', 'webCommandMetadata', 'url'),
1051 expected_type
=str)) or ''
1052 url
= f
'https://www.youtube.com/watch?v={video_id}'
1053 if overlay_style
== 'SHORTS' or '/shorts/' in navigation_url
:
1054 url
= f
'https://www.youtube.com/shorts/{video_id}'
1056 time_text
= (self
._get
_text
(renderer
, 'publishedTimeText', 'videoInfo')
1057 or self
._get
_text
(reel_header_renderer
, 'timestampText') or '')
1058 scheduled_timestamp
= str_to_int(traverse_obj(renderer
, ('upcomingEventData', 'startTime'), get_all
=False))
1061 'is_upcoming' if scheduled_timestamp
is not None
1062 else 'was_live' if 'streamed' in time_text
.lower()
1063 else 'is_live' if overlay_style
== 'LIVE' or self
._has
_badge
(badges
, BadgeType
.LIVE_NOW
)
1066 # videoInfo is a string like '50K views • 10 years ago'.
1067 view_count_text
= self
._get
_text
(renderer
, 'viewCountText', 'shortViewCountText', 'videoInfo') or ''
1068 view_count
= (0 if 'no views' in view_count_text
.lower()
1069 else self
._get
_count
({'simpleText': view_count_text}
))
1070 view_count_field
= 'concurrent_view_count' if live_status
in ('is_live', 'is_upcoming') else 'view_count'
1072 channel
= (self
._get
_text
(renderer
, 'ownerText', 'shortBylineText')
1073 or self
._get
_text
(reel_header_renderer
, 'channelTitleText'))
1075 channel_handle
= traverse_obj(renderer
, (
1076 'shortBylineText', 'runs', ..., 'navigationEndpoint',
1077 (('commandMetadata', 'webCommandMetadata', 'url'), ('browseEndpoint', 'canonicalBaseUrl'))),
1078 expected_type
=self
.handle_from_url
, get_all
=False)
1081 'ie_key': YoutubeIE
.ie_key(),
1085 'description': description
,
1086 'duration': duration
,
1087 'channel_id': channel_id
,
1089 'channel_url': f
'https://www.youtube.com/channel/{channel_id}' if channel_id
else None,
1090 'uploader': channel
,
1091 'uploader_id': channel_handle
,
1092 'uploader_url': format_field(channel_handle
, None, 'https://www.youtube.com/%s', default
=None),
1093 'thumbnails': self
._extract
_thumbnails
(renderer
, 'thumbnail'),
1094 'timestamp': (self
._parse
_time
_text
(time_text
)
1095 if self
._configuration
_arg
('approximate_date', ie_key
=YoutubeTabIE
)
1097 'release_timestamp': scheduled_timestamp
,
1099 'public' if self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PUBLIC
)
1100 else self
._availability
(
1101 is_private
=self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PRIVATE
) or None,
1102 needs_premium
=self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PREMIUM
) or None,
1103 needs_subscription
=self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_SUBSCRIPTION
) or None,
1104 is_unlisted
=self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_UNLISTED
) or None),
1105 view_count_field
: view_count
,
1106 'live_status': live_status
,
1107 'channel_is_verified': True if self
._has
_badge
(owner_badges
, BadgeType
.VERIFIED
) else None
1111 class YoutubeIE(YoutubeBaseInfoExtractor
):
1113 _VALID_URL
= r
"""(?x)^
1115 (?:https?://|//) # http(s):// or protocol-independent URL
1116 (?:(?:(?:(?:\w+\.)?[yY][oO][uU][tT][uU][bB][eE](?:-nocookie|kids)?\.com|
1117 (?:www\.)?deturl\.com/www\.youtube\.com|
1118 (?:www\.)?pwnyoutube\.com|
1119 (?:www\.)?hooktube\.com|
1120 (?:www\.)?yourepeat\.com|
1121 tube\.majestyc\.net|
1123 youtube\.googleapis\.com)/ # the various hostnames, with wildcard subdomains
1124 (?:.*?\#/)? # handle anchor (#/) redirect urls
1125 (?: # the various things that can precede the ID:
1126 (?:(?:v|embed|e|shorts|live)/(?!videoseries|live_stream)) # v/ or embed/ or e/ or shorts/
1127 |(?: # or the v= param in all its forms
1128 (?:(?:watch|movie)(?:_popup)?(?:\.php)?/?)? # preceding watch(_popup|.php) or nothing (like /?v=xxxx)
1129 (?:\?|\#!?) # the params delimiter ? or # or #!
1130 (?:.*?[&;])?? # any other preceding param (like /?s=tuff&v=xxxx or ?s=tuff&v=V36LpHqtcDY)
1135 youtu\.be| # just youtu.be/xxxx
1136 vid\.plus| # or vid.plus/xxxx
1137 zwearz\.com/watch| # or zwearz.com/watch/xxxx
1140 |(?:www\.)?cleanvideosearch\.com/media/action/yt/watch\?videoId=
1142 )? # all until now is optional -> you can pass the naked ID
1143 (?P<id>[0-9A-Za-z_-]{11}) # here is it! the YouTube video ID
1144 (?(1).+)? # if we found the ID, everything can follow
1146 'invidious': '|'.join(YoutubeBaseInfoExtractor
._INVIDIOUS
_SITES
),
1151 <(?:[0-9A-Za-z-]+?)?iframe[^>]+?src=|
1159 (?P
<url
>(?
:https?
:)?
//(?
:www\
.)?
youtube(?
:-nocookie
)?\
.com
/
1160 (?
:embed|v|p
)/[0-9A
-Za
-z_
-]{11}
.*?
)
1162 # https://wordpress.org/plugins/lazy-load-for-videos/
1164 <a\s
[^
>]*\bhref
="(?P<url>https://www\.youtube\.com/watch\?v=[0-9A-Za-z_-]{11})"
1165 \s
[^
>]*\bclass
="[^"]*\blazy
-load
-youtube
''',
1167 _RETURN_TYPE = 'video' # XXX: How to handle multifeed?
1170 r'/s/player/(?P<id>[a-zA-Z0-9_-]{8,})/player',
1171 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$',
1172 r'\b(?P<id>vfl[a-zA-Z0-9_-]+)\b.*?\.js$',
1175 '5': {'ext': 'flv', 'width': 400, 'height': 240, 'acodec': 'mp3', 'abr': 64, 'vcodec': 'h263'},
1176 '6': {'ext': 'flv', 'width': 450, 'height': 270, 'acodec': 'mp3', 'abr': 64, 'vcodec': 'h263'},
1177 '13': {'ext': '3gp', 'acodec': 'aac', 'vcodec': 'mp4v'},
1178 '17': {'ext': '3gp', 'width': 176, 'height': 144, 'acodec': 'aac', 'abr': 24, 'vcodec': 'mp4v'},
1179 '18': {'ext': 'mp4', 'width': 640, 'height': 360, 'acodec': 'aac', 'abr': 96, 'vcodec': 'h264'},
1180 '22': {'ext': 'mp4', 'width': 1280, 'height': 720, 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264'},
1181 '34': {'ext': 'flv', 'width': 640, 'height': 360, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'},
1182 '35': {'ext': 'flv', 'width': 854, 'height': 480, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'},
1183 # itag 36 videos are either 320x180 (BaW_jenozKc) or 320x240 (__2ABJjxzNo), abr varies as well
1184 '36': {'ext': '3gp', 'width': 320, 'acodec': 'aac', 'vcodec': 'mp4v'},
1185 '37': {'ext': 'mp4', 'width': 1920, 'height': 1080, 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264'},
1186 '38': {'ext': 'mp4', 'width': 4096, 'height': 3072, 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264'},
1187 '43': {'ext': 'webm', 'width': 640, 'height': 360, 'acodec': 'vorbis', 'abr': 128, 'vcodec': 'vp8'},
1188 '44': {'ext': 'webm', 'width': 854, 'height': 480, 'acodec': 'vorbis', 'abr': 128, 'vcodec': 'vp8'},
1189 '45': {'ext': 'webm', 'width': 1280, 'height': 720, 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8'},
1190 '46': {'ext': 'webm', 'width': 1920, 'height': 1080, 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8'},
1191 '59': {'ext': 'mp4', 'width': 854, 'height': 480, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'},
1192 '78': {'ext': 'mp4', 'width': 854, 'height': 480, 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264'},
1196 '82': {'ext': 'mp4', 'height': 360, 'format_note': '3D', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -20},
1197 '83': {'ext': 'mp4', 'height': 480, 'format_note': '3D', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -20},
1198 '84': {'ext': 'mp4', 'height': 720, 'format_note': '3D', 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264', 'preference': -20},
1199 '85': {'ext': 'mp4', 'height': 1080, 'format_note': '3D', 'acodec': 'aac', 'abr': 192, 'vcodec': 'h264', 'preference': -20},
1200 '100': {'ext': 'webm', 'height': 360, 'format_note': '3D', 'acodec': 'vorbis', 'abr': 128, 'vcodec': 'vp8', 'preference': -20},
1201 '101': {'ext': 'webm', 'height': 480, 'format_note': '3D', 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8', 'preference': -20},
1202 '102': {'ext': 'webm', 'height': 720, 'format_note': '3D', 'acodec': 'vorbis', 'abr': 192, 'vcodec': 'vp8', 'preference': -20},
1204 # Apple HTTP Live Streaming
1205 '91': {'ext': 'mp4', 'height': 144, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 48, 'vcodec': 'h264', 'preference': -10},
1206 '92': {'ext': 'mp4', 'height': 240, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 48, 'vcodec': 'h264', 'preference': -10},
1207 '93': {'ext': 'mp4', 'height': 360, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -10},
1208 '94': {'ext': 'mp4', 'height': 480, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 128, 'vcodec': 'h264', 'preference': -10},
1209 '95': {'ext': 'mp4', 'height': 720, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 256, 'vcodec': 'h264', 'preference': -10},
1210 '96': {'ext': 'mp4', 'height': 1080, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 256, 'vcodec': 'h264', 'preference': -10},
1211 '132': {'ext': 'mp4', 'height': 240, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 48, 'vcodec': 'h264', 'preference': -10},
1212 '151': {'ext': 'mp4', 'height': 72, 'format_note': 'HLS', 'acodec': 'aac', 'abr': 24, 'vcodec': 'h264', 'preference': -10},
1215 '133': {'ext': 'mp4', 'height': 240, 'format_note': 'DASH video', 'vcodec': 'h264'},
1216 '134': {'ext': 'mp4', 'height': 360, 'format_note': 'DASH video', 'vcodec': 'h264'},
1217 '135': {'ext': 'mp4', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'h264'},
1218 '136': {'ext': 'mp4', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'h264'},
1219 '137': {'ext': 'mp4', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'h264'},
1220 '138': {'ext': 'mp4', 'format_note': 'DASH video', 'vcodec': 'h264'}, # Height can vary (https://github.com/ytdl-org/youtube-dl/issues/4559)
1221 '160': {'ext': 'mp4', 'height': 144, 'format_note': 'DASH video', 'vcodec': 'h264'},
1222 '212': {'ext': 'mp4', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'h264'},
1223 '264': {'ext': 'mp4', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'h264'},
1224 '298': {'ext': 'mp4', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'h264', 'fps': 60},
1225 '299': {'ext': 'mp4', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'h264', 'fps': 60},
1226 '266': {'ext': 'mp4', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'h264'},
1229 '139': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'abr': 48, 'container': 'm4a_dash'},
1230 '140': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'abr': 128, 'container': 'm4a_dash'},
1231 '141': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'abr': 256, 'container': 'm4a_dash'},
1232 '256': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'container': 'm4a_dash'},
1233 '258': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'aac', 'container': 'm4a_dash'},
1234 '325': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'dtse', 'container': 'm4a_dash'},
1235 '328': {'ext': 'm4a', 'format_note': 'DASH audio', 'acodec': 'ec-3', 'container': 'm4a_dash'},
1238 '167': {'ext': 'webm', 'height': 360, 'width': 640, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1239 '168': {'ext': 'webm', 'height': 480, 'width': 854, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1240 '169': {'ext': 'webm', 'height': 720, 'width': 1280, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1241 '170': {'ext': 'webm', 'height': 1080, 'width': 1920, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1242 '218': {'ext': 'webm', 'height': 480, 'width': 854, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1243 '219': {'ext': 'webm', 'height': 480, 'width': 854, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp8'},
1244 '278': {'ext': 'webm', 'height': 144, 'format_note': 'DASH video', 'container': 'webm', 'vcodec': 'vp9'},
1245 '242': {'ext': 'webm', 'height': 240, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1246 '243': {'ext': 'webm', 'height': 360, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1247 '244': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1248 '245': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1249 '246': {'ext': 'webm', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1250 '247': {'ext': 'webm', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1251 '248': {'ext': 'webm', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1252 '271': {'ext': 'webm', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1253 # itag 272 videos are either 3840x2160 (e.g. RtoitU2A-3E) or 7680x4320 (sLprVF6d7Ug)
1254 '272': {'ext': 'webm', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1255 '302': {'ext': 'webm', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60},
1256 '303': {'ext': 'webm', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60},
1257 '308': {'ext': 'webm', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60},
1258 '313': {'ext': 'webm', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'vp9'},
1259 '315': {'ext': 'webm', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'vp9', 'fps': 60},
1262 '171': {'ext': 'webm', 'acodec': 'vorbis', 'format_note': 'DASH audio', 'abr': 128},
1263 '172': {'ext': 'webm', 'acodec': 'vorbis', 'format_note': 'DASH audio', 'abr': 256},
1265 # Dash webm audio with opus inside
1266 '249': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 50},
1267 '250': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 70},
1268 '251': {'ext': 'webm', 'format_note': 'DASH audio', 'acodec': 'opus', 'abr': 160},
1271 '_rtmp': {'protocol': 'rtmp'},
1273 # av01 video only formats sometimes served with "unknown" codecs
1274 '394': {'ext': 'mp4', 'height': 144, 'format_note': 'DASH video', 'vcodec': 'av01.0.00M.08'},
1275 '395': {'ext': 'mp4', 'height': 240, 'format_note': 'DASH video', 'vcodec': 'av01.0.00M.08'},
1276 '396': {'ext': 'mp4', 'height': 360, 'format_note': 'DASH video', 'vcodec': 'av01.0.01M.08'},
1277 '397': {'ext': 'mp4', 'height': 480, 'format_note': 'DASH video', 'vcodec': 'av01.0.04M.08'},
1278 '398': {'ext': 'mp4', 'height': 720, 'format_note': 'DASH video', 'vcodec': 'av01.0.05M.08'},
1279 '399': {'ext': 'mp4', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'av01.0.08M.08'},
1280 '400': {'ext': 'mp4', 'height': 1440, 'format_note': 'DASH video', 'vcodec': 'av01.0.12M.08'},
1281 '401': {'ext': 'mp4', 'height': 2160, 'format_note': 'DASH video', 'vcodec': 'av01.0.12M.08'},
1283 _SUBTITLE_FORMATS = ('json3', 'srv1', 'srv2', 'srv3', 'ttml', 'vtt')
1290 'url': 'https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9',
1292 'id': 'BaW_jenozKc',
1294 'title': 'youtube-dl test video "\'/\\ä↭𝕐',
1295 'channel': 'Philipp Hagemeister',
1296 'channel_id': 'UCLqxVugv74EIW3VWh2NOa3Q',
1297 'channel_url': r're:https?://(?:www\.)?youtube\.com/channel/UCLqxVugv74EIW3VWh2NOa3Q',
1298 'upload_date': '20121002',
1299 'description': 'md5:8fb536f4877b8a7455c2ec23794dbc22',
1300 'categories': ['Science & Technology'],
1301 'tags': ['youtube-dl'],
1305 'availability': 'public',
1306 'playable_in_embed': True,
1307 'thumbnail': 'https://i.ytimg.com/vi/BaW_jenozKc/maxresdefault.jpg',
1308 'live_status': 'not_live',
1312 'comment_count': int,
1313 'channel_follower_count': int,
1314 'uploader': 'Philipp Hagemeister',
1315 'uploader_url': 'https://www.youtube.com/@PhilippHagemeister',
1316 'uploader_id': '@PhilippHagemeister',
1317 'heatmap': 'count:100',
1321 'url': '//www.YouTube.com/watch?v=yZIXLfi8CZQ',
1322 'note': 'Embed-only video (#1746)',
1324 'id': 'yZIXLfi8CZQ',
1326 'upload_date': '20120608',
1327 'title': 'Principal Sexually Assaults A Teacher - Episode 117 - 8th June 2012',
1328 'description': 'md5:09b78bd971f1e3e289601dfba15ca4f7',
1331 'skip': 'Private video',
1334 'url': 'https://www.youtube.com/watch?v=BaW_jenozKc&v=yZIXLfi8CZQ',
1335 'note': 'Use the first video ID in the URL',
1337 'id': 'BaW_jenozKc',
1339 'title': 'youtube-dl test video "\'/\\ä↭𝕐',
1340 'channel': 'Philipp Hagemeister',
1341 'channel_id': 'UCLqxVugv74EIW3VWh2NOa3Q',
1342 'channel_url': r're:https?://(?:www\.)?youtube\.com/channel/UCLqxVugv74EIW3VWh2NOa3Q',
1343 'upload_date': '20121002',
1344 'description': 'md5:8fb536f4877b8a7455c2ec23794dbc22',
1345 'categories': ['Science & Technology'],
1346 'tags': ['youtube-dl'],
1350 'availability': 'public',
1351 'playable_in_embed': True,
1352 'thumbnail': 'https://i.ytimg.com/vi/BaW_jenozKc/maxresdefault.jpg',
1353 'live_status': 'not_live',
1355 'comment_count': int,
1356 'channel_follower_count': int,
1357 'uploader': 'Philipp Hagemeister',
1358 'uploader_url': 'https://www.youtube.com/@PhilippHagemeister',
1359 'uploader_id': '@PhilippHagemeister',
1360 'heatmap': 'count:100',
1363 'skip_download': True,
1367 'url': 'https://www.youtube.com/watch?v=a9LDPn-MO4I',
1368 'note': '256k DASH audio (format 141) via DASH manifest',
1370 'id': 'a9LDPn-MO4I',
1372 'upload_date': '20121002',
1374 'title': 'UHDTV TEST 8K VIDEO.mp4'
1377 'youtube_include_dash_manifest': True,
1380 'skip': 'format 141 not served anymore',
1382 # DASH manifest with encrypted signature
1384 'url': 'https://www.youtube.com/watch?v=IB3lcPjvWLA',
1386 'id': 'IB3lcPjvWLA',
1388 'title': 'Afrojack, Spree Wilson - The Spark (Official Music Video) ft. Spree Wilson',
1389 'description': 'md5:8f5e2b82460520b619ccac1f509d43bf',
1391 'upload_date': '20131011',
1394 'channel_id': 'UChuZAo1RKL85gev3Eal9_zg',
1395 'playable_in_embed': True,
1396 'channel_url': 'https://www.youtube.com/channel/UChuZAo1RKL85gev3Eal9_zg',
1398 'track': 'The Spark',
1399 'live_status': 'not_live',
1400 'thumbnail': 'https://i.ytimg.com/vi_webp/IB3lcPjvWLA/maxresdefault.webp',
1401 'channel': 'Afrojack',
1403 'availability': 'public',
1404 'categories': ['Music'],
1406 'alt_title': 'The Spark',
1407 'channel_follower_count': int,
1408 'uploader': 'Afrojack',
1409 'uploader_url': 'https://www.youtube.com/@Afrojack',
1410 'uploader_id': '@Afrojack',
1413 'youtube_include_dash_manifest': True,
1414 'format': '141/bestaudio[ext=m4a]',
1417 # Age-gate videos. See https://github.com/yt-dlp/yt-dlp/pull/575#issuecomment-888837000
1419 'note': 'Embed allowed age-gate video',
1420 'url': 'https://youtube.com/watch?v=HtVdAasjOgU',
1422 'id': 'HtVdAasjOgU',
1424 'title': 'The Witcher 3: Wild Hunt - The Sword Of Destiny Trailer',
1425 'description': r're:(?s).{100,}About the Game\n.*?The Witcher 3: Wild Hunt.{100,}',
1427 'upload_date': '20140605',
1429 'categories': ['Gaming'],
1430 'thumbnail': 'https://i.ytimg.com/vi_webp/HtVdAasjOgU/maxresdefault.webp',
1431 'availability': 'needs_auth',
1432 'channel_url': 'https://www.youtube.com/channel/UCzybXLxv08IApdjdN0mJhEg',
1434 'channel': 'The Witcher',
1435 'live_status': 'not_live',
1437 'channel_id': 'UCzybXLxv08IApdjdN0mJhEg',
1438 'playable_in_embed': True,
1440 'channel_follower_count': int,
1441 'uploader': 'The Witcher',
1442 'uploader_url': 'https://www.youtube.com/@thewitcher',
1443 'uploader_id': '@thewitcher',
1444 'comment_count': int,
1445 'channel_is_verified': True,
1446 'heatmap': 'count:100',
1450 'note': 'Age-gate video with embed allowed in public site',
1451 'url': 'https://youtube.com/watch?v=HsUATh_Nc2U',
1453 'id': 'HsUATh_Nc2U',
1455 'title': 'Godzilla 2 (Official Video)',
1456 'description': 'md5:bf77e03fcae5529475e500129b05668a',
1457 'upload_date': '20200408',
1459 'availability': 'needs_auth',
1460 'channel_id': 'UCYQT13AtrJC0gsM1far_zJg',
1461 'channel': 'FlyingKitty',
1462 'channel_url': 'https://www.youtube.com/channel/UCYQT13AtrJC0gsM1far_zJg',
1464 'categories': ['Entertainment'],
1465 'live_status': 'not_live',
1466 'tags': ['Flyingkitty', 'godzilla 2'],
1467 'thumbnail': 'https://i.ytimg.com/vi/HsUATh_Nc2U/maxresdefault.jpg',
1470 'playable_in_embed': True,
1471 'channel_follower_count': int,
1472 'uploader': 'FlyingKitty',
1473 'uploader_url': 'https://www.youtube.com/@FlyingKitty900',
1474 'uploader_id': '@FlyingKitty900',
1475 'comment_count': int,
1476 'channel_is_verified': True,
1480 'note': 'Age-gate video embedable only with clientScreen=EMBED',
1481 'url': 'https://youtube.com/watch?v=Tq92D6wQ1mg',
1483 'id': 'Tq92D6wQ1mg',
1484 'title': '[MMD] Adios - EVERGLOW [+Motion DL]',
1486 'upload_date': '20191228',
1487 'description': 'md5:17eccca93a786d51bc67646756894066',
1490 'availability': 'needs_auth',
1491 'channel_id': 'UC1yoRdFoFJaCY-AGfD9W0wQ',
1493 'thumbnail': 'https://i.ytimg.com/vi_webp/Tq92D6wQ1mg/sddefault.webp',
1494 'channel': 'Projekt Melody',
1495 'live_status': 'not_live',
1496 'tags': ['mmd', 'dance', 'mikumikudance', 'kpop', 'vtuber'],
1497 'playable_in_embed': True,
1498 'categories': ['Entertainment'],
1500 'channel_url': 'https://www.youtube.com/channel/UC1yoRdFoFJaCY-AGfD9W0wQ',
1501 'comment_count': int,
1502 'channel_follower_count': int,
1503 'uploader': 'Projekt Melody',
1504 'uploader_url': 'https://www.youtube.com/@ProjektMelody',
1505 'uploader_id': '@ProjektMelody',
1509 'note': 'Non-Agegated non-embeddable video',
1510 'url': 'https://youtube.com/watch?v=MeJVWBSsPAY',
1512 'id': 'MeJVWBSsPAY',
1514 'title': 'OOMPH! - Such Mich Find Mich (Lyrics)',
1515 'description': 'Fan Video. Music & Lyrics by OOMPH!.',
1516 'upload_date': '20130730',
1517 'track': 'Such mich find mich',
1519 'tags': ['oomph', 'such mich find mich', 'lyrics', 'german industrial', 'musica industrial'],
1521 'playable_in_embed': False,
1522 'creator': 'OOMPH!',
1523 'thumbnail': 'https://i.ytimg.com/vi/MeJVWBSsPAY/sddefault.jpg',
1525 'alt_title': 'Such mich find mich',
1527 'channel': 'Herr Lurik',
1528 'channel_id': 'UCdR3RSDPqub28LjZx0v9-aA',
1529 'categories': ['Music'],
1530 'availability': 'public',
1531 'channel_url': 'https://www.youtube.com/channel/UCdR3RSDPqub28LjZx0v9-aA',
1532 'live_status': 'not_live',
1534 'channel_follower_count': int,
1535 'uploader': 'Herr Lurik',
1536 'uploader_url': 'https://www.youtube.com/@HerrLurik',
1537 'uploader_id': '@HerrLurik',
1541 'note': 'Non-bypassable age-gated video',
1542 'url': 'https://youtube.com/watch?v=Cr381pDsSsA',
1543 'only_matching': True,
1545 # video_info is None (https://github.com/ytdl-org/youtube-dl/issues/4421)
1546 # YouTube Red ad is not captured for creator
1548 'url': '__2ABJjxzNo',
1550 'id': '__2ABJjxzNo',
1553 'upload_date': '20100430',
1554 'creator': 'deadmau5',
1555 'description': 'md5:6cbcd3a92ce1bc676fc4d6ab4ace2336',
1556 'title': 'Deadmau5 - Some Chords (HD)',
1557 'alt_title': 'Some Chords',
1558 'availability': 'public',
1560 'channel_id': 'UCYEK6xds6eo-3tr4xRdflmQ',
1562 'live_status': 'not_live',
1563 'channel': 'deadmau5',
1564 'thumbnail': 'https://i.ytimg.com/vi_webp/__2ABJjxzNo/maxresdefault.webp',
1566 'track': 'Some Chords',
1567 'artist': 'deadmau5',
1568 'playable_in_embed': True,
1570 'channel_url': 'https://www.youtube.com/channel/UCYEK6xds6eo-3tr4xRdflmQ',
1571 'categories': ['Music'],
1572 'album': 'Some Chords',
1573 'channel_follower_count': int,
1574 'uploader': 'deadmau5',
1575 'uploader_url': 'https://www.youtube.com/@deadmau5',
1576 'uploader_id': '@deadmau5',
1578 'expected_warnings': [
1579 'DASH manifest missing',
1582 # Olympics (https://github.com/ytdl-org/youtube-dl/issues/4431)
1584 'url': 'lqQg6PlCWgI',
1586 'id': 'lqQg6PlCWgI',
1589 'upload_date': '20150827',
1590 'description': 'md5:04bbbf3ccceb6795947572ca36f45904',
1591 'title': 'Hockey - Women - GER-AUS - London 2012 Olympic Games',
1593 'release_timestamp': 1343767800,
1594 'playable_in_embed': True,
1595 'categories': ['Sports'],
1596 'release_date': '20120731',
1597 'channel': 'Olympics',
1598 'tags': ['Hockey', '2012-07-31', '31 July 2012', 'Riverbank Arena', 'Session', 'Olympics', 'Olympic Games', 'London 2012', '2012 Summer Olympics', 'Summer Games'],
1599 'channel_id': 'UCTl3QQTvqHFjurroKxexy2Q',
1600 'thumbnail': 'https://i.ytimg.com/vi/lqQg6PlCWgI/maxresdefault.jpg',
1602 'availability': 'public',
1603 'live_status': 'was_live',
1605 'channel_url': 'https://www.youtube.com/channel/UCTl3QQTvqHFjurroKxexy2Q',
1606 'channel_follower_count': int,
1607 'uploader': 'Olympics',
1608 'uploader_url': 'https://www.youtube.com/@Olympics',
1609 'uploader_id': '@Olympics',
1610 'channel_is_verified': True,
1613 'skip_download': 'requires avconv',
1618 'url': 'https://www.youtube.com/watch?v=_b-2C3KPAM0',
1620 'id': '_b-2C3KPAM0',
1622 'stretched_ratio': 16 / 9.,
1624 'upload_date': '20110310',
1625 'description': 'made by Wacom from Korea | 字幕&加油添醋 by TY\'s Allen | 感謝heylisa00cavey1001同學熱情提供梗及翻譯',
1626 'title': '[A-made] 變態妍字幕版 太妍 我就是這樣的人',
1627 'playable_in_embed': True,
1631 'channel_url': 'https://www.youtube.com/channel/UCS-xxCmRaA6BFdmgDPA_BIw',
1632 'channel_id': 'UCS-xxCmRaA6BFdmgDPA_BIw',
1633 'thumbnail': 'https://i.ytimg.com/vi/_b-2C3KPAM0/maxresdefault.jpg',
1635 'categories': ['People & Blogs'],
1637 'live_status': 'not_live',
1638 'availability': 'unlisted',
1639 'comment_count': int,
1640 'channel_follower_count': int,
1642 'uploader_url': 'https://www.youtube.com/@AllenMeow',
1643 'uploader_id': '@AllenMeow',
1646 # url_encoded_fmt_stream_map is empty string
1648 'url': 'qEJwOuvDf7I',
1650 'id': 'qEJwOuvDf7I',
1652 'title': 'Обсуждение судебной практики по выборам 14 сентября 2014 года в Санкт-Петербурге',
1654 'upload_date': '20150404',
1657 'skip_download': 'requires avconv',
1659 'skip': 'This live event has ended.',
1661 # Extraction from multiple DASH manifests (https://github.com/ytdl-org/youtube-dl/pull/6097)
1663 'url': 'https://www.youtube.com/watch?v=FIl7x6_3R5Y',
1665 'id': 'FIl7x6_3R5Y',
1667 'title': 'md5:7b81415841e02ecd4313668cde88737a',
1668 'description': 'md5:116377fd2963b81ec4ce64b542173306',
1670 'upload_date': '20150625',
1671 'formats': 'mincount:31',
1673 'skip': 'not actual anymore',
1675 # DASH manifest with segment_list
1677 'url': 'https://www.youtube.com/embed/CsmdDsKjzN8',
1678 'md5': '8ce563a1d667b599d21064e982ab9e31',
1680 'id': 'CsmdDsKjzN8',
1682 'upload_date': '20150501', # According to '<meta itemprop="datePublished"', but in other places it's 20150510
1683 'description': 'Retransmisión en directo de la XVIII media maratón de Zaragoza.',
1684 'title': 'Retransmisión XVIII Media maratón Zaragoza 2015',
1687 'youtube_include_dash_manifest': True,
1688 'format': '135', # bestvideo
1690 'skip': 'This live event has ended.',
1693 # Multifeed videos (multiple cameras), URL can be of any Camera
1694 # TODO: fix multifeed titles
1695 'url': 'https://www.youtube.com/watch?v=zaPI8MvL8pg',
1697 'id': 'zaPI8MvL8pg',
1698 'title': 'Terraria 1.2 Live Stream | Let\'s Play - Part 04',
1699 'description': 'md5:563ccbc698b39298481ca3c571169519',
1703 'id': 'j5yGuxZ8lLU',
1705 'title': 'Terraria 1.2 Live Stream | Let\'s Play - Part 04 (Chris)',
1706 'description': 'md5:563ccbc698b39298481ca3c571169519',
1708 'channel_follower_count': int,
1709 'channel_url': 'https://www.youtube.com/channel/UCN2XePorRokPB9TEgRZpddg',
1710 'availability': 'public',
1711 'playable_in_embed': True,
1712 'upload_date': '20131105',
1713 'categories': ['Gaming'],
1714 'live_status': 'was_live',
1716 'release_timestamp': 1383701910,
1717 'thumbnail': 'https://i.ytimg.com/vi/j5yGuxZ8lLU/maxresdefault.jpg',
1718 'comment_count': int,
1721 'channel_id': 'UCN2XePorRokPB9TEgRZpddg',
1722 'channel': 'WiiLikeToPlay',
1724 'release_date': '20131106',
1725 'uploader': 'WiiLikeToPlay',
1726 'uploader_id': '@WLTP',
1727 'uploader_url': 'https://www.youtube.com/@WLTP',
1731 'id': 'zaPI8MvL8pg',
1733 'title': 'Terraria 1.2 Live Stream | Let\'s Play - Part 04 (Tyson)',
1734 'availability': 'public',
1735 'channel_url': 'https://www.youtube.com/channel/UCN2XePorRokPB9TEgRZpddg',
1736 'channel': 'WiiLikeToPlay',
1737 'channel_follower_count': int,
1738 'description': 'md5:563ccbc698b39298481ca3c571169519',
1743 'channel_id': 'UCN2XePorRokPB9TEgRZpddg',
1744 'release_timestamp': 1383701915,
1745 'comment_count': int,
1746 'upload_date': '20131105',
1747 'thumbnail': 'https://i.ytimg.com/vi/zaPI8MvL8pg/maxresdefault.jpg',
1748 'release_date': '20131106',
1749 'playable_in_embed': True,
1750 'live_status': 'was_live',
1751 'categories': ['Gaming'],
1753 'uploader': 'WiiLikeToPlay',
1754 'uploader_id': '@WLTP',
1755 'uploader_url': 'https://www.youtube.com/@WLTP',
1759 'id': 'R7r3vfO7Hao',
1761 'title': 'Terraria 1.2 Live Stream | Let\'s Play - Part 04 (Spencer)',
1762 'thumbnail': 'https://i.ytimg.com/vi/R7r3vfO7Hao/maxresdefault.jpg',
1763 'channel_id': 'UCN2XePorRokPB9TEgRZpddg',
1765 'availability': 'public',
1766 'playable_in_embed': True,
1767 'upload_date': '20131105',
1768 'description': 'md5:563ccbc698b39298481ca3c571169519',
1769 'channel_follower_count': int,
1771 'release_date': '20131106',
1772 'comment_count': int,
1773 'channel_url': 'https://www.youtube.com/channel/UCN2XePorRokPB9TEgRZpddg',
1774 'channel': 'WiiLikeToPlay',
1775 'categories': ['Gaming'],
1776 'release_timestamp': 1383701914,
1777 'live_status': 'was_live',
1781 'uploader': 'WiiLikeToPlay',
1782 'uploader_id': '@WLTP',
1783 'uploader_url': 'https://www.youtube.com/@WLTP',
1786 'params': {'skip_download': True},
1789 # Multifeed video with comma in title (see https://github.com/ytdl-org/youtube-dl/issues/8536)
1790 'url': 'https://www.youtube.com/watch?v=gVfLd0zydlo',
1792 'id': 'gVfLd0zydlo',
1793 'title': 'DevConf.cz 2016 Day 2 Workshops 1 14:00 - 15:30',
1795 'playlist_count': 2,
1796 'skip': 'Not multifeed anymore',
1799 'url': 'https://vid.plus/FlRa-iH7PGw',
1800 'only_matching': True,
1803 'url': 'https://zwearz.com/watch/9lWxNJF-ufM/electra-woman-dyna-girl-official-trailer-grace-helbig.html',
1804 'only_matching': True,
1807 # Title with JS-like syntax "};" (see https://github.com/ytdl-org/youtube-dl/issues/7468)
1808 # Also tests cut-off URL expansion in video description (see
1809 # https://github.com/ytdl-org/youtube-dl/issues/1892,
1810 # https://github.com/ytdl-org/youtube-dl/issues/8164)
1811 'url': 'https://www.youtube.com/watch?v=lsguqyKfVQg',
1813 'id': 'lsguqyKfVQg',
1815 'title': '{dark walk}; Loki/AC/Dishonored; collab w/Elflover21',
1816 'alt_title': 'Dark Walk',
1817 'description': 'md5:8085699c11dc3f597ce0410b0dcbb34a',
1819 'upload_date': '20151119',
1820 'creator': 'Todd Haberman;\nDaniel Law Heath and Aaron Kaplan',
1821 'track': 'Dark Walk',
1822 'artist': 'Todd Haberman;\nDaniel Law Heath and Aaron Kaplan',
1823 'album': 'Position Music - Production Music Vol. 143 - Dark Walk',
1824 'thumbnail': 'https://i.ytimg.com/vi_webp/lsguqyKfVQg/maxresdefault.webp',
1825 'categories': ['Film & Animation'],
1827 'live_status': 'not_live',
1828 'channel_url': 'https://www.youtube.com/channel/UCTSRgz5jylBvFt_S7wnsqLQ',
1829 'channel_id': 'UCTSRgz5jylBvFt_S7wnsqLQ',
1831 'availability': 'public',
1832 'channel': 'IronSoulElf',
1833 'playable_in_embed': True,
1836 'channel_follower_count': int
1839 'skip_download': True,
1843 # Tags with '};' (see https://github.com/ytdl-org/youtube-dl/issues/7468)
1844 'url': 'https://www.youtube.com/watch?v=Ms7iBXnlUO8',
1845 'only_matching': True,
1848 # Video with yt:stretch=17:0
1849 'url': 'https://www.youtube.com/watch?v=Q39EVAstoRM',
1851 'id': 'Q39EVAstoRM',
1853 'title': 'Clash Of Clans#14 Dicas De Ataque Para CV 4',
1854 'description': 'md5:ee18a25c350637c8faff806845bddee9',
1855 'upload_date': '20151107',
1858 'skip_download': True,
1860 'skip': 'This video does not exist.',
1863 # Video with incomplete 'yt:stretch=16:'
1864 'url': 'https://www.youtube.com/watch?v=FRhJzUSJbGI',
1865 'only_matching': True,
1868 # Video licensed under Creative Commons
1869 'url': 'https://www.youtube.com/watch?v=M4gD1WSo5mA',
1871 'id': 'M4gD1WSo5mA',
1873 'title': 'md5:e41008789470fc2533a3252216f1c1d1',
1874 'description': 'md5:a677553cf0840649b731a3024aeff4cc',
1876 'upload_date': '20150128',
1877 'license': 'Creative Commons Attribution license (reuse allowed)',
1878 'channel_id': 'UCuLGmD72gJDBwmLw06X58SA',
1879 'channel_url': 'https://www.youtube.com/channel/UCuLGmD72gJDBwmLw06X58SA',
1882 'tags': ['Copyright (Legal Subject)', 'Law (Industry)', 'William W. Fisher (Author)'],
1883 'channel': 'The Berkman Klein Center for Internet & Society',
1884 'availability': 'public',
1886 'categories': ['Education'],
1887 'thumbnail': 'https://i.ytimg.com/vi_webp/M4gD1WSo5mA/maxresdefault.webp',
1888 'live_status': 'not_live',
1889 'playable_in_embed': True,
1890 'channel_follower_count': int,
1892 'uploader': 'The Berkman Klein Center for Internet & Society',
1893 'uploader_id': '@BKCHarvard',
1894 'uploader_url': 'https://www.youtube.com/@BKCHarvard',
1897 'skip_download': True,
1901 'url': 'https://www.youtube.com/watch?v=eQcmzGIKrzg',
1903 'id': 'eQcmzGIKrzg',
1905 'title': 'Democratic Socialism and Foreign Policy | Bernie Sanders',
1906 'description': 'md5:13a2503d7b5904ef4b223aa101628f39',
1908 'upload_date': '20151120',
1909 'license': 'Creative Commons Attribution license (reuse allowed)',
1910 'playable_in_embed': True,
1913 'channel_id': 'UCH1dpzjCEiGAt8CXkryhkZg',
1915 'availability': 'public',
1916 'categories': ['News & Politics'],
1917 'channel': 'Bernie Sanders',
1918 'thumbnail': 'https://i.ytimg.com/vi_webp/eQcmzGIKrzg/maxresdefault.webp',
1920 'live_status': 'not_live',
1921 'channel_url': 'https://www.youtube.com/channel/UCH1dpzjCEiGAt8CXkryhkZg',
1922 'comment_count': int,
1923 'channel_follower_count': int,
1925 'uploader': 'Bernie Sanders',
1926 'uploader_url': 'https://www.youtube.com/@BernieSanders',
1927 'uploader_id': '@BernieSanders',
1928 'channel_is_verified': True,
1929 'heatmap': 'count:100',
1932 'skip_download': True,
1936 'url': 'https://www.youtube.com/watch?feature=player_embedded&amp;v=V36LpHqtcDY',
1937 'only_matching': True,
1940 # YouTube Red paid video (https://github.com/ytdl-org/youtube-dl/issues/10059)
1941 'url': 'https://www.youtube.com/watch?v=i1Ko8UG-Tdo',
1942 'only_matching': True,
1945 # Rental video preview
1946 'url': 'https://www.youtube.com/watch?v=yYr8q0y5Jfg',
1948 'id': 'uGpuVWrhIzE',
1950 'title': 'Piku - Trailer',
1951 'description': 'md5:c36bd60c3fd6f1954086c083c72092eb',
1952 'upload_date': '20150811',
1953 'license': 'Standard YouTube License',
1956 'skip_download': True,
1958 'skip': 'This video is not available.',
1961 # YouTube Red video with episode data
1962 'url': 'https://www.youtube.com/watch?v=iqKdEhx-dD4',
1964 'id': 'iqKdEhx-dD4',
1966 'title': 'Isolation - Mind Field (Ep 1)',
1967 'description': 'md5:f540112edec5d09fc8cc752d3d4ba3cd',
1969 'upload_date': '20170118',
1970 'series': 'Mind Field',
1972 'episode_number': 1,
1973 'thumbnail': 'https://i.ytimg.com/vi_webp/iqKdEhx-dD4/maxresdefault.webp',
1976 'availability': 'public',
1978 'channel': 'Vsauce',
1979 'episode': 'Episode 1',
1980 'categories': ['Entertainment'],
1981 'season': 'Season 1',
1982 'channel_id': 'UC6nSFpj9HTCZ5t-N3Rm3-HA',
1983 'channel_url': 'https://www.youtube.com/channel/UC6nSFpj9HTCZ5t-N3Rm3-HA',
1985 'playable_in_embed': True,
1986 'live_status': 'not_live',
1987 'channel_follower_count': int,
1988 'uploader': 'Vsauce',
1989 'uploader_url': 'https://www.youtube.com/@Vsauce',
1990 'uploader_id': '@Vsauce',
1991 'comment_count': int,
1992 'channel_is_verified': True,
1995 'skip_download': True,
1997 'expected_warnings': [
1998 'Skipping DASH manifest',
2002 # The following content has been identified by the YouTube community
2003 # as inappropriate or offensive to some audiences.
2004 'url': 'https://www.youtube.com/watch?v=6SJNVb0GnPI',
2006 'id': '6SJNVb0GnPI',
2008 'title': 'Race Differences in Intelligence',
2009 'description': 'md5:5d161533167390427a1f8ee89a1fc6f1',
2011 'upload_date': '20140124',
2014 'skip_download': True,
2016 'skip': 'This video has been removed for violating YouTube\'s policy on hate speech.',
2020 'url': '1t24XAntNCY',
2021 'only_matching': True,
2024 # geo restricted to JP
2025 'url': 'sJL6WA-aGkQ',
2026 'only_matching': True,
2029 'url': 'https://invidio.us/watch?v=BaW_jenozKc',
2030 'only_matching': True,
2033 'url': 'https://redirect.invidious.io/watch?v=BaW_jenozKc',
2034 'only_matching': True,
2037 # from https://nitter.pussthecat.org/YouTube/status/1360363141947944964#m
2038 'url': 'https://redirect.invidious.io/Yh0AhrY9GjA',
2039 'only_matching': True,
2043 'url': 'https://www.youtube.com/watch?v=s7_qI6_mIXc',
2044 'only_matching': True,
2047 # Video with unsupported adaptive stream type formats
2048 'url': 'https://www.youtube.com/watch?v=Z4Vy8R84T1U',
2050 'id': 'Z4Vy8R84T1U',
2052 'title': 'saman SMAN 53 Jakarta(Sancety) opening COFFEE4th at SMAN 53 Jakarta',
2053 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
2055 'upload_date': '20130923',
2056 'formats': 'maxcount:10',
2059 'skip_download': True,
2060 'youtube_include_dash_manifest': False,
2062 'skip': 'not actual anymore',
2065 # Youtube Music Auto-generated description
2066 # TODO: fix metadata extraction
2067 'url': 'https://music.youtube.com/watch?v=MgNrAu2pzNs',
2069 'id': 'MgNrAu2pzNs',
2071 'title': 'Voyeur Girl',
2072 'description': 'md5:7ae382a65843d6df2685993e90a8628f',
2073 'upload_date': '20190312',
2074 'artists': ['Stephen'],
2075 'creators': ['Stephen'],
2076 'track': 'Voyeur Girl',
2077 'album': 'it\'s too much love to know my dear',
2078 'release_date': '20190313',
2079 'alt_title': 'Voyeur Girl',
2081 'playable_in_embed': True,
2083 'categories': ['Music'],
2084 'channel_url': 'https://www.youtube.com/channel/UC-pWHpBjdGG69N9mM2auIAA',
2085 'channel': 'Stephen', # TODO: should be "Stephen - Topic"
2086 'uploader': 'Stephen',
2087 'availability': 'public',
2089 'thumbnail': 'https://i.ytimg.com/vi_webp/MgNrAu2pzNs/maxresdefault.webp',
2091 'channel_id': 'UC-pWHpBjdGG69N9mM2auIAA',
2093 'live_status': 'not_live',
2094 'channel_follower_count': int
2097 'skip_download': True,
2101 'url': 'https://www.youtubekids.com/watch?v=3b8nCWDgZ6Q',
2102 'only_matching': True,
2105 # invalid -> valid video id redirection
2106 'url': 'DJztXj2GPfl',
2108 'id': 'DJztXj2GPfk',
2110 'title': 'Panjabi MC - Mundian To Bach Ke (The Dictator Soundtrack)',
2111 'description': 'md5:bf577a41da97918e94fa9798d9228825',
2112 'upload_date': '20090125',
2113 'artist': 'Panjabi MC',
2114 'track': 'Beware of the Boys (Mundian to Bach Ke) - Motivo Hi-Lectro Remix',
2115 'album': 'Beware of the Boys (Mundian To Bach Ke)',
2118 'skip_download': True,
2120 'skip': 'Video unavailable',
2123 # empty description results in an empty string
2124 'url': 'https://www.youtube.com/watch?v=x41yOUIvK2k',
2126 'id': 'x41yOUIvK2k',
2128 'title': 'IMG 3456',
2130 'upload_date': '20170613',
2132 'thumbnail': 'https://i.ytimg.com/vi_webp/x41yOUIvK2k/maxresdefault.webp',
2134 'channel_id': 'UCo03ZQPBW5U4UC3regpt1nw',
2136 'channel_url': 'https://www.youtube.com/channel/UCo03ZQPBW5U4UC3regpt1nw',
2137 'availability': 'public',
2139 'categories': ['Pets & Animals'],
2141 'playable_in_embed': True,
2142 'live_status': 'not_live',
2143 'channel': 'l\'Or Vert asbl',
2144 'channel_follower_count': int,
2145 'uploader': 'l\'Or Vert asbl',
2146 'uploader_url': 'https://www.youtube.com/@ElevageOrVert',
2147 'uploader_id': '@ElevageOrVert',
2150 'skip_download': True,
2154 # with '};' inside yt initial data (see [1])
2155 # see [2] for an example with '};' inside ytInitialPlayerResponse
2156 # 1. https://github.com/ytdl-org/youtube-dl/issues/27093
2157 # 2. https://github.com/ytdl-org/youtube-dl/issues/27216
2158 'url': 'https://www.youtube.com/watch?v=CHqg6qOn4no',
2160 'id': 'CHqg6qOn4no',
2162 'title': 'Part 77 Sort a list of simple types in c#',
2163 'description': 'md5:b8746fa52e10cdbf47997903f13b20dc',
2164 'upload_date': '20130831',
2165 'channel_id': 'UCCTVrRB5KpIiK6V2GGVsR1Q',
2167 'channel_url': 'https://www.youtube.com/channel/UCCTVrRB5KpIiK6V2GGVsR1Q',
2168 'live_status': 'not_live',
2169 'categories': ['Education'],
2170 'availability': 'public',
2171 'thumbnail': 'https://i.ytimg.com/vi/CHqg6qOn4no/sddefault.jpg',
2173 'playable_in_embed': True,
2177 'channel': 'kudvenkat',
2178 'comment_count': int,
2179 'channel_follower_count': int,
2181 'uploader': 'kudvenkat',
2182 'uploader_url': 'https://www.youtube.com/@Csharp-video-tutorialsBlogspot',
2183 'uploader_id': '@Csharp-video-tutorialsBlogspot',
2184 'channel_is_verified': True,
2185 'heatmap': 'count:100',
2188 'skip_download': True,
2192 # another example of '};' in ytInitialData
2193 'url': 'https://www.youtube.com/watch?v=gVfgbahppCY',
2194 'only_matching': True,
2197 'url': 'https://www.youtube.com/watch_popup?v=63RmMXCd_bQ',
2198 'only_matching': True,
2201 # https://github.com/ytdl-org/youtube-dl/pull/28094
2202 'url': 'OtqTfy26tG0',
2204 'id': 'OtqTfy26tG0',
2206 'title': 'Burn Out',
2207 'description': 'md5:8d07b84dcbcbfb34bc12a56d968b6131',
2208 'upload_date': '20141120',
2209 'artist': 'The Cinematic Orchestra',
2210 'track': 'Burn Out',
2211 'album': 'Every Day',
2213 'live_status': 'not_live',
2214 'alt_title': 'Burn Out',
2218 'channel_url': 'https://www.youtube.com/channel/UCIzsJBIyo8hhpFm1NK0uLgw',
2219 'creator': 'The Cinematic Orchestra',
2220 'channel': 'The Cinematic Orchestra',
2221 'tags': ['The Cinematic Orchestra', 'Every Day', 'Burn Out'],
2222 'channel_id': 'UCIzsJBIyo8hhpFm1NK0uLgw',
2223 'availability': 'public',
2224 'thumbnail': 'https://i.ytimg.com/vi/OtqTfy26tG0/maxresdefault.jpg',
2225 'categories': ['Music'],
2226 'playable_in_embed': True,
2227 'channel_follower_count': int,
2228 'uploader': 'The Cinematic Orchestra',
2229 'comment_count': int,
2232 'skip_download': True,
2236 # controversial video, only works with bpctr when authenticated with cookies
2237 'url': 'https://www.youtube.com/watch?v=nGC3D_FkCmg',
2238 'only_matching': True,
2241 # controversial video, requires bpctr/contentCheckOk
2242 'url': 'https://www.youtube.com/watch?v=SZJvDhaSDnc',
2244 'id': 'SZJvDhaSDnc',
2246 'title': 'San Diego teen commits suicide after bullying over embarrassing video',
2247 'channel_id': 'UC-SJ6nODDmufqBzPBwCvYvQ',
2248 'upload_date': '20140716',
2249 'description': 'md5:acde3a73d3f133fc97e837a9f76b53b7',
2251 'categories': ['News & Politics'],
2253 'channel': 'CBS Mornings',
2254 'tags': ['suicide', 'bullying', 'video', 'cbs', 'news'],
2255 'thumbnail': 'https://i.ytimg.com/vi/SZJvDhaSDnc/hqdefault.jpg',
2257 'availability': 'needs_auth',
2258 'channel_url': 'https://www.youtube.com/channel/UC-SJ6nODDmufqBzPBwCvYvQ',
2260 'live_status': 'not_live',
2261 'playable_in_embed': True,
2262 'channel_follower_count': int,
2263 'uploader': 'CBS Mornings',
2264 'uploader_url': 'https://www.youtube.com/@CBSMornings',
2265 'uploader_id': '@CBSMornings',
2266 'comment_count': int,
2267 'channel_is_verified': True,
2271 # restricted location, https://github.com/ytdl-org/youtube-dl/issues/28685
2272 'url': 'cBvYw8_A0vQ',
2274 'id': 'cBvYw8_A0vQ',
2276 'title': '4K Ueno Okachimachi Street Scenes 上野御徒町歩き',
2277 'description': 'md5:ea770e474b7cd6722b4c95b833c03630',
2278 'upload_date': '20201120',
2280 'categories': ['Travel & Events'],
2281 'channel_id': 'UC3o_t8PzBmXf5S9b7GLx1Mw',
2283 'channel': 'Walk around Japan',
2284 'tags': ['Ueno Tokyo', 'Okachimachi Tokyo', 'Ameyoko Street', 'Tokyo attraction', 'Travel in Tokyo'],
2285 'thumbnail': 'https://i.ytimg.com/vi_webp/cBvYw8_A0vQ/hqdefault.webp',
2287 'availability': 'public',
2288 'channel_url': 'https://www.youtube.com/channel/UC3o_t8PzBmXf5S9b7GLx1Mw',
2289 'live_status': 'not_live',
2290 'playable_in_embed': True,
2291 'channel_follower_count': int,
2292 'uploader': 'Walk around Japan',
2293 'uploader_url': 'https://www.youtube.com/@walkaroundjapan7124',
2294 'uploader_id': '@walkaroundjapan7124',
2297 'skip_download': True,
2300 # Has multiple audio streams
2301 'url': 'WaOKSUlf4TM',
2302 'only_matching': True
2304 # Requires Premium: has format 141 when requested using YTM url
2305 'url': 'https://music.youtube.com/watch?v=XclachpHxis',
2306 'only_matching': True
2308 # multiple subtitles with same lang_code
2309 'url': 'https://www.youtube.com/watch?v=wsQiKKfKxug',
2310 'only_matching': True,
2312 # Force use android client fallback
2313 'url': 'https://www.youtube.com/watch?v=YOelRv7fMxY',
2315 'id': 'YOelRv7fMxY',
2316 'title': 'DIGGING A SECRET TUNNEL Part 1',
2318 'upload_date': '20210624',
2319 'channel_id': 'UCp68_FLety0O-n9QU6phsgw',
2320 'channel_url': r're:https?://(?:www\.)?youtube\.com/channel/UCp68_FLety0O-n9QU6phsgw',
2321 'description': 'md5:5d5991195d599b56cd0c4148907eec50',
2323 'categories': ['Entertainment'],
2325 'channel': 'colinfurze',
2326 'tags': ['Colin', 'furze', 'Terry', 'tunnel', 'underground', 'bunker'],
2327 'thumbnail': 'https://i.ytimg.com/vi/YOelRv7fMxY/maxresdefault.jpg',
2329 'availability': 'public',
2331 'live_status': 'not_live',
2332 'playable_in_embed': True,
2333 'channel_follower_count': int,
2335 'uploader': 'colinfurze',
2336 'uploader_url': 'https://www.youtube.com/@colinfurze',
2337 'uploader_id': '@colinfurze',
2338 'comment_count': int,
2339 'channel_is_verified': True,
2340 'heatmap': 'count:100',
2343 'format': '17', # 3gp format available on android
2344 'extractor_args': {'youtube': {'player_client': ['android']}},
2348 # Skip download of additional client configs (remix client config in this case)
2349 'url': 'https://music.youtube.com/watch?v=MgNrAu2pzNs',
2350 'only_matching': True,
2352 'extractor_args': {'youtube': {'player_skip': ['configs']}},
2356 'url': 'https://www.youtube.com/shorts/BGQWPY4IigY',
2357 'only_matching': True,
2359 'note': 'Storyboards',
2360 'url': 'https://www.youtube.com/watch?v=5KLPxDtMqe8',
2362 'id': '5KLPxDtMqe8',
2365 'title': 'Your Brain is Plastic',
2366 'description': 'md5:89cd86034bdb5466cd87c6ba206cd2bc',
2367 'upload_date': '20140324',
2369 'channel_id': 'UCZYTClx2T1of7BRZ86-8fow',
2370 'channel_url': 'https://www.youtube.com/channel/UCZYTClx2T1of7BRZ86-8fow',
2372 'thumbnail': 'https://i.ytimg.com/vi/5KLPxDtMqe8/maxresdefault.jpg',
2373 'playable_in_embed': True,
2375 'availability': 'public',
2376 'channel': 'SciShow',
2377 'live_status': 'not_live',
2379 'categories': ['Education'],
2381 'channel_follower_count': int,
2383 'uploader': 'SciShow',
2384 'uploader_url': 'https://www.youtube.com/@SciShow',
2385 'uploader_id': '@SciShow',
2386 'comment_count': int,
2387 'channel_is_verified': True,
2388 'heatmap': 'count:100',
2389 }, 'params': {'format': 'mhtml', 'skip_download': True}
2391 # Ensure video upload_date is in UTC timezone (video was uploaded 1641170939)
2392 'url': 'https://www.youtube.com/watch?v=2NUZ8W2llS4',
2394 'id': '2NUZ8W2llS4',
2396 'title': 'The NP that test your phone performance 🙂',
2397 'description': 'md5:144494b24d4f9dfacb97c1bbef5de84d',
2398 'channel_id': 'UCRqNBSOHgilHfAczlUmlWHA',
2399 'channel_url': 'https://www.youtube.com/channel/UCRqNBSOHgilHfAczlUmlWHA',
2403 'categories': ['Gaming'],
2405 'playable_in_embed': True,
2406 'live_status': 'not_live',
2407 'upload_date': '20220103',
2409 'availability': 'public',
2410 'channel': 'Leon Nguyen',
2411 'thumbnail': 'https://i.ytimg.com/vi_webp/2NUZ8W2llS4/maxresdefault.webp',
2412 'comment_count': int,
2413 'channel_follower_count': int,
2414 'uploader': 'Leon Nguyen',
2415 'uploader_url': 'https://www.youtube.com/@LeonNguyen',
2416 'uploader_id': '@LeonNguyen',
2417 'heatmap': 'count:100',
2420 # Same video as above, but with --compat-opt no-youtube-prefer-utc-upload-date
2421 'url': 'https://www.youtube.com/watch?v=2NUZ8W2llS4',
2423 'id': '2NUZ8W2llS4',
2425 'title': 'The NP that test your phone performance 🙂',
2426 'description': 'md5:144494b24d4f9dfacb97c1bbef5de84d',
2427 'channel_id': 'UCRqNBSOHgilHfAczlUmlWHA',
2428 'channel_url': 'https://www.youtube.com/channel/UCRqNBSOHgilHfAczlUmlWHA',
2432 'categories': ['Gaming'],
2434 'playable_in_embed': True,
2435 'live_status': 'not_live',
2436 'upload_date': '20220102',
2438 'availability': 'public',
2439 'channel': 'Leon Nguyen',
2440 'thumbnail': 'https://i.ytimg.com/vi_webp/2NUZ8W2llS4/maxresdefault.webp',
2441 'comment_count': int,
2442 'channel_follower_count': int,
2443 'uploader': 'Leon Nguyen',
2444 'uploader_url': 'https://www.youtube.com/@LeonNguyen',
2445 'uploader_id': '@LeonNguyen',
2446 'heatmap': 'count:100',
2448 'params': {'compat_opts': ['no-youtube-prefer-utc-upload-date']}
2450 # date text is premiered video, ensure upload date in UTC (published 1641172509)
2451 'url': 'https://www.youtube.com/watch?v=mzZzzBU6lrM',
2453 'id': 'mzZzzBU6lrM',
2455 'title': 'I Met GeorgeNotFound In Real Life...',
2456 'description': 'md5:978296ec9783a031738b684d4ebf302d',
2457 'channel_id': 'UC_8NknAFiyhOUaZqHR3lq3Q',
2458 'channel_url': 'https://www.youtube.com/channel/UC_8NknAFiyhOUaZqHR3lq3Q',
2462 'categories': ['Entertainment'],
2464 'playable_in_embed': True,
2465 'live_status': 'not_live',
2466 'release_timestamp': 1641172509,
2467 'release_date': '20220103',
2468 'upload_date': '20220103',
2470 'availability': 'public',
2471 'channel': 'Quackity',
2472 'thumbnail': 'https://i.ytimg.com/vi/mzZzzBU6lrM/maxresdefault.jpg',
2473 'channel_follower_count': int,
2474 'uploader': 'Quackity',
2475 'uploader_id': '@Quackity',
2476 'uploader_url': 'https://www.youtube.com/@Quackity',
2477 'comment_count': int,
2478 'channel_is_verified': True,
2479 'heatmap': 'count:100',
2482 { # continuous livestream. Microformat upload date should be preferred.
2483 # Upload date was 2021-06-19 (not UTC), while stream start is 2021-11-27
2484 'url': 'https://www.youtube.com/watch?v=kgx4WGK0oNU',
2486 'id': 'kgx4WGK0oNU',
2487 '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}',
2489 'channel_id': 'UC84whx2xxsiA1gXHXXqKGOA',
2490 'availability': 'public',
2492 'release_timestamp': 1637975704,
2493 'upload_date': '20210619',
2494 'channel_url': 'https://www.youtube.com/channel/UC84whx2xxsiA1gXHXXqKGOA',
2495 'live_status': 'is_live',
2496 'thumbnail': 'https://i.ytimg.com/vi/kgx4WGK0oNU/maxresdefault.jpg',
2497 'channel': 'Abao in Tokyo',
2498 'channel_follower_count': int,
2499 'release_date': '20211127',
2501 'categories': ['People & Blogs'],
2504 'playable_in_embed': True,
2505 'description': 'md5:2ef1d002cad520f65825346e2084e49d',
2506 'concurrent_view_count': int,
2507 'uploader': 'Abao in Tokyo',
2508 'uploader_url': 'https://www.youtube.com/@abaointokyo',
2509 'uploader_id': '@abaointokyo',
2511 'params': {'skip_download': True}
2513 'url': 'https://www.youtube.com/watch?v=tjjjtzRLHvA',
2515 'id': 'tjjjtzRLHvA',
2517 'title': 'ハッシュタグ無し };if window.ytcsi',
2518 'upload_date': '20220323',
2520 'availability': 'unlisted',
2521 'channel': 'Lesmiscore',
2522 'thumbnail': r're:^https?://.*\.jpg',
2524 'categories': ['Music'],
2527 'channel_url': 'https://www.youtube.com/channel/UCdqltm_7iv1Vs6kp6Syke5A',
2528 'channel_id': 'UCdqltm_7iv1Vs6kp6Syke5A',
2529 'live_status': 'not_live',
2530 'playable_in_embed': True,
2531 'channel_follower_count': int,
2534 'uploader_id': '@lesmiscore',
2535 'uploader': 'Lesmiscore',
2536 'uploader_url': 'https://www.youtube.com/@lesmiscore',
2539 # Prefer primary title+description language metadata by default
2540 # Do not prefer translated description if primary is empty
2541 'url': 'https://www.youtube.com/watch?v=el3E4MbxRqQ',
2543 'id': 'el3E4MbxRqQ',
2545 'title': 'dlp test video 2 - primary sv no desc',
2547 'channel': 'cole-dlp-test-acc',
2550 'channel_url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
2552 'playable_in_embed': True,
2553 'availability': 'unlisted',
2554 'thumbnail': r're:^https?://.*\.jpg',
2557 'live_status': 'not_live',
2558 'upload_date': '20220908',
2559 'categories': ['People & Blogs'],
2560 'channel_id': 'UCiu-3thuViMebBjw_5nWYrA',
2561 'uploader_url': 'https://www.youtube.com/@coletdjnz',
2562 'uploader_id': '@coletdjnz',
2563 'uploader': 'cole-dlp-test-acc',
2565 'params': {'skip_download': True}
2567 # Extractor argument: prefer translated title+description
2568 'url': 'https://www.youtube.com/watch?v=gHKT4uU8Zng',
2570 'id': 'gHKT4uU8Zng',
2572 'channel': 'cole-dlp-test-acc',
2575 'live_status': 'not_live',
2576 'channel_id': 'UCiu-3thuViMebBjw_5nWYrA',
2577 'upload_date': '20220728',
2579 'categories': ['People & Blogs'],
2580 'thumbnail': r're:^https?://.*\.jpg',
2581 'title': 'dlp test video title translated (fr)',
2582 'availability': 'public',
2584 'description': 'dlp test video description translated (fr)',
2585 'playable_in_embed': True,
2586 'channel_url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
2587 'uploader_url': 'https://www.youtube.com/@coletdjnz',
2588 'uploader_id': '@coletdjnz',
2589 'uploader': 'cole-dlp-test-acc',
2591 'params': {'skip_download': True, 'extractor_args': {'youtube': {'lang': ['fr']}}},
2592 'expected_warnings': [r'Preferring "fr" translated fields'],
2594 'note': '6 channel audio',
2595 'url': 'https://www.youtube.com/watch?v=zgdo7-RRjgo',
2596 'only_matching': True,
2598 'note': 'Multiple HLS formats with same itag',
2599 'url': 'https://www.youtube.com/watch?v=kX3nB4PpJko',
2601 'id': 'kX3nB4PpJko',
2603 'categories': ['Entertainment'],
2604 'description': 'md5:e8031ff6e426cdb6a77670c9b81f6fa6',
2605 'live_status': 'not_live',
2607 'channel_follower_count': int,
2608 'thumbnail': 'https://i.ytimg.com/vi_webp/kX3nB4PpJko/maxresdefault.webp',
2609 'title': 'Last To Take Hand Off Jet, Keeps It!',
2610 'channel': 'MrBeast',
2611 'playable_in_embed': True,
2613 'upload_date': '20221112',
2614 'channel_url': 'https://www.youtube.com/channel/UCX6OQ3DkcsbYNE6H8uQQuVA',
2616 'availability': 'public',
2617 'channel_id': 'UCX6OQ3DkcsbYNE6H8uQQuVA',
2620 'uploader': 'MrBeast',
2621 'uploader_url': 'https://www.youtube.com/@MrBeast',
2622 'uploader_id': '@MrBeast',
2623 'comment_count': int,
2624 'channel_is_verified': True,
2625 'heatmap': 'count:100',
2627 'params': {'extractor_args': {'youtube': {'player_client': ['ios']}}, 'format': '233-1'},
2629 'note': 'Audio formats with Dynamic Range Compression',
2630 'url': 'https://www.youtube.com/watch?v=Tq92D6wQ1mg',
2632 'id': 'Tq92D6wQ1mg',
2634 'title': '[MMD] Adios - EVERGLOW [+Motion DL]',
2635 'channel_url': 'https://www.youtube.com/channel/UC1yoRdFoFJaCY-AGfD9W0wQ',
2636 'channel_id': 'UC1yoRdFoFJaCY-AGfD9W0wQ',
2637 'channel_follower_count': int,
2638 'description': 'md5:17eccca93a786d51bc67646756894066',
2639 'upload_date': '20191228',
2640 'tags': ['mmd', 'dance', 'mikumikudance', 'kpop', 'vtuber'],
2641 'playable_in_embed': True,
2643 'categories': ['Entertainment'],
2644 'thumbnail': 'https://i.ytimg.com/vi/Tq92D6wQ1mg/sddefault.jpg',
2646 'channel': 'Projekt Melody',
2648 'availability': 'needs_auth',
2649 'comment_count': int,
2650 'live_status': 'not_live',
2652 'uploader': 'Projekt Melody',
2653 'uploader_id': '@ProjektMelody',
2654 'uploader_url': 'https://www.youtube.com/@ProjektMelody',
2656 'params': {'extractor_args': {'youtube': {'player_client': ['tv_embedded']}}, 'format': '251-drc'},
2659 'url': 'https://www.youtube.com/live/qVv6vCqciTM',
2661 'id': 'qVv6vCqciTM',
2664 'comment_count': int,
2665 'chapters': 'count:13',
2666 'upload_date': '20221223',
2667 'thumbnail': 'https://i.ytimg.com/vi/qVv6vCqciTM/maxresdefault.jpg',
2668 'channel_url': 'https://www.youtube.com/channel/UCIdEIHpS0TdkqRkHL5OkLtA',
2670 'release_date': '20221223',
2671 'tags': ['Vtuber', '月ノ美兎', '名取さな', 'にじさんじ', 'クリスマス', '3D配信'],
2672 'title': '【 #インターネット女クリスマス 】3Dで歌ってはしゃぐインターネットの女たち【月ノ美兎/名取さな】',
2674 'playable_in_embed': True,
2676 'availability': 'public',
2677 'channel_follower_count': int,
2678 'channel_id': 'UCIdEIHpS0TdkqRkHL5OkLtA',
2679 'categories': ['Entertainment'],
2680 'live_status': 'was_live',
2681 'release_timestamp': 1671793345,
2682 'channel': 'さなちゃんねる',
2683 'description': 'md5:6aebf95cc4a1d731aebc01ad6cc9806d',
2684 'uploader': 'さなちゃんねる',
2685 'uploader_url': 'https://www.youtube.com/@sana_natori',
2686 'uploader_id': '@sana_natori',
2687 'channel_is_verified': True,
2688 'heatmap': 'count:100',
2692 # Fallbacks when webpage and web client is unavailable
2693 'url': 'https://www.youtube.com/watch?v=wSSmNUl9Snw',
2695 'id': 'wSSmNUl9Snw',
2697 # 'categories': ['Science & Technology'],
2699 'chapters': 'count:2',
2700 'channel': 'Scott Manley',
2703 # 'availability': 'public',
2704 'channel_follower_count': int,
2705 'live_status': 'not_live',
2706 'upload_date': '20170831',
2709 'uploader_url': 'https://www.youtube.com/@scottmanley',
2710 'description': 'md5:f4bed7b200404b72a394c2f97b782c02',
2711 'uploader': 'Scott Manley',
2712 'uploader_id': '@scottmanley',
2713 'title': 'The Computer Hack That Saved Apollo 14',
2714 'channel_id': 'UCxzC4EngIsMrPmbm6Nxvb-A',
2715 'thumbnail': r're:^https?://.*\.webp',
2716 'channel_url': 'https://www.youtube.com/channel/UCxzC4EngIsMrPmbm6Nxvb-A',
2717 'playable_in_embed': True,
2718 'comment_count': int,
2719 'channel_is_verified': True,
2720 'heatmap': 'count:100',
2723 'extractor_args': {'youtube': {'player_client': ['android'], 'player_skip': ['webpage']}},
2729 # YouTube <object> embed
2731 'url': 'http://www.improbable.com/2017/04/03/untrained-modern-youths-and-ancient-masters-in-selfie-portraits/',
2732 'md5': '873c81d308b979f0e23ee7e620b312a3',
2734 'id': 'msN87y-iEx0',
2736 'title': 'Feynman: Mirrors FUN TO IMAGINE 6',
2737 'upload_date': '20080526',
2738 'description': 'md5:873c81d308b979f0e23ee7e620b312a3',
2740 'tags': ['feynman', 'mirror', 'science', 'physics', 'imagination', 'fun', 'cool', 'puzzle'],
2741 'channel_id': 'UCCeo--lls1vna5YJABWAcVA',
2742 'playable_in_embed': True,
2743 'thumbnail': 'https://i.ytimg.com/vi/msN87y-iEx0/hqdefault.jpg',
2745 'comment_count': int,
2746 'channel': 'Christopher Sykes',
2747 'live_status': 'not_live',
2748 'channel_url': 'https://www.youtube.com/channel/UCCeo--lls1vna5YJABWAcVA',
2749 'availability': 'public',
2752 'categories': ['Science & Technology'],
2753 'channel_follower_count': int,
2754 'uploader': 'Christopher Sykes',
2755 'uploader_url': 'https://www.youtube.com/@ChristopherSykesDocumentaries',
2756 'uploader_id': '@ChristopherSykesDocumentaries',
2757 'heatmap': 'count:100',
2760 'skip_download': True,
2766 def suitable(cls, url):
2767 from ..utils import parse_qs
2770 if qs.get('list', [None])[0]:
2772 return super().suitable(url)
2774 def __init__(self, *args, **kwargs):
2775 super().__init__(*args, **kwargs)
2776 self._code_cache = {}
2777 self._player_cache = {}
2779 def _prepare_live_from_start_formats(self, formats, video_id, live_start_time, url, webpage_url, smuggled_data, is_live):
2780 lock = threading.Lock()
2781 start_time = time.time()
2782 formats = [f for f in formats if f.get('is_from_start')]
2784 def refetch_manifest(format_id, delay):
2785 nonlocal formats, start_time, is_live
2786 if time.time() <= start_time + delay:
2789 _, _, prs, player_url = self._download_player_responses(url, smuggled_data, video_id, webpage_url)
2790 video_details = traverse_obj(prs, (..., 'videoDetails'), expected_type=dict)
2791 microformats = traverse_obj(
2792 prs, (..., 'microformat', 'playerMicroformatRenderer'),
2794 _, live_status, _, formats, _ = self._list_formats(video_id, microformats, video_details, prs, player_url)
2795 is_live = live_status == 'is_live'
2796 start_time = time.time()
2798 def mpd_feed(format_id, delay):
2800 @returns (manifest_url, manifest_stream_number, is_live) or None
2802 for retry in self.RetryManager(fatal=False):
2804 refetch_manifest(format_id, delay)
2806 f = next((f for f in formats if f['format_id'] == format_id), None)
2809 retry.error = f'{video_id}: Video is no longer live'
2811 retry.error = f'Cannot find refreshed manifest for format {format_id}{bug_reports_message()}'
2813 return f['manifest_url'], f['manifest_stream_number'], is_live
2817 f['is_live'] = is_live
2818 gen = functools.partial(self._live_dash_fragments, video_id, f['format_id'],
2819 live_start_time, mpd_feed, not is_live and f.copy())
2821 f['fragments'] = gen
2822 f['protocol'] = 'http_dash_segments_generator'
2824 f['fragments'] = LazyList(gen({}))
2825 del f['is_from_start']
2827 def _live_dash_fragments(self, video_id, format_id, live_start_time, mpd_feed, manifestless_orig_fmt, ctx):
2828 FETCH_SPAN, MAX_DURATION = 5, 432000
2830 mpd_url, stream_number, is_live = None, None, True
2833 download_start_time = ctx.get('start') or time.time()
2835 lack_early_segments = download_start_time - (live_start_time or download_start_time) > MAX_DURATION
2836 if lack_early_segments:
2837 self.report_warning(bug_reports_message(
2838 'Starting download from the last 120 hours of the live stream since '
2839 'YouTube does not have data before that. If you think this is wrong,'), only_once=True)
2840 lack_early_segments = True
2842 known_idx, no_fragment_score, last_segment_url = begin_index, 0, None
2843 fragments, fragment_base_url = None, None
2845 def _extract_sequence_from_mpd(refresh_sequence, immediate):
2846 nonlocal mpd_url, stream_number, is_live, no_fragment_score, fragments, fragment_base_url
2847 # Obtain from MPD's maximum seq value
2848 old_mpd_url = mpd_url
2849 last_error = ctx.pop('last_error', None)
2850 expire_fast = immediate or last_error and isinstance(last_error, HTTPError) and last_error.status == 403
2851 mpd_url, stream_number, is_live = (mpd_feed(format_id, 5 if expire_fast else 18000)
2852 or (mpd_url, stream_number, False))
2853 if not refresh_sequence:
2854 if expire_fast and not is_live:
2855 return False, last_seq
2856 elif old_mpd_url == mpd_url:
2857 return True, last_seq
2858 if manifestless_orig_fmt:
2859 fmt_info = manifestless_orig_fmt
2862 fmts, _ = self._extract_mpd_formats_and_subtitles(
2863 mpd_url, None, note=False, errnote=False, fatal=False)
2864 except ExtractorError:
2867 no_fragment_score += 2
2868 return False, last_seq
2869 fmt_info = next(x for x in fmts if x['manifest_stream_number'] == stream_number)
2870 fragments = fmt_info['fragments']
2871 fragment_base_url = fmt_info['fragment_base_url']
2872 assert fragment_base_url
2874 _last_seq = int(re.search(r'(?:/|^)sq/(\d+)', fragments[-1]['path']).group(1))
2875 return True, _last_seq
2877 self.write_debug(f'[{video_id}] Generating fragments for format {format_id}')
2879 fetch_time = time.time()
2880 if no_fragment_score > 30:
2882 if last_segment_url:
2883 # Obtain from "X-Head-Seqnum" header value from each segment
2885 urlh = self._request_webpage(
2886 last_segment_url, None, note=False, errnote=False, fatal=False)
2887 except ExtractorError:
2889 last_seq = try_get(urlh, lambda x: int_or_none(x.headers['X-Head-Seqnum']))
2890 if last_seq is None:
2891 no_fragment_score += 2
2892 last_segment_url = None
2895 should_continue, last_seq = _extract_sequence_from_mpd(True, no_fragment_score > 15)
2896 no_fragment_score += 2
2897 if not should_continue:
2900 if known_idx > last_seq:
2901 last_segment_url = None
2906 if begin_index < 0 and known_idx < 0:
2907 # skip from the start when it's negative value
2908 known_idx = last_seq + begin_index
2909 if lack_early_segments:
2910 known_idx = max(known_idx, last_seq - int(MAX_DURATION // fragments[-1]['duration']))
2912 for idx in range(known_idx, last_seq):
2913 # do not update sequence here or you'll get skipped some part of it
2914 should_continue, _ = _extract_sequence_from_mpd(False, False)
2915 if not should_continue:
2917 raise ExtractorError('breaking out of outer loop')
2918 last_segment_url = urljoin(fragment_base_url, 'sq/%d' % idx)
2920 'url': last_segment_url,
2921 'fragment_count': last_seq,
2923 if known_idx == last_seq:
2924 no_fragment_score += 5
2926 no_fragment_score = 0
2927 known_idx = last_seq
2928 except ExtractorError:
2931 if manifestless_orig_fmt:
2932 # Stop at the first iteration if running for post-live manifestless;
2933 # fragment count no longer increase since it starts
2936 time.sleep(max(0, FETCH_SPAN + fetch_time - time.time()))
2938 def _extract_player_url(self, *ytcfgs, webpage=None):
2939 player_url = traverse_obj(
2940 ytcfgs, (..., 'PLAYER_JS_URL'), (..., 'WEB_PLAYER_CONTEXT_CONFIGS', ..., 'jsUrl'),
2941 get_all=False, expected_type=str)
2944 return urljoin('https://www.youtube.com', player_url)
2946 def _download_player_url(self, video_id, fatal=False):
2947 res = self._download_webpage(
2948 'https://www.youtube.com/iframe_api',
2949 note='Downloading iframe API JS', video_id=video_id, fatal=fatal)
2951 player_version = self._search_regex(
2952 r'player\\?/([0-9a-fA-F]{8})\\?/', res, 'player version', fatal=fatal)
2954 return f'https://www.youtube.com/s/player/{player_version}/player_ias.vflset/en_US/base.js'
2956 def _signature_cache_id(self, example_sig):
2957 """ Return a string representation of a signature """
2958 return '.'.join(str(len(part)) for part in example_sig.split('.'))
2961 def _extract_player_info(cls, player_url):
2962 for player_re in cls._PLAYER_INFO_RE:
2963 id_m = re.search(player_re, player_url)
2967 raise ExtractorError('Cannot identify player %r' % player_url)
2968 return id_m.group('id')
2970 def _load_player(self, video_id, player_url, fatal=True):
2971 player_id = self._extract_player_info(player_url)
2972 if player_id not in self._code_cache:
2973 code = self._download_webpage(
2974 player_url, video_id, fatal=fatal,
2975 note='Downloading player ' + player_id,
2976 errnote='Download of %s failed' % player_url)
2978 self._code_cache[player_id] = code
2979 return self._code_cache.get(player_id)
2981 def _extract_signature_function(self, video_id, player_url, example_sig):
2982 player_id = self._extract_player_info(player_url)
2984 # Read from filesystem cache
2985 func_id = f'js_{player_id}_{self._signature_cache_id(example_sig)}'
2986 assert os.path.basename(func_id) == func_id
2988 self.write_debug(f'Extracting signature function {func_id}')
2989 cache_spec, code = self.cache.load('youtube-sigfuncs', func_id), None
2992 code = self._load_player(video_id, player_url)
2994 res = self._parse_sig_js(code)
2995 test_string = ''.join(map(chr, range(len(example_sig))))
2996 cache_spec = [ord(c) for c in res(test_string)]
2997 self.cache.store('youtube-sigfuncs', func_id, cache_spec)
2999 return lambda s: ''.join(s[i] for i in cache_spec)
3001 def _print_sig_code(self, func, example_sig):
3002 if not self.get_param('youtube_print_sig_code'):
3005 def gen_sig_code(idxs):
3006 def _genslice(start, end, step):
3007 starts = '' if start == 0 else str(start)
3008 ends = (':%d' % (end + step)) if end + step >= 0 else ':'
3009 steps = '' if step == 1 else (':%d' % step)
3010 return f's[{starts}{ends}{steps}]'
3013 # Quelch pyflakes warnings - start will be set when step is set
3014 start = '(Never used)'
3015 for i, prev in zip(idxs[1:], idxs[:-1]):
3016 if step is not None:
3017 if i - prev == step:
3019 yield _genslice(start, prev, step)
3022 if i - prev in [-1, 1]:
3027 yield 's[%d]' % prev
3031 yield _genslice(start, i, step)
3033 test_string = ''.join(map(chr, range(len(example_sig))))
3034 cache_res = func(test_string)
3035 cache_spec = [ord(c) for c in cache_res]
3036 expr_code = ' + '.join(gen_sig_code(cache_spec))
3037 signature_id_tuple = '(%s)' % (
3038 ', '.join(str(len(p)) for p in example_sig.split('.')))
3039 code = ('if tuple(len(p) for p in s.split(\'.\')) == %s:\n'
3040 ' return %s\n') % (signature_id_tuple, expr_code)
3041 self.to_screen('Extracted signature function:\n' + code)
3043 def _parse_sig_js(self, jscode):
3044 funcname = self._search_regex(
3045 (r'\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
3046 r'\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
3047 r'\bm=(?P<sig>[a-zA-Z0-9$]{2,})\(decodeURIComponent\(h\.s\)\)',
3048 r'\bc&&\(c=(?P<sig>[a-zA-Z0-9$]{2,})\(decodeURIComponent\(c\)\)',
3049 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+\))?',
3050 r'(?P<sig>[a-zA-Z0-9$]+)\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)',
3052 r'("|\')signature\1\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
3053 r'\.sig\|\|(?P<sig>[a-zA-Z0-9$]+)\(',
3054 r'yt\.akamaized\.net/\)\s*\|\|\s*.*?\s*[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*(?:encodeURIComponent\s*\()?\s*(?P<sig>[a-zA-Z0-9$]+)\(',
3055 r'\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
3056 r'\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
3057 r'\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\('),
3058 jscode, 'Initial JS player signature function name', group='sig')
3060 jsi = JSInterpreter(jscode)
3061 initial_function = jsi.extract_function(funcname)
3062 return lambda s: initial_function([s])
3064 def _cached(self, func, *cache_id):
3065 def inner(*args, **kwargs):
3066 if cache_id not in self._player_cache:
3068 self._player_cache[cache_id] = func(*args, **kwargs)
3069 except ExtractorError as e:
3070 self._player_cache[cache_id] = e
3071 except Exception as e:
3072 self._player_cache[cache_id] = ExtractorError(traceback.format_exc(), cause=e)
3074 ret = self._player_cache[cache_id]
3075 if isinstance(ret, Exception):
3080 def _decrypt_signature(self, s, video_id, player_url):
3081 """Turn the encrypted s field into a working signature"""
3082 extract_sig = self._cached(
3083 self._extract_signature_function, 'sig', player_url, self._signature_cache_id(s))
3084 func = extract_sig(video_id, player_url, s)
3085 self._print_sig_code(func, s)
3088 def _decrypt_nsig(self, s, video_id, player_url):
3089 """Turn the encrypted n field into a working signature"""
3090 if player_url is None:
3091 raise ExtractorError('Cannot decrypt nsig without player_url')
3092 player_url = urljoin('https://www.youtube.com', player_url)
3095 jsi, player_id, func_code = self._extract_n_function_code(video_id, player_url)
3096 except ExtractorError as e:
3097 raise ExtractorError('Unable to extract nsig function code', cause=e)
3098 if self.get_param('youtube_print_sig_code'):
3099 self.to_screen(f'Extracted nsig function from {player_id}:\n{func_code[1]}\n')
3102 extract_nsig = self._cached(self._extract_n_function_from_code, 'nsig func', player_url)
3103 ret = extract_nsig(jsi, func_code)(s)
3104 except JSInterpreter.Exception as e:
3106 jsi = PhantomJSwrapper(self, timeout=5000)
3107 except ExtractorError:
3109 self.report_warning(
3110 f'Native nsig extraction failed: Trying with PhantomJS\n'
3111 f' n = {s} ; player = {player_url}', video_id)
3112 self.write_debug(e, only_once=True)
3114 args, func_body = func_code
3116 f'console.log(function({", ".join(args)}) {{ {func_body} }}({s!r}));',
3117 video_id=video_id, note='Executing signature code').strip()
3119 self.write_debug(f'Decrypted nsig {s} => {ret}')
3122 def _extract_n_function_name(self, jscode):
3123 funcname, idx = self._search_regex(
3124 r'\.get\("n"\)\)&&\(b=(?P<nfunc>[a-zA-Z0-9$]+)(?:\[(?P<idx>\d+)\])?\([a-zA-Z0-9]\)',
3125 jscode, 'Initial JS player n function name', group=('nfunc', 'idx'))
3129 return json.loads(js_to_json(self._search_regex(
3130 rf'var {re.escape(funcname)}\s*=\s*(\[.+?\])\s*[,;]', jscode,
3131 f'Initial JS player n function list ({funcname}.{idx})')))[int(idx)]
3133 def _extract_n_function_code(self, video_id, player_url):
3134 player_id = self._extract_player_info(player_url)
3135 func_code = self.cache.load('youtube-nsig', player_id, min_ver='2022.09.1')
3136 jscode = func_code or self._load_player(video_id, player_url)
3137 jsi = JSInterpreter(jscode)
3140 return jsi, player_id, func_code
3142 func_name = self._extract_n_function_name(jscode)
3145 func_code = self._search_regex(
3146 r'''(?xs
)%s\s
*=\s
*function\s
*\
((?P
<var
>[\w$
]+)\
)\s
*
3147 # NB: The end of the regex is intentionally kept strict
3148 {(?P<code>.+?}\s
*return\
[\w$
]+.join\
(""\
))};''' % func_name,
3149 jscode, 'nsig function', group=('var', 'code'), default=None)
3151 func_code = ([func_code[0]], func_code[1])
3153 self.write_debug('Extracting nsig function with jsinterp')
3154 func_code = jsi.extract_function_code(func_name)
3156 self.cache.store('youtube-nsig', player_id, func_code)
3157 return jsi, player_id, func_code
3159 def _extract_n_function_from_code(self, jsi, func_code):
3160 func = jsi.extract_function_from_code(*func_code)
3162 def extract_nsig(s):
3165 except JSInterpreter.Exception:
3167 except Exception as e:
3168 raise JSInterpreter.Exception(traceback.format_exc(), cause=e)
3170 if ret.startswith('enhanced_except_'):
3171 raise JSInterpreter.Exception('Signature function returned an exception')
3176 def _extract_signature_timestamp(self, video_id, player_url, ytcfg=None, fatal=False):
3178 Extract signatureTimestamp (sts)
3179 Required to tell API what sig/player version is in use.
3182 if isinstance(ytcfg, dict):
3183 sts = int_or_none(ytcfg.get('STS'))
3186 # Attempt to extract from player
3187 if player_url is None:
3188 error_msg = 'Cannot extract signature timestamp without player_url.'
3190 raise ExtractorError(error_msg)
3191 self.report_warning(error_msg)
3193 code = self._load_player(video_id, player_url, fatal=fatal)
3195 sts = int_or_none(self._search_regex(
3196 r'(?:signatureTimestamp|sts)\s*:\s*(?P<sts>[0-9]{5})', code,
3197 'JS player signature timestamp', group='sts', fatal=fatal))
3200 def _mark_watched(self, video_id, player_responses):
3201 for is_full, key in enumerate(('videostatsPlaybackUrl', 'videostatsWatchtimeUrl')):
3202 label = 'fully ' if is_full else ''
3203 url = get_first(player_responses, ('playbackTracking', key, 'baseUrl'),
3204 expected_type=url_or_none)
3206 self.report_warning(f'Unable to mark {label}watched')
3208 parsed_url = urllib.parse.urlparse(url)
3209 qs = urllib.parse.parse_qs(parsed_url.query)
3211 # cpn generation algorithm is reverse engineered from base.js.
3212 # In fact it works even with dummy cpn.
3213 CPN_ALPHABET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'
3214 cpn = ''.join(CPN_ALPHABET[random.randint(0, 256) & 63] for _ in range(0, 16))
3216 # # more consistent results setting it to right before the end
3217 video_length = [str(float((qs.get('len') or ['1.5'])[0]) - 1)]
3222 'cmt': video_length,
3223 'el': 'detailpage', # otherwise defaults to "shorts"
3227 # these seem to mark watchtime "history" in the real world
3228 # they're required, so send in a single value
3234 url = urllib.parse.urlunparse(
3235 parsed_url._replace(query=urllib.parse.urlencode(qs, True)))
3237 self._download_webpage(
3238 url, video_id, f'Marking {label}watched',
3239 'Unable to mark watched', fatal=False)
3242 def _extract_from_webpage(cls, url, webpage):
3243 # Invidious Instances
3244 # https://github.com/yt-dlp/yt-dlp/issues/195
3245 # https://github.com/iv-org/invidious/pull/1730
3247 r'<link rel="alternate" href="(?P<url>https://www\.youtube\.com/watch\?v=[0-9A-Za-z_-]{11})"',
3250 yield cls.url_result(mobj.group('url'), cls)
3251 raise cls.StopExtraction()
3253 yield from super()._extract_from_webpage(url, webpage)
3255 # lazyYT YouTube embed
3256 for id_ in re.findall(r'class="lazyYT" data-youtube-id="([^"]+)"', webpage):
3257 yield cls.url_result(unescapeHTML(id_), cls, id_)
3259 # Wordpress "YouTube Video Importer" plugin
3260 for m in re.findall(r'''(?x
)<div
[^
>]+
3261 class=(?P
<q1
>[\'"])[^\'"]*\byvii
_single
_video
_player
\b[^
\'"]*(?P=q1)[^>]+
3262 data-video_id=(?P<q2>[\'"])([^
\'"]+)(?P=q2)''', webpage):
3263 yield cls.url_result(m[-1], cls, m[-1])
3266 def extract_id(cls, url):
3267 video_id = cls.get_temp_id(url)
3269 raise ExtractorError(f'Invalid URL: {url}')
3272 def _extract_chapters_from_json(self, data, duration):
3273 chapter_list = traverse_obj(
3275 'playerOverlays', 'playerOverlayRenderer', 'decoratedPlayerBarRenderer',
3276 'decoratedPlayerBarRenderer', 'playerBar', 'chapteredPlayerBarRenderer', 'chapters'
3277 ), expected_type=list)
3279 return self._extract_chapters_helper(
3281 start_function=lambda chapter: float_or_none(
3282 traverse_obj(chapter, ('chapterRenderer', 'timeRangeStartMillis')), scale=1000),
3283 title_function=lambda chapter: traverse_obj(
3284 chapter, ('chapterRenderer', 'title', 'simpleText'), expected_type=str),
3287 def _extract_chapters_from_engagement_panel(self, data, duration):
3288 content_list = traverse_obj(
3290 ('engagementPanels', ..., 'engagementPanelSectionListRenderer', 'content', 'macroMarkersListRenderer', 'contents'),
3292 chapter_time = lambda chapter: parse_duration(self._get_text(chapter, 'timeDescription'))
3293 chapter_title = lambda chapter: self._get_text(chapter, 'title')
3295 return next(filter(None, (
3296 self._extract_chapters_helper(traverse_obj(contents, (..., 'macroMarkersListItemRenderer')),
3297 chapter_time, chapter_title, duration)
3298 for contents in content_list)), [])
3300 def _extract_heatmap(self, data):
3301 return traverse_obj(data, (
3302 'frameworkUpdates', 'entityBatchUpdate', 'mutations',
3303 lambda _, v: v['payload']['macroMarkersListEntity']['markersList']['markerType'] == 'MARKER_TYPE_HEATMAP',
3304 'payload', 'macroMarkersListEntity', 'markersList', 'markers', ..., {
3305 'start_time': ('startMillis', {functools.partial(float_or_none, scale=1000)}),
3306 'end_time': {lambda x: (int(x['startMillis']) + int(x['durationMillis'])) / 1000},
3307 'value': ('intensityScoreNormalized', {float_or_none}),
3310 def _extract_comment(self, comment_renderer, parent=None):
3311 comment_id = comment_renderer.get('commentId')
3317 'text': self._get_text(comment_renderer, 'contentText'),
3318 'like_count': self._get_count(comment_renderer, 'voteCount'),
3319 'author_id': traverse_obj(comment_renderer, ('authorEndpoint', 'browseEndpoint', 'browseId', {self.ucid_or_none})),
3320 'author': self._get_text(comment_renderer, 'authorText'),
3321 'author_thumbnail': traverse_obj(comment_renderer, ('authorThumbnail', 'thumbnails', -1, 'url', {url_or_none})),
3322 'parent': parent or 'root',
3325 # Timestamp is an estimate calculated from the current time and time_text
3326 time_text = self._get_text(comment_renderer, 'publishedTimeText') or ''
3327 timestamp = self._parse_time_text(time_text)
3330 # FIXME: non-standard, but we need a way of showing that it is an estimate.
3331 '_time_text': time_text,
3332 'timestamp': timestamp,
3335 info['author_url'] = urljoin(
3336 'https://www.youtube.com', traverse_obj(comment_renderer, ('authorEndpoint', (
3337 ('browseEndpoint', 'canonicalBaseUrl'), ('commandMetadata', 'webCommandMetadata', 'url'))),
3338 expected_type=str, get_all=False))
3340 author_is_uploader = traverse_obj(comment_renderer, 'authorIsChannelOwner')
3341 if author_is_uploader is not None:
3342 info['author_is_uploader'] = author_is_uploader
3344 comment_abr = traverse_obj(
3345 comment_renderer, ('actionButtons', 'commentActionButtonsRenderer'), expected_type=dict)
3346 if comment_abr is not None:
3347 info['is_favorited'] = 'creatorHeart' in comment_abr
3349 badges = self._extract_badges([traverse_obj(comment_renderer, 'authorCommentBadge')])
3350 if self._has_badge(badges, BadgeType.VERIFIED):
3351 info['author_is_verified'] = True
3353 is_pinned = traverse_obj(comment_renderer, 'pinnedCommentBadge')
3355 info['is_pinned'] = True
3359 def _comment_entries(self, root_continuation_data, ytcfg, video_id, parent=None, tracker=None):
3361 get_single_config_arg = lambda c: self._configuration_arg(c, [''])[0]
3363 def extract_header(contents):
3364 _continuation = None
3365 for content in contents:
3366 comments_header_renderer = traverse_obj(content, 'commentsHeaderRenderer')
3367 expected_comment_count = self._get_count(
3368 comments_header_renderer, 'countText', 'commentsCount')
3370 if expected_comment_count is not None:
3371 tracker['est_total'] = expected_comment_count
3372 self.to_screen(f'Downloading ~{expected_comment_count} comments')
3373 comment_sort_index = int(get_single_config_arg('comment_sort') != 'top') # 1 = new, 0 = top
3375 sort_menu_item = try_get(
3376 comments_header_renderer,
3377 lambda x: x['sortMenu']['sortFilterSubMenuRenderer']['subMenuItems'][comment_sort_index], dict) or {}
3378 sort_continuation_ep = sort_menu_item.get('serviceEndpoint') or {}
3380 _continuation = self._extract_continuation_ep_data(sort_continuation_ep) or self._extract_continuation(sort_menu_item)
3381 if not _continuation:
3384 sort_text = str_or_none(sort_menu_item.get('title'))
3386 sort_text = 'top comments' if comment_sort_index == 0 else 'newest first'
3387 self.to_screen('Sorting comments by %s' % sort_text.lower())
3389 return _continuation
3391 def extract_thread(contents):
3393 tracker['current_page_thread'] = 0
3394 for content in contents:
3395 if not parent and tracker['total_parent_comments'] >= max_parents:
3397 comment_thread_renderer = try_get(content, lambda x: x['commentThreadRenderer'])
3398 comment_renderer = get_first(
3399 (comment_thread_renderer, content), [['commentRenderer', ('comment', 'commentRenderer')]],
3400 expected_type=dict, default={})
3402 comment = self._extract_comment(comment_renderer, parent)
3405 comment_id = comment['id']
3406 if comment.get('is_pinned'):
3407 tracker['pinned_comment_ids'].add(comment_id)
3408 # Sometimes YouTube may break and give us infinite looping comments.
3409 # See: https://github.com/yt-dlp/yt-dlp/issues/6290
3410 if comment_id in tracker['seen_comment_ids']:
3411 if comment_id in tracker['pinned_comment_ids'] and not comment.get('is_pinned'):
3412 # Pinned comments may appear a second time in newest first sort
3413 # See: https://github.com/yt-dlp/yt-dlp/issues/6712
3415 self.report_warning(
3416 'Detected YouTube comments looping. Stopping comment extraction '
3417 f'{"for this thread" if parent else ""} as we probably cannot get any more.')
3420 tracker['seen_comment_ids'].add(comment['id'])
3422 tracker['running_total'] += 1
3423 tracker['total_reply_comments' if parent else 'total_parent_comments'] += 1
3426 # Attempt to get the replies
3427 comment_replies_renderer = try_get(
3428 comment_thread_renderer, lambda x: x['replies']['commentRepliesRenderer'], dict)
3430 if comment_replies_renderer:
3431 tracker['current_page_thread'] += 1
3432 comment_entries_iter = self._comment_entries(
3433 comment_replies_renderer, ytcfg, video_id,
3434 parent=comment.get('id'), tracker=tracker)
3435 yield from itertools.islice(comment_entries_iter, min(
3436 max_replies_per_thread, max(0, max_replies - tracker['total_reply_comments'])))
3438 # Keeps track of counts across recursive calls
3443 current_page_thread=0,
3444 total_parent_comments=0,
3445 total_reply_comments=0,
3446 seen_comment_ids=set(),
3447 pinned_comment_ids=set()
3451 # YouTube comments have a max depth of 2
3452 max_depth = int_or_none(get_single_config_arg('max_comment_depth'))
3454 self._downloader.deprecated_feature('[youtube] max_comment_depth extractor argument is deprecated. '
3455 'Set max replies in the max-comments extractor argument instead')
3456 if max_depth == 1 and parent:
3459 max_comments, max_parents, max_replies, max_replies_per_thread, *_ = map(
3460 lambda p: int_or_none(p, default=sys.maxsize), self._configuration_arg('max_comments', ) + [''] * 4)
3462 continuation = self._extract_continuation(root_continuation_data)
3465 is_forced_continuation = False
3466 is_first_continuation = parent is None
3467 if is_first_continuation and not continuation:
3468 # Sometimes you can get comments by generating the continuation yourself,
3469 # even if YouTube initially reports them being disabled - e.g. stories comments.
3470 # Note: if the comment section is actually disabled, YouTube may return a response with
3471 # required check_get_keys missing. So we will disable that check initially in this case.
3472 continuation = self._build_api_continuation_query(self._generate_comment_continuation(video_id))
3473 is_forced_continuation = True
3475 continuation_items_path = (
3476 'onResponseReceivedEndpoints', ..., ('reloadContinuationItemsCommand', 'appendContinuationItemsAction'), 'continuationItems')
3477 for page_num in itertools.count(0):
3478 if not continuation:
3480 headers = self.generate_api_headers(ytcfg=ytcfg, visitor_data=self._extract_visitor_data(response))
3481 comment_prog_str = f"({tracker['running_total']}
/~{tracker['est_total']}
)"
3483 if is_first_continuation:
3484 note_prefix = 'Downloading comment section API JSON'
3486 note_prefix = ' Downloading comment API JSON reply thread %d %s' % (
3487 tracker['current_page_thread'], comment_prog_str)
3489 note_prefix = '%sDownloading comment%s API JSON page %d %s' % (
3490 ' ' if parent else '', ' replies' if parent else '',
3491 page_num, comment_prog_str)
3493 # Do a deep check for incomplete data as sometimes YouTube may return no comments for a continuation
3494 # Ignore check if YouTube says the comment count is 0.
3495 check_get_keys = None
3496 if not is_forced_continuation and not (tracker['est_total'] == 0 and tracker['running_total'] == 0):
3497 check_get_keys = [[*continuation_items_path, ..., (
3498 'commentsHeaderRenderer' if is_first_continuation else ('commentThreadRenderer', 'commentRenderer'))]]
3500 response = self._extract_response(
3501 item_id=None, query=continuation,
3502 ep='next', ytcfg=ytcfg, headers=headers, note=note_prefix,
3503 check_get_keys=check_get_keys)
3504 except ExtractorError as e:
3505 # Ignore incomplete data error for replies if retries didn't work.
3506 # This is to allow any other parent comments and comment threads to be downloaded.
3507 # See: https://github.com/yt-dlp/yt-dlp/issues/4669
3508 if 'incomplete data' in str(e).lower() and parent:
3509 if self.get_param('ignoreerrors') in (True, 'only_download'):
3510 self.report_warning(
3511 'Received incomplete data for a comment reply thread and retrying did not help. '
3512 'Ignoring to let other comments be downloaded. Pass --no-ignore-errors to not ignore.')
3515 raise ExtractorError(
3516 'Incomplete data received for comment reply thread. '
3517 'Pass --ignore-errors to ignore and allow rest of comments to download.',
3520 is_forced_continuation = False
3522 for continuation_items in traverse_obj(response, continuation_items_path, expected_type=list, default=[]):
3523 if is_first_continuation:
3524 continuation = extract_header(continuation_items)
3525 is_first_continuation = False
3530 for entry in extract_thread(continuation_items):
3534 continuation = self._extract_continuation({'contents': continuation_items})
3538 message = self._get_text(root_continuation_data, ('contents', ..., 'messageRenderer', 'text'), max_runs=1)
3539 if message and not parent and tracker['running_total'] == 0:
3540 self.report_warning(f'Youtube said: {message}', video_id=video_id, only_once=True)
3541 raise self.CommentsDisabled
3544 def _generate_comment_continuation(video_id):
3546 Generates initial comment section continuation token from given video id
3548 token = f'\x12\r\x12\x0b{video_id}\x18\x062\'"\x11"\x0b{video_id}0\x00x\x020\x00B\x10comments-section'
3549 return base64.b64encode(token.encode()).decode()
3551 def _get_comments(self, ytcfg, video_id, contents, webpage):
3552 """Entry for comment extraction"""
3553 def _real_comment_extract(contents):
3555 item for item in traverse_obj(contents, (..., 'itemSectionRenderer'), default={})
3556 if item.get('sectionIdentifier') == 'comment-item-section'), None)
3557 yield from self._comment_entries(renderer, ytcfg, video_id)
3559 max_comments = int_or_none(self._configuration_arg('max_comments', [''])[0])
3560 return itertools.islice(_real_comment_extract(contents), 0, max_comments)
3563 def _get_checkok_params():
3564 return {'contentCheckOk': True, 'racyCheckOk': True}
3567 def _generate_player_context(cls, sts=None):
3569 'html5Preference': 'HTML5_PREF_WANTS',
3572 context['signatureTimestamp'] = sts
3574 'playbackContext': {
3575 'contentPlaybackContext': context
3577 **cls._get_checkok_params()
3581 def _is_agegated(player_response):
3582 if traverse_obj(player_response, ('playabilityStatus', 'desktopLegacyAgeGateReason')):
3585 reasons = traverse_obj(player_response, ('playabilityStatus', ('status', 'reason')))
3586 AGE_GATE_REASONS = (
3587 'confirm your age', 'age-restricted', 'inappropriate', # reason
3588 'age_verification_required', 'age_check_required', # status
3590 return any(expected in reason for expected in AGE_GATE_REASONS for reason in reasons)
3593 def _is_unplayable(player_response):
3594 return traverse_obj(player_response, ('playabilityStatus', 'status')) == 'UNPLAYABLE'
3596 def _extract_player_response(self, client, video_id, master_ytcfg, player_ytcfg, player_url, initial_pr, smuggled_data):
3598 session_index = self._extract_session_index(player_ytcfg, master_ytcfg)
3599 syncid = self._extract_account_syncid(player_ytcfg, master_ytcfg, initial_pr)
3600 sts = self._extract_signature_timestamp(video_id, player_url, master_ytcfg, fatal=False) if player_url else None
3601 headers = self.generate_api_headers(
3602 ytcfg=player_ytcfg, account_syncid=syncid, session_index=session_index, default_client=client)
3605 'videoId': video_id,
3607 if _split_innertube_client(client)[0] in ('android', 'android_embedscreen'):
3608 yt_query['params'] = 'CgIIAQ=='
3610 pp_arg = self._configuration_arg('player_params', [None], casesense=True)[0]
3612 yt_query['params'] = pp_arg
3614 yt_query.update(self._generate_player_context(sts))
3615 return self._extract_response(
3616 item_id=video_id, ep='player', query=yt_query,
3617 ytcfg=player_ytcfg, headers=headers, fatal=True,
3618 default_client=client,
3619 note='Downloading %s player API JSON' % client.replace('_', ' ').strip()
3622 def _get_requested_clients(self, url, smuggled_data):
3623 requested_clients = []
3624 default = ['ios', 'android', 'web']
3625 allowed_clients = sorted(
3626 (client for client in INNERTUBE_CLIENTS.keys() if client[:1] != '_'),
3627 key=lambda client: INNERTUBE_CLIENTS[client]['priority'], reverse=True)
3628 for client in self._configuration_arg('player_client'):
3629 if client in allowed_clients:
3630 requested_clients.append(client)
3631 elif client == 'default':
3632 requested_clients.extend(default)
3633 elif client == 'all':
3634 requested_clients.extend(allowed_clients)
3636 self.report_warning(f'Skipping unsupported client {client}')
3637 if not requested_clients:
3638 requested_clients = default
3640 if smuggled_data.get('is_music_url') or self.is_music_url(url):
3641 requested_clients.extend(
3642 f'{client}_music' for client in requested_clients if f'{client}_music' in INNERTUBE_CLIENTS)
3644 return orderedSet(requested_clients)
3646 def _invalid_player_response(self, pr, video_id):
3647 # YouTube may return a different video player response than expected.
3648 # See: https://github.com/TeamNewPipe/NewPipe/issues/8713
3649 if (pr_id := traverse_obj(pr, ('videoDetails', 'videoId'))) != video_id:
3652 def _extract_player_responses(self, clients, video_id, webpage, master_ytcfg, smuggled_data):
3655 initial_pr = self._search_json(
3656 self._YT_INITIAL_PLAYER_RESPONSE_RE, webpage, 'initial player response', video_id, fatal=False)
3659 if initial_pr and not self._invalid_player_response(initial_pr, video_id):
3660 # Android player_response does not have microFormats which are needed for
3661 # extraction of some data. So we return the initial_pr with formats
3662 # stripped out even if not requested by the user
3663 # See: https://github.com/yt-dlp/yt-dlp/issues/501
3664 prs.append({**initial_pr, 'streamingData': None})
3666 all_clients = set(clients)
3667 clients = clients[::-1]
3669 def append_client(*client_names):
3670 """ Append the first client name that exists but not already used """
3671 for client_name in client_names:
3672 actual_client = _split_innertube_client(client_name)[0]
3673 if actual_client in INNERTUBE_CLIENTS:
3674 if actual_client not in all_clients:
3675 clients.append(client_name)
3676 all_clients.add(actual_client)
3679 tried_iframe_fallback = False
3681 skipped_clients = {}
3683 client, base_client, variant = _split_innertube_client(clients.pop())
3684 player_ytcfg = master_ytcfg if client == 'web' else {}
3685 if 'configs' not in self._configuration_arg('player_skip') and client != 'web':
3686 player_ytcfg = self._download_ytcfg(client, video_id) or player_ytcfg
3688 player_url = player_url or self._extract_player_url(master_ytcfg, player_ytcfg, webpage=webpage)
3689 require_js_player = self._get_default_ytcfg(client).get('REQUIRE_JS_PLAYER')
3690 if 'js' in self._configuration_arg('player_skip'):
3691 require_js_player = False
3694 if not player_url and not tried_iframe_fallback and require_js_player:
3695 player_url = self._download_player_url(video_id)
3696 tried_iframe_fallback = True
3699 pr = initial_pr if client == 'web' and initial_pr else self._extract_player_response(
3700 client, video_id, player_ytcfg or master_ytcfg, player_ytcfg, player_url if require_js_player else None, initial_pr, smuggled_data)
3701 except ExtractorError as e:
3702 self.report_warning(e)
3705 if pr_id := self._invalid_player_response(pr, video_id):
3706 skipped_clients[client] = pr_id
3708 # Save client name for introspection later
3709 name = short_client_name(client)
3710 sd = traverse_obj(pr, ('streamingData', {dict})) or {}
3711 sd[STREAMING_DATA_CLIENT_NAME] = name
3712 for f in traverse_obj(sd, (('formats', 'adaptiveFormats'), ..., {dict})):
3713 f[STREAMING_DATA_CLIENT_NAME] = name
3716 # creator clients can bypass AGE_VERIFICATION_REQUIRED if logged in
3717 if variant == 'embedded' and self._is_unplayable(pr) and self.is_authenticated:
3718 append_client(f'{base_client}_creator')
3719 elif self._is_agegated(pr):
3720 if variant == 'tv_embedded':
3721 append_client(f'{base_client}_embedded')
3723 append_client(f'tv_embedded.{base_client}', f'{base_client}_embedded')
3726 self.report_warning(
3727 f'Skipping player responses from {"/".join(skipped_clients)} clients '
3728 f'(got player responses for video "{"/".join(set(skipped_clients.values()))}
" instead of "{video_id}
")')
3730 raise ExtractorError(
3731 'All player responses are invalid. Your IP is likely being blocked by Youtube', expected=True)
3733 raise ExtractorError('Failed to extract any player response')
3734 return prs, player_url
3736 def _needs_live_processing(self, live_status, duration):
3737 if (live_status == 'is_live' and self.get_param('live_from_start')
3738 or live_status == 'post_live' and (duration or 0) > 2 * 3600):
3741 def _extract_formats_and_subtitles(self, streaming_data, video_id, player_url, live_status, duration):
3742 CHUNK_SIZE = 10 << 20
3743 itags, stream_ids = collections.defaultdict(set), []
3744 itag_qualities, res_qualities = {}, {0: None}
3746 # Normally tiny is the smallest video-only formats. But
3747 # audio-only formats with unknown quality may get tagged as tiny
3749 'audio_quality_ultralow', 'audio_quality_low', 'audio_quality_medium', 'audio_quality_high', # Audio only formats
3750 'small', 'medium', 'large', 'hd720', 'hd1080', 'hd1440', 'hd2160', 'hd2880', 'highres'
3752 streaming_formats = traverse_obj(streaming_data, (..., ('formats', 'adaptiveFormats'), ...))
3753 format_types = self._configuration_arg('formats')
3754 all_formats = 'duplicate' in format_types
3755 if self._configuration_arg('include_duplicate_formats'):
3757 self._downloader.deprecated_feature('[youtube] include_duplicate_formats extractor argument is deprecated. '
3758 'Use formats=duplicate extractor argument instead')
3760 def build_fragments(f):
3762 'url': update_url_query(f['url'], {
3763 'range': f'{range_start}-{min(range_start + CHUNK_SIZE - 1, f["filesize"])}'
3765 } for range_start in range(0, f['filesize'], CHUNK_SIZE))
3767 for fmt in streaming_formats:
3768 if fmt.get('targetDurationSec'):
3771 itag = str_or_none(fmt.get('itag'))
3772 audio_track = fmt.get('audioTrack') or {}
3773 stream_id = (itag, audio_track.get('id'), fmt.get('isDrc'))
3775 if stream_id in stream_ids:
3778 quality = fmt.get('quality')
3779 height = int_or_none(fmt.get('height'))
3780 if quality == 'tiny' or not quality:
3781 quality = fmt.get('audioQuality', '').lower() or quality
3782 # The 3gp format (17) in android client has a quality of "small
",
3783 # but is actually worse than other formats
3788 itag_qualities[itag] = quality
3790 res_qualities[height] = quality
3791 # FORMAT_STREAM_TYPE_OTF(otf=1) requires downloading the init fragment
3792 # (adding `&sq=0` to the URL) and parsing emsg box to determine the
3793 # number of fragment that would subsequently requested with (`&sq=N`)
3794 if fmt.get('type') == 'FORMAT_STREAM_TYPE_OTF':
3797 fmt_url = fmt.get('url')
3799 sc = urllib.parse.parse_qs(fmt.get('signatureCipher'))
3800 fmt_url = url_or_none(try_get(sc, lambda x: x['url'][0]))
3801 encrypted_sig = try_get(sc, lambda x: x['s'][0])
3802 if not all((sc, fmt_url, player_url, encrypted_sig)):
3805 fmt_url += '&%s=%s' % (
3806 traverse_obj(sc, ('sp', -1)) or 'signature',
3807 self._decrypt_signature(encrypted_sig, video_id, player_url)
3809 except ExtractorError as e:
3810 self.report_warning('Signature extraction failed: Some formats may be missing',
3811 video_id=video_id, only_once=True)
3812 self.write_debug(e, only_once=True)
3815 query = parse_qs(fmt_url)
3819 decrypt_nsig = self._cached(self._decrypt_nsig, 'nsig', query['n'][0])
3820 fmt_url = update_url_query(fmt_url, {
3821 'n': decrypt_nsig(query['n'][0], video_id, player_url)
3823 except ExtractorError as e:
3825 if isinstance(e, JSInterpreter.Exception):
3826 phantomjs_hint = (f' Install {self._downloader._format_err("PhantomJS", self._downloader.Styles.EMPHASIS)} '
3827 f'to workaround the issue. {PhantomJSwrapper.INSTALL_HINT}\n')
3829 self.report_warning(
3830 f'nsig extraction failed: You may experience throttling for some formats\n{phantomjs_hint}'
3831 f' n = {query["n"][0]} ; player = {player_url}', video_id=video_id, only_once=True)
3832 self.write_debug(e, only_once=True)
3834 self.report_warning(
3835 'Cannot decrypt nsig without player_url: You may experience throttling for some formats',
3836 video_id=video_id, only_once=True)
3839 tbr = float_or_none(fmt.get('averageBitrate') or fmt.get('bitrate'), 1000)
3840 language_preference = (
3841 10 if audio_track.get('audioIsDefault') and 10
3842 else -10 if 'descriptive' in (audio_track.get('displayName') or '').lower() and -10
3844 format_duration = traverse_obj(fmt, ('approxDurationMs', {lambda x: float_or_none(x, 1000)}))
3845 # Some formats may have much smaller duration than others (possibly damaged during encoding)
3846 # E.g. 2-nOtRESiUc Ref: https://github.com/yt-dlp/yt-dlp/issues/2823
3847 # Make sure to avoid false positives with small duration differences.
3848 # E.g. __2ABJjxzNo, ySuUZEjARPY
3849 is_damaged = try_call(lambda: format_duration < duration // 2)
3851 self.report_warning(
3852 f'{video_id}: Some formats are possibly damaged. They will be deprioritized', only_once=True)
3854 client_name = fmt.get(STREAMING_DATA_CLIENT_NAME)
3855 name = fmt.get('qualityLabel') or quality.replace('audio_quality_', '') or ''
3856 fps = int_or_none(fmt.get('fps')) or 0
3858 'asr': int_or_none(fmt.get('audioSampleRate')),
3859 'filesize': int_or_none(fmt.get('contentLength')),
3860 'format_id': f'{itag}{"-drc" if fmt.get("isDrc") else ""}',
3861 'format_note': join_nonempty(
3862 join_nonempty(audio_track.get('displayName'),
3863 language_preference > 0 and ' (default)', delim=''),
3864 name, fmt.get('isDrc') and 'DRC',
3865 try_get(fmt, lambda x: x['projectionType'].replace('RECTANGULAR', '').lower()),
3866 try_get(fmt, lambda x: x['spatialAudioType'].replace('SPATIAL_AUDIO_TYPE_', '').lower()),
3867 throttled and 'THROTTLED', is_damaged and 'DAMAGED',
3868 (self.get_param('verbose') or all_formats) and client_name,
3870 # Format 22 is likely to be damaged. See https://github.com/yt-dlp/yt-dlp/issues/3372
3871 'source_preference': ((-10 if throttled else -5 if itag == '22' else -1)
3872 + (100 if 'Premium' in name else 0)),
3873 'fps': fps if fps > 1 else None, # For some formats, fps is wrongly returned as 1
3874 'audio_channels': fmt.get('audioChannels'),
3876 'quality': q(quality) - bool(fmt.get('isDrc')) / 2,
3877 'has_drm': bool(fmt.get('drmFamilies')),
3879 'filesize_approx': filesize_from_tbr(tbr, format_duration),
3881 'width': int_or_none(fmt.get('width')),
3882 'language': join_nonempty(audio_track.get('id', '').split('.')[0],
3883 'desc' if language_preference < -1 else '') or None,
3884 'language_preference': language_preference,
3885 # Strictly de-prioritize damaged and 3gp formats
3886 'preference': -10 if is_damaged else -2 if itag == '17' else None,
3888 mime_mobj = re.match(
3889 r'((?:[^/]+)/(?:[^;]+))(?:;\s*codecs="([^
"]+)")?
', fmt.get('mimeType
') or '')
3891 dct['ext
'] = mimetype2ext(mime_mobj.group(1))
3892 dct.update(parse_codecs(mime_mobj.group(2)))
3894 itags[itag].add(('https
', dct.get('language
')))
3895 stream_ids.append(stream_id)
3896 single_stream = 'none
' in (dct.get('acodec
'), dct.get('vcodec
'))
3897 if single_stream and dct.get('ext
'):
3898 dct['container
'] = dct['ext
'] + '_dash
'
3900 if (all_formats or 'dashy
' in format_types) and dct['filesize
']:
3903 'format_id
': f'{dct["format_id"]}
-dashy
' if all_formats else dct['format_id
'],
3904 'protocol
': 'http_dash_segments
',
3905 'fragments
': build_fragments(dct),
3907 if all_formats or 'dashy
' not in format_types:
3908 dct['downloader_options
'] = {'http_chunk_size': CHUNK_SIZE}
3911 needs_live_processing = self._needs_live_processing(live_status, duration)
3912 skip_bad_formats = 'incomplete
' not in format_types
3913 if self._configuration_arg('include_incomplete_formats
'):
3914 skip_bad_formats = False
3915 self._downloader.deprecated_feature('[youtube
] include_incomplete_formats extractor argument
is deprecated
. '
3916 'Use formats
=incomplete extractor argument instead
')
3918 skip_manifests = set(self._configuration_arg('skip
'))
3919 if (not self.get_param('youtube_include_hls_manifest
', True)
3920 or needs_live_processing == 'is_live
' # These will be filtered out by YoutubeDL anyway
3921 or needs_live_processing and skip_bad_formats):
3922 skip_manifests.add('hls
')
3924 if not self.get_param('youtube_include_dash_manifest
', True):
3925 skip_manifests.add('dash
')
3926 if self._configuration_arg('include_live_dash
'):
3927 self._downloader.deprecated_feature('[youtube
] include_live_dash extractor argument
is deprecated
. '
3928 'Use formats
=incomplete extractor argument instead
')
3929 elif skip_bad_formats and live_status == 'is_live
' and needs_live_processing != 'is_live
':
3930 skip_manifests.add('dash
')
3932 def process_manifest_format(f, proto, client_name, itag):
3933 key = (proto, f.get('language
'))
3934 if not all_formats and key in itags[itag]:
3936 itags[itag].add(key)
3938 if itag and all_formats:
3939 f['format_id
'] = f'{itag}
-{proto}
'
3940 elif any(p != proto for p, _ in itags[itag]):
3941 f['format_id
'] = f'{itag}
-{proto}
'
3943 f['format_id
'] = itag
3945 if f.get('source_preference
') is None:
3946 f['source_preference
'] = -1
3948 if itag in ('616', '235'):
3949 f['format_note
'] = join_nonempty(f.get('format_note
'), 'Premium
', delim=' ')
3950 f['source_preference
'] += 100
3952 f['quality
'] = q(itag_qualities.get(try_get(f, lambda f: f['format_id
'].split('-')[0]), -1))
3953 if f['quality
'] == -1 and f.get('height
'):
3954 f['quality
'] = q(res_qualities[min(res_qualities, key=lambda x: abs(x - f['height
']))])
3955 if self.get_param('verbose
') or all_formats:
3956 f['format_note
'] = join_nonempty(f.get('format_note
'), client_name, delim=', ')
3957 if f.get('fps
') and f['fps
'] <= 1:
3960 if proto == 'hls
' and f.get('has_drm
'):
3961 f['has_drm
'] = 'maybe
'
3962 f['source_preference
'] -= 5
3966 for sd in streaming_data:
3967 client_name = sd.get(STREAMING_DATA_CLIENT_NAME)
3969 hls_manifest_url = 'hls
' not in skip_manifests and sd.get('hlsManifestUrl
')
3970 if hls_manifest_url:
3971 fmts, subs = self._extract_m3u8_formats_and_subtitles(
3972 hls_manifest_url, video_id, 'mp4
', fatal=False, live=live_status == 'is_live
')
3973 subtitles = self._merge_subtitles(subs, subtitles)
3975 if process_manifest_format(f, 'hls
', client_name, self._search_regex(
3976 r'/itag
/(\d
+)', f['url
'], 'itag
', default=None)):
3979 dash_manifest_url = 'dash
' not in skip_manifests and sd.get('dashManifestUrl
')
3980 if dash_manifest_url:
3981 formats, subs = self._extract_mpd_formats_and_subtitles(dash_manifest_url, video_id, fatal=False)
3982 subtitles = self._merge_subtitles(subs, subtitles) # Prioritize HLS subs over DASH
3984 if process_manifest_format(f, 'dash
', client_name, f['format_id
']):
3985 f['filesize
'] = int_or_none(self._search_regex(
3986 r'/clen
/(\d
+)', f.get('fragment_base_url
') or f['url
'], 'file size
', default=None))
3987 if needs_live_processing:
3988 f['is_from_start
'] = True
3993 def _extract_storyboard(self, player_responses, duration):
3995 player_responses, ('storyboards
', 'playerStoryboardSpecRenderer
', 'spec
'), default='').split('|
')[::-1]
3996 base_url = url_or_none(urljoin('https
://i
.ytimg
.com
/', spec.pop() or None))
4000 for i, args in enumerate(spec):
4001 args = args.split('#')
4002 counts
= list(map(int_or_none
, args
[:5]))
4003 if len(args
) != 8 or not all(counts
):
4004 self
.report_warning(f
'Malformed storyboard {i}: {"#".join(args)}{bug_reports_message()}')
4006 width
, height
, frame_count
, cols
, rows
= counts
4009 url
= base_url
.replace('$L', str(L
- i
)).replace('$N', N
) + f
'&sigh={sigh}'
4010 fragment_count
= frame_count
/ (cols
* rows
)
4011 fragment_duration
= duration
/ fragment_count
4013 'format_id': f
'sb{i}',
4014 'format_note': 'storyboard',
4016 'protocol': 'mhtml',
4022 'fps': frame_count
/ duration
,
4026 'url': url
.replace('$M', str(j
)),
4027 'duration': min(fragment_duration
, duration
- (j
* fragment_duration
)),
4028 } for j
in range(math
.ceil(fragment_count
))],
4031 def _download_player_responses(self
, url
, smuggled_data
, video_id
, webpage_url
):
4033 if 'webpage' not in self
._configuration
_arg
('player_skip'):
4034 query
= {'bpctr': '9999999999', 'has_verified': '1'}
4035 pp
= self
._configuration
_arg
('player_params', [None], casesense
=True)[0]
4038 webpage
= self
._download
_webpage
(
4039 webpage_url
, video_id
, fatal
=False, query
=query
)
4041 master_ytcfg
= self
.extract_ytcfg(video_id
, webpage
) or self
._get
_default
_ytcfg
()
4043 player_responses
, player_url
= self
._extract
_player
_responses
(
4044 self
._get
_requested
_clients
(url
, smuggled_data
),
4045 video_id
, webpage
, master_ytcfg
, smuggled_data
)
4047 return webpage
, master_ytcfg
, player_responses
, player_url
4049 def _list_formats(self
, video_id
, microformats
, video_details
, player_responses
, player_url
, duration
=None):
4050 live_broadcast_details
= traverse_obj(microformats
, (..., 'liveBroadcastDetails'))
4051 is_live
= get_first(video_details
, 'isLive')
4053 is_live
= get_first(live_broadcast_details
, 'isLiveNow')
4054 live_content
= get_first(video_details
, 'isLiveContent')
4055 is_upcoming
= get_first(video_details
, 'isUpcoming')
4056 post_live
= get_first(video_details
, 'isPostLiveDvr')
4057 live_status
= ('post_live' if post_live
4058 else 'is_live' if is_live
4059 else 'is_upcoming' if is_upcoming
4060 else 'was_live' if live_content
4061 else 'not_live' if False in (is_live
, live_content
)
4063 streaming_data
= traverse_obj(player_responses
, (..., 'streamingData'))
4064 *formats
, subtitles
= self
._extract
_formats
_and
_subtitles
(streaming_data
, video_id
, player_url
, live_status
, duration
)
4065 if all(f
.get('has_drm') for f
in formats
):
4066 # If there are no formats that definitely don't have DRM, all have DRM
4070 return live_broadcast_details
, live_status
, streaming_data
, formats
, subtitles
4072 def _real_extract(self
, url
):
4073 url
, smuggled_data
= unsmuggle_url(url
, {})
4074 video_id
= self
._match
_id
(url
)
4076 base_url
= self
.http_scheme() + '//www.youtube.com/'
4077 webpage_url
= base_url
+ 'watch?v=' + video_id
4079 webpage
, master_ytcfg
, player_responses
, player_url
= self
._download
_player
_responses
(url
, smuggled_data
, video_id
, webpage_url
)
4081 playability_statuses
= traverse_obj(
4082 player_responses
, (..., 'playabilityStatus'), expected_type
=dict)
4084 trailer_video_id
= get_first(
4085 playability_statuses
,
4086 ('errorScreen', 'playerLegacyDesktopYpcTrailerRenderer', 'trailerVideoId'),
4088 if trailer_video_id
:
4089 return self
.url_result(
4090 trailer_video_id
, self
.ie_key(), trailer_video_id
)
4092 search_meta
= ((lambda x
: self
._html
_search
_meta
(x
, webpage
, default
=None))
4093 if webpage
else (lambda x
: None))
4095 video_details
= traverse_obj(player_responses
, (..., 'videoDetails'), expected_type
=dict)
4096 microformats
= traverse_obj(
4097 player_responses
, (..., 'microformat', 'playerMicroformatRenderer'),
4100 translated_title
= self
._get
_text
(microformats
, (..., 'title'))
4101 video_title
= (self
._preferred
_lang
and translated_title
4102 or get_first(video_details
, 'title') # primary
4104 or search_meta(['og:title', 'twitter:title', 'title']))
4105 translated_description
= self
._get
_text
(microformats
, (..., 'description'))
4106 original_description
= get_first(video_details
, 'shortDescription')
4107 video_description
= (
4108 self
._preferred
_lang
and translated_description
4109 # If original description is blank, it will be an empty string.
4110 # Do not prefer translated description in this case.
4111 or original_description
if original_description
is not None else translated_description
)
4113 multifeed_metadata_list
= get_first(
4115 ('multicamera', 'playerLegacyMulticameraRenderer', 'metadataList'),
4117 if multifeed_metadata_list
and not smuggled_data
.get('force_singlefeed'):
4118 if self
.get_param('noplaylist'):
4119 self
.to_screen('Downloading just video %s because of --no-playlist' % video_id
)
4123 for feed
in multifeed_metadata_list
.split(','):
4124 # Unquote should take place before split on comma (,) since textual
4125 # fields may contain comma as well (see
4126 # https://github.com/ytdl-org/youtube-dl/issues/8536)
4127 feed_data
= urllib
.parse
.parse_qs(
4128 urllib
.parse
.unquote_plus(feed
))
4130 def feed_entry(name
):
4132 feed_data
, lambda x
: x
[name
][0], str)
4134 feed_id
= feed_entry('id')
4137 feed_title
= feed_entry('title')
4140 title
+= ' (%s)' % feed_title
4142 '_type': 'url_transparent',
4143 'ie_key': 'Youtube',
4145 '%swatch?v=%s' % (base_url
, feed_data
['id'][0]),
4146 {'force_singlefeed': True}
),
4149 feed_ids
.append(feed_id
)
4151 'Downloading multifeed video (%s) - add --no-playlist to just download video %s'
4152 % (', '.join(feed_ids
), video_id
))
4153 return self
.playlist_result(
4154 entries
, video_id
, video_title
, video_description
)
4156 duration
= (int_or_none(get_first(video_details
, 'lengthSeconds'))
4157 or int_or_none(get_first(microformats
, 'lengthSeconds'))
4158 or parse_duration(search_meta('duration')) or None)
4160 live_broadcast_details
, live_status
, streaming_data
, formats
, automatic_captions
= \
4161 self
._list
_formats
(video_id
, microformats
, video_details
, player_responses
, player_url
, duration
)
4162 if live_status
== 'post_live':
4163 self
.write_debug(f
'{video_id}: Video is in Post-Live Manifestless mode')
4166 if not self
.get_param('allow_unplayable_formats') and traverse_obj(streaming_data
, (..., 'licenseInfos')):
4167 self
.report_drm(video_id
)
4169 playability_statuses
,
4170 ('errorScreen', 'playerErrorMessageRenderer'), expected_type
=dict) or {}
4171 reason
= self
._get
_text
(pemr
, 'reason') or get_first(playability_statuses
, 'reason')
4172 subreason
= clean_html(self
._get
_text
(pemr
, 'subreason') or '')
4174 if subreason
== 'The uploader has not made this video available in your country.':
4175 countries
= get_first(microformats
, 'availableCountries')
4177 regions_allowed
= search_meta('regionsAllowed')
4178 countries
= regions_allowed
.split(',') if regions_allowed
else None
4179 self
.raise_geo_restricted(subreason
, countries
, metadata_available
=True)
4180 reason
+= f
'. {subreason}'
4182 self
.raise_no_formats(reason
, expected
=True)
4184 keywords
= get_first(video_details
, 'keywords', expected_type
=list) or []
4185 if not keywords
and webpage
:
4187 unescapeHTML(m
.group('content'))
4188 for m
in re
.finditer(self
._meta
_regex
('og:video:tag'), webpage
)]
4189 for keyword
in keywords
:
4190 if keyword
.startswith('yt:stretch='):
4191 mobj
= re
.search(r
'(\d+)\s*:\s*(\d+)', keyword
)
4193 # NB: float is intentional for forcing float division
4194 w
, h
= (float(v
) for v
in mobj
.groups())
4198 if f
.get('vcodec') != 'none':
4199 f
['stretched_ratio'] = ratio
4201 thumbnails
= self
._extract
_thumbnails
((video_details
, microformats
), (..., ..., 'thumbnail'))
4202 thumbnail_url
= search_meta(['og:image', 'twitter:image'])
4205 'url': thumbnail_url
,
4207 original_thumbnails
= thumbnails
.copy()
4209 # The best resolution thumbnails sometimes does not appear in the webpage
4210 # See: https://github.com/yt-dlp/yt-dlp/issues/340
4211 # List of possible thumbnails - Ref: <https://stackoverflow.com/a/20542029>
4213 # While the *1,*2,*3 thumbnails are just below their corresponding "*default" variants
4214 # in resolution, these are not the custom thumbnail. So de-prioritize them
4215 'maxresdefault', 'hq720', 'sddefault', 'hqdefault', '0', 'mqdefault', 'default',
4216 'sd1', 'sd2', 'sd3', 'hq1', 'hq2', 'hq3', 'mq1', 'mq2', 'mq3', '1', '2', '3'
4218 n_thumbnail_names
= len(thumbnail_names
)
4220 'url': 'https://i.ytimg.com/vi{webp}/{video_id}/{name}{live}.{ext}'.format(
4221 video_id
=video_id
, name
=name
, ext
=ext
,
4222 webp
='_webp' if ext
== 'webp' else '', live
='_live' if live_status
== 'is_live' else ''),
4223 } for name
in thumbnail_names
for ext
in ('webp', 'jpg'))
4224 for thumb
in thumbnails
:
4225 i
= next((i
for i
, t
in enumerate(thumbnail_names
) if f
'/{video_id}/{t}' in thumb
['url']), n_thumbnail_names
)
4226 thumb
['preference'] = (0 if '.webp' in thumb
['url'] else -1) - (2 * i
)
4227 self
._remove
_duplicate
_formats
(thumbnails
)
4228 self
._downloader
._sort
_thumbnails
(original_thumbnails
)
4230 category
= get_first(microformats
, 'category') or search_meta('genre')
4231 channel_id
= self
.ucid_or_none(str_or_none(
4232 get_first(video_details
, 'channelId')
4233 or get_first(microformats
, 'externalChannelId')
4234 or search_meta('channelId')))
4235 owner_profile_url
= get_first(microformats
, 'ownerProfileUrl')
4237 live_start_time
= parse_iso8601(get_first(live_broadcast_details
, 'startTimestamp'))
4238 live_end_time
= parse_iso8601(get_first(live_broadcast_details
, 'endTimestamp'))
4239 if not duration
and live_end_time
and live_start_time
:
4240 duration
= live_end_time
- live_start_time
4242 needs_live_processing
= self
._needs
_live
_processing
(live_status
, duration
)
4244 def is_bad_format(fmt
):
4245 if needs_live_processing
and not fmt
.get('is_from_start'):
4247 elif (live_status
== 'is_live' and needs_live_processing
!= 'is_live'
4248 and fmt
.get('protocol') == 'http_dash_segments'):
4251 for fmt
in filter(is_bad_format
, formats
):
4252 fmt
['preference'] = (fmt
.get('preference') or -1) - 10
4253 fmt
['format_note'] = join_nonempty(fmt
.get('format_note'), '(Last 2 hours)', delim
=' ')
4255 if needs_live_processing
:
4256 self
._prepare
_live
_from
_start
_formats
(
4257 formats
, video_id
, live_start_time
, url
, webpage_url
, smuggled_data
, live_status
== 'is_live')
4259 formats
.extend(self
._extract
_storyboard
(player_responses
, duration
))
4261 channel_handle
= self
.handle_from_url(owner_profile_url
)
4265 'title': video_title
,
4267 'thumbnails': thumbnails
,
4268 # The best thumbnail that we are sure exists. Prevents unnecessary
4269 # URL checking if user don't care about getting the best possible thumbnail
4270 'thumbnail': traverse_obj(original_thumbnails
, (-1, 'url')),
4271 'description': video_description
,
4272 'channel_id': channel_id
,
4273 'channel_url': format_field(channel_id
, None, 'https://www.youtube.com/channel/%s', default
=None),
4274 'duration': duration
,
4275 'view_count': int_or_none(
4276 get_first((video_details
, microformats
), (..., 'viewCount'))
4277 or search_meta('interactionCount')),
4278 'average_rating': float_or_none(get_first(video_details
, 'averageRating')),
4279 'age_limit': 18 if (
4280 get_first(microformats
, 'isFamilySafe') is False
4281 or search_meta('isFamilyFriendly') == 'false'
4282 or search_meta('og:restrictions:age') == '18+') else 0,
4283 'webpage_url': webpage_url
,
4284 'categories': [category
] if category
else None,
4286 'playable_in_embed': get_first(playability_statuses
, 'playableInEmbed'),
4287 'live_status': live_status
,
4288 'release_timestamp': live_start_time
,
4289 '_format_sort_fields': ( # source_preference is lower for throttled/potentially damaged formats
4290 'quality', 'res', 'fps', 'hdr:12', 'source', 'vcodec:vp9.2', 'channels', 'acodec', 'lang', 'proto')
4294 pctr
= traverse_obj(player_responses
, (..., 'captions', 'playerCaptionsTracklistRenderer'), expected_type
=dict)
4296 def get_lang_code(track
):
4297 return (remove_start(track
.get('vssId') or '', '.').replace('.', '-')
4298 or track
.get('languageCode'))
4300 # Converted into dicts to remove duplicates
4302 get_lang_code(sub
): sub
4303 for sub
in traverse_obj(pctr
, (..., 'captionTracks', ...))}
4304 translation_languages
= {
4305 lang
.get('languageCode'): self
._get
_text
(lang
.get('languageName'), max_runs
=1)
4306 for lang
in traverse_obj(pctr
, (..., 'translationLanguages', ...))}
4308 def process_language(container
, base_url
, lang_code
, sub_name
, query
):
4309 lang_subs
= container
.setdefault(lang_code
, [])
4310 for fmt
in self
._SUBTITLE
_FORMATS
:
4316 'url': urljoin('https://www.youtube.com', update_url_query(base_url
, query
)),
4320 # NB: Constructing the full subtitle dictionary is slow
4321 get_translated_subs
= 'translated_subs' not in self
._configuration
_arg
('skip') and (
4322 self
.get_param('writeautomaticsub', False) or self
.get_param('listsubtitles'))
4323 for lang_code
, caption_track
in captions
.items():
4324 base_url
= caption_track
.get('baseUrl')
4325 orig_lang
= parse_qs(base_url
).get('lang', [None])[-1]
4328 lang_name
= self
._get
_text
(caption_track
, 'name', max_runs
=1)
4329 if caption_track
.get('kind') != 'asr':
4333 subtitles
, base_url
, lang_code
, lang_name
, {})
4334 if not caption_track
.get('isTranslatable'):
4336 for trans_code
, trans_name
in translation_languages
.items():
4339 orig_trans_code
= trans_code
4340 if caption_track
.get('kind') != 'asr' and trans_code
!= 'und':
4341 if not get_translated_subs
:
4343 trans_code
+= f
'-{lang_code}'
4344 trans_name
+= format_field(lang_name
, None, ' from %s')
4345 if lang_code
== f
'a-{orig_trans_code}':
4346 # Set audio language based on original subtitles
4348 if f
.get('acodec') != 'none' and not f
.get('language'):
4349 f
['language'] = orig_trans_code
4350 # Add an "-orig" label to the original language so that it can be distinguished.
4351 # The subs are returned without "-orig" as well for compatibility
4353 automatic_captions
, base_url
, f
'{trans_code}-orig', f
'{trans_name} (Original)', {})
4354 # Setting tlang=lang returns damaged subtitles.
4355 process_language(automatic_captions
, base_url
, trans_code
, trans_name
,
4356 {} if orig_lang == orig_trans_code else {'tlang': trans_code}
)
4358 info
['automatic_captions'] = automatic_captions
4359 info
['subtitles'] = subtitles
4361 parsed_url
= urllib
.parse
.urlparse(url
)
4362 for component
in [parsed_url
.fragment
, parsed_url
.query
]:
4363 query
= urllib
.parse
.parse_qs(component
)
4364 for k
, v
in query
.items():
4365 for d_k
, s_ks
in [('start', ('start', 't')), ('end', ('end',))]:
4367 if d_k
not in info
and k
in s_ks
:
4368 info
[d_k
] = parse_duration(query
[k
][0])
4370 # Youtube Music Auto-generated description
4371 if (video_description
or '').strip().endswith('\nAuto-generated by YouTube.'):
4372 # XXX: Causes catastrophic backtracking if description has "·"
4373 # E.g. https://www.youtube.com/watch?v=DoPaAxMQoiI
4374 # Simulating atomic groups: (?P<a>[^xy]+)x => (?=(?P<a>[^xy]+))(?P=a)x
4375 # reduces it, but does not fully fix it. https://regex101.com/r/8Ssf2h/2
4378 (?=(?P<track>[^\n·]+))(?P=track)·
4379 (?=(?P<artist>[^\n]+))(?P=artist)\n+
4380 (?=(?P<album>[^\n]+))(?P=album)\n
4381 (?:.+?℗\s*(?P<release_year>\d{4})(?!\d))?
4382 (?:.+?Released on\s*:\s*(?P<release_date>\d{4}-\d{2}-\d{2}))?
4384 (?=(?P<clean_artist>[^\n]+))(?P=clean_artist)\n
4385 )?.+\nAuto-generated\ by\ YouTube\.\s*$
4386 ''', video_description
)
4388 release_year
= mobj
.group('release_year')
4389 release_date
= mobj
.group('release_date')
4391 release_date
= release_date
.replace('-', '')
4392 if not release_year
:
4393 release_year
= release_date
[:4]
4395 'album': mobj
.group('album'.strip()),
4396 'artists': ([a
] if (a
:= mobj
.group('clean_artist'))
4397 else [a
.strip() for a
in mobj
.group('artist').split('·')]),
4398 'track': mobj
.group('track').strip(),
4399 'release_date': release_date
,
4400 'release_year': int_or_none(release_year
),
4405 initial_data
= self
.extract_yt_initial_data(video_id
, webpage
, fatal
=False)
4406 if not traverse_obj(initial_data
, 'contents'):
4407 self
.report_warning('Incomplete data received in embedded initial data; re-fetching using API.')
4409 if not initial_data
:
4410 query
= {'videoId': video_id}
4411 query
.update(self
._get
_checkok
_params
())
4412 initial_data
= self
._extract
_response
(
4413 item_id
=video_id
, ep
='next', fatal
=False,
4414 ytcfg
=master_ytcfg
, query
=query
, check_get_keys
='contents',
4415 headers
=self
.generate_api_headers(ytcfg
=master_ytcfg
),
4416 note
='Downloading initial data API JSON')
4418 info
['comment_count'] = traverse_obj(initial_data
, (
4419 'contents', 'twoColumnWatchNextResults', 'results', 'results', 'contents', ..., 'itemSectionRenderer',
4420 'contents', ..., 'commentsEntryPointHeaderRenderer', 'commentCount'
4422 'engagementPanels', lambda _
, v
: v
['engagementPanelSectionListRenderer']['panelIdentifier'] == 'comment-item-section',
4423 'engagementPanelSectionListRenderer', 'header', 'engagementPanelTitleHeaderRenderer', 'contextualInfo'
4424 ), expected_type
=self
._get
_count
, get_all
=False)
4426 try: # This will error if there is no livechat
4427 initial_data
['contents']['twoColumnWatchNextResults']['conversationBar']['liveChatRenderer']['continuations'][0]['reloadContinuationData']['continuation']
4428 except (KeyError, IndexError, TypeError):
4431 info
.setdefault('subtitles', {})['live_chat'] = [{
4432 # url is needed to set cookies
4433 'url': f
'https://www.youtube.com/watch?v={video_id}&bpctr=9999999999&has_verified=1',
4434 'video_id': video_id
,
4436 'protocol': ('youtube_live_chat' if live_status
in ('is_live', 'is_upcoming')
4437 else 'youtube_live_chat_replay'),
4441 info
['chapters'] = (
4442 self
._extract
_chapters
_from
_json
(initial_data
, duration
)
4443 or self
._extract
_chapters
_from
_engagement
_panel
(initial_data
, duration
)
4444 or self
._extract
_chapters
_from
_description
(video_description
, duration
)
4447 info
['heatmap'] = self
._extract
_heatmap
(initial_data
)
4449 contents
= traverse_obj(
4450 initial_data
, ('contents', 'twoColumnWatchNextResults', 'results', 'results', 'contents'),
4451 expected_type
=list, default
=[])
4453 vpir
= get_first(contents
, 'videoPrimaryInfoRenderer')
4455 stl
= vpir
.get('superTitleLink')
4457 stl
= self
._get
_text
(stl
)
4460 lambda x
: x
['superTitleIcon']['iconType']) == 'LOCATION_PIN':
4461 info
['location'] = stl
4463 mobj
= re
.search(r
'(.+?)\s*S(\d+)\s*•?\s*E(\d+)', stl
)
4466 'series': mobj
.group(1),
4467 'season_number': int(mobj
.group(2)),
4468 'episode_number': int(mobj
.group(3)),
4470 for tlb
in (try_get(
4472 lambda x
: x
['videoActions']['menuRenderer']['topLevelButtons'],
4476 tlb
, ('toggleButtonRenderer', ...),
4477 ('segmentedLikeDislikeButtonRenderer', ..., 'toggleButtonRenderer')))
4479 for getter
, regex
in [(
4480 lambda x
: x
['defaultText']['accessibility']['accessibilityData'],
4481 r
'(?P<count>[\d,]+)\s*(?P<type>(?:dis)?like)'), ([
4482 lambda x
: x
['accessibility'],
4483 lambda x
: x
['accessibilityData']['accessibilityData'],
4484 ], r
'(?P<type>(?:dis)?like) this video along with (?P<count>[\d,]+) other people')]:
4485 label
= (try_get(tbr
, getter
, dict) or {}).get('label')
4487 mobj
= re
.match(regex
, label
)
4489 info
[mobj
.group('type') + '_count'] = str_to_int(mobj
.group('count'))
4492 info
['like_count'] = traverse_obj(vpir
, (
4493 'videoActions', 'menuRenderer', 'topLevelButtons', ...,
4494 'segmentedLikeDislikeButtonViewModel', 'likeButtonViewModel', 'likeButtonViewModel',
4495 'toggleButtonViewModel', 'toggleButtonViewModel', 'defaultButtonViewModel',
4496 'buttonViewModel', 'accessibilityText', {parse_count}
), get_all
=False)
4498 vcr
= traverse_obj(vpir
, ('viewCount', 'videoViewCountRenderer'))
4500 vc
= self
._get
_count
(vcr
, 'viewCount')
4501 # Upcoming premieres with waiting count are treated as live here
4502 if vcr
.get('isLive'):
4503 info
['concurrent_view_count'] = vc
4504 elif info
.get('view_count') is None:
4505 info
['view_count'] = vc
4507 vsir
= get_first(contents
, 'videoSecondaryInfoRenderer')
4509 vor
= traverse_obj(vsir
, ('owner', 'videoOwnerRenderer'))
4511 'channel': self
._get
_text
(vor
, 'title'),
4512 'channel_follower_count': self
._get
_count
(vor
, 'subscriberCountText')})
4514 if not channel_handle
:
4515 channel_handle
= self
.handle_from_url(
4517 ('navigationEndpoint', ('title', 'runs', ..., 'navigationEndpoint')),
4518 (('commandMetadata', 'webCommandMetadata', 'url'), ('browseEndpoint', 'canonicalBaseUrl')),
4519 {str}
), get_all
=False))
4523 lambda x
: x
['metadataRowContainer']['metadataRowContainerRenderer']['rows'],
4525 multiple_songs
= False
4527 if try_get(row
, lambda x
: x
['metadataRowRenderer']['hasDividerLine']) is True:
4528 multiple_songs
= True
4531 mrr
= row
.get('metadataRowRenderer') or {}
4532 mrr_title
= mrr
.get('title')
4535 mrr_title
= self
._get
_text
(mrr
, 'title')
4536 mrr_contents_text
= self
._get
_text
(mrr
, ('contents', 0))
4537 if mrr_title
== 'License':
4538 info
['license'] = mrr_contents_text
4539 elif not multiple_songs
:
4540 if mrr_title
== 'Album':
4541 info
['album'] = mrr_contents_text
4542 elif mrr_title
== 'Artist':
4543 info
['artists'] = [mrr_contents_text
] if mrr_contents_text
else None
4544 elif mrr_title
== 'Song':
4545 info
['track'] = mrr_contents_text
4546 owner_badges
= self
._extract
_badges
(traverse_obj(vsir
, ('owner', 'videoOwnerRenderer', 'badges')))
4547 if self
._has
_badge
(owner_badges
, BadgeType
.VERIFIED
):
4548 info
['channel_is_verified'] = True
4551 'uploader': info
.get('channel'),
4552 'uploader_id': channel_handle
,
4553 'uploader_url': format_field(channel_handle
, None, 'https://www.youtube.com/%s', default
=None),
4555 # The upload date for scheduled, live and past live streams / premieres in microformats
4556 # may be different from the stream date. Although not in UTC, we will prefer it in this case.
4557 # See: https://github.com/yt-dlp/yt-dlp/pull/2223#issuecomment-1008485139
4559 unified_strdate(get_first(microformats
, 'uploadDate'))
4560 or unified_strdate(search_meta('uploadDate')))
4561 if not upload_date
or (
4562 live_status
in ('not_live', None)
4563 and 'no-youtube-prefer-utc-upload-date' not in self
.get_param('compat_opts', [])
4565 upload_date
= strftime_or_none(
4566 self
._parse
_time
_text
(self
._get
_text
(vpir
, 'dateText'))) or upload_date
4567 info
['upload_date'] = upload_date
4569 if upload_date
and live_status
not in ('is_live', 'post_live', 'is_upcoming'):
4570 # Newly uploaded videos' HLS formats are potentially problematic and need to be checked
4571 upload_datetime
= datetime_from_str(upload_date
).replace(tzinfo
=dt
.timezone
.utc
)
4572 if upload_datetime
>= datetime_from_str('today-2days'):
4573 for fmt
in info
['formats']:
4574 if fmt
.get('protocol') == 'm3u8_native':
4575 fmt
['__needs_testing'] = True
4577 for s_k
, d_k
in [('artists', 'creators'), ('track', 'alt_title')]:
4582 badges
= self
._extract
_badges
(traverse_obj(vpir
, 'badges'))
4584 is_private
= (self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PRIVATE
)
4585 or get_first(video_details
, 'isPrivate', expected_type
=bool))
4587 info
['availability'] = (
4588 'public' if self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PUBLIC
)
4589 else self
._availability
(
4590 is_private
=is_private
,
4592 self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PREMIUM
)
4593 or False if initial_data
and is_private
is not None else None),
4594 needs_subscription
=(
4595 self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_SUBSCRIPTION
)
4596 or False if initial_data
and is_private
is not None else None),
4597 needs_auth
=info
['age_limit'] >= 18,
4598 is_unlisted
=None if is_private
is None else (
4599 self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_UNLISTED
)
4600 or get_first(microformats
, 'isUnlisted', expected_type
=bool))))
4602 info
['__post_extractor'] = self
.extract_comments(master_ytcfg
, video_id
, contents
, webpage
)
4604 self
.mark_watched(video_id
, player_responses
)
4609 class YoutubeTabBaseInfoExtractor(YoutubeBaseInfoExtractor
):
4611 def passthrough_smuggled_data(func
):
4612 def _smuggle(info
, smuggled_data
):
4613 if info
.get('_type') not in ('url', 'url_transparent'):
4615 if smuggled_data
.get('is_music_url'):
4616 parsed_url
= urllib
.parse
.urlparse(info
['url'])
4617 if parsed_url
.netloc
in ('www.youtube.com', 'music.youtube.com'):
4618 smuggled_data
.pop('is_music_url')
4619 info
['url'] = urllib
.parse
.urlunparse(parsed_url
._replace
(netloc
='music.youtube.com'))
4621 info
['url'] = smuggle_url(info
['url'], smuggled_data
)
4624 @functools.wraps(func
)
4625 def wrapper(self
, url
):
4626 url
, smuggled_data
= unsmuggle_url(url
, {})
4627 if self
.is_music_url(url
):
4628 smuggled_data
['is_music_url'] = True
4629 info_dict
= func(self
, url
, smuggled_data
)
4631 _smuggle(info_dict
, smuggled_data
)
4632 if info_dict
.get('entries'):
4633 info_dict
['entries'] = (_smuggle(i
, smuggled_data
.copy()) for i
in info_dict
['entries'])
4638 def _extract_basic_item_renderer(item
):
4639 # Modified from _extract_grid_item_renderer
4640 known_basic_renderers
= (
4641 'playlistRenderer', 'videoRenderer', 'channelRenderer', 'showRenderer', 'reelItemRenderer'
4643 for key
, renderer
in item
.items():
4644 if not isinstance(renderer
, dict):
4646 elif key
in known_basic_renderers
:
4648 elif key
.startswith('grid') and key
.endswith('Renderer'):
4651 def _extract_channel_renderer(self
, renderer
):
4652 channel_id
= self
.ucid_or_none(renderer
['channelId'])
4653 title
= self
._get
_text
(renderer
, 'title')
4654 channel_url
= format_field(channel_id
, None, 'https://www.youtube.com/channel/%s', default
=None)
4655 channel_handle
= self
.handle_from_url(
4656 traverse_obj(renderer
, (
4657 'navigationEndpoint', (('commandMetadata', 'webCommandMetadata', 'url'),
4658 ('browseEndpoint', 'canonicalBaseUrl')),
4659 {str}
), get_all
=False))
4660 if not channel_handle
:
4661 # As of 2023-06-01, YouTube sets subscriberCountText to the handle in search
4662 channel_handle
= self
.handle_or_none(self
._get
_text
(renderer
, 'subscriberCountText'))
4667 'ie_key': YoutubeTabIE
.ie_key(),
4670 'channel_id': channel_id
,
4671 'channel_url': channel_url
,
4673 'uploader_id': channel_handle
,
4674 'uploader_url': format_field(channel_handle
, None, 'https://www.youtube.com/%s', default
=None),
4675 # See above. YouTube sets videoCountText to the subscriber text in search channel renderers.
4676 # However, in feed/channels this is set correctly to the subscriber count
4677 'channel_follower_count': traverse_obj(
4678 renderer
, 'subscriberCountText', 'videoCountText', expected_type
=self
._get
_count
),
4679 'thumbnails': self
._extract
_thumbnails
(renderer
, 'thumbnail'),
4681 # videoCountText may be the subscriber count
4682 self
._get
_count
(renderer
, 'videoCountText')
4683 if self
._get
_count
(renderer
, 'subscriberCountText') is not None else None),
4684 'description': self
._get
_text
(renderer
, 'descriptionSnippet'),
4685 'channel_is_verified': True if self
._has
_badge
(
4686 self
._extract
_badges
(traverse_obj(renderer
, 'ownerBadges')), BadgeType
.VERIFIED
) else None,
4689 def _grid_entries(self
, grid_renderer
):
4690 for item
in grid_renderer
['items']:
4691 if not isinstance(item
, dict):
4693 renderer
= self
._extract
_basic
_item
_renderer
(item
)
4694 if not isinstance(renderer
, dict):
4696 title
= self
._get
_text
(renderer
, 'title')
4699 playlist_id
= renderer
.get('playlistId')
4701 yield self
.url_result(
4702 'https://www.youtube.com/playlist?list=%s' % playlist_id
,
4703 ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
,
4707 video_id
= renderer
.get('videoId')
4709 yield self
._extract
_video
(renderer
)
4712 channel_id
= renderer
.get('channelId')
4714 yield self
._extract
_channel
_renderer
(renderer
)
4716 # generic endpoint URL support
4717 ep_url
= urljoin('https://www.youtube.com/', try_get(
4718 renderer
, lambda x
: x
['navigationEndpoint']['commandMetadata']['webCommandMetadata']['url'],
4721 for ie
in (YoutubeTabIE
, YoutubePlaylistIE
, YoutubeIE
):
4722 if ie
.suitable(ep_url
):
4723 yield self
.url_result(
4724 ep_url
, ie
=ie
.ie_key(), video_id
=ie
._match
_id
(ep_url
), video_title
=title
)
4727 def _music_reponsive_list_entry(self
, renderer
):
4728 video_id
= traverse_obj(renderer
, ('playlistItemData', 'videoId'))
4730 title
= traverse_obj(renderer
, (
4731 'flexColumns', 0, 'musicResponsiveListItemFlexColumnRenderer',
4732 'text', 'runs', 0, 'text'))
4733 return self
.url_result(f
'https://music.youtube.com/watch?v={video_id}',
4734 ie
=YoutubeIE
.ie_key(), video_id
=video_id
, title
=title
)
4735 playlist_id
= traverse_obj(renderer
, ('navigationEndpoint', 'watchEndpoint', 'playlistId'))
4737 video_id
= traverse_obj(renderer
, ('navigationEndpoint', 'watchEndpoint', 'videoId'))
4739 return self
.url_result(f
'https://music.youtube.com/watch?v={video_id}&list={playlist_id}',
4740 ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
)
4741 return self
.url_result(f
'https://music.youtube.com/playlist?list={playlist_id}',
4742 ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
)
4743 browse_id
= traverse_obj(renderer
, ('navigationEndpoint', 'browseEndpoint', 'browseId'))
4745 return self
.url_result(f
'https://music.youtube.com/browse/{browse_id}',
4746 ie
=YoutubeTabIE
.ie_key(), video_id
=browse_id
)
4748 def _shelf_entries_from_content(self
, shelf_renderer
):
4749 content
= shelf_renderer
.get('content')
4750 if not isinstance(content
, dict):
4752 renderer
= content
.get('gridRenderer') or content
.get('expandedShelfContentsRenderer')
4754 # TODO: add support for nested playlists so each shelf is processed
4755 # as separate playlist
4756 # TODO: this includes only first N items
4757 yield from self
._grid
_entries
(renderer
)
4758 renderer
= content
.get('horizontalListRenderer')
4763 def _shelf_entries(self
, shelf_renderer
, skip_channels
=False):
4765 shelf_renderer
, lambda x
: x
['endpoint']['commandMetadata']['webCommandMetadata']['url'],
4767 shelf_url
= urljoin('https://www.youtube.com', ep
)
4769 # Skipping links to another channels, note that checking for
4770 # endpoint.commandMetadata.webCommandMetadata.webPageTypwebPageType == WEB_PAGE_TYPE_CHANNEL
4772 if skip_channels
and '/channels?' in shelf_url
:
4774 title
= self
._get
_text
(shelf_renderer
, 'title')
4775 yield self
.url_result(shelf_url
, video_title
=title
)
4776 # Shelf may not contain shelf URL, fallback to extraction from content
4777 yield from self
._shelf
_entries
_from
_content
(shelf_renderer
)
4779 def _playlist_entries(self
, video_list_renderer
):
4780 for content
in video_list_renderer
['contents']:
4781 if not isinstance(content
, dict):
4783 renderer
= content
.get('playlistVideoRenderer') or content
.get('playlistPanelVideoRenderer')
4784 if not isinstance(renderer
, dict):
4786 video_id
= renderer
.get('videoId')
4789 yield self
._extract
_video
(renderer
)
4791 def _rich_entries(self
, rich_grid_renderer
):
4792 renderer
= traverse_obj(
4794 ('content', ('videoRenderer', 'reelItemRenderer', 'playlistRenderer')), get_all
=False) or {}
4795 video_id
= renderer
.get('videoId')
4797 yield self
._extract
_video
(renderer
)
4799 playlist_id
= renderer
.get('playlistId')
4801 yield self
.url_result(
4802 f
'https://www.youtube.com/playlist?list={playlist_id}',
4803 ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
,
4804 video_title
=self
._get
_text
(renderer
, 'title'))
4807 def _video_entry(self
, video_renderer
):
4808 video_id
= video_renderer
.get('videoId')
4810 return self
._extract
_video
(video_renderer
)
4812 def _hashtag_tile_entry(self
, hashtag_tile_renderer
):
4813 url
= urljoin('https://youtube.com', traverse_obj(
4814 hashtag_tile_renderer
, ('onTapCommand', 'commandMetadata', 'webCommandMetadata', 'url')))
4816 return self
.url_result(
4817 url
, ie
=YoutubeTabIE
.ie_key(), title
=self
._get
_text
(hashtag_tile_renderer
, 'hashtag'))
4819 def _post_thread_entries(self
, post_thread_renderer
):
4820 post_renderer
= try_get(
4821 post_thread_renderer
, lambda x
: x
['post']['backstagePostRenderer'], dict)
4822 if not post_renderer
:
4825 video_renderer
= try_get(
4826 post_renderer
, lambda x
: x
['backstageAttachment']['videoRenderer'], dict) or {}
4827 video_id
= video_renderer
.get('videoId')
4829 entry
= self
._extract
_video
(video_renderer
)
4832 # playlist attachment
4833 playlist_id
= try_get(
4834 post_renderer
, lambda x
: x
['backstageAttachment']['playlistRenderer']['playlistId'], str)
4836 yield self
.url_result(
4837 'https://www.youtube.com/playlist?list=%s' % playlist_id
,
4838 ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
)
4839 # inline video links
4840 runs
= try_get(post_renderer
, lambda x
: x
['contentText']['runs'], list) or []
4842 if not isinstance(run
, dict):
4845 run
, lambda x
: x
['navigationEndpoint']['urlEndpoint']['url'], str)
4848 if not YoutubeIE
.suitable(ep_url
):
4850 ep_video_id
= YoutubeIE
._match
_id
(ep_url
)
4851 if video_id
== ep_video_id
:
4853 yield self
.url_result(ep_url
, ie
=YoutubeIE
.ie_key(), video_id
=ep_video_id
)
4855 def _post_thread_continuation_entries(self
, post_thread_continuation
):
4856 contents
= post_thread_continuation
.get('contents')
4857 if not isinstance(contents
, list):
4859 for content
in contents
:
4860 renderer
= content
.get('backstagePostThreadRenderer')
4861 if isinstance(renderer
, dict):
4862 yield from self
._post
_thread
_entries
(renderer
)
4864 renderer
= content
.get('videoRenderer')
4865 if isinstance(renderer
, dict):
4866 yield self
._video
_entry
(renderer
)
4869 def _rich_grid_entries(self, contents):
4870 for content in contents:
4871 video_renderer = try_get(content, lambda x: x['richItemRenderer']['content']['videoRenderer'], dict)
4873 entry = self._video_entry(video_renderer)
4878 def _report_history_entries(self
, renderer
):
4879 for url
in traverse_obj(renderer
, (
4880 'rows', ..., 'reportHistoryTableRowRenderer', 'cells', ...,
4881 'reportHistoryTableCellRenderer', 'cell', 'reportHistoryTableTextCellRenderer', 'text', 'runs', ...,
4882 'navigationEndpoint', 'commandMetadata', 'webCommandMetadata', 'url')):
4883 yield self
.url_result(urljoin('https://www.youtube.com', url
), YoutubeIE
)
4885 def _extract_entries(self
, parent_renderer
, continuation_list
):
4886 # continuation_list is modified in-place with continuation_list = [continuation_token]
4887 continuation_list
[:] = [None]
4888 contents
= try_get(parent_renderer
, lambda x
: x
['contents'], list) or []
4889 for content
in contents
:
4890 if not isinstance(content
, dict):
4892 is_renderer
= traverse_obj(
4893 content
, 'itemSectionRenderer', 'musicShelfRenderer', 'musicShelfContinuation',
4896 if content
.get('richItemRenderer'):
4897 for entry
in self
._rich
_entries
(content
['richItemRenderer']):
4899 continuation_list
[0] = self
._extract
_continuation
(parent_renderer
)
4900 elif content
.get('reportHistorySectionRenderer'): # https://www.youtube.com/reporthistory
4901 table
= traverse_obj(content
, ('reportHistorySectionRenderer', 'table', 'tableRenderer'))
4902 yield from self
._report
_history
_entries
(table
)
4903 continuation_list
[0] = self
._extract
_continuation
(table
)
4906 isr_contents
= try_get(is_renderer
, lambda x
: x
['contents'], list) or []
4907 for isr_content
in isr_contents
:
4908 if not isinstance(isr_content
, dict):
4912 'playlistVideoListRenderer': self
._playlist
_entries
,
4913 'gridRenderer': self
._grid
_entries
,
4914 'reelShelfRenderer': self
._grid
_entries
,
4915 'shelfRenderer': self
._shelf
_entries
,
4916 'musicResponsiveListItemRenderer': lambda x
: [self
._music
_reponsive
_list
_entry
(x
)],
4917 'backstagePostThreadRenderer': self
._post
_thread
_entries
,
4918 'videoRenderer': lambda x
: [self
._video
_entry
(x
)],
4919 'playlistRenderer': lambda x
: self
._grid
_entries
({'items': [{'playlistRenderer': x}
]}),
4920 'channelRenderer': lambda x
: self
._grid
_entries
({'items': [{'channelRenderer': x}
]}),
4921 'hashtagTileRenderer': lambda x
: [self
._hashtag
_tile
_entry
(x
)],
4922 'richGridRenderer': lambda x
: self
._extract
_entries
(x
, continuation_list
),
4924 for key
, renderer
in isr_content
.items():
4925 if key
not in known_renderers
:
4927 for entry
in known_renderers
[key
](renderer
):
4930 continuation_list
[0] = self
._extract
_continuation
(renderer
)
4933 if not continuation_list
[0]:
4934 continuation_list
[0] = self
._extract
_continuation
(is_renderer
)
4936 if not continuation_list
[0]:
4937 continuation_list
[0] = self
._extract
_continuation
(parent_renderer
)
4939 def _entries(self
, tab
, item_id
, ytcfg
, account_syncid
, visitor_data
):
4940 continuation_list
= [None]
4941 extract_entries
= lambda x
: self
._extract
_entries
(x
, continuation_list
)
4942 tab_content
= try_get(tab
, lambda x
: x
['content'], dict)
4946 try_get(tab_content
, lambda x
: x
['sectionListRenderer'], dict)
4947 or try_get(tab_content
, lambda x
: x
['richGridRenderer'], dict) or {})
4948 yield from extract_entries(parent_renderer
)
4949 continuation
= continuation_list
[0]
4950 seen_continuations
= set()
4951 for page_num
in itertools
.count(1):
4952 if not continuation
:
4954 continuation_token
= continuation
.get('continuation')
4955 if continuation_token
is not None and continuation_token
in seen_continuations
:
4956 self
.write_debug('Detected YouTube feed looping - assuming end of feed.')
4958 seen_continuations
.add(continuation_token
)
4959 headers
= self
.generate_api_headers(
4960 ytcfg
=ytcfg
, account_syncid
=account_syncid
, visitor_data
=visitor_data
)
4961 response
= self
._extract
_response
(
4962 item_id
=f
'{item_id} page {page_num}',
4963 query
=continuation
, headers
=headers
, ytcfg
=ytcfg
,
4964 check_get_keys
=('continuationContents', 'onResponseReceivedActions', 'onResponseReceivedEndpoints'))
4968 # Extracting updated visitor data is required to prevent an infinite extraction loop in some cases
4969 # See: https://github.com/ytdl-org/youtube-dl/issues/28702
4970 visitor_data
= self
._extract
_visitor
_data
(response
) or visitor_data
4973 'videoRenderer': (self
._grid
_entries
, 'items'), # for membership tab
4974 'gridPlaylistRenderer': (self
._grid
_entries
, 'items'),
4975 'gridVideoRenderer': (self
._grid
_entries
, 'items'),
4976 'gridChannelRenderer': (self
._grid
_entries
, 'items'),
4977 'playlistVideoRenderer': (self
._playlist
_entries
, 'contents'),
4978 'itemSectionRenderer': (extract_entries
, 'contents'), # for feeds
4979 'richItemRenderer': (extract_entries
, 'contents'), # for hashtag
4980 'backstagePostThreadRenderer': (self
._post
_thread
_continuation
_entries
, 'contents'),
4981 'reportHistoryTableRowRenderer': (self
._report
_history
_entries
, 'rows'),
4982 'playlistVideoListContinuation': (self
._playlist
_entries
, None),
4983 'gridContinuation': (self
._grid
_entries
, None),
4984 'itemSectionContinuation': (self
._post
_thread
_continuation
_entries
, None),
4985 'sectionListContinuation': (extract_entries
, None), # for feeds
4988 continuation_items
= traverse_obj(response
, (
4989 ('onResponseReceivedActions', 'onResponseReceivedEndpoints'), ...,
4990 'appendContinuationItemsAction', 'continuationItems'
4991 ), 'continuationContents', get_all
=False)
4992 continuation_item
= traverse_obj(continuation_items
, 0, None, expected_type
=dict, default
={})
4994 video_items_renderer
= None
4995 for key
in continuation_item
.keys():
4996 if key
not in known_renderers
:
4998 func
, parent_key
= known_renderers
[key
]
4999 video_items_renderer
= {parent_key: continuation_items}
if parent_key
else continuation_items
5000 continuation_list
= [None]
5001 yield from func(video_items_renderer
)
5002 continuation
= continuation_list
[0] or self
._extract
_continuation
(video_items_renderer
)
5004 if not video_items_renderer
:
5008 def _extract_selected_tab(tabs
, fatal
=True):
5009 for tab_renderer
in tabs
:
5010 if tab_renderer
.get('selected'):
5013 raise ExtractorError('Unable to find selected tab')
5016 def _extract_tab_renderers(response
):
5017 return traverse_obj(
5018 response
, ('contents', 'twoColumnBrowseResultsRenderer', 'tabs', ..., ('tabRenderer', 'expandableTabRenderer')), expected_type
=dict)
5020 def _extract_from_tabs(self
, item_id
, ytcfg
, data
, tabs
):
5021 metadata
= self
._extract
_metadata
_from
_tabs
(item_id
, data
)
5023 selected_tab
= self
._extract
_selected
_tab
(tabs
)
5024 metadata
['title'] += format_field(selected_tab
, 'title', ' - %s')
5025 metadata
['title'] += format_field(selected_tab
, 'expandedText', ' - %s')
5027 return self
.playlist_result(
5029 selected_tab
, metadata
['id'], ytcfg
,
5030 self
._extract
_account
_syncid
(ytcfg
, data
),
5031 self
._extract
_visitor
_data
(data
, ytcfg
)),
5034 def _extract_metadata_from_tabs(self
, item_id
, data
):
5035 info
= {'id': item_id}
5037 metadata_renderer
= traverse_obj(data
, ('metadata', 'channelMetadataRenderer'), expected_type
=dict)
5038 if metadata_renderer
:
5039 channel_id
= traverse_obj(metadata_renderer
, ('externalId', {self.ucid_or_none}
),
5040 ('channelUrl', {self.ucid_from_url}
))
5042 'channel': metadata_renderer
.get('title'),
5043 'channel_id': channel_id
,
5045 if info
['channel_id']:
5046 info
['id'] = info
['channel_id']
5048 metadata_renderer
= traverse_obj(data
, ('metadata', 'playlistMetadataRenderer'), expected_type
=dict)
5050 # We can get the uncropped banner/avatar by replacing the crop params with '=s0'
5051 # See: https://github.com/yt-dlp/yt-dlp/issues/2237#issuecomment-1013694714
5052 def _get_uncropped(url
):
5053 return url_or_none((url
or '').split('=')[0] + '=s0')
5055 avatar_thumbnails
= self
._extract
_thumbnails
(metadata_renderer
, 'avatar')
5056 if avatar_thumbnails
:
5057 uncropped_avatar
= _get_uncropped(avatar_thumbnails
[0]['url'])
5058 if uncropped_avatar
:
5059 avatar_thumbnails
.append({
5060 'url': uncropped_avatar
,
5061 'id': 'avatar_uncropped',
5065 channel_banners
= self
._extract
_thumbnails
(
5066 data
, ('header', ..., ('banner', 'mobileBanner', 'tvBanner')))
5067 for banner
in channel_banners
:
5068 banner
['preference'] = -10
5071 uncropped_banner
= _get_uncropped(channel_banners
[0]['url'])
5072 if uncropped_banner
:
5073 channel_banners
.append({
5074 'url': uncropped_banner
,
5075 'id': 'banner_uncropped',
5079 # Deprecated - remove primary_sidebar_renderer when layout discontinued
5080 primary_sidebar_renderer
= self
._extract
_sidebar
_info
_renderer
(data
, 'playlistSidebarPrimaryInfoRenderer')
5081 playlist_header_renderer
= traverse_obj(data
, ('header', 'playlistHeaderRenderer'), expected_type
=dict)
5083 primary_thumbnails
= self
._extract
_thumbnails
(
5084 primary_sidebar_renderer
, ('thumbnailRenderer', ('playlistVideoThumbnailRenderer', 'playlistCustomThumbnailRenderer'), 'thumbnail'))
5085 playlist_thumbnails
= self
._extract
_thumbnails
(
5086 playlist_header_renderer
, ('playlistHeaderBanner', 'heroPlaylistThumbnailRenderer', 'thumbnail'))
5089 'title': (traverse_obj(metadata_renderer
, 'title')
5090 or self
._get
_text
(data
, ('header', 'hashtagHeaderRenderer', 'hashtag'))
5092 'availability': self
._extract
_availability
(data
),
5093 'channel_follower_count': self
._get
_count
(data
, ('header', ..., 'subscriberCountText')),
5094 'description': try_get(metadata_renderer
, lambda x
: x
.get('description', '')),
5095 'tags': (traverse_obj(data
, ('microformat', 'microformatDataRenderer', 'tags', ..., {str}
))
5096 or traverse_obj(metadata_renderer
, ('keywords', {lambda x: x and shlex.split(x)}
, ...))),
5097 'thumbnails': (primary_thumbnails
or playlist_thumbnails
) + avatar_thumbnails
+ channel_banners
,
5101 traverse_obj(metadata_renderer
, (('vanityChannelUrl', ('ownerUrls', ...)), {self.handle_from_url}
), get_all
=False)
5102 or traverse_obj(data
, ('header', ..., 'channelHandleText', {self.handle_or_none}
), get_all
=False))
5106 'uploader_id': channel_handle
,
5107 'uploader_url': format_field(channel_handle
, None, 'https://www.youtube.com/%s', default
=None),
5110 channel_badges
= self
._extract
_badges
(traverse_obj(data
, ('header', ..., 'badges'), get_all
=False))
5111 if self
._has
_badge
(channel_badges
, BadgeType
.VERIFIED
):
5112 info
['channel_is_verified'] = True
5113 # Playlist stats is a text runs array containing [video count, view count, last updated].
5114 # last updated or (view count and last updated) may be missing.
5115 playlist_stats
= get_first(
5116 (primary_sidebar_renderer
, playlist_header_renderer
), (('stats', 'briefStats', 'numVideosText'), ))
5118 last_updated_unix
= self
._parse
_time
_text
(
5119 self
._get
_text
(playlist_stats
, 2) # deprecated, remove when old layout discontinued
5120 or self
._get
_text
(playlist_header_renderer
, ('byline', 1, 'playlistBylineRenderer', 'text')))
5121 info
['modified_date'] = strftime_or_none(last_updated_unix
)
5123 info
['view_count'] = self
._get
_count
(playlist_stats
, 1)
5124 if info
['view_count'] is None: # 0 is allowed
5125 info
['view_count'] = self
._get
_count
(playlist_header_renderer
, 'viewCountText')
5126 if info
['view_count'] is None:
5127 info
['view_count'] = self
._get
_count
(data
, (
5128 'contents', 'twoColumnBrowseResultsRenderer', 'tabs', ..., 'tabRenderer', 'content', 'sectionListRenderer',
5129 'contents', ..., 'itemSectionRenderer', 'contents', ..., 'channelAboutFullMetadataRenderer', 'viewCountText'))
5131 info
['playlist_count'] = self
._get
_count
(playlist_stats
, 0)
5132 if info
['playlist_count'] is None: # 0 is allowed
5133 info
['playlist_count'] = self
._get
_count
(playlist_header_renderer
, ('byline', 0, 'playlistBylineRenderer', 'text'))
5135 if not info
.get('channel_id'):
5136 owner
= traverse_obj(playlist_header_renderer
, 'ownerText')
5137 if not owner
: # Deprecated
5138 owner
= traverse_obj(
5139 self
._extract
_sidebar
_info
_renderer
(data
, 'playlistSidebarSecondaryInfoRenderer'),
5140 ('videoOwner', 'videoOwnerRenderer', 'title'))
5141 owner_text
= self
._get
_text
(owner
)
5142 browse_ep
= traverse_obj(owner
, ('runs', 0, 'navigationEndpoint', 'browseEndpoint')) or {}
5144 'channel': self
._search
_regex
(r
'^by (.+) and \d+ others?$', owner_text
, 'uploader', default
=owner_text
),
5145 'channel_id': self
.ucid_or_none(browse_ep
.get('browseId')),
5146 'uploader_id': self
.handle_from_url(urljoin('https://www.youtube.com', browse_ep
.get('canonicalBaseUrl')))
5150 'uploader': info
['channel'],
5151 'channel_url': format_field(info
.get('channel_id'), None, 'https://www.youtube.com/channel/%s', default
=None),
5152 'uploader_url': format_field(info
.get('uploader_id'), None, 'https://www.youtube.com/%s', default
=None),
5157 def _extract_inline_playlist(self
, playlist
, playlist_id
, data
, ytcfg
):
5158 first_id
= last_id
= response
= None
5159 for page_num
in itertools
.count(1):
5160 videos
= list(self
._playlist
_entries
(playlist
))
5163 start
= next((i
for i
, v
in enumerate(videos
) if v
['id'] == last_id
), -1) + 1
5164 if start
>= len(videos
):
5166 yield from videos
[start
:]
5167 first_id
= first_id
or videos
[0]['id']
5168 last_id
= videos
[-1]['id']
5169 watch_endpoint
= try_get(
5170 playlist
, lambda x
: x
['contents'][-1]['playlistPanelVideoRenderer']['navigationEndpoint']['watchEndpoint'])
5171 headers
= self
.generate_api_headers(
5172 ytcfg
=ytcfg
, account_syncid
=self
._extract
_account
_syncid
(ytcfg
, data
),
5173 visitor_data
=self
._extract
_visitor
_data
(response
, data
, ytcfg
))
5175 'playlistId': playlist_id
,
5176 'videoId': watch_endpoint
.get('videoId') or last_id
,
5177 'index': watch_endpoint
.get('index') or len(videos
),
5178 'params': watch_endpoint
.get('params') or 'OAE%3D'
5180 response
= self
._extract
_response
(
5181 item_id
='%s page %d' % (playlist_id
, page_num
),
5182 query
=query
, ep
='next', headers
=headers
, ytcfg
=ytcfg
,
5183 check_get_keys
='contents'
5186 response
, lambda x
: x
['contents']['twoColumnWatchNextResults']['playlist']['playlist'], dict)
5188 def _extract_from_playlist(self
, item_id
, url
, data
, playlist
, ytcfg
):
5189 title
= playlist
.get('title') or try_get(
5190 data
, lambda x
: x
['titleText']['simpleText'], str)
5191 playlist_id
= playlist
.get('playlistId') or item_id
5193 # Delegating everything except mix playlists to regular tab-based playlist URL
5194 playlist_url
= urljoin(url
, try_get(
5195 playlist
, lambda x
: x
['endpoint']['commandMetadata']['webCommandMetadata']['url'],
5198 # Some playlists are unviewable but YouTube still provides a link to the (broken) playlist page [1]
5199 # [1] MLCT, RLTDwFCb4jeqaKWnciAYM-ZVHg
5200 is_known_unviewable
= re
.fullmatch(r
'MLCT|RLTD[\w-]{22}', playlist_id
)
5202 if playlist_url
and playlist_url
!= url
and not is_known_unviewable
:
5203 return self
.url_result(
5204 playlist_url
, ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
,
5207 return self
.playlist_result(
5208 self
._extract
_inline
_playlist
(playlist
, playlist_id
, data
, ytcfg
),
5209 playlist_id
=playlist_id
, playlist_title
=title
)
5211 def _extract_availability(self
, data
):
5213 Gets the availability of a given playlist/tab.
5214 Note: Unless YouTube tells us explicitly, we do not assume it is public
5215 @param data: response
5217 sidebar_renderer
= self
._extract
_sidebar
_info
_renderer
(data
, 'playlistSidebarPrimaryInfoRenderer') or {}
5218 playlist_header_renderer
= traverse_obj(data
, ('header', 'playlistHeaderRenderer')) or {}
5219 player_header_privacy
= playlist_header_renderer
.get('privacy')
5221 badges
= self
._extract
_badges
(traverse_obj(sidebar_renderer
, 'badges'))
5223 # Personal playlists, when authenticated, have a dropdown visibility selector instead of a badge
5224 privacy_setting_icon
= get_first(
5225 (playlist_header_renderer
, sidebar_renderer
),
5226 ('privacyForm', 'dropdownFormFieldRenderer', 'dropdown', 'dropdownRenderer', 'entries',
5227 lambda _
, v
: v
['privacyDropdownItemRenderer']['isSelected'], 'privacyDropdownItemRenderer', 'icon', 'iconType'),
5230 microformats_is_unlisted
= traverse_obj(
5231 data
, ('microformat', 'microformatDataRenderer', 'unlisted'), expected_type
=bool)
5235 self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PUBLIC
)
5236 or player_header_privacy
== 'PUBLIC'
5237 or privacy_setting_icon
== 'PRIVACY_PUBLIC')
5238 else self
._availability
(
5240 self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PRIVATE
)
5241 or player_header_privacy
== 'PRIVATE' if player_header_privacy
is not None
5242 else privacy_setting_icon
== 'PRIVACY_PRIVATE' if privacy_setting_icon
is not None else None),
5244 self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_UNLISTED
)
5245 or player_header_privacy
== 'UNLISTED' if player_header_privacy
is not None
5246 else privacy_setting_icon
== 'PRIVACY_UNLISTED' if privacy_setting_icon
is not None
5247 else microformats_is_unlisted
if microformats_is_unlisted
is not None else None),
5248 needs_subscription
=self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_SUBSCRIPTION
) or None,
5249 needs_premium
=self
._has
_badge
(badges
, BadgeType
.AVAILABILITY_PREMIUM
) or None,
5253 def _extract_sidebar_info_renderer(data
, info_renderer
, expected_type
=dict):
5254 sidebar_renderer
= try_get(
5255 data
, lambda x
: x
['sidebar']['playlistSidebarRenderer']['items'], list) or []
5256 for item
in sidebar_renderer
:
5257 renderer
= try_get(item
, lambda x
: x
[info_renderer
], expected_type
)
5261 def _reload_with_unavailable_videos(self
, item_id
, data
, ytcfg
):
5263 Reload playlists with unavailable videos (e.g. private videos, region blocked, etc.)
5265 is_playlist
= bool(traverse_obj(
5266 data
, ('metadata', 'playlistMetadataRenderer'), ('header', 'playlistHeaderRenderer')))
5269 headers
= self
.generate_api_headers(
5270 ytcfg
=ytcfg
, account_syncid
=self
._extract
_account
_syncid
(ytcfg
, data
),
5271 visitor_data
=self
._extract
_visitor
_data
(data
, ytcfg
))
5273 'params': 'wgYCCAA=',
5274 'browseId': f
'VL{item_id}'
5276 return self
._extract
_response
(
5277 item_id
=item_id
, headers
=headers
, query
=query
,
5278 check_get_keys
='contents', fatal
=False, ytcfg
=ytcfg
,
5279 note
='Redownloading playlist API JSON with unavailable videos')
5281 @functools.cached_property
5282 def skip_webpage(self
):
5283 return 'webpage' in self
._configuration
_arg
('skip', ie_key
=YoutubeTabIE
.ie_key())
5285 def _extract_webpage(self
, url
, item_id
, fatal
=True):
5286 webpage
, data
= None, None
5287 for retry
in self
.RetryManager(fatal
=fatal
):
5289 webpage
= self
._download
_webpage
(url
, item_id
, note
='Downloading webpage')
5290 data
= self
.extract_yt_initial_data(item_id
, webpage
or '', fatal
=fatal
) or {}
5291 except ExtractorError
as e
:
5292 if isinstance(e
.cause
, network_exceptions
):
5293 if not isinstance(e
.cause
, HTTPError
) or e
.cause
.status
not in (403, 429):
5296 self
._error
_or
_warning
(e
, fatal
=fatal
)
5300 self
._extract
_and
_report
_alerts
(data
)
5301 except ExtractorError
as e
:
5302 self
._error
_or
_warning
(e
, fatal
=fatal
)
5305 # Sometimes youtube returns a webpage with incomplete ytInitialData
5306 # See: https://github.com/yt-dlp/yt-dlp/issues/116
5307 if not traverse_obj(data
, 'contents', 'currentVideoEndpoint', 'onResponseReceivedActions'):
5308 retry
.error
= ExtractorError('Incomplete yt initial data received')
5312 return webpage
, data
5314 def _report_playlist_authcheck(self
, ytcfg
, fatal
=True):
5315 """Use if failed to extract ytcfg (and data) from initial webpage"""
5316 if not ytcfg
and self
.is_authenticated
:
5317 msg
= 'Playlists that require authentication may not extract correctly without a successful webpage download'
5318 if 'authcheck' not in self
._configuration
_arg
('skip', ie_key
=YoutubeTabIE
.ie_key()) and fatal
:
5319 raise ExtractorError(
5320 f
'{msg}. If you are not downloading private content, or '
5321 'your cookies are only for the first account and channel,'
5322 ' pass "--extractor-args youtubetab:skip=authcheck" to skip this check',
5324 self
.report_warning(msg
, only_once
=True)
5326 def _extract_data(self
, url
, item_id
, ytcfg
=None, fatal
=True, webpage_fatal
=False, default_client
='web'):
5328 if not self
.skip_webpage
:
5329 webpage
, data
= self
._extract
_webpage
(url
, item_id
, fatal
=webpage_fatal
)
5330 ytcfg
= ytcfg
or self
.extract_ytcfg(item_id
, webpage
)
5331 # Reject webpage data if redirected to home page without explicitly requesting
5332 selected_tab
= self
._extract
_selected
_tab
(self
._extract
_tab
_renderers
(data
), fatal
=False) or {}
5333 if (url
!= 'https://www.youtube.com/feed/recommended'
5334 and selected_tab
.get('tabIdentifier') == 'FEwhat_to_watch' # Home page
5335 and 'no-youtube-channel-redirect' not in self
.get_param('compat_opts', [])):
5336 msg
= 'The channel/playlist does not exist and the URL redirected to youtube.com home page'
5338 raise ExtractorError(msg
, expected
=True)
5339 self
.report_warning(msg
, only_once
=True)
5341 self
._report
_playlist
_authcheck
(ytcfg
, fatal
=fatal
)
5342 data
= self
._extract
_tab
_endpoint
(url
, item_id
, ytcfg
, fatal
=fatal
, default_client
=default_client
)
5345 def _extract_tab_endpoint(self
, url
, item_id
, ytcfg
=None, fatal
=True, default_client
='web'):
5346 headers
= self
.generate_api_headers(ytcfg
=ytcfg
, default_client
=default_client
)
5347 resolve_response
= self
._extract
_response
(
5348 item_id
=item_id
, query
={'url': url}
, check_get_keys
='endpoint', headers
=headers
, ytcfg
=ytcfg
, fatal
=fatal
,
5349 ep
='navigation/resolve_url', note
='Downloading API parameters API JSON', default_client
=default_client
)
5350 endpoints
= {'browseEndpoint': 'browse', 'watchEndpoint': 'next'}
5351 for ep_key
, ep
in endpoints
.items():
5352 params
= try_get(resolve_response
, lambda x
: x
['endpoint'][ep_key
], dict)
5354 return self
._extract
_response
(
5355 item_id
=item_id
, query
=params
, ep
=ep
, headers
=headers
,
5356 ytcfg
=ytcfg
, fatal
=fatal
, default_client
=default_client
,
5357 check_get_keys
=('contents', 'currentVideoEndpoint', 'onResponseReceivedActions'))
5358 err_note
= 'Failed to resolve url (does the playlist exist?)'
5360 raise ExtractorError(err_note
, expected
=True)
5361 self
.report_warning(err_note
, item_id
)
5363 _SEARCH_PARAMS
= None
5365 def _search_results(self
, query
, params
=NO_DEFAULT
, default_client
='web'):
5366 data
= {'query': query}
5367 if params
is NO_DEFAULT
:
5368 params
= self
._SEARCH
_PARAMS
5370 data
['params'] = params
5373 ('contents', 'twoColumnSearchResultsRenderer', 'primaryContents', 'sectionListRenderer', 'contents'),
5374 ('onResponseReceivedCommands', 0, 'appendContinuationItemsAction', 'continuationItems'),
5376 ('contents', 'tabbedSearchResultsRenderer', 'tabs', 0, 'tabRenderer', 'content', 'sectionListRenderer', 'contents'),
5377 ('continuationContents', ),
5379 display_id
= f
'query "{query}"'
5380 check_get_keys
= tuple({keys[0] for keys in content_keys}
)
5381 ytcfg
= self
._download
_ytcfg
(default_client
, display_id
) if not self
.skip_webpage
else {}
5382 self
._report
_playlist
_authcheck
(ytcfg
, fatal
=False)
5384 continuation_list
= [None]
5386 for page_num
in itertools
.count(1):
5387 data
.update(continuation_list
[0] or {})
5388 headers
= self
.generate_api_headers(
5389 ytcfg
=ytcfg
, visitor_data
=self
._extract
_visitor
_data
(search
), default_client
=default_client
)
5390 search
= self
._extract
_response
(
5391 item_id
=f
'{display_id} page {page_num}', ep
='search', query
=data
,
5392 default_client
=default_client
, check_get_keys
=check_get_keys
, ytcfg
=ytcfg
, headers
=headers
)
5393 slr_contents
= traverse_obj(search
, *content_keys
)
5394 yield from self
._extract
_entries
({'contents': list(variadic(slr_contents))}
, continuation_list
)
5395 if not continuation_list
[0]:
5399 class YoutubeTabIE(YoutubeTabBaseInfoExtractor
):
5400 IE_DESC
= 'YouTube Tabs'
5401 _VALID_URL
= r
'''(?x:
5403 (?!consent\.)(?:\w+\.)?
5405 youtube(?:kids)?\.com|
5409 (?P<channel_type>channel|c|user|browse)/|
5412 (?:playlist|watch)\?.*?\blist=
5414 (?!(?:%(reserved_names)s)\b) # Direct URLs
5418 'reserved_names': YoutubeBaseInfoExtractor
._RESERVED
_NAMES
,
5419 'invidious': '|'.join(YoutubeBaseInfoExtractor
._INVIDIOUS
_SITES
),
5421 IE_NAME
= 'youtube:tab'
5424 'note': 'playlists, multipage',
5425 'url': 'https://www.youtube.com/c/ИгорьКлейнер/playlists?view=1&flow=grid',
5426 'playlist_mincount': 94,
5428 'id': 'UCqj7Cz7revf5maW9g5pgNcg',
5429 'title': 'Igor Kleiner Ph.D. - Playlists',
5430 'description': 'md5:15d7dd9e333cb987907fcb0d604b233a',
5431 'uploader': 'Igor Kleiner Ph.D.',
5432 'uploader_id': '@IgorDataScience',
5433 'uploader_url': 'https://www.youtube.com/@IgorDataScience',
5434 'channel': 'Igor Kleiner Ph.D.',
5435 'channel_id': 'UCqj7Cz7revf5maW9g5pgNcg',
5436 'tags': ['критическое мышление', 'наука просто', 'математика', 'анализ данных'],
5437 'channel_url': 'https://www.youtube.com/channel/UCqj7Cz7revf5maW9g5pgNcg',
5438 'channel_follower_count': int
5441 'note': 'playlists, multipage, different order',
5442 'url': 'https://www.youtube.com/user/igorkle1/playlists?view=1&sort=dd',
5443 'playlist_mincount': 94,
5445 'id': 'UCqj7Cz7revf5maW9g5pgNcg',
5446 'title': 'Igor Kleiner Ph.D. - Playlists',
5447 'description': 'md5:15d7dd9e333cb987907fcb0d604b233a',
5448 'uploader': 'Igor Kleiner Ph.D.',
5449 'uploader_id': '@IgorDataScience',
5450 'uploader_url': 'https://www.youtube.com/@IgorDataScience',
5451 'tags': ['критическое мышление', 'наука просто', 'математика', 'анализ данных'],
5452 'channel_id': 'UCqj7Cz7revf5maW9g5pgNcg',
5453 'channel': 'Igor Kleiner Ph.D.',
5454 'channel_url': 'https://www.youtube.com/channel/UCqj7Cz7revf5maW9g5pgNcg',
5455 'channel_follower_count': int
5458 'note': 'playlists, series',
5459 'url': 'https://www.youtube.com/c/3blue1brown/playlists?view=50&sort=dd&shelf_id=3',
5460 'playlist_mincount': 5,
5462 'id': 'UCYO_jab_esuFRV4b17AJtAw',
5463 'title': '3Blue1Brown - Playlists',
5464 'description': 'md5:4d1da95432004b7ba840ebc895b6b4c9',
5465 'channel_url': 'https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw',
5466 'channel': '3Blue1Brown',
5467 'channel_id': 'UCYO_jab_esuFRV4b17AJtAw',
5468 'uploader_id': '@3blue1brown',
5469 'uploader_url': 'https://www.youtube.com/@3blue1brown',
5470 'uploader': '3Blue1Brown',
5471 'tags': ['Mathematics'],
5472 'channel_follower_count': int,
5473 'channel_is_verified': True,
5476 'note': 'playlists, singlepage',
5477 'url': 'https://www.youtube.com/user/ThirstForScience/playlists',
5478 'playlist_mincount': 4,
5480 'id': 'UCAEtajcuhQ6an9WEzY9LEMQ',
5481 'title': 'ThirstForScience - Playlists',
5482 'description': 'md5:609399d937ea957b0f53cbffb747a14c',
5483 'uploader': 'ThirstForScience',
5484 'uploader_url': 'https://www.youtube.com/@ThirstForScience',
5485 'uploader_id': '@ThirstForScience',
5486 'channel_id': 'UCAEtajcuhQ6an9WEzY9LEMQ',
5487 'channel_url': 'https://www.youtube.com/channel/UCAEtajcuhQ6an9WEzY9LEMQ',
5489 'channel': 'ThirstForScience',
5490 'channel_follower_count': int
5493 'url': 'https://www.youtube.com/c/ChristophLaimer/playlists',
5494 'only_matching': True,
5496 'note': 'basic, single video playlist',
5497 'url': 'https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc',
5499 'id': 'PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc',
5500 'title': 'youtube-dl public playlist',
5504 'modified_date': '20201130',
5505 'channel': 'Sergey M.',
5506 'channel_id': 'UCmlqkdCBesrv2Lak1mF_MxA',
5507 'channel_url': 'https://www.youtube.com/channel/UCmlqkdCBesrv2Lak1mF_MxA',
5508 'availability': 'public',
5509 'uploader': 'Sergey M.',
5510 'uploader_url': 'https://www.youtube.com/@sergeym.6173',
5511 'uploader_id': '@sergeym.6173',
5513 'playlist_count': 1,
5515 'note': 'empty playlist',
5516 'url': 'https://www.youtube.com/playlist?list=PL4lCao7KL_QFodcLWhDpGCYnngnHtQ-Xf',
5518 'id': 'PL4lCao7KL_QFodcLWhDpGCYnngnHtQ-Xf',
5519 'title': 'youtube-dl empty playlist',
5521 'channel': 'Sergey M.',
5523 'modified_date': '20230921',
5524 'channel_id': 'UCmlqkdCBesrv2Lak1mF_MxA',
5525 'channel_url': 'https://www.youtube.com/channel/UCmlqkdCBesrv2Lak1mF_MxA',
5526 'availability': 'unlisted',
5527 'uploader_url': 'https://www.youtube.com/@sergeym.6173',
5528 'uploader_id': '@sergeym.6173',
5529 'uploader': 'Sergey M.',
5531 'playlist_count': 0,
5534 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/featured',
5536 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5537 'title': 'lex will - Home',
5538 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
5539 'uploader': 'lex will',
5540 'uploader_id': '@lexwill718',
5541 'channel': 'lex will',
5542 'tags': ['bible', 'history', 'prophesy'],
5543 'uploader_url': 'https://www.youtube.com/@lexwill718',
5544 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5545 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5546 'channel_follower_count': int
5548 'playlist_mincount': 2,
5550 'note': 'Videos tab',
5551 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/videos',
5553 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5554 'title': 'lex will - Videos',
5555 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
5556 'uploader': 'lex will',
5557 'uploader_id': '@lexwill718',
5558 'tags': ['bible', 'history', 'prophesy'],
5559 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5560 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5561 'uploader_url': 'https://www.youtube.com/@lexwill718',
5562 'channel': 'lex will',
5563 'channel_follower_count': int
5565 'playlist_mincount': 975,
5567 'note': 'Videos tab, sorted by popular',
5568 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/videos?view=0&sort=p&flow=grid',
5570 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5571 'title': 'lex will - Videos',
5572 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
5573 'uploader': 'lex will',
5574 'uploader_id': '@lexwill718',
5575 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5576 'uploader_url': 'https://www.youtube.com/@lexwill718',
5577 'channel': 'lex will',
5578 'tags': ['bible', 'history', 'prophesy'],
5579 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5580 'channel_follower_count': int
5582 'playlist_mincount': 199,
5584 'note': 'Playlists tab',
5585 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/playlists',
5587 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5588 'title': 'lex will - Playlists',
5589 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
5590 'uploader': 'lex will',
5591 'uploader_id': '@lexwill718',
5592 'uploader_url': 'https://www.youtube.com/@lexwill718',
5593 'channel': 'lex will',
5594 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5595 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5596 'tags': ['bible', 'history', 'prophesy'],
5597 'channel_follower_count': int
5599 'playlist_mincount': 17,
5601 'note': 'Community tab',
5602 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/community',
5604 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5605 'title': 'lex will - Community',
5606 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
5607 'channel': 'lex will',
5608 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5609 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5610 'tags': ['bible', 'history', 'prophesy'],
5611 'channel_follower_count': int,
5612 'uploader_url': 'https://www.youtube.com/@lexwill718',
5613 'uploader_id': '@lexwill718',
5614 'uploader': 'lex will',
5616 'playlist_mincount': 18,
5618 'note': 'Channels tab',
5619 'url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w/channels',
5621 'id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5622 'title': 'lex will - Channels',
5623 'description': 'md5:2163c5d0ff54ed5f598d6a7e6211e488',
5624 'channel': 'lex will',
5625 'channel_url': 'https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w',
5626 'channel_id': 'UCKfVa3S1e4PHvxWcwyMMg8w',
5627 'tags': ['bible', 'history', 'prophesy'],
5628 'channel_follower_count': int,
5629 'uploader_url': 'https://www.youtube.com/@lexwill718',
5630 'uploader_id': '@lexwill718',
5631 'uploader': 'lex will',
5633 'playlist_mincount': 12,
5635 'note': 'Search tab',
5636 'url': 'https://www.youtube.com/c/3blue1brown/search?query=linear%20algebra',
5637 'playlist_mincount': 40,
5639 'id': 'UCYO_jab_esuFRV4b17AJtAw',
5640 'title': '3Blue1Brown - Search - linear algebra',
5641 'description': 'md5:4d1da95432004b7ba840ebc895b6b4c9',
5642 'channel_url': 'https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw',
5643 'tags': ['Mathematics'],
5644 'channel': '3Blue1Brown',
5645 'channel_id': 'UCYO_jab_esuFRV4b17AJtAw',
5646 'channel_follower_count': int,
5647 'uploader_url': 'https://www.youtube.com/@3blue1brown',
5648 'uploader_id': '@3blue1brown',
5649 'uploader': '3Blue1Brown',
5650 'channel_is_verified': True,
5653 'url': 'https://invidio.us/channel/UCmlqkdCBesrv2Lak1mF_MxA',
5654 'only_matching': True,
5656 'url': 'https://www.youtubekids.com/channel/UCmlqkdCBesrv2Lak1mF_MxA',
5657 'only_matching': True,
5659 'url': 'https://music.youtube.com/channel/UCmlqkdCBesrv2Lak1mF_MxA',
5660 'only_matching': True,
5662 'note': 'Playlist with deleted videos (#651). As a bonus, the video #51 is also twice in this list.',
5663 'url': 'https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC',
5665 'title': '29C3: Not my department',
5666 'id': 'PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC',
5667 'description': 'md5:a14dc1a8ef8307a9807fe136a0660268',
5670 'modified_date': '20150605',
5671 'channel_id': 'UCEPzS1rYsrkqzSLNp76nrcg',
5672 'channel_url': 'https://www.youtube.com/channel/UCEPzS1rYsrkqzSLNp76nrcg',
5673 'channel': 'Christiaan008',
5674 'availability': 'public',
5675 'uploader_id': '@ChRiStIaAn008',
5676 'uploader': 'Christiaan008',
5677 'uploader_url': 'https://www.youtube.com/@ChRiStIaAn008',
5679 'playlist_count': 96,
5681 'note': 'Large playlist',
5682 'url': 'https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q',
5684 'title': 'Uploads from Cauchemar',
5685 'id': 'UUBABnxM4Ar9ten8Mdjj1j0Q',
5686 'channel_url': 'https://www.youtube.com/channel/UCBABnxM4Ar9ten8Mdjj1j0Q',
5688 'modified_date': r
're:\d{8}',
5689 'channel': 'Cauchemar',
5692 'channel_id': 'UCBABnxM4Ar9ten8Mdjj1j0Q',
5693 'availability': 'public',
5694 'uploader_id': '@Cauchemar89',
5695 'uploader': 'Cauchemar',
5696 'uploader_url': 'https://www.youtube.com/@Cauchemar89',
5698 'playlist_mincount': 1123,
5699 'expected_warnings': [r
'[Uu]navailable videos (are|will be) hidden'],
5701 'note': 'even larger playlist, 8832 videos',
5702 'url': 'http://www.youtube.com/user/NASAgovVideo/videos',
5703 'only_matching': True,
5705 'note': 'Buggy playlist: the webpage has a "Load more" button but it doesn\'t have more videos',
5706 'url': 'https://www.youtube.com/playlist?list=UUXw-G3eDE9trcvY2sBMM_aA',
5708 'title': 'Uploads from Interstellar Movie',
5709 'id': 'UUXw-G3eDE9trcvY2sBMM_aA',
5712 'channel_id': 'UCXw-G3eDE9trcvY2sBMM_aA',
5713 'channel_url': 'https://www.youtube.com/channel/UCXw-G3eDE9trcvY2sBMM_aA',
5714 'channel': 'Interstellar Movie',
5716 'modified_date': r
're:\d{8}',
5717 'availability': 'public',
5718 'uploader_id': '@InterstellarMovie',
5719 'uploader': 'Interstellar Movie',
5720 'uploader_url': 'https://www.youtube.com/@InterstellarMovie',
5722 'playlist_mincount': 21,
5724 'note': 'Playlist with "show unavailable videos" button',
5725 'url': 'https://www.youtube.com/playlist?list=UUTYLiWFZy8xtPwxFwX9rV7Q',
5727 'title': 'Uploads from Phim Siêu Nhân Nhật Bản',
5728 'id': 'UUTYLiWFZy8xtPwxFwX9rV7Q',
5730 'channel': 'Phim Siêu Nhân Nhật Bản',
5733 'channel_url': 'https://www.youtube.com/channel/UCTYLiWFZy8xtPwxFwX9rV7Q',
5734 'channel_id': 'UCTYLiWFZy8xtPwxFwX9rV7Q',
5735 'modified_date': r
're:\d{8}',
5736 'availability': 'public',
5737 'uploader_url': 'https://www.youtube.com/@phimsieunhannhatban',
5738 'uploader_id': '@phimsieunhannhatban',
5739 'uploader': 'Phim Siêu Nhân Nhật Bản',
5741 'playlist_mincount': 200,
5742 'expected_warnings': [r
'[Uu]navailable videos (are|will be) hidden'],
5744 'note': 'Playlist with unavailable videos in page 7',
5745 'url': 'https://www.youtube.com/playlist?list=UU8l9frL61Yl5KFOl87nIm2w',
5747 'title': 'Uploads from BlankTV',
5748 'id': 'UU8l9frL61Yl5KFOl87nIm2w',
5749 'channel': 'BlankTV',
5750 'channel_url': 'https://www.youtube.com/channel/UC8l9frL61Yl5KFOl87nIm2w',
5751 'channel_id': 'UC8l9frL61Yl5KFOl87nIm2w',
5754 'modified_date': r
're:\d{8}',
5756 'availability': 'public',
5757 'uploader_id': '@blanktv',
5758 'uploader': 'BlankTV',
5759 'uploader_url': 'https://www.youtube.com/@blanktv',
5761 'playlist_mincount': 1000,
5762 'expected_warnings': [r
'[Uu]navailable videos (are|will be) hidden'],
5764 'note': 'https://github.com/ytdl-org/youtube-dl/issues/21844',
5765 'url': 'https://www.youtube.com/playlist?list=PLzH6n4zXuckpfMu_4Ff8E7Z1behQks5ba',
5767 'title': 'Data Analysis with Dr Mike Pound',
5768 'id': 'PLzH6n4zXuckpfMu_4Ff8E7Z1behQks5ba',
5769 'description': 'md5:7f567c574d13d3f8c0954d9ffee4e487',
5772 'channel_id': 'UC9-y-6csu5WGm29I7JiwpnA',
5773 'channel_url': 'https://www.youtube.com/channel/UC9-y-6csu5WGm29I7JiwpnA',
5774 'channel': 'Computerphile',
5775 'availability': 'public',
5776 'modified_date': '20190712',
5777 'uploader_id': '@Computerphile',
5778 'uploader': 'Computerphile',
5779 'uploader_url': 'https://www.youtube.com/@Computerphile',
5781 'playlist_mincount': 11,
5783 'url': 'https://invidio.us/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc',
5784 'only_matching': True,
5786 'note': 'Playlist URL that does not actually serve a playlist',
5787 'url': 'https://www.youtube.com/watch?v=FqZTN594JQw&list=PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4',
5789 'id': 'FqZTN594JQw',
5791 'title': "Smiley's People 01 detective, Adventure Series, Action",
5792 'upload_date': '20150526',
5793 'license': 'Standard YouTube License',
5794 'description': 'md5:507cdcb5a49ac0da37a920ece610be80',
5795 'categories': ['People & Blogs'],
5801 'skip_download': True,
5803 'skip': 'This video is not available.',
5804 'add_ie': [YoutubeIE
.ie_key()],
5806 'url': 'https://www.youtubekids.com/watch?v=Agk7R8I8o5U&list=PUZ6jURNr1WQZCNHF0ao-c0g',
5807 'only_matching': True,
5809 'url': 'https://www.youtube.com/watch?v=MuAGGZNfUkU&list=RDMM',
5810 'only_matching': True,
5812 'url': 'https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ/live',
5814 'id': 'hGkQjiJLjWQ', # This will keep changing
5817 'upload_date': r
're:\d{8}',
5819 'categories': ['News & Politics'],
5822 'release_timestamp': int,
5823 'channel': 'Sky News',
5824 'channel_id': 'UCoMdktPbSTixAyNGwb-UYkQ',
5827 'thumbnail': r
're:https?://i\.ytimg\.com/vi/[^/]+/maxresdefault(?:_live)?\.jpg',
5828 'playable_in_embed': True,
5829 'release_date': r
're:\d+',
5830 'availability': 'public',
5831 'live_status': 'is_live',
5832 'channel_url': 'https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ',
5833 'channel_follower_count': int,
5834 'concurrent_view_count': int,
5835 'uploader_url': 'https://www.youtube.com/@SkyNews',
5836 'uploader_id': '@SkyNews',
5837 'uploader': 'Sky News',
5838 'channel_is_verified': True,
5841 'skip_download': True,
5843 'expected_warnings': ['Ignoring subtitle tracks found in '],
5845 'url': 'https://www.youtube.com/user/TheYoungTurks/live',
5847 'id': 'a48o2S1cPoo',
5849 'title': 'The Young Turks - Live Main Show',
5850 'upload_date': '20150715',
5851 'license': 'Standard YouTube License',
5852 'description': 'md5:438179573adcdff3c97ebb1ee632b891',
5853 'categories': ['News & Politics'],
5854 'tags': ['Cenk Uygur (TV Program Creator)', 'The Young Turks (Award-Winning Work)', 'Talk Show (TV Genre)'],
5858 'skip_download': True,
5860 'only_matching': True,
5862 'url': 'https://www.youtube.com/channel/UC1yBKRuGpC1tSM73A0ZjYjQ/live',
5863 'only_matching': True,
5865 'url': 'https://www.youtube.com/c/CommanderVideoHq/live',
5866 'only_matching': True,
5868 'note': 'A channel that is not live. Should raise error',
5869 'url': 'https://www.youtube.com/user/numberphile/live',
5870 'only_matching': True,
5872 'url': 'https://www.youtube.com/feed/trending',
5873 'only_matching': True,
5875 'url': 'https://www.youtube.com/feed/library',
5876 'only_matching': True,
5878 'url': 'https://www.youtube.com/feed/history',
5879 'only_matching': True,
5881 'url': 'https://www.youtube.com/feed/subscriptions',
5882 'only_matching': True,
5884 'url': 'https://www.youtube.com/feed/watch_later',
5885 'only_matching': True,
5887 'note': 'Recommended - redirects to home page.',
5888 'url': 'https://www.youtube.com/feed/recommended',
5889 'only_matching': True,
5891 'note': 'inline playlist with not always working continuations',
5892 'url': 'https://www.youtube.com/watch?v=UC6u0Tct-Fo&list=PL36D642111D65BE7C',
5893 'only_matching': True,
5895 'url': 'https://www.youtube.com/course',
5896 'only_matching': True,
5898 'url': 'https://www.youtube.com/zsecurity',
5899 'only_matching': True,
5901 'url': 'http://www.youtube.com/NASAgovVideo/videos',
5902 'only_matching': True,
5904 'url': 'https://www.youtube.com/TheYoungTurks/live',
5905 'only_matching': True,
5907 'url': 'https://www.youtube.com/hashtag/cctv9',
5910 'title': 'cctv9 - All',
5913 'playlist_mincount': 300, # not consistent but should be over 300
5915 'url': 'https://www.youtube.com/watch?list=PLW4dVinRY435CBE_JD3t-0SRXKfnZHS1P&feature=youtu.be&v=M9cJMXmQ_ZU',
5916 'only_matching': True,
5918 'note': 'Requires Premium: should request additional YTM-info webpage (and have format 141) for videos in playlist',
5919 'url': 'https://music.youtube.com/playlist?list=PLRBp0Fe2GpgmgoscNFLxNyBVSFVdYmFkq',
5920 'only_matching': True
5922 'note': '/browse/ should redirect to /channel/',
5923 'url': 'https://music.youtube.com/browse/UC1a8OFewdjuLq6KlF8M_8Ng',
5924 'only_matching': True
5926 'note': 'VLPL, should redirect to playlist?list=PL...',
5927 'url': 'https://music.youtube.com/browse/VLPLRBp0Fe2GpgmgoscNFLxNyBVSFVdYmFkq',
5929 'id': 'PLRBp0Fe2GpgmgoscNFLxNyBVSFVdYmFkq',
5930 'description': 'Providing you with copyright free / safe music for gaming, live streaming, studying and more!',
5931 'title': 'NCS : All Releases 💿',
5932 'channel_url': 'https://www.youtube.com/channel/UC_aEa8K-EOJ3D6gOs7HcyNg',
5933 'modified_date': r
're:\d{8}',
5935 'channel_id': 'UC_aEa8K-EOJ3D6gOs7HcyNg',
5937 'channel': 'NoCopyrightSounds',
5938 'availability': 'public',
5939 'uploader_url': 'https://www.youtube.com/@NoCopyrightSounds',
5940 'uploader': 'NoCopyrightSounds',
5941 'uploader_id': '@NoCopyrightSounds',
5943 'playlist_mincount': 166,
5944 'expected_warnings': [r
'[Uu]navailable videos (are|will be) hidden', 'YouTube Music is not directly supported'],
5946 # TODO: fix 'unviewable' issue with this playlist when reloading with unavailable videos
5947 'note': 'Topic, should redirect to playlist?list=UU...',
5948 'url': 'https://music.youtube.com/browse/UC9ALqqC4aIeG5iDs7i90Bfw',
5950 'id': 'UU9ALqqC4aIeG5iDs7i90Bfw',
5951 'title': 'Uploads from Royalty Free Music - Topic',
5953 'channel_id': 'UC9ALqqC4aIeG5iDs7i90Bfw',
5954 'channel': 'Royalty Free Music - Topic',
5956 'channel_url': 'https://www.youtube.com/channel/UC9ALqqC4aIeG5iDs7i90Bfw',
5957 'modified_date': r
're:\d{8}',
5959 'availability': 'public',
5960 'uploader': 'Royalty Free Music - Topic',
5962 'playlist_mincount': 101,
5963 'expected_warnings': ['YouTube Music is not directly supported', r
'[Uu]navailable videos (are|will be) hidden'],
5965 # Destination channel with only a hidden self tab (tab id is UCtFRv9O2AHqOZjjynzrv-xg)
5966 # Treat as a general feed
5967 'url': 'https://www.youtube.com/channel/UCtFRv9O2AHqOZjjynzrv-xg',
5969 'id': 'UCtFRv9O2AHqOZjjynzrv-xg',
5970 'title': 'UCtFRv9O2AHqOZjjynzrv-xg',
5973 'playlist_mincount': 9,
5975 'note': 'Youtube music Album',
5976 'url': 'https://music.youtube.com/browse/MPREb_gTAcphH99wE',
5978 'id': 'OLAK5uy_l1m0thk3g31NmIIz_vMIbWtyv7eZixlH0',
5979 'title': 'Album - Royalty Free Music Library V2 (50 Songs)',
5983 'availability': 'unlisted',
5984 'modified_date': r
're:\d{8}',
5986 'playlist_count': 50,
5987 'expected_warnings': ['YouTube Music is not directly supported'],
5989 'note': 'unlisted single video playlist',
5990 'url': 'https://www.youtube.com/playlist?list=PLwL24UFy54GrB3s2KMMfjZscDi1x5Dajf',
5992 'id': 'PLwL24UFy54GrB3s2KMMfjZscDi1x5Dajf',
5993 'title': 'yt-dlp unlisted playlist test',
5994 'availability': 'unlisted',
5996 'modified_date': '20220418',
5997 'channel': 'colethedj',
6000 'channel_id': 'UC9zHu_mHU96r19o-wV5Qs1Q',
6001 'channel_url': 'https://www.youtube.com/channel/UC9zHu_mHU96r19o-wV5Qs1Q',
6002 'uploader_url': 'https://www.youtube.com/@colethedj1894',
6003 'uploader_id': '@colethedj1894',
6004 'uploader': 'colethedj',
6008 'title': 'youtube-dl test video "\'/\\ä↭𝕐',
6009 'id': 'BaW_jenozKc',
6011 'ie_key': 'Youtube',
6013 'channel_id': 'UCLqxVugv74EIW3VWh2NOa3Q',
6014 'channel_url': 'https://www.youtube.com/channel/UCLqxVugv74EIW3VWh2NOa3Q',
6016 'url': 'https://www.youtube.com/watch?v=BaW_jenozKc',
6017 'channel': 'Philipp Hagemeister',
6018 'uploader_id': '@PhilippHagemeister',
6019 'uploader_url': 'https://www.youtube.com/@PhilippHagemeister',
6020 'uploader': 'Philipp Hagemeister',
6023 'playlist_count': 1,
6024 'params': {'extract_flat': True}
,
6026 'note': 'API Fallback: Recommended - redirects to home page. Requires visitorData',
6027 'url': 'https://www.youtube.com/feed/recommended',
6029 'id': 'recommended',
6030 'title': 'recommended',
6033 'playlist_mincount': 50,
6035 'skip_download': True,
6036 'extractor_args': {'youtubetab': {'skip': ['webpage']}
}
6039 'note': 'API Fallback: /videos tab, sorted by oldest first',
6040 'url': 'https://www.youtube.com/user/theCodyReeder/videos?view=0&sort=da&flow=grid',
6042 'id': 'UCu6mSoMNzHQiBIOCkHUa2Aw',
6043 'title': 'Cody\'sLab - Videos',
6044 'description': 'md5:d083b7c2f0c67ee7a6c74c3e9b4243fa',
6045 'channel': 'Cody\'sLab',
6046 'channel_id': 'UCu6mSoMNzHQiBIOCkHUa2Aw',
6048 'channel_url': 'https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw',
6049 'channel_follower_count': int
6051 'playlist_mincount': 650,
6053 'skip_download': True,
6054 'extractor_args': {'youtubetab': {'skip': ['webpage']}
}
6056 'skip': 'Query for sorting no longer works',
6058 'note': 'API Fallback: Topic, should redirect to playlist?list=UU...',
6059 'url': 'https://music.youtube.com/browse/UC9ALqqC4aIeG5iDs7i90Bfw',
6061 'id': 'UU9ALqqC4aIeG5iDs7i90Bfw',
6062 'title': 'Uploads from Royalty Free Music - Topic',
6063 'modified_date': r
're:\d{8}',
6064 'channel_id': 'UC9ALqqC4aIeG5iDs7i90Bfw',
6066 'channel_url': 'https://www.youtube.com/channel/UC9ALqqC4aIeG5iDs7i90Bfw',
6068 'channel': 'Royalty Free Music - Topic',
6070 'availability': 'public',
6071 'uploader': 'Royalty Free Music - Topic',
6073 'playlist_mincount': 101,
6075 'skip_download': True,
6076 'extractor_args': {'youtubetab': {'skip': ['webpage']}
}
6078 'expected_warnings': ['YouTube Music is not directly supported', r
'[Uu]navailable videos (are|will be) hidden'],
6080 'note': 'non-standard redirect to regional channel',
6081 'url': 'https://www.youtube.com/channel/UCwVVpHQ2Cs9iGJfpdFngePQ',
6082 'only_matching': True
6084 'note': 'collaborative playlist (uploader name in the form "by <uploader> and x other(s)")',
6085 'url': 'https://www.youtube.com/playlist?list=PLx-_-Kk4c89oOHEDQAojOXzEzemXxoqx6',
6087 'id': 'PLx-_-Kk4c89oOHEDQAojOXzEzemXxoqx6',
6088 'modified_date': '20220407',
6089 'channel_url': 'https://www.youtube.com/channel/UCKcqXmCcyqnhgpA5P0oHH_Q',
6091 'availability': 'unlisted',
6092 'channel_id': 'UCKcqXmCcyqnhgpA5P0oHH_Q',
6093 'channel': 'pukkandan',
6094 'description': 'Test for collaborative playlist',
6095 'title': 'yt-dlp test - collaborative playlist',
6097 'uploader_url': 'https://www.youtube.com/@pukkandan',
6098 'uploader_id': '@pukkandan',
6099 'uploader': 'pukkandan',
6101 'playlist_mincount': 2
6103 'note': 'translated tab name',
6104 'url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA/playlists',
6106 'id': 'UCiu-3thuViMebBjw_5nWYrA',
6108 'channel_url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
6109 'description': 'test description',
6110 'title': 'cole-dlp-test-acc - 再生リスト',
6111 'channel_id': 'UCiu-3thuViMebBjw_5nWYrA',
6112 'channel': 'cole-dlp-test-acc',
6113 'uploader_url': 'https://www.youtube.com/@coletdjnz',
6114 'uploader_id': '@coletdjnz',
6115 'uploader': 'cole-dlp-test-acc',
6117 'playlist_mincount': 1,
6118 'params': {'extractor_args': {'youtube': {'lang': ['ja']}
}},
6119 'expected_warnings': ['Preferring "ja"'],
6121 # XXX: this should really check flat playlist entries, but the test suite doesn't support that
6122 'note': 'preferred lang set with playlist with translated video titles',
6123 'url': 'https://www.youtube.com/playlist?list=PLt5yu3-wZAlQAaPZ5Z-rJoTdbT-45Q7c0',
6125 'id': 'PLt5yu3-wZAlQAaPZ5Z-rJoTdbT-45Q7c0',
6128 'channel_url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
6129 'channel': 'cole-dlp-test-acc',
6130 'channel_id': 'UCiu-3thuViMebBjw_5nWYrA',
6131 'description': 'test',
6132 'title': 'dlp test playlist',
6133 'availability': 'public',
6134 'uploader_url': 'https://www.youtube.com/@coletdjnz',
6135 'uploader_id': '@coletdjnz',
6136 'uploader': 'cole-dlp-test-acc',
6138 'playlist_mincount': 1,
6139 'params': {'extractor_args': {'youtube': {'lang': ['ja']}
}},
6140 'expected_warnings': ['Preferring "ja"'],
6142 # shorts audio pivot for 2GtVksBMYFM.
6143 'url': 'https://www.youtube.com/feed/sfv_audio_pivot?bp=8gUrCikSJwoLMkd0VmtzQk1ZRk0SCzJHdFZrc0JNWUZNGgsyR3RWa3NCTVlGTQ==',
6145 'id': 'sfv_audio_pivot',
6146 'title': 'sfv_audio_pivot',
6149 'playlist_mincount': 50,
6152 # Channel with a real live tab (not to be mistaken with streams tab)
6153 # Do not treat like it should redirect to live stream
6154 'url': 'https://www.youtube.com/channel/UCEH7P7kyJIkS_gJf93VYbmg/live',
6156 'id': 'UCEH7P7kyJIkS_gJf93VYbmg',
6157 'title': 'UCEH7P7kyJIkS_gJf93VYbmg - Live',
6160 'playlist_mincount': 20,
6162 # Tab name is not the same as tab id
6163 'url': 'https://www.youtube.com/channel/UCQvWX73GQygcwXOTSf_VDVg/letsplay',
6165 'id': 'UCQvWX73GQygcwXOTSf_VDVg',
6166 'title': 'UCQvWX73GQygcwXOTSf_VDVg - Let\'s play',
6169 'playlist_mincount': 8,
6171 # Home tab id is literally home. Not to get mistaken with featured
6172 'url': 'https://www.youtube.com/channel/UCQvWX73GQygcwXOTSf_VDVg/home',
6174 'id': 'UCQvWX73GQygcwXOTSf_VDVg',
6175 'title': 'UCQvWX73GQygcwXOTSf_VDVg - Home',
6178 'playlist_mincount': 8,
6180 # Should get three playlists for videos, shorts and streams tabs
6181 'url': 'https://www.youtube.com/channel/UCK9V2B22uJYu3N7eR_BT9QA',
6183 'id': 'UCK9V2B22uJYu3N7eR_BT9QA',
6184 'title': 'Polka Ch. 尾丸ポルカ',
6185 'channel_follower_count': int,
6186 'channel_id': 'UCK9V2B22uJYu3N7eR_BT9QA',
6187 'channel_url': 'https://www.youtube.com/channel/UCK9V2B22uJYu3N7eR_BT9QA',
6188 'description': 'md5:49809d8bf9da539bc48ed5d1f83c33f2',
6189 'channel': 'Polka Ch. 尾丸ポルカ',
6191 'uploader_url': 'https://www.youtube.com/@OmaruPolka',
6192 'uploader': 'Polka Ch. 尾丸ポルカ',
6193 'uploader_id': '@OmaruPolka',
6194 'channel_is_verified': True,
6196 'playlist_count': 3,
6198 # Shorts tab with channel with handle
6199 # TODO: fix channel description
6200 'url': 'https://www.youtube.com/@NotJustBikes/shorts',
6202 'id': 'UC0intLFzLaudFG-xAvUEO-A',
6203 'title': 'Not Just Bikes - Shorts',
6205 'channel_url': 'https://www.youtube.com/channel/UC0intLFzLaudFG-xAvUEO-A',
6206 'description': 'md5:5e82545b3a041345927a92d0585df247',
6207 'channel_follower_count': int,
6208 'channel_id': 'UC0intLFzLaudFG-xAvUEO-A',
6209 'channel': 'Not Just Bikes',
6210 'uploader_url': 'https://www.youtube.com/@NotJustBikes',
6211 'uploader': 'Not Just Bikes',
6212 'uploader_id': '@NotJustBikes',
6213 'channel_is_verified': True,
6215 'playlist_mincount': 10,
6218 'url': 'https://www.youtube.com/channel/UC3eYAvjCVwNHgkaGbXX3sig/streams',
6220 'id': 'UC3eYAvjCVwNHgkaGbXX3sig',
6221 'title': '中村悠一 - Live',
6223 'channel_id': 'UC3eYAvjCVwNHgkaGbXX3sig',
6224 'channel_url': 'https://www.youtube.com/channel/UC3eYAvjCVwNHgkaGbXX3sig',
6226 'channel_follower_count': int,
6227 'description': 'md5:e744f6c93dafa7a03c0c6deecb157300',
6228 'uploader_url': 'https://www.youtube.com/@Yuichi-Nakamura',
6229 'uploader_id': '@Yuichi-Nakamura',
6232 'playlist_mincount': 60,
6234 # Channel with no uploads and hence no videos, streams, shorts tabs or uploads playlist. This should fail.
6235 # See test_youtube_lists
6236 'url': 'https://www.youtube.com/channel/UC2yXPzFejc422buOIzn_0CA',
6237 'only_matching': True,
6239 # No uploads and no UCID given. Should fail with no uploads error
6240 # See test_youtube_lists
6241 'url': 'https://www.youtube.com/news',
6242 'only_matching': True
6244 # No videos tab but has a shorts tab
6245 'url': 'https://www.youtube.com/c/TKFShorts',
6247 'id': 'UCgJ5_1F6yJhYLnyMszUdmUg',
6248 'title': 'Shorts Break - Shorts',
6250 'channel_id': 'UCgJ5_1F6yJhYLnyMszUdmUg',
6251 'channel': 'Shorts Break',
6252 'description': 'md5:6de33c5e7ba686e5f3efd4e19c7ef499',
6253 'channel_follower_count': int,
6254 'channel_url': 'https://www.youtube.com/channel/UCgJ5_1F6yJhYLnyMszUdmUg',
6255 'uploader_url': 'https://www.youtube.com/@ShortsBreak_Official',
6256 'uploader': 'Shorts Break',
6257 'uploader_id': '@ShortsBreak_Official',
6259 'playlist_mincount': 30,
6261 # Trending Now Tab. tab id is empty
6262 'url': 'https://www.youtube.com/feed/trending',
6265 'title': 'trending - Now',
6268 'playlist_mincount': 30,
6270 # Trending Gaming Tab. tab id is empty
6271 'url': 'https://www.youtube.com/feed/trending?bp=4gIcGhpnYW1pbmdfY29ycHVzX21vc3RfcG9wdWxhcg%3D%3D',
6274 'title': 'trending - Gaming',
6277 'playlist_mincount': 30,
6279 # Shorts url result in shorts tab
6280 # TODO: Fix channel id extraction
6281 'url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA/shorts',
6283 'id': 'UCiu-3thuViMebBjw_5nWYrA',
6284 'title': 'cole-dlp-test-acc - Shorts',
6285 'channel': 'cole-dlp-test-acc',
6286 'description': 'test description',
6287 'channel_id': 'UCiu-3thuViMebBjw_5nWYrA',
6288 'channel_url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
6290 'uploader_url': 'https://www.youtube.com/@coletdjnz',
6291 'uploader_id': '@coletdjnz',
6292 'uploader': 'cole-dlp-test-acc',
6296 # Channel data is not currently available for short renderers (as of 2023-03-01)
6298 'ie_key': 'Youtube',
6299 'url': 'https://www.youtube.com/shorts/sSM9J5YH_60',
6300 'id': 'sSM9J5YH_60',
6301 'title': 'SHORT short',
6306 'params': {'extract_flat': True}
,
6308 # Live video status should be extracted
6309 'url': 'https://www.youtube.com/channel/UCQvWX73GQygcwXOTSf_VDVg/live',
6311 'id': 'UCQvWX73GQygcwXOTSf_VDVg',
6312 'title': 'UCQvWX73GQygcwXOTSf_VDVg - Live', # TODO, should be Minecraft - Live or Minecraft - Topic - Live
6318 'ie_key': 'Youtube',
6319 'url': 'startswith:https://www.youtube.com/watch?v=',
6322 'live_status': 'is_live',
6325 'concurrent_view_count': int,
6328 'uploader_url': str,
6330 'channel_is_verified': bool, # this will keep changing
6333 'params': {'extract_flat': True, 'playlist_items': '1'}
,
6334 'playlist_mincount': 1
6336 # Channel renderer metadata. Contains number of videos on the channel
6337 'url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA/channels',
6339 'id': 'UCiu-3thuViMebBjw_5nWYrA',
6340 'title': 'cole-dlp-test-acc - Channels',
6341 'channel': 'cole-dlp-test-acc',
6342 'description': 'test description',
6343 'channel_id': 'UCiu-3thuViMebBjw_5nWYrA',
6344 'channel_url': 'https://www.youtube.com/channel/UCiu-3thuViMebBjw_5nWYrA',
6346 'uploader_url': 'https://www.youtube.com/@coletdjnz',
6347 'uploader_id': '@coletdjnz',
6348 'uploader': 'cole-dlp-test-acc',
6353 'ie_key': 'YoutubeTab',
6354 'url': 'https://www.youtube.com/channel/UC-lHJZR3Gqxm24_Vd_AJ5Yw',
6355 'id': 'UC-lHJZR3Gqxm24_Vd_AJ5Yw',
6356 'channel_id': 'UC-lHJZR3Gqxm24_Vd_AJ5Yw',
6357 'title': 'PewDiePie',
6358 'channel': 'PewDiePie',
6359 'channel_url': 'https://www.youtube.com/channel/UC-lHJZR3Gqxm24_Vd_AJ5Yw',
6361 'channel_follower_count': int,
6362 'playlist_count': int,
6363 'uploader': 'PewDiePie',
6364 'uploader_url': 'https://www.youtube.com/@PewDiePie',
6365 'uploader_id': '@PewDiePie',
6366 'channel_is_verified': True,
6369 'params': {'extract_flat': True}
,
6371 'url': 'https://www.youtube.com/@3blue1brown/about',
6373 'id': '@3blue1brown',
6374 'tags': ['Mathematics'],
6375 'title': '3Blue1Brown',
6376 'channel_follower_count': int,
6377 'channel_id': 'UCYO_jab_esuFRV4b17AJtAw',
6378 'channel': '3Blue1Brown',
6379 'channel_url': 'https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw',
6380 'description': 'md5:4d1da95432004b7ba840ebc895b6b4c9',
6381 'uploader_url': 'https://www.youtube.com/@3blue1brown',
6382 'uploader_id': '@3blue1brown',
6383 'uploader': '3Blue1Brown',
6384 'channel_is_verified': True,
6386 'playlist_count': 0,
6388 # Podcasts tab, with rich entry playlistRenderers
6389 'url': 'https://www.youtube.com/@99percentinvisiblepodcast/podcasts',
6391 'id': 'UCVMF2HD4ZgC0QHpU9Yq5Xrw',
6392 'channel_id': 'UCVMF2HD4ZgC0QHpU9Yq5Xrw',
6393 'uploader_url': 'https://www.youtube.com/@99percentinvisiblepodcast',
6394 'description': 'md5:3a0ed38f1ad42a68ef0428c04a15695c',
6395 'title': '99 Percent Invisible - Podcasts',
6396 'uploader': '99 Percent Invisible',
6397 'channel_follower_count': int,
6398 'channel_url': 'https://www.youtube.com/channel/UCVMF2HD4ZgC0QHpU9Yq5Xrw',
6400 'channel': '99 Percent Invisible',
6401 'uploader_id': '@99percentinvisiblepodcast',
6403 'playlist_count': 0,
6405 # Releases tab, with rich entry playlistRenderers (same as Podcasts tab)
6406 'url': 'https://www.youtube.com/@AHimitsu/releases',
6408 'id': 'UCgFwu-j5-xNJml2FtTrrB3A',
6409 'channel': 'A Himitsu',
6410 'uploader_url': 'https://www.youtube.com/@AHimitsu',
6411 'title': 'A Himitsu - Releases',
6412 'uploader_id': '@AHimitsu',
6413 'uploader': 'A Himitsu',
6414 'channel_id': 'UCgFwu-j5-xNJml2FtTrrB3A',
6416 'description': 'I make music',
6417 'channel_url': 'https://www.youtube.com/channel/UCgFwu-j5-xNJml2FtTrrB3A',
6418 'channel_follower_count': int,
6419 'channel_is_verified': True,
6421 'playlist_mincount': 10,
6423 # Playlist with only shorts, shown as reel renderers
6424 # FIXME: future: YouTube currently doesn't give continuation for this,
6426 'url': 'https://www.youtube.com/playlist?list=UUxqPAgubo4coVn9Lx1FuKcg',
6428 'id': 'UUxqPAgubo4coVn9Lx1FuKcg',
6429 'channel_url': 'https://www.youtube.com/channel/UCxqPAgubo4coVn9Lx1FuKcg',
6431 'uploader_id': '@BangyShorts',
6433 'uploader_url': 'https://www.youtube.com/@BangyShorts',
6434 'channel_id': 'UCxqPAgubo4coVn9Lx1FuKcg',
6435 'channel': 'Bangy Shorts',
6436 'uploader': 'Bangy Shorts',
6438 'availability': 'public',
6439 'modified_date': r
're:\d{8}',
6440 'title': 'Uploads from Bangy Shorts',
6442 'playlist_mincount': 100,
6443 'expected_warnings': [r
'[Uu]navailable videos (are|will be) hidden'],
6445 'note': 'Tags containing spaces',
6446 'url': 'https://www.youtube.com/channel/UC7_YxT-KID8kRbqZo7MyscQ',
6447 'playlist_count': 3,
6449 'id': 'UC7_YxT-KID8kRbqZo7MyscQ',
6450 'channel': 'Markiplier',
6451 'channel_id': 'UC7_YxT-KID8kRbqZo7MyscQ',
6452 'title': 'Markiplier',
6453 'channel_follower_count': int,
6454 'description': 'md5:0c010910558658824402809750dc5d97',
6455 'uploader_id': '@markiplier',
6456 'uploader_url': 'https://www.youtube.com/@markiplier',
6457 'uploader': 'Markiplier',
6458 'channel_url': 'https://www.youtube.com/channel/UC7_YxT-KID8kRbqZo7MyscQ',
6459 'channel_is_verified': True,
6460 'tags': ['markiplier', 'comedy', 'gaming', 'funny videos', 'funny moments',
6461 'sketch comedy', 'laughing', 'lets play', 'challenge videos', 'hilarious',
6462 'challenges', 'sketches', 'scary games', 'funny games', 'rage games',
6468 def suitable(cls
, url
):
6469 return False if YoutubeIE
.suitable(url
) else super().suitable(url
)
6471 _URL_RE
= re
.compile(rf
'(?P<pre>{_VALID_URL})(?(not_channel)|(?P<tab>/[^?#/]+))?(?P<post>.*)$')
6473 def _get_url_mobj(self
, url
):
6474 mobj
= self
._URL
_RE
.match(url
).groupdict()
6475 mobj
.update((k
, '') for k
, v
in mobj
.items() if v
is None)
6478 def _extract_tab_id_and_name(self
, tab
, base_url
='https://www.youtube.com'):
6479 tab_name
= (tab
.get('title') or '').lower()
6480 tab_url
= urljoin(base_url
, traverse_obj(
6481 tab
, ('endpoint', 'commandMetadata', 'webCommandMetadata', 'url')))
6483 tab_id
= (tab_url
and self
._get
_url
_mobj
(tab_url
)['tab'][1:]
6484 or traverse_obj(tab
, 'tabIdentifier', expected_type
=str))
6487 'TAB_ID_SPONSORSHIPS': 'membership',
6488 }.get(tab_id
, tab_id
), tab_name
6490 # Fallback to tab name if we cannot get the tab id.
6491 # XXX: should we strip non-ascii letters? e.g. in case of 'let's play' tab example on special gaming channel
6492 # Note that in the case of translated tab name this may result in an empty string, which we don't want.
6494 self
.write_debug(f
'Falling back to selected tab name: {tab_name}')
6498 }.get(tab_name
, tab_name
), tab_name
6500 def _has_tab(self
, tabs
, tab_id
):
6501 return any(self
._extract
_tab
_id
_and
_name
(tab
)[0] == tab_id
for tab
in tabs
)
6503 def _empty_playlist(self
, item_id
, data
):
6504 return self
.playlist_result([], item_id
, **self
._extract
_metadata
_from
_tabs
(item_id
, data
))
6506 @YoutubeTabBaseInfoExtractor.passthrough_smuggled_data
6507 def _real_extract(self
, url
, smuggled_data
):
6508 item_id
= self
._match
_id
(url
)
6509 url
= urllib
.parse
.urlunparse(
6510 urllib
.parse
.urlparse(url
)._replace
(netloc
='www.youtube.com'))
6511 compat_opts
= self
.get_param('compat_opts', [])
6513 mobj
= self
._get
_url
_mobj
(url
)
6514 pre
, tab
, post
, is_channel
= mobj
['pre'], mobj
['tab'], mobj
['post'], not mobj
['not_channel']
6515 if is_channel
and smuggled_data
.get('is_music_url'):
6516 if item_id
[:2] == 'VL': # Youtube music VL channels have an equivalent playlist
6517 return self
.url_result(
6518 f
'https://music.youtube.com/playlist?list={item_id[2:]}', YoutubeTabIE
, item_id
[2:])
6519 elif item_id
[:2] == 'MP': # Resolve albums (/[channel/browse]/MP...) to their equivalent playlist
6520 mdata
= self
._extract
_tab
_endpoint
(
6521 f
'https://music.youtube.com/channel/{item_id}', item_id
, default_client
='web_music')
6522 murl
= traverse_obj(mdata
, ('microformat', 'microformatDataRenderer', 'urlCanonical'),
6523 get_all
=False, expected_type
=str)
6525 raise ExtractorError('Failed to resolve album to playlist')
6526 return self
.url_result(murl
, YoutubeTabIE
)
6527 elif mobj
['channel_type'] == 'browse': # Youtube music /browse/ should be changed to /channel/
6528 return self
.url_result(
6529 f
'https://music.youtube.com/channel/{item_id}{tab}{post}', YoutubeTabIE
, item_id
)
6531 original_tab_id
, display_id
= tab
[1:], f
'{item_id}{tab}'
6532 if is_channel
and not tab
and 'no-youtube-channel-redirect' not in compat_opts
:
6533 url
= f
'{pre}/videos{post}'
6534 if smuggled_data
.get('is_music_url'):
6535 self
.report_warning(f
'YouTube Music is not directly supported. Redirecting to {url}')
6537 # Handle both video/playlist URLs
6539 video_id
, playlist_id
= [traverse_obj(qs
, (key
, 0)) for key
in ('v', 'list')]
6540 if not video_id
and mobj
['not_channel'].startswith('watch'):
6542 # If there is neither video or playlist ids, youtube redirects to home page, which is undesirable
6543 raise ExtractorError('A video URL was given without video ID', expected
=True)
6544 # Common mistake: https://www.youtube.com/watch?list=playlist_id
6545 self
.report_warning(f
'A video URL was given without video ID. Trying to download playlist {playlist_id}')
6546 return self
.url_result(
6547 f
'https://www.youtube.com/playlist?list={playlist_id}', YoutubeTabIE
, playlist_id
)
6549 if not self
._yes
_playlist
(playlist_id
, video_id
):
6550 return self
.url_result(
6551 f
'https://www.youtube.com/watch?v={video_id}', YoutubeIE
, video_id
)
6553 data
, ytcfg
= self
._extract
_data
(url
, display_id
)
6555 # YouTube may provide a non-standard redirect to the regional channel
6556 # See: https://github.com/yt-dlp/yt-dlp/issues/2694
6557 # https://support.google.com/youtube/answer/2976814#zippy=,conditional-redirects
6558 redirect_url
= traverse_obj(
6559 data
, ('onResponseReceivedActions', ..., 'navigateAction', 'endpoint', 'commandMetadata', 'webCommandMetadata', 'url'), get_all
=False)
6560 if redirect_url
and 'no-youtube-channel-redirect' not in compat_opts
:
6561 redirect_url
= ''.join((urljoin('https://www.youtube.com', redirect_url
), tab
, post
))
6562 self
.to_screen(f
'This playlist is likely not available in your region. Following conditional redirect to {redirect_url}')
6563 return self
.url_result(redirect_url
, YoutubeTabIE
)
6565 tabs
, extra_tabs
= self
._extract
_tab
_renderers
(data
), []
6566 if is_channel
and tabs
and 'no-youtube-channel-redirect' not in compat_opts
:
6567 selected_tab
= self
._extract
_selected
_tab
(tabs
)
6568 selected_tab_id
, selected_tab_name
= self
._extract
_tab
_id
_and
_name
(selected_tab
, url
) # NB: Name may be translated
6569 self
.write_debug(f
'Selected tab: {selected_tab_id!r} ({selected_tab_name}), Requested tab: {original_tab_id!r}')
6571 # /about is no longer a tab
6572 if original_tab_id
== 'about':
6573 return self
._empty
_playlist
(item_id
, data
)
6575 if not original_tab_id
and selected_tab_name
:
6576 self
.to_screen('Downloading all uploads of the channel. '
6577 'To download only the videos in a specific tab, pass the tab\'s URL')
6578 if self
._has
_tab
(tabs
, 'streams'):
6579 extra_tabs
.append(''.join((pre
, '/streams', post
)))
6580 if self
._has
_tab
(tabs
, 'shorts'):
6581 extra_tabs
.append(''.join((pre
, '/shorts', post
)))
6582 # XXX: Members-only tab should also be extracted
6584 if not extra_tabs
and selected_tab_id
!= 'videos':
6585 # Channel does not have streams, shorts or videos tabs
6586 if item_id
[:2] != 'UC':
6587 return self
._empty
_playlist
(item_id
, data
)
6589 # Topic channels don't have /videos. Use the equivalent playlist instead
6590 pl_id
= f
'UU{item_id[2:]}'
6591 pl_url
= f
'https://www.youtube.com/playlist?list={pl_id}'
6593 data
, ytcfg
= self
._extract
_data
(pl_url
, pl_id
, ytcfg
=ytcfg
, fatal
=True, webpage_fatal
=True)
6594 except ExtractorError
:
6595 return self
._empty
_playlist
(item_id
, data
)
6597 item_id
, url
= pl_id
, pl_url
6599 f
'The channel does not have a videos, shorts, or live tab. Redirecting to playlist {pl_id} instead')
6601 elif extra_tabs
and selected_tab_id
!= 'videos':
6602 # When there are shorts/live tabs but not videos tab
6603 url
, data
= f
'{pre}{post}', None
6605 elif (original_tab_id
or 'videos') != selected_tab_id
:
6606 if original_tab_id
== 'live':
6607 # Live tab should have redirected to the video
6608 # Except in the case the channel has an actual live tab
6609 # Example: https://www.youtube.com/channel/UCEH7P7kyJIkS_gJf93VYbmg/live
6610 raise UserNotLive(video_id
=item_id
)
6611 elif selected_tab_name
:
6612 raise ExtractorError(f
'This channel does not have a {original_tab_id} tab', expected
=True)
6614 # For channels such as https://www.youtube.com/channel/UCtFRv9O2AHqOZjjynzrv-xg
6615 url
= f
'{pre}{post}'
6617 # YouTube sometimes provides a button to reload playlist with unavailable videos.
6618 if 'no-youtube-unavailable-videos' not in compat_opts
:
6619 data
= self
._reload
_with
_unavailable
_videos
(display_id
, data
, ytcfg
) or data
6620 self
._extract
_and
_report
_alerts
(data
, only_once
=True)
6622 tabs
, entries
= self
._extract
_tab
_renderers
(data
), []
6624 entries
= [self
._extract
_from
_tabs
(item_id
, ytcfg
, data
, tabs
)]
6626 'extractor_key': YoutubeTabIE
.ie_key(),
6627 'extractor': YoutubeTabIE
.IE_NAME
,
6630 if self
.get_param('playlist_items') == '0':
6631 entries
.extend(self
.url_result(u
, YoutubeTabIE
) for u
in extra_tabs
)
6632 else: # Users expect to get all `video_id`s even with `--flat-playlist`. So don't return `url_result`
6633 entries
.extend(map(self
._real
_extract
, extra_tabs
))
6635 if len(entries
) == 1:
6638 metadata
= self
._extract
_metadata
_from
_tabs
(item_id
, data
)
6639 uploads_url
= 'the Uploads (UU) playlist URL'
6640 if try_get(metadata
, lambda x
: x
['channel_id'].startswith('UC')):
6641 uploads_url
= f
'https://www.youtube.com/playlist?list=UU{metadata["channel_id"][2:]}'
6643 'Downloading as multiple playlists, separated by tabs. '
6644 f
'To download as a single playlist instead, pass {uploads_url}')
6645 return self
.playlist_result(entries
, item_id
, **metadata
)
6648 playlist
= traverse_obj(
6649 data
, ('contents', 'twoColumnWatchNextResults', 'playlist', 'playlist'), expected_type
=dict)
6651 return self
._extract
_from
_playlist
(item_id
, url
, data
, playlist
, ytcfg
)
6653 video_id
= traverse_obj(
6654 data
, ('currentVideoEndpoint', 'watchEndpoint', 'videoId'), expected_type
=str) or video_id
6656 if tab
!= '/live': # live tab is expected to redirect to video
6657 self
.report_warning(f
'Unable to recognize playlist. Downloading just video {video_id}')
6658 return self
.url_result(f
'https://www.youtube.com/watch?v={video_id}', YoutubeIE
, video_id
)
6660 raise ExtractorError('Unable to recognize tab page')
6663 class YoutubePlaylistIE(InfoExtractor
):
6664 IE_DESC
= 'YouTube playlists'
6665 _VALID_URL
= r
'''(?x)(?:
6670 youtube(?:kids)?\.com|
6675 (?P<id>%(playlist_id)s)
6677 'playlist_id': YoutubeBaseInfoExtractor
._PLAYLIST
_ID
_RE
,
6678 'invidious': '|'.join(YoutubeBaseInfoExtractor
._INVIDIOUS
_SITES
),
6680 IE_NAME
= 'youtube:playlist'
6682 'note': 'issue #673',
6683 'url': 'PLBB231211A4F62143',
6685 'title': '[OLD]Team Fortress 2 (Class-based LP)',
6686 'id': 'PLBB231211A4F62143',
6687 'uploader': 'Wickman',
6688 'uploader_id': '@WickmanVT',
6689 'description': 'md5:8fa6f52abb47a9552002fa3ddfc57fc2',
6691 'uploader_url': 'https://www.youtube.com/@WickmanVT',
6692 'modified_date': r
're:\d{8}',
6693 'channel_id': 'UCKSpbfbl5kRQpTdL7kMc-1Q',
6694 'channel': 'Wickman',
6696 'channel_url': 'https://www.youtube.com/channel/UCKSpbfbl5kRQpTdL7kMc-1Q',
6697 'availability': 'public',
6699 'playlist_mincount': 29,
6701 'url': 'PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl',
6703 'title': 'YDL_safe_search',
6704 'id': 'PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl',
6706 'playlist_count': 2,
6707 'skip': 'This playlist is private',
6710 'url': 'https://www.youtube.com/embed/videoseries?list=PL6IaIsEjSbf96XFRuNccS_RuEXwNdsoEu',
6711 'playlist_count': 4,
6714 'id': 'PL6IaIsEjSbf96XFRuNccS_RuEXwNdsoEu',
6715 'uploader': 'milan',
6716 'uploader_id': '@milan5503',
6718 'channel_url': 'https://www.youtube.com/channel/UCEI1-PVPcYXjB73Hfelbmaw',
6720 'modified_date': '20140919',
6723 'channel_id': 'UCEI1-PVPcYXjB73Hfelbmaw',
6724 'uploader_url': 'https://www.youtube.com/@milan5503',
6725 'availability': 'public',
6727 'expected_warnings': [r
'[Uu]navailable videos? (is|are|will be) hidden', 'Retrying', 'Giving up'],
6729 'url': 'http://www.youtube.com/embed/_xDOZElKyNU?list=PLsyOSbh5bs16vubvKePAQ1x3PhKavfBIl',
6730 'playlist_mincount': 455,
6732 'title': '2018 Chinese New Singles (11/6 updated)',
6733 'id': 'PLsyOSbh5bs16vubvKePAQ1x3PhKavfBIl',
6735 'uploader_id': '@music_king',
6736 'description': 'md5:da521864744d60a198e3a88af4db0d9d',
6739 'channel_url': 'https://www.youtube.com/channel/UC21nz3_MesPLqtDqwdvnoxA',
6741 'uploader_url': 'https://www.youtube.com/@music_king',
6742 'channel_id': 'UC21nz3_MesPLqtDqwdvnoxA',
6743 'modified_date': r
're:\d{8}',
6744 'availability': 'public',
6746 'expected_warnings': [r
'[Uu]navailable videos (are|will be) hidden'],
6748 'url': 'TLGGrESM50VT6acwMjAyMjAxNw',
6749 'only_matching': True,
6751 # music album playlist
6752 'url': 'OLAK5uy_m4xAFdmMC5rX3Ji3g93pQe3hqLZw_9LhM',
6753 'only_matching': True,
6757 def suitable(cls
, url
):
6758 if YoutubeTabIE
.suitable(url
):
6760 from ..utils
import parse_qs
6762 if qs
.get('v', [None])[0]:
6764 return super().suitable(url
)
6766 def _real_extract(self
, url
):
6767 playlist_id
= self
._match
_id
(url
)
6768 is_music_url
= YoutubeBaseInfoExtractor
.is_music_url(url
)
6769 url
= update_url_query(
6770 'https://www.youtube.com/playlist',
6771 parse_qs(url
) or {'list': playlist_id}
)
6773 url
= smuggle_url(url
, {'is_music_url': True}
)
6774 return self
.url_result(url
, ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
)
6777 class YoutubeYtBeIE(InfoExtractor
):
6778 IE_DESC
= 'youtu.be'
6779 _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}
6781 'url': 'https://youtu.be/yeWKywCrFtk?list=PL2qgrgXsNUG5ig9cat4ohreBjYLAPC0J5',
6783 'id': 'yeWKywCrFtk',
6785 'title': 'Small Scale Baler and Braiding Rugs',
6786 'uploader': 'Backus-Page House Museum',
6787 'uploader_id': '@backuspagemuseum',
6788 'uploader_url': r
're:https?://(?:www\.)?youtube\.com/@backuspagemuseum',
6789 'upload_date': '20161008',
6790 'description': 'md5:800c0c78d5eb128500bffd4f0b4f2e8a',
6791 'categories': ['Nonprofits & Activism'],
6795 'playable_in_embed': True,
6796 'thumbnail': r
're:^https?://.*\.webp',
6797 'channel': 'Backus-Page House Museum',
6798 'channel_id': 'UCEfMCQ9bs3tjvjy1s451zaw',
6799 'live_status': 'not_live',
6801 'channel_url': 'https://www.youtube.com/channel/UCEfMCQ9bs3tjvjy1s451zaw',
6802 'availability': 'public',
6804 'comment_count': int,
6805 'channel_follower_count': int
6809 'skip_download': True,
6812 'url': 'https://youtu.be/uWyaPkt-VOI?list=PL9D9FC436B881BA21',
6813 'only_matching': True,
6816 def _real_extract(self
, url
):
6817 mobj
= self
._match
_valid
_url
(url
)
6818 video_id
= mobj
.group('id')
6819 playlist_id
= mobj
.group('playlist_id')
6820 return self
.url_result(
6821 update_url_query('https://www.youtube.com/watch', {
6823 'list': playlist_id
,
6824 'feature': 'youtu.be',
6825 }), ie
=YoutubeTabIE
.ie_key(), video_id
=playlist_id
)
6828 class YoutubeLivestreamEmbedIE(InfoExtractor
):
6829 IE_DESC
= 'YouTube livestream embeds'
6830 _VALID_URL
= r
'https?://(?:\w+\.)?youtube\.com/embed/live_stream/?\?(?:[^#]+&)?channel=(?P<id>[^&#]+)'
6832 'url': 'https://www.youtube.com/embed/live_stream?channel=UC2_KI6RB__jGdlnK6dvFEZA',
6833 'only_matching': True,
6836 def _real_extract(self
, url
):
6837 channel_id
= self
._match
_id
(url
)
6838 return self
.url_result(
6839 f
'https://www.youtube.com/channel/{channel_id}/live',
6840 ie
=YoutubeTabIE
.ie_key(), video_id
=channel_id
)
6843 class YoutubeYtUserIE(InfoExtractor
):
6844 IE_DESC
= 'YouTube user videos; "ytuser:" prefix'
6845 IE_NAME
= 'youtube:user'
6846 _VALID_URL
= r
'ytuser:(?P<id>.+)'
6848 'url': 'ytuser:phihag',
6849 'only_matching': True,
6852 def _real_extract(self
, url
):
6853 user_id
= self
._match
_id
(url
)
6854 return self
.url_result(f
'https://www.youtube.com/user/{user_id}', YoutubeTabIE
, user_id
)
6857 class YoutubeFavouritesIE(YoutubeBaseInfoExtractor
):
6858 IE_NAME
= 'youtube:favorites'
6859 IE_DESC
= 'YouTube liked videos; ":ytfav" keyword (requires cookies)'
6860 _VALID_URL
= r
':ytfav(?:ou?rite)?s?'
6861 _LOGIN_REQUIRED
= True
6864 'only_matching': True,
6866 'url': ':ytfavorites',
6867 'only_matching': True,
6870 def _real_extract(self
, url
):
6871 return self
.url_result(
6872 'https://www.youtube.com/playlist?list=LL',
6873 ie
=YoutubeTabIE
.ie_key())
6876 class YoutubeNotificationsIE(YoutubeTabBaseInfoExtractor
):
6877 IE_NAME
= 'youtube:notif'
6878 IE_DESC
= 'YouTube notifications; ":ytnotif" keyword (requires cookies)'
6879 _VALID_URL
= r
':ytnotif(?:ication)?s?'
6880 _LOGIN_REQUIRED
= True
6883 'only_matching': True,
6885 'url': ':ytnotifications',
6886 'only_matching': True,
6889 def _extract_notification_menu(self
, response
, continuation_list
):
6890 notification_list
= traverse_obj(
6892 ('actions', 0, 'openPopupAction', 'popup', 'multiPageMenuRenderer', 'sections', 0, 'multiPageMenuNotificationSectionRenderer', 'items'),
6893 ('actions', 0, 'appendContinuationItemsAction', 'continuationItems'),
6894 expected_type
=list) or []
6895 continuation_list
[0] = None
6896 for item
in notification_list
:
6897 entry
= self
._extract
_notification
_renderer
(item
.get('notificationRenderer'))
6900 continuation
= item
.get('continuationItemRenderer')
6902 continuation_list
[0] = continuation
6904 def _extract_notification_renderer(self
, notification
):
6905 video_id
= traverse_obj(
6906 notification
, ('navigationEndpoint', 'watchEndpoint', 'videoId'), expected_type
=str)
6907 url
= f
'https://www.youtube.com/watch?v={video_id}'
6910 browse_ep
= traverse_obj(
6911 notification
, ('navigationEndpoint', 'browseEndpoint'), expected_type
=dict)
6912 channel_id
= self
.ucid_or_none(traverse_obj(browse_ep
, 'browseId', expected_type
=str))
6913 post_id
= self
._search
_regex
(
6914 r
'/post/(.+)', traverse_obj(browse_ep
, 'canonicalBaseUrl', expected_type
=str),
6915 'post id', default
=None)
6916 if not channel_id
or not post_id
:
6918 # The direct /post url redirects to this in the browser
6919 url
= f
'https://www.youtube.com/channel/{channel_id}/community?lb={post_id}'
6921 channel
= traverse_obj(
6922 notification
, ('contextualMenu', 'menuRenderer', 'items', 1, 'menuServiceItemRenderer', 'text', 'runs', 1, 'text'),
6924 notification_title
= self
._get
_text
(notification
, 'shortMessage')
6925 if notification_title
:
6926 notification_title
= notification_title
.replace('\xad', '') # remove soft hyphens
6927 # TODO: handle recommended videos
6928 title
= self
._search
_regex
(
6929 rf
'{re.escape(channel or "")}[^:]+: (.+)', notification_title
,
6930 'video title', default
=None)
6931 timestamp
= (self
._parse
_time
_text
(self
._get
_text
(notification
, 'sentTimeText'))
6932 if self
._configuration
_arg
('approximate_date', ie_key
=YoutubeTabIE
)
6937 'ie_key': (YoutubeIE
if video_id
else YoutubeTabIE
).ie_key(),
6938 'video_id': video_id
,
6940 'channel_id': channel_id
,
6942 'uploader': channel
,
6943 'thumbnails': self
._extract
_thumbnails
(notification
, 'videoThumbnail'),
6944 'timestamp': timestamp
,
6947 def _notification_menu_entries(self
, ytcfg
):
6948 continuation_list
= [None]
6950 for page
in itertools
.count(1):
6951 ctoken
= traverse_obj(
6952 continuation_list
, (0, 'continuationEndpoint', 'getNotificationMenuEndpoint', 'ctoken'), expected_type
=str)
6953 response
= self
._extract
_response
(
6954 item_id
=f
'page {page}', query
={'ctoken': ctoken}
if ctoken
else {}, ytcfg
=ytcfg
,
6955 ep
='notification/get_notification_menu', check_get_keys
='actions',
6956 headers
=self
.generate_api_headers(ytcfg
=ytcfg
, visitor_data
=self
._extract
_visitor
_data
(response
)))
6957 yield from self
._extract
_notification
_menu
(response
, continuation_list
)
6958 if not continuation_list
[0]:
6961 def _real_extract(self
, url
):
6962 display_id
= 'notifications'
6963 ytcfg
= self
._download
_ytcfg
('web', display_id
) if not self
.skip_webpage
else {}
6964 self
._report
_playlist
_authcheck
(ytcfg
)
6965 return self
.playlist_result(self
._notification
_menu
_entries
(ytcfg
), display_id
, display_id
)
6968 class YoutubeSearchIE(YoutubeTabBaseInfoExtractor
, SearchInfoExtractor
):
6969 IE_DESC
= 'YouTube search'
6970 IE_NAME
= 'youtube:search'
6971 _SEARCH_KEY
= 'ytsearch'
6972 _SEARCH_PARAMS
= 'EgIQAfABAQ==' # Videos only
6974 'url': 'ytsearch5:youtube-dl test video',
6975 'playlist_count': 5,
6977 'id': 'youtube-dl test video',
6978 'title': 'youtube-dl test video',
6981 'note': 'Suicide/self-harm search warning',
6982 'url': 'ytsearch1:i hate myself and i wanna die',
6983 'playlist_count': 1,
6985 'id': 'i hate myself and i wanna die',
6986 'title': 'i hate myself and i wanna die',
6991 class YoutubeSearchDateIE(YoutubeTabBaseInfoExtractor
, SearchInfoExtractor
):
6992 IE_NAME
= YoutubeSearchIE
.IE_NAME
+ ':date'
6993 _SEARCH_KEY
= 'ytsearchdate'
6994 IE_DESC
= 'YouTube search, newest videos first'
6995 _SEARCH_PARAMS
= 'CAISAhAB8AEB' # Videos only, sorted by date
6997 'url': 'ytsearchdate5:youtube-dl test video',
6998 'playlist_count': 5,
7000 'id': 'youtube-dl test video',
7001 'title': 'youtube-dl test video',
7006 class YoutubeSearchURLIE(YoutubeTabBaseInfoExtractor
):
7007 IE_DESC
= 'YouTube search URLs with sorting and filter support'
7008 IE_NAME
= YoutubeSearchIE
.IE_NAME
+ '_url'
7009 _VALID_URL
= r
'https?://(?:www\.)?youtube\.com/(?:results|search)\?([^#]+&)?(?:search_query|q)=(?:[^&]+)(?:[&#]|$)'
7011 'url': 'https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video',
7012 'playlist_mincount': 5,
7014 'id': 'youtube-dl test video',
7015 'title': 'youtube-dl test video',
7018 'url': 'https://www.youtube.com/results?search_query=python&sp=EgIQAg%253D%253D',
7019 'playlist_mincount': 5,
7025 'url': 'https://www.youtube.com/results?search_query=%23cats',
7026 'playlist_mincount': 1,
7030 # The test suite does not have support for nested playlists
7032 # 'url': r're:https://(www\.)?youtube\.com/hashtag/cats',
7038 'url': 'https://www.youtube.com/results?search_query=kurzgesagt&sp=EgIQAg%253D%253D',
7041 'title': 'kurzgesagt',
7046 'id': 'UCsXVk37bltHxD1rDPwtNM8Q',
7047 'url': 'https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q',
7048 'ie_key': 'YoutubeTab',
7049 'channel': 'Kurzgesagt – In a Nutshell',
7050 'description': 'md5:4ae48dfa9505ffc307dad26342d06bfc',
7051 'title': 'Kurzgesagt – In a Nutshell',
7052 'channel_id': 'UCsXVk37bltHxD1rDPwtNM8Q',
7053 # No longer available for search as it is set to the handle.
7054 # 'playlist_count': int,
7055 'channel_url': 'https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q',
7057 'uploader_id': '@kurzgesagt',
7058 'uploader_url': 'https://www.youtube.com/@kurzgesagt',
7059 'uploader': 'Kurzgesagt – In a Nutshell',
7060 'channel_is_verified': True,
7061 'channel_follower_count': int,
7064 'params': {'extract_flat': True, 'playlist_items': '1'}
,
7065 'playlist_mincount': 1,
7067 'url': 'https://www.youtube.com/results?q=test&sp=EgQIBBgB',
7068 'only_matching': True,
7071 def _real_extract(self
, url
):
7073 query
= (qs
.get('search_query') or qs
.get('q'))[0]
7074 return self
.playlist_result(self
._search
_results
(query
, qs
.get('sp', (None,))[0]), query
, query
)
7077 class YoutubeMusicSearchURLIE(YoutubeTabBaseInfoExtractor
):
7078 IE_DESC
= 'YouTube music search URLs with selectable sections, e.g. #songs'
7079 IE_NAME
= 'youtube:music:search_url'
7080 _VALID_URL
= r
'https?://music\.youtube\.com/search\?([^#]+&)?(?:search_query|q)=(?:[^&]+)(?:[&#]|$)'
7082 'url': 'https://music.youtube.com/search?q=royalty+free+music',
7083 'playlist_count': 16,
7085 'id': 'royalty free music',
7086 'title': 'royalty free music',
7089 'url': 'https://music.youtube.com/search?q=royalty+free+music&sp=EgWKAQIIAWoKEAoQAxAEEAkQBQ%3D%3D',
7090 'playlist_mincount': 30,
7092 'id': 'royalty free music - songs',
7093 'title': 'royalty free music - songs',
7095 'params': {'extract_flat': 'in_playlist'}
7097 'url': 'https://music.youtube.com/search?q=royalty+free+music#community+playlists',
7098 'playlist_mincount': 30,
7100 'id': 'royalty free music - community playlists',
7101 'title': 'royalty free music - community playlists',
7103 'params': {'extract_flat': 'in_playlist'}
7107 'albums': 'EgWKAQIYAWoKEAoQAxAEEAkQBQ==',
7108 'artists': 'EgWKAQIgAWoKEAoQAxAEEAkQBQ==',
7109 'community playlists': 'EgeKAQQoAEABagoQChADEAQQCRAF',
7110 'featured playlists': 'EgeKAQQoADgBagwQAxAJEAQQDhAKEAU==',
7111 'songs': 'EgWKAQIIAWoKEAoQAxAEEAkQBQ==',
7112 'videos': 'EgWKAQIQAWoKEAoQAxAEEAkQBQ==',
7115 def _real_extract(self
, url
):
7117 query
= (qs
.get('search_query') or qs
.get('q'))[0]
7118 params
= qs
.get('sp', (None,))[0]
7120 section
= next((k
for k
, v
in self
._SECTIONS
.items() if v
== params
), params
)
7122 section
= urllib
.parse
.unquote_plus((url
.split('#') + [''])[1]).lower()
7123 params
= self
._SECTIONS
.get(section
)
7126 title
= join_nonempty(query
, section
, delim
=' - ')
7127 return self
.playlist_result(self
._search
_results
(query
, params
, default_client
='web_music'), title
, title
)
7130 class YoutubeFeedsInfoExtractor(InfoExtractor
):
7132 Base class for feed extractors
7133 Subclasses must re-define the _FEED_NAME property.
7135 _LOGIN_REQUIRED
= True
7136 _FEED_NAME
= 'feeds'
7138 def _real_initialize(self
):
7139 YoutubeBaseInfoExtractor
._check
_login
_required
(self
)
7143 return f
'youtube:{self._FEED_NAME}'
7145 def _real_extract(self
, url
):
7146 return self
.url_result(
7147 f
'https://www.youtube.com/feed/{self._FEED_NAME}', ie
=YoutubeTabIE
.ie_key())
7150 class YoutubeWatchLaterIE(InfoExtractor
):
7151 IE_NAME
= 'youtube:watchlater'
7152 IE_DESC
= 'Youtube watch later list; ":ytwatchlater" keyword (requires cookies)'
7153 _VALID_URL
= r
':ytwatchlater'
7155 'url': ':ytwatchlater',
7156 'only_matching': True,
7159 def _real_extract(self
, url
):
7160 return self
.url_result(
7161 'https://www.youtube.com/playlist?list=WL', ie
=YoutubeTabIE
.ie_key())
7164 class YoutubeRecommendedIE(YoutubeFeedsInfoExtractor
):
7165 IE_DESC
= 'YouTube recommended videos; ":ytrec" keyword'
7166 _VALID_URL
= r
'https?://(?:www\.)?youtube\.com/?(?:[?#]|$)|:ytrec(?:ommended)?'
7167 _FEED_NAME
= 'recommended'
7168 _LOGIN_REQUIRED
= False
7171 'only_matching': True,
7173 'url': ':ytrecommended',
7174 'only_matching': True,
7176 'url': 'https://youtube.com',
7177 'only_matching': True,
7181 class YoutubeSubscriptionsIE(YoutubeFeedsInfoExtractor
):
7182 IE_DESC
= 'YouTube subscriptions feed; ":ytsubs" keyword (requires cookies)'
7183 _VALID_URL
= r
':ytsub(?:scription)?s?'
7184 _FEED_NAME
= 'subscriptions'
7187 'only_matching': True,
7189 'url': ':ytsubscriptions',
7190 'only_matching': True,
7194 class YoutubeHistoryIE(YoutubeFeedsInfoExtractor
):
7195 IE_DESC
= 'Youtube watch history; ":ythis" keyword (requires cookies)'
7196 _VALID_URL
= r
':ythis(?:tory)?'
7197 _FEED_NAME
= 'history'
7199 'url': ':ythistory',
7200 'only_matching': True,
7204 class YoutubeShortsAudioPivotIE(InfoExtractor
):
7205 IE_DESC
= 'YouTube Shorts audio pivot (Shorts using audio of a given video)'
7206 IE_NAME
= 'youtube:shorts:pivot:audio'
7207 _VALID_URL
= r
'https?://(?:www\.)?youtube\.com/source/(?P<id>[\w-]{11})/shorts'
7209 'url': 'https://www.youtube.com/source/Lyj-MZSAA9o/shorts',
7210 'only_matching': True,
7214 def _generate_audio_pivot_params(video_id
):
7216 Generates sfv_audio_pivot browse params for this video id
7218 pb_params
= b
'\xf2\x05+\n)\x12\'\n\x0b%b\x12\x0b%b\x1a\x0b%b' % ((video_id
.encode(),) * 3)
7219 return urllib
.parse
.quote(base64
.b64encode(pb_params
).decode())
7221 def _real_extract(self
, url
):
7222 video_id
= self
._match
_id
(url
)
7223 return self
.url_result(
7224 f
'https://www.youtube.com/feed/sfv_audio_pivot?bp={self._generate_audio_pivot_params(video_id)}',
7228 class YoutubeTruncatedURLIE(InfoExtractor
):
7229 IE_NAME
= 'youtube:truncated_url'
7230 IE_DESC
= False # Do not list
7231 _VALID_URL
= r
'''(?x)
7233 (?:\w+\.)?[yY][oO][uU][tT][uU][bB][eE](?:-nocookie)?\.com/
7236 annotation_id=annotation_[^&]+|
7242 attribution_link\?a=[^&]+
7248 'url': 'https://www.youtube.com/watch?annotation_id=annotation_3951667041',
7249 'only_matching': True,
7251 'url': 'https://www.youtube.com/watch?',
7252 'only_matching': True,
7254 'url': 'https://www.youtube.com/watch?x-yt-cl=84503534',
7255 'only_matching': True,
7257 'url': 'https://www.youtube.com/watch?feature=foo',
7258 'only_matching': True,
7260 'url': 'https://www.youtube.com/watch?hl=en-GB',
7261 'only_matching': True,
7263 'url': 'https://www.youtube.com/watch?t=2372',
7264 'only_matching': True,
7267 def _real_extract(self
, url
):
7268 raise ExtractorError(
7269 'Did you forget to quote the URL? Remember that & is a meta '
7270 'character in most shells, so you want to put the URL in quotes, '
7272 '"https://www.youtube.com/watch?feature=foo&v=BaW_jenozKc" '
7273 ' or simply youtube-dl BaW_jenozKc .',
7277 class YoutubeClipIE(YoutubeTabBaseInfoExtractor
):
7278 IE_NAME
= 'youtube:clip'
7279 _VALID_URL
= r
'https?://(?:www\.)?youtube\.com/clip/(?P<id>[^/?#]+)'
7281 # FIXME: Other metadata should be extracted from the clip, not from the base video
7282 'url': 'https://www.youtube.com/clip/UgytZKpehg-hEMBSn3F4AaABCQ',
7284 'id': 'UgytZKpehg-hEMBSn3F4AaABCQ',
7286 'section_start': 29.0,
7287 'section_end': 39.7,
7290 'availability': 'public',
7291 'categories': ['Gaming'],
7292 'channel': 'Scott The Woz',
7293 'channel_id': 'UC4rqhyiTs7XyuODcECvuiiQ',
7294 'channel_url': 'https://www.youtube.com/channel/UC4rqhyiTs7XyuODcECvuiiQ',
7295 'description': 'md5:7a4517a17ea9b4bd98996399d8bb36e7',
7297 'playable_in_embed': True,
7299 'thumbnail': 'https://i.ytimg.com/vi_webp/ScPX26pdQik/maxresdefault.webp',
7300 'title': 'Mobile Games on Console - Scott The Woz',
7301 'upload_date': '20210920',
7302 'uploader': 'Scott The Woz',
7303 'uploader_id': '@ScottTheWoz',
7304 'uploader_url': 'https://www.youtube.com/@ScottTheWoz',
7306 'live_status': 'not_live',
7307 'channel_follower_count': int,
7308 'chapters': 'count:20',
7309 'comment_count': int,
7310 'heatmap': 'count:100',
7314 def _real_extract(self
, url
):
7315 clip_id
= self
._match
_id
(url
)
7316 _
, data
= self
._extract
_webpage
(url
, clip_id
)
7318 video_id
= traverse_obj(data
, ('currentVideoEndpoint', 'watchEndpoint', 'videoId'))
7320 raise ExtractorError('Unable to find video ID')
7322 clip_data
= traverse_obj(data
, (
7323 'engagementPanels', ..., 'engagementPanelSectionListRenderer', 'content', 'clipSectionRenderer',
7324 'contents', ..., 'clipAttributionRenderer', 'onScrubExit', 'commandExecutorCommand', 'commands', ...,
7325 'openPopupAction', 'popup', 'notificationActionRenderer', 'actionButton', 'buttonRenderer', 'command',
7326 'commandExecutorCommand', 'commands', ..., 'loopCommand'), get_all
=False)
7329 '_type': 'url_transparent',
7330 'url': f
'https://www.youtube.com/watch?v={video_id}',
7331 'ie_key': YoutubeIE
.ie_key(),
7333 'section_start': int(clip_data
['startTimeMs']) / 1000,
7334 'section_end': int(clip_data
['endTimeMs']) / 1000,
7338 class YoutubeConsentRedirectIE(YoutubeBaseInfoExtractor
):
7339 IE_NAME
= 'youtube:consent'
7340 IE_DESC
= False # Do not list
7341 _VALID_URL
= r
'https?://consent\.youtube\.com/m\?'
7343 'url': 'https://consent.youtube.com/m?continue=https%3A%2F%2Fwww.youtube.com%2Flive%2FqVv6vCqciTM%3Fcbrd%3D1&gl=NL&m=0&pc=yt&hl=en&src=1',
7345 'id': 'qVv6vCqciTM',
7348 'uploader_id': '@sana_natori',
7349 'comment_count': int,
7350 'chapters': 'count:13',
7351 'upload_date': '20221223',
7352 'thumbnail': 'https://i.ytimg.com/vi/qVv6vCqciTM/maxresdefault.jpg',
7353 'channel_url': 'https://www.youtube.com/channel/UCIdEIHpS0TdkqRkHL5OkLtA',
7354 'uploader_url': 'https://www.youtube.com/@sana_natori',
7356 'release_date': '20221223',
7357 'tags': ['Vtuber', '月ノ美兎', '名取さな', 'にじさんじ', 'クリスマス', '3D配信'],
7358 'title': '【 #インターネット女クリスマス 】3Dで歌ってはしゃぐインターネットの女たち【月ノ美兎/名取さな】',
7360 'playable_in_embed': True,
7362 'availability': 'public',
7363 'channel_follower_count': int,
7364 'channel_id': 'UCIdEIHpS0TdkqRkHL5OkLtA',
7365 'categories': ['Entertainment'],
7366 'live_status': 'was_live',
7367 'release_timestamp': 1671793345,
7368 'channel': 'さなちゃんねる',
7369 'description': 'md5:6aebf95cc4a1d731aebc01ad6cc9806d',
7370 'uploader': 'さなちゃんねる',
7371 'channel_is_verified': True,
7372 'heatmap': 'count:100',
7374 'add_ie': ['Youtube'],
7375 'params': {'skip_download': 'Youtube'}
,
7378 def _real_extract(self
, url
):
7379 redirect_url
= url_or_none(parse_qs(url
).get('continue', [None])[-1])
7380 if not redirect_url
:
7381 raise ExtractorError('Invalid cookie consent redirect URL', expected
=True)
7382 return self
.url_result(redirect_url
)
7385 class YoutubeTruncatedIDIE(InfoExtractor
):
7386 IE_NAME
= 'youtube:truncated_id'
7387 IE_DESC
= False # Do not list
7388 _VALID_URL
= r
'https?://(?:www\.)?youtube\.com/watch\?v=(?P<id>[0-9A-Za-z_-]{1,10})$'
7391 'url': 'https://www.youtube.com/watch?v=N_708QY7Ob',
7392 'only_matching': True,
7395 def _real_extract(self
, url
):
7396 video_id
= self
._match
_id
(url
)
7397 raise ExtractorError(
7398 f
'Incomplete YouTube ID {video_id}. URL {url} looks truncated.',