A feature-rich command-line audio/video downloader
[ie/youtube] Add `web_embedded` client for age-restricted videos (#13089)
bashonly0feec6dc131f
diff --git a/README.md b/README.mdindex e8d4a1fe81..a87b52832a 100644--- a/README.md+++ b/README.md@@ -1792,7 +1792,7 @@ The following extractors use this feature:#### youtube* `lang`: Prefer translated metadata (`title`, `description` etc) of this language code (case-sensitive). By default, the video primary language metadata is preferred, with a fallback to `en` translated. See [youtube.py](https://github.com/yt-dlp/yt-dlp/blob/c26f9b991a0681fd3ea548d535919cec1fbbd430/yt_dlp/extractor/youtube.py#L381-L390) for list of supported content language codes* `skip`: One or more of `hls`, `dash` or `translated_subs` to skip extraction of the m3u8 manifests, dash manifests and [auto-translated subtitles](https://github.com/yt-dlp/yt-dlp/issues/4090#issuecomment-1158102032) respectively-* `player_client`: Clients to extract video data from. The currently available clients are `web`, `web_safari`, `web_embedded`, `web_music`, `web_creator`, `mweb`, `ios`, `android`, `android_vr`, `tv` and `tv_embedded`. By default, `tv,ios,web` is used, or `tv,web` is used when authenticating with cookies. The `web_music` client is added for `music.youtube.com` URLs when logged-in cookies are used. The `tv_embedded` and `web_creator` clients are added for age-restricted videos if account age-verification is required. Some clients, such as `web` and `web_music`, require a `po_token` for their formats to be downloadable. Some clients, such as `web_creator`, will only work with authentication. Not all clients support authentication via cookies. You can use `default` for the default clients, or you can use `all` for all clients (not recommended). You can prefix a client with `-` to exclude it, e.g. `youtube:player_client=default,-ios`+* `player_client`: Clients to extract video data from. The currently available clients are `web`, `web_safari`, `web_embedded`, `web_music`, `web_creator`, `mweb`, `ios`, `android`, `android_vr`, `tv` and `tv_embedded`. By default, `tv,ios,web` is used, or `tv,web` is used when authenticating with cookies. The `web_music` client is added for `music.youtube.com` URLs when logged-in cookies are used. The `web_embedded` client is added for age-restricted videos but only works if the video is embeddable. The `tv_embedded` and `web_creator` clients are added for age-restricted videos if account age-verification is required. Some clients, such as `web` and `web_music`, require a `po_token` for their formats to be downloadable. Some clients, such as `web_creator`, will only work with authentication. Not all clients support authentication via cookies. You can use `default` for the default clients, or you can use `all` for all clients (not recommended). You can prefix a client with `-` to exclude it, e.g. `youtube:player_client=default,-ios`* `player_skip`: Skip some network requests that are generally needed for robust extraction. One or more of `configs` (skip client configs), `webpage` (skip initial webpage), `js` (skip js player), `initial_data` (skip initial data/next ep request). While these options can help reduce the number of requests needed or avoid some rate-limiting, they could cause issues such as missing formats or metadata. See [#860](https://github.com/yt-dlp/yt-dlp/pull/860) and [#12826](https://github.com/yt-dlp/yt-dlp/issues/12826) for more details* `player_params`: YouTube player parameters to use for player requests. Will overwrite any default ones set by yt-dlp.* `comment_sort`: `top` or `new` (default) - choose comment sorting mode (on YouTube's side)diff --git a/yt_dlp/extractor/youtube/_video.py b/yt_dlp/extractor/youtube/_video.pyindex b79094db18..872b09b216 100644--- a/yt_dlp/extractor/youtube/_video.py+++ b/yt_dlp/extractor/youtube/_video.py@@ -3115,9 +3115,19 @@ class YoutubeIE(YoutubeBaseInfoExtractor):else:prs.append(pr)+ # web_embedded can work around age-gate and age-verification for some embeddable videos+ if self._is_agegated(pr) and variant != 'web_embedded':+ append_client(f'web_embedded.{base_client}')+ # Unauthenticated users will only get web_embedded client formats if age-gated+ if self._is_agegated(pr) and not self.is_authenticated:+ self.to_screen(+ f'{video_id}: This video is age-restricted; some formats may be missing '+ f'without authentication. {self._youtube_login_hint}', only_once=True)+# EU countries require age-verification for accounts to access age-restricted videos# If account is not age-verified, _is_agegated() will be truthy for non-embedded clients- if self.is_authenticated and self._is_agegated(pr):+ embedding_is_disabled = variant == 'web_embedded' and self._is_unplayable(pr)+ if self.is_authenticated and (self._is_agegated(pr) or embedding_is_disabled):self.to_screen(f'{video_id}: This video is age-restricted and YouTube is requiring ''account age-verification; some formats may be missing', only_once=True)