6 from .common
import InfoExtractor
7 from .openload
import PhantomJSwrapper
8 from ..compat
import compat_str
, compat_urllib_parse_unquote
, compat_urllib_parse_urlencode
15 get_element_by_attribute
,
33 return hashlib
.md5(text
.encode('utf-8')).hexdigest()
37 def __init__(self
, target
, ip
, timestamp
):
40 self
.timestamp
= timestamp
44 return compat_str(sum(map(lambda p
: int(p
, 16), list(data
))))
48 if isinstance(num
, int):
50 return compat_str(sum(map(int, num
)))
53 even
= self
.digit_sum(compat_str(self
.timestamp
)[::2])
54 odd
= self
.digit_sum(compat_str(self
.timestamp
)[1::2])
57 def preprocess(self
, chunksize
):
58 self
.target
= md5_text(self
.target
)
60 for i
in range(32 // chunksize
):
61 chunks
.append(self
.target
[chunksize
* i
:chunksize
* (i
+ 1)])
63 chunks
.append(self
.target
[32 - 32 % chunksize
:])
64 return chunks
, list(map(int, self
.ip
.split('.')))
66 def mod(self
, modulus
):
67 chunks
, ip
= self
.preprocess(32)
68 self
.target
= chunks
[0] + ''.join(map(lambda p
: compat_str(p
% modulus
), ip
))
70 def split(self
, chunksize
):
77 chunks
, ip
= self
.preprocess(chunksize
)
79 for i
in range(len(chunks
)):
80 ip_part
= compat_str(ip
[i
] % modulus_map
[chunksize
]) if i
< 4 else ''
82 ret
+= ip_part
+ chunks
[i
]
84 ret
+= chunks
[i
] + ip_part
87 def handle_input16(self
):
88 self
.target
= md5_text(self
.target
)
89 self
.target
= self
.split_sum(self
.target
[:16]) + self
.target
+ self
.split_sum(self
.target
[16:])
91 def handle_input8(self
):
92 self
.target
= md5_text(self
.target
)
95 part
= self
.target
[8 * i
:8 * (i
+ 1)]
96 ret
+= self
.split_sum(part
) + part
100 self
.target
= md5_text(self
.target
)
101 self
.target
= self
.split_sum(self
.target
) + self
.target
103 def date(self
, scheme
):
104 self
.target
= md5_text(self
.target
)
105 d
= time
.localtime(self
.timestamp
)
107 'y': compat_str(d
.tm_year
),
108 'm': '%02d' % d
.tm_mon
,
109 'd': '%02d' % d
.tm_mday
,
111 self
.target
+= ''.join(map(lambda c
: strings
[c
], list(scheme
)))
113 def split_time_even_odd(self
):
114 even
, odd
= self
.even_odd()
115 self
.target
= odd
+ md5_text(self
.target
) + even
117 def split_time_odd_even(self
):
118 even
, odd
= self
.even_odd()
119 self
.target
= even
+ md5_text(self
.target
) + odd
121 def split_ip_time_sum(self
):
122 chunks
, ip
= self
.preprocess(32)
123 self
.target
= compat_str(sum(ip
)) + chunks
[0] + self
.digit_sum(self
.timestamp
)
125 def split_time_ip_sum(self
):
126 chunks
, ip
= self
.preprocess(32)
127 self
.target
= self
.digit_sum(self
.timestamp
) + chunks
[0] + compat_str(sum(ip
))
130 class IqiyiSDKInterpreter
:
131 def __init__(self
, sdk_code
):
132 self
.sdk_code
= sdk_code
134 def run(self
, target
, ip
, timestamp
):
135 self
.sdk_code
= decode_packed_codes(self
.sdk_code
)
137 functions
= re
.findall(r
'input=([a-zA-Z0-9]+)\(input', self
.sdk_code
)
139 sdk
= IqiyiSDK(target
, ip
, timestamp
)
142 'handleSum': sdk
.handleSum
,
143 'handleInput8': sdk
.handle_input8
,
144 'handleInput16': sdk
.handle_input16
,
145 'splitTimeEvenOdd': sdk
.split_time_even_odd
,
146 'splitTimeOddEven': sdk
.split_time_odd_even
,
147 'splitIpTimeSum': sdk
.split_ip_time_sum
,
148 'splitTimeIpSum': sdk
.split_time_ip_sum
,
150 for function
in functions
:
151 if re
.match(r
'mod\d+', function
):
152 sdk
.mod(int(function
[3:]))
153 elif re
.match(r
'date[ymd]{3}', function
):
154 sdk
.date(function
[4:])
155 elif re
.match(r
'split\d+', function
):
156 sdk
.split(int(function
[5:]))
157 elif function
in other_functions
:
158 other_functions
[function
]()
160 raise ExtractorError('Unknown function %s' % function
)
165 class IqiyiIE(InfoExtractor
):
169 _VALID_URL
= r
'https?://(?:(?:[^.]+\.)?iqiyi\.com|www\.pps\.tv)/.+\.html'
171 _NETRC_MACHINE
= 'iqiyi'
174 'url': 'http://www.iqiyi.com/v_19rrojlavg.html',
175 # MD5 checksum differs on my machine and Travis CI
177 'id': '9c1fb1b99d192b21c559e5a1a2cb3c73',
179 'title': '美国德州空中惊现奇异云团 酷似UFO',
182 'url': 'http://www.iqiyi.com/v_19rrhnnclk.html',
183 'md5': 'b7dc800a4004b1b57749d9abae0472da',
185 'id': 'e3f585b550a280af23c98b6cb2be19fb',
187 # This can be either Simplified Chinese or Traditional Chinese
188 'title': r
're:^(?:名侦探柯南 国语版:第752集 迫近灰原秘密的黑影 下篇|名偵探柯南 國語版:第752集 迫近灰原秘密的黑影 下篇)$',
190 'skip': 'Geo-restricted to China',
192 'url': 'http://www.iqiyi.com/w_19rt6o8t9p.html',
193 'only_matching': True,
195 'url': 'http://www.iqiyi.com/a_19rrhbc6kt.html',
196 'only_matching': True,
198 'url': 'http://yule.iqiyi.com/pcb.html',
200 'id': '4a0af228fddb55ec96398a364248ed7f',
202 'title': '第2017-04-21期 女艺人频遭极端粉丝骚扰',
205 # VIP-only video. The first 2 parts (6 minutes) are available without login
206 # MD5 sums omitted as values are different on Travis CI and my machine
207 'url': 'http://www.iqiyi.com/v_19rrny4w8w.html',
209 'id': 'f3cf468b39dddb30d676f89a91200dc1',
213 'skip': 'Geo-restricted to China',
215 'url': 'http://www.iqiyi.com/a_19rrhb8ce1.html',
220 'playlist_count': 101,
222 'url': 'http://www.pps.tv/w_19rrbav0ph.html',
223 'only_matching': True,
227 '96': 1, # 216p, 240p
233 '5': 6, # 1072p, 1080p
239 # public key extracted from http://static.iqiyi.com/js/qiyiV2/20160129180840/jobs/i18n/i18nIndex.js
240 N
= 0xab86b6371b5318aaa1d3c9e612a9f1264f372323c8c0f19875b5fc3b3fd3afcc1e5bec527aa94bfa85bffc157e4245aebda05389a5357b75115ac94f074aefcd
243 return ohdave_rsa_encrypt(data
, e
, N
)
245 def _perform_login(self
, username
, password
):
247 data
= self
._download
_json
(
248 'http://kylin.iqiyi.com/get_token', None,
249 note
='Get token for logging', errnote
='Unable to get token for logging')
251 timestamp
= int(time
.time())
252 target
= '/apis/reglogin/login.action?lang=zh_TW&area_code=null&email=%s&passwd=%s&agenttype=1&from=undefined&keeplogin=0&piccode=&fromurl=&_pos=1' % (
253 username
, self
._rsa
_fun
(password
.encode('utf-8')))
255 interp
= IqiyiSDKInterpreter(sdk
)
256 sign
= interp
.run(target
, data
['ip'], timestamp
)
258 validation_params
= {
260 'server': 'BEA3AA1908656AABCCFF76582C4C6660',
261 'token': data
['token'],
262 'bird_src': 'f8d91d57af224da7893dd397d52d811a',
266 validation_result
= self
._download
_json
(
267 'http://kylin.iqiyi.com/validate?' + compat_urllib_parse_urlencode(validation_params
), None,
268 note
='Validate credentials', errnote
='Unable to validate credentials')
271 'P00107': 'please login via the web interface and enter the CAPTCHA code',
272 'P00117': 'bad username or password',
275 code
= validation_result
['code']
277 msg
= MSG_MAP
.get(code
)
279 msg
= 'error %s' % code
280 if validation_result
.get('msg'):
281 msg
+= ': ' + validation_result
['msg']
282 self
.report_warning('unable to log in: ' + msg
)
287 def get_raw_data(self
, tvid
, video_id
):
288 tm
= int(time
.time() * 1000)
290 key
= 'd5fb4bd9d50c4be6948c97edd7254b0e'
291 sc
= md5_text(compat_str(tm
) + key
+ tvid
)
295 'src': '76f90cbd92f94a2e925d83e8ccd22cb7',
300 return self
._download
_json
(
301 'http://cache.m.iqiyi.com/jp/tmts/%s/%s/' % (tvid
, video_id
),
302 video_id
, transform_source
=lambda s
: remove_start(s
, 'var tvInfoJs='),
303 query
=params
, headers
=self
.geo_verification_headers())
305 def _extract_playlist(self
, webpage
):
309 r
'<a[^>]+class="site-piclist_pic_link"[^>]+href="(http://www\.iqiyi\.com/.+\.html)"',
314 album_id
= self
._search
_regex
(
315 r
'albumId\s*:\s*(\d+),', webpage
, 'album ID')
316 album_title
= self
._search
_regex
(
317 r
'data-share-title="([^"]+)"', webpage
, 'album title', fatal
=False)
319 entries
= list(map(self
.url_result
, links
))
321 # Start from 2 because links in the first page are already on webpage
322 for page_num
in itertools
.count(2):
323 pagelist_page
= self
._download
_webpage
(
324 'http://cache.video.qiyi.com/jp/avlist/%s/%d/%d/' % (album_id
, page_num
, PAGE_SIZE
),
326 note
='Download playlist page %d' % page_num
,
327 errnote
='Failed to download playlist page %d' % page_num
)
328 pagelist
= self
._parse
_json
(
329 remove_start(pagelist_page
, 'var tvInfoJs='), album_id
)
330 vlist
= pagelist
['data']['vlist']
332 entries
.append(self
.url_result(item
['vurl']))
333 if len(vlist
) < PAGE_SIZE
:
336 return self
.playlist_result(entries
, album_id
, album_title
)
338 def _real_extract(self
, url
):
339 webpage
= self
._download
_webpage
(
340 url
, 'temp_id', note
='download video page')
342 # There's no simple way to determine whether an URL is a playlist or not
343 # Sometimes there are playlist links in individual videos, so treat it
344 # as a single video first
345 tvid
= self
._search
_regex
(
346 r
'data-(?:player|shareplattrigger)-tvid\s*=\s*[\'"](\d+)', webpage, 'tvid', default=None)
348 playlist_result = self._extract_playlist(webpage)
350 return playlist_result
351 raise ExtractorError('Can\'t find any video')
353 video_id = self._search_regex(
354 r'data-(?:player|shareplattrigger)-videoid\s*=\s*[\'"]([a
-f\d
]+)', webpage, 'video_id
')
358 raw_data = self.get_raw_data(tvid, video_id)
360 if raw_data['code
'] != 'A00000
':
361 if raw_data['code
'] == 'A00111
':
362 self.raise_geo_restricted()
363 raise ExtractorError('Unable to load data
. Error code
: ' + raw_data['code
'])
365 data = raw_data['data
']
367 for stream in data['vidl
']:
368 if 'm3utx
' not in stream:
370 vd = compat_str(stream['vd
'])
372 'url
': stream['m3utx
'],
375 'quality
': self._FORMATS_MAP.get(vd, -1),
376 'protocol
': 'm3u8_native
',
382 self._sleep(5, video_id)
384 title = (get_element_by_id('widget
-videotitle
', webpage)
385 or clean_html(get_element_by_attribute('class', 'mod
-play
-tit
', webpage))
386 or self._html_search_regex(r'<span
[^
>]+data
-videochanged
-title
="word"[^
>]*>([^
<]+)</span
>', webpage, 'title
'))
395 class IqIE(InfoExtractor):
397 IE_DESC = 'International version of iQiyi
'
398 _VALID_URL = r'https?
://(?
:www\
.)?iq\
.com
/play
/(?
:[\w
%-]*-)?
(?P
<id>\w
+)'
400 'url
': 'https
://www
.iq
.com
/play
/one
-piece
-episode
-1000-1ma1i6ferf4
',
401 'md5
': '2d7caf6eeca8a32b407094b33b757d39
',
405 'title
': '航海王 第
1000集
',
406 'description
': 'Subtitle available on Sunday
4PM(GMT
+8)
.',
408 'timestamp
': 1637488203,
409 'upload_date
': '20211121',
410 'episode_number
': 1000,
411 'episode
': 'Episode
1000',
412 'series
': 'One Piece
',
414 'average_rating
': float,
419 'expected_warnings
': ['format
is restricted
']
421 # VIP-restricted video
422 'url
': 'https
://www
.iq
.com
/play
/mermaid
-in-the
-fog
-2021-gbdpx13bs4
',
423 'only_matching
': True
451 console.log(page.evaluate(function() {
452 var tvid = "%(tvid)s"; var vid = "%(vid)s"; var src = "%(src)s";
453 var uid = "%(uid)s"; var dfp = "%(dfp)s"; var mode = "%(mode)s"; var lang = "%(lang)s";
454 var bid_list = %(bid_list)s; var ut_list = %(ut_list)s; var tm = new Date().getTime();
455 var cmd5x_func = %(cmd5x_func)s; var cmd5x_exporter = {}; cmd5x_func({}, cmd5x_exporter, {}); var cmd5x = cmd5x_exporter.cmd5x;
456 var authKey = cmd5x(cmd5x('') + tm + '' + tvid);
457 var k_uid = Array.apply(null, Array(32)).map(function() {return Math.floor(Math.random() * 15).toString(16)}).join('');
459 bid_list.forEach(function(bid) {
484 'prio
': JSON.stringify({
498 'k_ft1
': '143486267424900',
502 'bop
': JSON.stringify({
508 for (var prop in query) {
509 enc_params.push(encodeURIComponent(prop) + '=' + encodeURIComponent(query[prop]));
511 ut_list.forEach(function(ut) {
512 enc_params.push('ut
=' + ut);
514 var dash_path = '/dash?
' + enc_params.join('&'); dash_path += '&vf
=' + cmd5x(dash_path);
515 dash_paths[bid] = dash_path;
517 return JSON.stringify(dash_paths);
522 def _extract_vms_player_js(self, webpage, video_id):
523 player_js_cache = self.cache.load('iq
', 'player_js
')
525 return player_js_cache
526 webpack_js_url = self._proto_relative_url(self._search_regex(
527 r'<script src
="((?:https?:)?//stc\.iqiyipic\.com/_next/static/chunks/webpack-\w+\.js)"', webpage, 'webpack URL
'))
528 webpack_js = self._download_webpage(webpack_js_url, video_id, note='Downloading webpack JS
', errnote='Unable to download webpack JS
')
530 webpack_map = self._search_json(
531 r'["\']\s*\+\s*', webpack_js, 'JS locations', video_id,
532 contains_pattern=r'{\s*(?:\d+\s*:\s*["\'][\da-f]+["\']\s*,?\s*)+}',
533 end_pattern=r'\[\w+\]\+["\']\
.js
', transform_source=js_to_json)
535 replacement_map = self._search_json(
536 r'["\']\s*\+\(\s*', webpack_js, 'replacement map', video_id,
537 contains_pattern=r'{\s*(?:\d+\s*:\s*["\'][\w.-]+["\']\s*,?\s*)+}',
538 end_pattern=r'\[\w+\]\|\|\w+\)\+["\']\
.', transform_source=js_to_json,
541 for module_index in reversed(webpack_map):
542 real_module = replacement_map.get(module_index) or module_index
543 module_js = self._download_webpage(
544 f'https
://stc
.iqiyipic
.com
/_next
/static
/chunks
/{real_module}
.{webpack_map[module_index]}
.js
',
545 video_id, note=f'Downloading
#{module_index} module JS', errnote='Unable to download module JS', fatal=False) or ''
546 if 'vms request' in module_js
:
547 self
.cache
.store('iq', 'player_js', module_js
)
549 raise ExtractorError('Unable to extract player JS')
551 def _extract_cmd5x_function(self
, webpage
, video_id
):
552 return self
._search
_regex
(r
',\s*(function\s*\([^\)]*\)\s*{\s*var _qda.+_qdc\(\)\s*})\s*,',
553 self
._extract
_vms
_player
_js
(webpage
, video_id
), 'signature function')
555 def _update_bid_tags(self
, webpage
, video_id
):
556 extracted_bid_tags
= self
._search
_json
(
557 r
'function\s*\([^)]*\)\s*\{\s*"use strict";?\s*var \w\s*=\s*',
558 self
._extract
_vms
_player
_js
(webpage
, video_id
), 'video tags', video_id
,
559 contains_pattern
=r
'{\s*\d+\s*:\s*\{\s*nbid\s*:.+}\s*}',
560 end_pattern
=r
'\s*,\s*\w\s*=\s*\{\s*getNewVd', fatal
=False, transform_source
=js_to_json
)
561 if not extracted_bid_tags
:
564 bid
: traverse_obj(extracted_bid_tags
, (bid
, 'value'), expected_type
=str, default
=self
._BID
_TAGS
.get(bid
))
565 for bid
in extracted_bid_tags
.keys()
568 def _get_cookie(self
, name
, default
=None):
569 cookie
= self
._get
_cookies
('https://iq.com/').get(name
)
570 return cookie
.value
if cookie
else default
572 def _real_extract(self
, url
):
573 video_id
= self
._match
_id
(url
)
574 webpage
= self
._download
_webpage
(url
, video_id
)
575 self
._update
_bid
_tags
(webpage
, video_id
)
577 next_props
= self
._search
_nextjs
_data
(webpage
, video_id
)['props']
578 page_data
= next_props
['initialState']['play']
579 video_info
= page_data
['curVideoInfo']
583 self
._get
_cookie
('I00002', '{}'), video_id
, transform_source
=compat_urllib_parse_unquote
, fatal
=False),
584 ('data', 'uid'), default
=0)
587 vip_data
= self
._download
_json
(
588 'https://pcw-api.iq.com/api/vtype', video_id
, note
='Downloading VIP data', errnote
='Unable to download VIP data', query
={
591 'modeCode': self
._get
_cookie
('mod', 'intl'),
592 'langCode': self
._get
_cookie
('lang', 'en_us'),
593 'deviceId': self
._get
_cookie
('QC005', '')
595 ut_list
= traverse_obj(vip_data
, ('data', 'all_vip', ..., 'vipType'), expected_type
=str_or_none
)
599 # bid 0 as an initial format checker
600 dash_paths
= self
._parse
_json
(PhantomJSwrapper(self
, timeout
=120_000).get(
601 url
, note2
='Executing signature code (this may take a couple minutes)',
602 html
='<!DOCTYPE html>', video_id
=video_id
, jscode
=self
._DASH
_JS
% {
603 'tvid': video_info
['tvId'],
604 'vid': video_info
['vid'],
605 'src': traverse_obj(next_props
, ('initialProps', 'pageProps', 'ptid'),
606 expected_type
=str, default
='04022001010011000000'),
608 'dfp': self
._get
_cookie
('dfp', ''),
609 'mode': self
._get
_cookie
('mod', 'intl'),
610 'lang': self
._get
_cookie
('lang', 'en_us'),
611 'bid_list': '[' + ','.join(['0', *self
._BID
_TAGS
.keys()]) + ']',
612 'ut_list': '[' + ','.join(ut_list
) + ']',
613 'cmd5x_func': self
._extract
_cmd
5x
_function
(webpage
, video_id
),
614 })[1].strip(), video_id
)
616 formats
, subtitles
= [], {}
617 initial_format_data
= self
._download
_json
(
618 urljoin('https://cache-video.iq.com', dash_paths
['0']), video_id
,
619 note
='Downloading initial video format info', errnote
='Unable to download initial video format info')['data']
621 preview_time
= traverse_obj(
622 initial_format_data
, ('boss_ts', (None, 'data'), ('previewTime', 'rtime')), expected_type
=float_or_none
, get_all
=False)
623 if traverse_obj(initial_format_data
, ('boss_ts', 'data', 'prv'), expected_type
=int_or_none
):
624 self
.report_warning('This preview video is limited%s' % format_field(preview_time
, None, ' to %s seconds'))
626 # TODO: Extract audio-only formats
627 for bid
in set(traverse_obj(initial_format_data
, ('program', 'video', ..., 'bid'), expected_type
=str_or_none
)):
628 dash_path
= dash_paths
.get(bid
)
630 self
.report_warning(f
'Unknown format id: {bid}. It is currently not being extracted')
632 format_data
= traverse_obj(self
._download
_json
(
633 urljoin('https://cache-video.iq.com', dash_path
), video_id
,
634 note
=f
'Downloading format data for {self._BID_TAGS[bid]}', errnote
='Unable to download format data',
635 fatal
=False), 'data', expected_type
=dict)
637 video_format
= traverse_obj(format_data
, ('program', 'video', lambda _
, v
: str(v
['bid']) == bid
),
638 expected_type
=dict, get_all
=False) or {}
639 extracted_formats
= []
640 if video_format
.get('m3u8Url'):
641 extracted_formats
.extend(self
._extract
_m
3u8_formats
(
642 urljoin(format_data
.get('dm3u8', 'https://cache-m.iq.com/dc/dt/'), video_format
['m3u8Url']),
643 'mp4', m3u8_id
=bid
, fatal
=False))
644 if video_format
.get('mpdUrl'):
645 # TODO: Properly extract mpd hostname
646 extracted_formats
.extend(self
._extract
_mpd
_formats
(
647 urljoin(format_data
.get('dm3u8', 'https://cache-m.iq.com/dc/dt/'), video_format
['mpdUrl']),
648 mpd_id
=bid
, fatal
=False))
649 if video_format
.get('m3u8'):
650 ff
= video_format
.get('ff', 'ts')
652 m3u8_formats
, _
= self
._parse
_m
3u8_formats
_and
_subtitles
(
653 video_format
['m3u8'], ext
='mp4', m3u8_id
=bid
, fatal
=False)
654 extracted_formats
.extend(m3u8_formats
)
656 mpd_data
= traverse_obj(
657 self
._parse
_json
(video_format
['m3u8'], video_id
, fatal
=False), ('payload', ..., 'data'), expected_type
=str)
660 mpd_formats
, _
= self
._parse
_mpd
_formats
_and
_subtitles
(
661 mpd_data
, bid
, format_data
.get('dm3u8', 'https://cache-m.iq.com/dc/dt/'))
662 extracted_formats
.extend(mpd_formats
)
664 self
.report_warning(f
'{ff} formats are currently not supported')
666 if not extracted_formats
:
667 if video_format
.get('s'):
668 self
.report_warning(f
'{self._BID_TAGS[bid]} format is restricted')
670 self
.report_warning(f
'Unable to extract {self._BID_TAGS[bid]} format')
671 for f
in extracted_formats
:
673 'quality': qualities(list(self
._BID
_TAGS
.keys()))(bid
),
674 'format_note': self
._BID
_TAGS
[bid
],
675 **parse_resolution(video_format
.get('scrsz'))
677 formats
.extend(extracted_formats
)
679 for sub_format
in traverse_obj(initial_format_data
, ('program', 'stl', ...), expected_type
=dict):
680 lang
= self
._LID
_TAGS
.get(str_or_none(sub_format
.get('lid')), sub_format
.get('_name'))
681 subtitles
.setdefault(lang
, []).extend([{
683 'url': urljoin(initial_format_data
.get('dstl', 'http://meta.video.iqiyi.com'), sub_format
[format_key
])
684 } for format_key
, format_ext
in [('srt', 'srt'), ('webvtt', 'vtt')] if sub_format
.get(format_key
)])
686 extra_metadata
= page_data
.get('albumInfo') if video_info
.get('albumId') and page_data
.get('albumInfo') else video_info
689 'title': video_info
['name'],
691 'subtitles': subtitles
,
692 'description': video_info
.get('mergeDesc'),
693 'duration': parse_duration(video_info
.get('len')),
694 'age_limit': parse_age_limit(video_info
.get('rating')),
695 'average_rating': traverse_obj(page_data
, ('playScoreInfo', 'score'), expected_type
=float_or_none
),
696 'timestamp': parse_iso8601(video_info
.get('isoUploadDate')),
697 'categories': traverse_obj(extra_metadata
, ('videoTagMap', ..., ..., 'name'), expected_type
=str),
698 'cast': traverse_obj(extra_metadata
, ('actorArr', ..., 'name'), expected_type
=str),
699 'episode_number': int_or_none(video_info
.get('order')) or None,
700 'series': video_info
.get('albumName'),
704 class IqAlbumIE(InfoExtractor
):
705 IE_NAME
= 'iq.com:album'
706 _VALID_URL
= r
'https?://(?:www\.)?iq\.com/album/(?:[\w%-]*-)?(?P<id>\w+)'
708 'url': 'https://www.iq.com/album/one-piece-1999-1bk9icvr331',
711 'title': 'One Piece',
712 'description': 'Subtitle available on Sunday 4PM(GMT+8).'
714 'playlist_mincount': 238
717 'url': 'https://www.iq.com/album/九龙城寨-2021-22yjnij099k',
722 'description': 'md5:8a09f50b8ba0db4dc69bc7c844228044',
724 'timestamp': 1641911371,
725 'upload_date': '20220111',
727 'cast': ['Shi Yan Neng', 'Yu Lang', 'Peter lv', 'Sun Zi Jun', 'Yang Xiao Bo'],
729 'average_rating': float,
731 'expected_warnings': ['format is restricted']
734 def _entries(self
, album_id_num
, page_ranges
, album_id
=None, mode_code
='intl', lang_code
='en_us'):
735 for page_range
in page_ranges
:
736 page
= self
._download
_json
(
737 f
'https://pcw-api.iq.com/api/episodeListSource/{album_id_num}', album_id
,
738 note
=f
'Downloading video list episodes {page_range.get("msg", "")}',
739 errnote
='Unable to download video list', query
={
741 'modeCode': mode_code
,
742 'langCode': lang_code
,
743 'endOrder': page_range
['to'],
744 'startOrder': page_range
['from']
746 for video
in page
['data']['epg']:
747 yield self
.url_result('https://www.iq.com/play/%s' % (video
.get('playLocSuffix') or video
['qipuIdStr']),
748 IqIE
.ie_key(), video
.get('qipuIdStr'), video
.get('name'))
750 def _real_extract(self
, url
):
751 album_id
= self
._match
_id
(url
)
752 webpage
= self
._download
_webpage
(url
, album_id
)
753 next_data
= self
._search
_nextjs
_data
(webpage
, album_id
)
754 album_data
= next_data
['props']['initialState']['album']['videoAlbumInfo']
756 if album_data
.get('videoType') == 'singleVideo':
757 return self
.url_result('https://www.iq.com/play/%s' % album_id
, IqIE
.ie_key())
758 return self
.playlist_result(
759 self
._entries
(album_data
['albumId'], album_data
['totalPageRange'], album_id
,
760 traverse_obj(next_data
, ('props', 'initialProps', 'pageProps', 'modeCode')),
761 traverse_obj(next_data
, ('props', 'initialProps', 'pageProps', 'langCode'))),
762 album_id
, album_data
.get('name'), album_data
.get('desc'))