From 2602a47685850b9540cf0746f91801f6ee5f761f Mon Sep 17 00:00:00 2001 From: coletdjnz Date: Fri, 16 May 2025 20:54:54 +1200 Subject: [PATCH] Add `never` fetch pot policy --- README.md | 2 +- yt_dlp/extractor/youtube/_video.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ff9142112e..39a7db3419 100644 --- a/README.md +++ b/README.md @@ -1807,7 +1807,7 @@ The following extractors use this feature: * `player_js_variant`: The player javascript variant to use for signature and nsig deciphering. The known variants are: `main`, `tce`, `tv`, `tv_es6`, `phone`, `tablet`. Only `main` is recommended as a possible workaround; the others are for debugging purposes. The default is to use what is prescribed by the site, and can be selected with `actual` * `po_token`: Proof of Origin (PO) Token(s) to use. Comma seperated list of PO Tokens in the format `CLIENT.CONTEXT+PO_TOKEN`, e.g. `youtube:po_token=web.gvs+XXX,web.player=XXX,web_safari.gvs+YYY`. Context can be either `gvs` (Google Video Server URLs) or `player` (Innertube player request) * `pot_trace`: Enable debug logging for PO Token fetching. Either `true` or `false` (default) -* `fetch_pot`: Policy to use for fetching a PO Token from providers. `always` to always try fetch a PO Token regardless if the client requires one for the given context, `auto` to only fetch a PO Token if the client requires one for the given context (default) +* `fetch_pot`: Policy to use for fetching a PO Token from providers. `always` to always try fetch a PO Token regardless if the client requires one for the given context, `never` to never fetch a PO Token, or `auto` to only fetch a PO Token if the client requires one for the given context (default) #### youtubepot-webpo * `bind_to_visitor_id`: Whether to use the Visitor ID instead of Visitor Data for caching WebPO tokens. Either `true` or `false` (default `true`) diff --git a/yt_dlp/extractor/youtube/_video.py b/yt_dlp/extractor/youtube/_video.py index 59dbf925f2..28fff19695 100644 --- a/yt_dlp/extractor/youtube/_video.py +++ b/yt_dlp/extractor/youtube/_video.py @@ -2934,13 +2934,18 @@ class YoutubeIE(YoutubeBaseInfoExtractor): return po_token def _fetch_po_token(self, client, **kwargs): - context = kwargs.get('context') # Avoid fetching PO Tokens when not required - if not ( - _PoTokenContext(context) in self._get_default_ytcfg(client)['PO_TOKEN_REQUIRED_CONTEXTS'] - or self._configuration_arg('fetch_pot', ['auto'], ie_key=YoutubeIE)[0] == 'always' + fetch_pot_policy = self._configuration_arg('fetch_pot', [''], ie_key=YoutubeIE)[0] + if fetch_pot_policy not in ('never', 'auto', 'always'): + fetch_pot_policy = 'auto' + if ( + fetch_pot_policy == 'never' + or ( + fetch_pot_policy == 'auto' + and _PoTokenContext(context) not in self._get_default_ytcfg(client)['PO_TOKEN_REQUIRED_CONTEXTS'] + ) ): return None