From 95a2971231d703d3a8585e45eeb48613340a7d5e Mon Sep 17 00:00:00 2001 From: yuan Date: Thu, 7 Aug 2025 07:25:56 -0700 Subject: [PATCH 1/3] fix/iqiyi-extractor --- yt_dlp/extractor/iqiyi.py | 81 ++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/yt_dlp/extractor/iqiyi.py b/yt_dlp/extractor/iqiyi.py index 735b44637..173db6607 100644 --- a/yt_dlp/extractor/iqiyi.py +++ b/yt_dlp/extractor/iqiyi.py @@ -1,3 +1,4 @@ +import base64 import hashlib import itertools import re @@ -337,57 +338,51 @@ def _extract_playlist(self, webpage): return self.playlist_result(entries, album_id, album_title) def _real_extract(self, url): - webpage = self._download_webpage( - url, 'temp_id', note='download video page') + js = self._download_webpage( + 'https://mesh.if.iqiyi.com/player/lw/lwplay/accelerator.js?apiVer=3', + 'temp_id_js', + headers={'Referer': url}, + ) - # There's no simple way to determine whether an URL is a playlist or not - # Sometimes there are playlist links in individual videos, so treat it - # as a single video first - tvid = self._search_regex( - r'data-(?:player|shareplattrigger)-tvid\s*=\s*[\'"](\d+)', webpage, 'tvid', default=None) - if tvid is None: - playlist_result = self._extract_playlist(webpage) - if playlist_result: - return playlist_result - raise ExtractorError('Can\'t find any video') + tvid = self._search_regex(r'"tvid":(\d+)', js, 'tvid') - video_id = self._search_regex( - r'data-(?:player|shareplattrigger)-videoid\s*=\s*[\'"]([a-f\d]+)', webpage, 'video_id') + params = { + 'tvid': tvid, + 'ad_cid': '', + 'disableDRM': 'false', + 'cpt': 0, + 'apiVer': 3, + 'format': 'json', + 'timestamp': int(time.time() * 1000), + } - formats = [] - for _ in range(5): - raw_data = self.get_raw_data(tvid, video_id) + download_info = self._download_json( + 'https://mesh.if.iqiyi.com/player/lw/lwplay/accelerator.js', 'temp_id_json', query=params) + ev = download_info.get('ev') + if not ev: + raise ExtractorError('No ev data in response') - if raw_data['code'] != 'A00000': - if raw_data['code'] == 'A00111': - self.raise_geo_restricted() - raise ExtractorError('Unable to load data. Error code: ' + raw_data['code']) + # Decode + try: + decoded = ''.join(chr(ord(c) ^ 90) for c in ev) + ev_data = self._parse_json(decoded, 'ev json') + except Exception as e: + raise ExtractorError('Failed to decode ev: ' + str(e)) - data = raw_data['data'] + m3u8_content = traverse_obj(ev_data, ('data', 'program', 'video', 2, 'm3u8')) + m3u8_base64 = base64.b64encode(m3u8_content.encode('utf-8')).decode('ascii') + m3u8_data_url = f'data:application/vnd.apple.mpegurl;base64,{m3u8_base64}' + title = traverse_obj(download_info,('videoInfo','title')) - for stream in data['vidl']: - if 'm3utx' not in stream: - continue - vd = str(stream['vd']) - formats.append({ - 'url': stream['m3utx'], - 'format_id': vd, - 'ext': 'mp4', - 'quality': self._FORMATS_MAP.get(vd, -1), - 'protocol': 'm3u8_native', - }) - - if formats: - break - - self._sleep(5, video_id) - - title = (get_element_by_id('widget-videotitle', webpage) - or clean_html(get_element_by_attribute('class', 'mod-play-tit', webpage)) - or self._html_search_regex(r']+data-videochanged-title="word"[^>]*>([^<]+)', webpage, 'title')) + formats = [{ + 'format_id': 'default', + 'url': m3u8_data_url, + 'ext': 'mp4', + 'protocol': 'm3u8_native', + }] return { - 'id': video_id, + 'id': tvid, 'title': title, 'formats': formats, } From 25f13a1717835d3865d2be959bbbfef1b2628f09 Mon Sep 17 00:00:00 2001 From: yuan Date: Thu, 7 Aug 2025 07:58:01 -0700 Subject: [PATCH 2/3] Motified --- yt_dlp/extractor/iqiyi.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/yt_dlp/extractor/iqiyi.py b/yt_dlp/extractor/iqiyi.py index 173db6607..4b8fa5d35 100644 --- a/yt_dlp/extractor/iqiyi.py +++ b/yt_dlp/extractor/iqiyi.py @@ -9,12 +9,9 @@ from .openload import PhantomJSwrapper from ..utils import ( ExtractorError, - clean_html, decode_packed_codes, float_or_none, format_field, - get_element_by_attribute, - get_element_by_id, int_or_none, js_to_json, ohdave_rsa_encrypt, @@ -172,14 +169,6 @@ class IqiyiIE(InfoExtractor): _NETRC_MACHINE = 'iqiyi' _TESTS = [{ - 'url': 'http://www.iqiyi.com/v_19rrojlavg.html', - # MD5 checksum differs on my machine and Travis CI - 'info_dict': { - 'id': '9c1fb1b99d192b21c559e5a1a2cb3c73', - 'ext': 'mp4', - 'title': '美国德州空中惊现奇异云团 酷似UFO', - }, - }, { 'url': 'http://www.iqiyi.com/v_19rrhnnclk.html', 'md5': 'b7dc800a4004b1b57749d9abae0472da', 'info_dict': { @@ -343,7 +332,6 @@ def _real_extract(self, url): 'temp_id_js', headers={'Referer': url}, ) - tvid = self._search_regex(r'"tvid":(\d+)', js, 'tvid') params = { From df676f59cd6f55d829112e82de0090b73b4ac02e Mon Sep 17 00:00:00 2001 From: yuan Date: Thu, 7 Aug 2025 08:00:26 -0700 Subject: [PATCH 3/3] Motified --- yt_dlp/extractor/iqiyi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yt_dlp/extractor/iqiyi.py b/yt_dlp/extractor/iqiyi.py index 4b8fa5d35..db2e99e97 100644 --- a/yt_dlp/extractor/iqiyi.py +++ b/yt_dlp/extractor/iqiyi.py @@ -360,7 +360,7 @@ def _real_extract(self, url): m3u8_content = traverse_obj(ev_data, ('data', 'program', 'video', 2, 'm3u8')) m3u8_base64 = base64.b64encode(m3u8_content.encode('utf-8')).decode('ascii') m3u8_data_url = f'data:application/vnd.apple.mpegurl;base64,{m3u8_base64}' - title = traverse_obj(download_info,('videoInfo','title')) + title = traverse_obj(download_info, ('videoInfo', 'title')) formats = [{ 'format_id': 'default',