A feature-rich command-line audio/video downloader
[ie/generic] Add `key_query` extractor-arg
bashonly5dbac313ae4e
diff --git a/README.md b/README.mdindex 42ffd9b520..ea7c671748 100644--- a/README.md+++ b/README.md@@ -1779,8 +1779,9 @@ The following extractors use this feature:* `approximate_date`: Extract approximate `upload_date` and `timestamp` in flat-playlist. This may cause date-based filters to be slightly off#### generic-* `fragment_query`: Passthrough any query in mpd/m3u8 manifest URLs to their fragments if no value is provided, or else apply the query string given as `fragment_query=VALUE`. Does not apply to ffmpeg+* `fragment_query`: Passthrough any query in mpd/m3u8 manifest URLs to their fragments if no value is provided, or else apply the query string given as `fragment_query=VALUE`. Note that if the stream has an HLS AES-128 key, then the query parameters will be passed to the key URI as well, unless the `key_query` extractor-arg is passed, or unless an external key URI is provided via the `hls_key` extractor-arg. Does not apply to ffmpeg* `variant_query`: Passthrough the master m3u8 URL query to its variant playlist URLs if no value is provided, or else apply the query string given as `variant_query=VALUE`+* `key_query`: Passthrough the master m3u8 URL query to its HLS AES-128 decryption key URI if no value is provided, or else apply the query string given as `key_query=VALUE`. Note that this will have no effect if the key URI is provided via the `hls_key` extractor-arg. Does not apply to ffmpeg* `hls_key`: An HLS AES-128 key URI *or* key (as hex), and optionally the IV (as hex), in the form of `(URI|KEY)[,IV]`; e.g. `generic:hls_key=ABCDEF1234567980,0xFEDCBA0987654321`. Passing any of these values will force usage of the native HLS downloader and override the corresponding values found in the m3u8 playlist* `is_live`: Bypass live HLS detection and manually set `live_status` - a value of `false` will set `not_live`, any other value (or no value) will set `is_live`diff --git a/yt_dlp/extractor/generic.py b/yt_dlp/extractor/generic.pyindex cc17890e76..3b8e1e957c 100644--- a/yt_dlp/extractor/generic.py+++ b/yt_dlp/extractor/generic.py@@ -2167,7 +2167,15 @@ class GenericIE(InfoExtractor):urllib.parse.urlparse(fragment_query).query or fragment_queryor urllib.parse.urlparse(manifest_url).query or None)- hex_or_none = lambda x: x if re.fullmatch(r'(0x)?[\da-f]+', x, re.IGNORECASE) else None+ key_query = self._configuration_arg('key_query', [None], casesense=True)[0]+ if key_query is not None:+ info['extra_param_to_key_url'] = (+ urllib.parse.urlparse(key_query).query or key_query+ or urllib.parse.urlparse(manifest_url).query or None)++ def hex_or_none(value):+ return value if re.fullmatch(r'(0x)?[\da-f]+', value, re.IGNORECASE) else None+info['hls_aes'] = traverse_obj(self._configuration_arg('hls_key', casesense=True), {'uri': (0, {url_or_none}), 'key': (0, {hex_or_none}), 'iv': (1, {hex_or_none}),}) or None