mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-08-15 08:58:28 +00:00
fix/iqiyi-extractor
This commit is contained in:
parent
e8d2807296
commit
95a2971231
@ -1,3 +1,4 @@
|
|||||||
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import itertools
|
import itertools
|
||||||
import re
|
import re
|
||||||
@ -337,57 +338,51 @@ def _extract_playlist(self, webpage):
|
|||||||
return self.playlist_result(entries, album_id, album_title)
|
return self.playlist_result(entries, album_id, album_title)
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
webpage = self._download_webpage(
|
js = self._download_webpage(
|
||||||
url, 'temp_id', note='download video page')
|
'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
|
tvid = self._search_regex(r'"tvid":(\d+)', js, 'tvid')
|
||||||
# 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')
|
|
||||||
|
|
||||||
video_id = self._search_regex(
|
params = {
|
||||||
r'data-(?:player|shareplattrigger)-videoid\s*=\s*[\'"]([a-f\d]+)', webpage, 'video_id')
|
'tvid': tvid,
|
||||||
|
'ad_cid': '',
|
||||||
|
'disableDRM': 'false',
|
||||||
|
'cpt': 0,
|
||||||
|
'apiVer': 3,
|
||||||
|
'format': 'json',
|
||||||
|
'timestamp': int(time.time() * 1000),
|
||||||
|
}
|
||||||
|
|
||||||
formats = []
|
download_info = self._download_json(
|
||||||
for _ in range(5):
|
'https://mesh.if.iqiyi.com/player/lw/lwplay/accelerator.js', 'temp_id_json', query=params)
|
||||||
raw_data = self.get_raw_data(tvid, video_id)
|
ev = download_info.get('ev')
|
||||||
|
if not ev:
|
||||||
|
raise ExtractorError('No ev data in response')
|
||||||
|
|
||||||
if raw_data['code'] != 'A00000':
|
# Decode
|
||||||
if raw_data['code'] == 'A00111':
|
try:
|
||||||
self.raise_geo_restricted()
|
decoded = ''.join(chr(ord(c) ^ 90) for c in ev)
|
||||||
raise ExtractorError('Unable to load data. Error code: ' + raw_data['code'])
|
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']:
|
formats = [{
|
||||||
if 'm3utx' not in stream:
|
'format_id': 'default',
|
||||||
continue
|
'url': m3u8_data_url,
|
||||||
vd = str(stream['vd'])
|
'ext': 'mp4',
|
||||||
formats.append({
|
'protocol': 'm3u8_native',
|
||||||
'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'<span[^>]+data-videochanged-title="word"[^>]*>([^<]+)</span>', webpage, 'title'))
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': tvid,
|
||||||
'title': title,
|
'title': title,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user