Repository: yt-dlp/yt-dlp

Issue:
[iq.com] subtitle encryption
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting that yt-dlp is broken on a **supported** site
- [X] I've verified that I'm running yt-dlp version **2023.07.06** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

Taiwan

### Provide a description that is worded well enough to be understood


iq.com uses WebAssembly to encrypt some subtitles.
I manually disabled WebAssembly: chrome.exe --js-flags=--noexpose_wasm, and I can download unencrypted subtitles normally.
But yt-dlp can't, I want to download subtitles through yt-dlp.
For example, the subtitles of the video below are encrypted.
https://www.iq.com/play/spy%C3%97family-%E9%97%B4%E8%B0%8D%E5%AE%B6%E5%AE%B6%E9%85%92-%E7%AC%AC6%E9%9B%86-1z4229zogro?lang=zh_cn
![image](https://github.com/yt-dlp/yt-dlp/assets/30733960/03d8fe61-1c8d-4580-a59a-b9c71df14ac5)
In addition, I found that the subtitle link requested after disabling WebAssembly is different from the yt-dlp subtitle link, where "586040f6d3b9d02bafa071659ce75e06" becomes "7cd5bb5ac6b5e39f5df92f1940b6230f"
`[debug] Invoking http downloader on "http://meta.video.iqiyi.com/20220513/01/6f/586040f6d3b9d02bafa071659ce75e06.srt?qd_sc=c50ad0be05b2ff94296b7401cb685c0c&qd_uid=0&qd_vip=0&qd_src=01011021010010000000&qd_tm=1690770751189&qd_p=a59ae262&qd_k=&qd_index=0&qd_tvid=7280958588696200"`
### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [X] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
[debug] Command-line config: ['https://www.iq.com/play/spy%C3%97family-%E9%96%93%E8%AB%9C%E5%AE%B6%E5%AE%B6%E9%85%92-%E7%AC%AC6%E9%9B%86-1z4229zogro?lang=zh_tw', '--sub-langs', 'zh_TW', '--sub-format', 'srt', '--write-sub', '--skip-download', '-vU']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2023.07.06 [b532a3481] (pip)
[debug] Python 3.9.2 (CPython x86_64 64bit) - Linux-5.10.0-21-amd64-x86_64-with-glibc2.31 (OpenSSL 1.1.1n  15 Mar 2022, glibc 2.31)
[debug] exe versions: ffmpeg N-111062-g09621fd7d9-20230612 (setts), ffprobe 4.3.6-0, phantomjs 4.14
[debug] Optional libraries: Cryptodome-3.18.0, brotli-1.0.9, certifi-2020.06.20, mutagen-1.46.0, sqlite3-2.6.0, websockets-11.0.3
[debug] Proxy map: {}
[debug] Loaded 1855 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Available version: stable@2023.07.06, Current version: stable@2023.07.06
yt-dlp is up to date (stable@2023.07.06)
[iq.com] Extracting URL: https://www.iq.com/play/spy%C3%97family-%E9%96%93%E8%AB%9C%E5%AE%B6%E5%AE%B6%E9%85%92-%E7%AC%AC6%E9%9B%86-1z4229zogro?lang=zh_tw
[iq.com] 1z4229zogro: Downloading webpage
[debug] Loading iq.player_js from cache
[debug] Loading iq.player_js from cache
[iq.com] 1z4229zogro: Executing signature code (this may take a couple minutes)
[debug] [iq.com] PhantomJS command line: phantomjs --ssl-protocol=any /tmp/tmpqo46dqid
[iq.com] 1z4229zogro: Downloading initial video format info
[iq.com] 1z4229zogro: Downloading format data for 720P
[iq.com] 1z4229zogro: Downloading format data for 240P
[iq.com] 1z4229zogro: Downloading format data for 360P
[iq.com] 1z4229zogro: Downloading format data for 480P
[iq.com] 1z4229zogro: Downloading format data for 1080P
WARNING: [iq.com] 1080P format is restricted
[info] 1z4229zogro: Downloading subtitles: zh_TW
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, hdr:12(7), vcodec:vp9.2(10), channels, acodec, size, br, asr, proto, vext, aext, hasaud, source, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] 1z4229zogro: Downloading 1 format(s): 500
Deleting existing file SPY×FAMILY 間諜家家酒 第6集 [1z4229zogro].zh_TW.srt
[info] Writing video subtitles to: SPY×FAMILY 間諜家家酒 第6集 [1z4229zogro].zh_TW.srt
[debug] Invoking http downloader on "http://meta.video.iqiyi.com/20220513/01/6f/586040f6d3b9d02bafa071659ce75e06.srt?qd_sc=c50ad0be05b2ff94296b7401cb685c0c&qd_uid=0&qd_vip=0&qd_src=01011021010010000000&qd_tm=1690770751189&qd_p=a59ae262&qd_k=&qd_index=0&qd_tvid=7280958588696200"
[download] Destination: SPY×FAMILY 間諜家家酒 第6集 [1z4229zogro].zh_TW.srt
[download] 100% of   42.02KiB in 00:00:01 at 33.98KiB/s
```



Discussion:
Today, I encountered encrypted subtitles again, and I was a little distressed. 😵

Resolving patch:
diff --git a/yt_dlp/extractor/iqiyi.py b/yt_dlp/extractor/iqiyi.py
--- a/yt_dlp/extractor/iqiyi.py
+++ b/yt_dlp/extractor/iqiyi.py
@@ -499,9 +499,10 @@ class IqIE(InfoExtractor):
                     'tm': tm,
                     'qdy': 'a',
                     'qds': 0,
-                    'k_ft1': 141287244169348,
-                    'k_ft4': 34359746564,
-                    'k_ft5': 1,
+                    'k_ft1': '143486267424900',
+                    'k_ft4': '1572868',
+                    'k_ft7': '4',
+                    'k_ft5': '1',
                     'bop': JSON.stringify({
                         'version': '10.0',
                         'dfp': dfp
@@ -529,14 +530,22 @@ def _extract_vms_player_js(self, webpage, video_id):
         webpack_js_url = self._proto_relative_url(self._search_regex(
             r'<script src="((?:https?:)?//stc\.iqiyipic\.com/_next/static/chunks/webpack-\w+\.js)"', webpage, 'webpack URL'))
         webpack_js = self._download_webpage(webpack_js_url, video_id, note='Downloading webpack JS', errnote='Unable to download webpack JS')
+
         webpack_map = self._search_json(
             r'["\']\s*\+\s*', webpack_js, 'JS locations', video_id,
             contains_pattern=r'{\s*(?:\d+\s*:\s*["\'][\da-f]+["\']\s*,?\s*)+}',
             end_pattern=r'\[\w+\]\+["\']\.js', transform_source=js_to_json)
 
+        replacement_map = self._search_json(
+            r'["\']\s*\+\(\s*', webpack_js, 'replacement map', video_id,
+            contains_pattern=r'{\s*(?:\d+\s*:\s*["\'][\w.-]+["\']\s*,?\s*)+}',
+            end_pattern=r'\[\w+\]\|\|\w+\)\+["\']\.', transform_source=js_to_json,
+            fatal=False) or {}
+
         for module_index in reversed(webpack_map):
+            real_module = replacement_map.get(module_index) or module_index
             module_js = self._download_webpage(
-                f'https://stc.iqiyipic.com/_next/static/chunks/{module_index}.{webpack_map[module_index]}.js',
+                f'https://stc.iqiyipic.com/_next/static/chunks/{real_module}.{webpack_map[module_index]}.js',
                 video_id, note=f'Downloading #{module_index} module JS', errnote='Unable to download module JS', fatal=False) or ''
             if 'vms request' in module_js:
                 self.cache.store('iq', 'player_js', module_js)


Test patch: