6 from .common
import InfoExtractor
7 from ..aes
import aes_cbc_encrypt_bytes
19 class TencentBaseIE(InfoExtractor
):
20 """Subclasses must set _API_URL, _APP_VERSION, _PLATFORM, _HOST, _REFERER"""
22 def _check_api_response(self
, api_response
):
23 msg
= api_response
.get('msg')
24 if api_response
.get('code') != '0.0' and msg
is not None:
26 '您所在区域暂无此内容版权(如设置VPN请关闭后重试)',
27 'This content is not available in your area due to copyright restrictions. Please choose other videos.',
29 self
.raise_geo_restricted()
30 raise ExtractorError(f
'Tencent said: {msg}')
32 def _get_ckey(self
, video_id
, url
, guid
):
33 ua
= self
.get_param('http_headers')['User-Agent']
35 payload
= (f
'{video_id}|{int(time.time())}|mg3c3b04ba|{self._APP_VERSION}|{guid}|'
36 f
'{self._PLATFORM}|{url[:48]}|{ua.lower()[:48]}||Mozilla|Netscape|Windows x86_64|00|')
38 return aes_cbc_encrypt_bytes(
39 bytes(f
'|{sum(map(ord, payload))}|{payload}', 'utf-8'),
40 b
'Ok\xda\xa3\x9e/\x8c\xb0\x7f^r-\x9e\xde\xf3\x14',
41 b
'\x01PJ\xf3V\xe6\x19\xcf.B\xbb\xa6\x8c?p\xf9',
42 padding_mode
='whitespace').hex().upper()
44 def _get_video_api_response(self
, video_url
, video_id
, series_id
, subtitle_format
, video_format
, video_quality
):
45 guid
= ''.join(random
.choices(string
.digits
+ string
.ascii_lowercase
, k
=16))
46 ckey
= self
._get
_ckey
(video_id
, video_url
, guid
)
52 'spcaptiontype': '1' if subtitle_format
== 'vtt' else '0',
53 'sphls': '2' if video_format
== 'hls' else '0',
54 'dtype': '3' if video_format
== 'hls' else '0',
55 'defn': video_quality
,
56 'spsrt': '2', # Enable subtitles
57 'sphttps': '1', # Enable HTTPS
60 'hevclv': '28', # Enable HEVC
61 'drm': '40', # Enable DRM
67 'referer': self
._REFERER
,
69 'appVer': self
._APP
_VERSION
,
70 'platform': self
._PLATFORM
,
73 'flowid': ''.join(random
.choices(string
.digits
+ string
.ascii_lowercase
, k
=32)),
76 return self
._search
_json
(r
'QZOutputJson=', self
._download
_webpage
(
77 self
._API
_URL
, video_id
, query
=query
), 'api_response', video_id
)
79 def _extract_video_formats_and_subtitles(self
, api_response
, video_id
):
80 video_response
= api_response
['vl']['vi'][0]
82 formats
, subtitles
= [], {}
83 for video_format
in video_response
['ul']['ui']:
84 if video_format
.get('hls') or determine_ext(video_format
['url']) == 'm3u8':
85 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
86 video_format
['url'] + traverse_obj(video_format
, ('hls', 'pt'), default
=''),
87 video_id
, 'mp4', fatal
=False)
90 self
._merge
_subtitles
(subs
, target
=subtitles
)
93 'url': f
'{video_format["url"]}{video_response["fn"]}?vkey={video_response["fvkey"]}',
97 identifier
= video_response
.get('br')
98 format_response
= traverse_obj(
99 api_response
, ('fl', 'fi', lambda _
, v
: v
['br'] == identifier
),
100 expected_type
=dict, get_all
=False) or {}
102 'width': video_response
.get('vw'),
103 'height': video_response
.get('vh'),
104 'abr': float_or_none(format_response
.get('audiobandwidth'), scale
=1000),
105 'vbr': float_or_none(format_response
.get('bandwidth'), scale
=1000),
106 'fps': format_response
.get('vfps'),
107 'format': format_response
.get('sname'),
108 'format_id': format_response
.get('name'),
109 'format_note': format_response
.get('resolution'),
110 'dynamic_range': {'hdr10': 'hdr10'}.get(format_response
.get('name'), 'sdr'),
111 'has_drm': format_response
.get('drm', 0) != 0,
114 f
.update(common_info
)
116 return formats
, subtitles
118 def _extract_video_native_subtitles(self
, api_response
):
120 for subtitle
in traverse_obj(api_response
, ('sfl', 'fi')) or ():
121 subtitles
.setdefault(subtitle
['lang'].lower(), []).append({
122 'url': subtitle
['url'],
123 'ext': 'srt' if subtitle
.get('captionType') == 1 else 'vtt',
124 'protocol': 'm3u8_native' if determine_ext(subtitle
['url']) == 'm3u8' else 'http',
129 def _extract_all_video_formats_and_subtitles(self
, url
, video_id
, series_id
):
130 api_responses
= [self
._get
_video
_api
_response
(url
, video_id
, series_id
, 'srt', 'hls', 'hd')]
131 self
._check
_api
_response
(api_responses
[0])
132 qualities
= traverse_obj(api_responses
, (0, 'fl', 'fi', ..., 'name')) or ('shd', 'fhd')
134 if q
not in ('ld', 'sd', 'hd'):
135 api_responses
.append(self
._get
_video
_api
_response
(
136 url
, video_id
, series_id
, 'vtt', 'hls', q
))
137 self
._check
_api
_response
(api_responses
[-1])
139 formats
, subtitles
= [], {}
140 for api_response
in api_responses
:
141 fmts
, subs
= self
._extract
_video
_formats
_and
_subtitles
(api_response
, video_id
)
142 native_subtitles
= self
._extract
_video
_native
_subtitles
(api_response
)
145 self
._merge
_subtitles
(subs
, native_subtitles
, target
=subtitles
)
147 return formats
, subtitles
149 def _get_clean_title(self
, title
):
151 r
'\s*[_\-]\s*(?:Watch online|Watch HD Video Online|WeTV|腾讯视频|(?:高清)?1080P在线观看平台).*?$',
152 '', title
or '').strip() or None
155 class VQQBaseIE(TencentBaseIE
):
156 _VALID_URL_BASE
= r
'https?://v\.qq\.com'
158 _API_URL
= 'https://h5vv6.video.qq.com/getvinfo'
159 _APP_VERSION
= '3.5.57'
162 _REFERER
= 'v.qq.com'
164 def _get_webpage_metadata(self
, webpage
, video_id
):
165 return self
._search
_json
(
166 r
'<script[^>]*>[^<]*window\.__(?:pinia|PINIA__)\s*=',
167 webpage
, 'pinia data', video_id
, transform_source
=js_to_json
, fatal
=False)
170 class VQQVideoIE(VQQBaseIE
):
171 IE_NAME
= 'vqq:video'
172 _VALID_URL
= VQQBaseIE
._VALID
_URL
_BASE
+ r
'/x/(?:page|cover/(?P<series_id>\w+))/(?P<id>\w+)'
175 'url': 'https://v.qq.com/x/page/q326831cny0.html',
176 'md5': 'b11c9cb781df710d686b950376676e2a',
180 'title': '我是选手:雷霆裂阵,终极时刻',
181 'description': 'md5:e7ed70be89244017dac2a835a10aeb1e',
182 'thumbnail': r
're:^https?://[^?#]+q326831cny0',
183 'format_id': r
're:^shd',
186 'url': 'https://v.qq.com/x/page/o3013za7cse.html',
187 'md5': 'a1bcf42c6d28c189bd2fe2d468abb287',
192 'description': 'md5:29fe847497a98e04a8c3826e499edd2e',
193 'thumbnail': r
're:^https?://[^?#]+o3013za7cse',
194 'format_id': r
're:^shd',
197 'url': 'https://v.qq.com/x/cover/7ce5noezvafma27/a00269ix3l8.html',
198 'md5': '87968df6238a65d2478f19c25adf850b',
202 'title': '鸡毛飞上天 第01集',
203 'description': 'md5:8cae3534327315b3872fbef5e51b5c5b',
204 'thumbnail': r
're:^https?://[^?#]+7ce5noezvafma27',
206 'format_id': r
're:^shd',
210 'url': 'https://v.qq.com/x/cover/mzc00200p29k31e/s0043cwsgj0.html',
211 'md5': 'fadd10bf88aec3420f06f19ee1d24c5b',
215 'title': '第1集:如何快乐吃糖?',
216 'description': 'md5:1d8c3a0b8729ae3827fa5b2d3ebd5213',
217 'thumbnail': r
're:^https?://[^?#]+s0043cwsgj0',
218 'series': '青年理工工作者生活研究所',
219 'format_id': r
're:^shd',
221 'params': {'skip_download': 'm3u8'},
223 # Geo-restricted to China
224 'url': 'https://v.qq.com/x/cover/mcv8hkc8zk8lnov/x0036x5qqsr.html',
225 'only_matching': True,
228 def _real_extract(self
, url
):
229 video_id
, series_id
= self
._match
_valid
_url
(url
).group('id', 'series_id')
230 webpage
= self
._download
_webpage
(url
, video_id
)
231 webpage_metadata
= self
._get
_webpage
_metadata
(webpage
, video_id
)
233 formats
, subtitles
= self
._extract
_all
_video
_formats
_and
_subtitles
(url
, video_id
, series_id
)
236 'title': self
._get
_clean
_title
(self
._og
_search
_title
(webpage
)
237 or traverse_obj(webpage_metadata
, ('global', 'videoInfo', 'title'))),
238 'description': (self
._og
_search
_description
(webpage
)
239 or traverse_obj(webpage_metadata
, ('global', 'videoInfo', 'desc'))),
241 'subtitles': subtitles
,
242 'thumbnail': (self
._og
_search
_thumbnail
(webpage
)
243 or traverse_obj(webpage_metadata
, ('global', 'videoInfo', 'pic160x90'))),
244 'series': traverse_obj(webpage_metadata
, ('global', 'coverInfo', 'title')),
248 class VQQSeriesIE(VQQBaseIE
):
249 IE_NAME
= 'vqq:series'
250 _VALID_URL
= VQQBaseIE
._VALID
_URL
_BASE
+ r
'/x/cover/(?P<id>\w+)\.html/?(?:[?#]|$)'
253 'url': 'https://v.qq.com/x/cover/7ce5noezvafma27.html',
255 'id': '7ce5noezvafma27',
257 'description': 'md5:8cae3534327315b3872fbef5e51b5c5b',
259 'playlist_count': 55,
261 'url': 'https://v.qq.com/x/cover/oshd7r0vy9sfq8e.html',
263 'id': 'oshd7r0vy9sfq8e',
265 'description': 'md5:9d8a2245679f71ca828534b0f95d2a03',
267 'playlist_count': 12,
270 def _real_extract(self
, url
):
271 series_id
= self
._match
_id
(url
)
272 webpage
= self
._download
_webpage
(url
, series_id
)
273 webpage_metadata
= self
._get
_webpage
_metadata
(webpage
, series_id
)
275 episode_paths
= [f
'/x/cover/{series_id}/{video_id}.html' for video_id
in re
.findall(
276 r
'<div[^>]+data-vid="(?P<video_id>[^"]+)"[^>]+class="[^"]+episode-item-rect--number',
279 return self
.playlist_from_matches(
280 episode_paths
, series_id
, ie
=VQQVideoIE
, getter
=urljoin(url
),
281 title
=self
._get
_clean
_title
(traverse_obj(webpage_metadata
, ('coverInfo', 'title'))
282 or self
._og
_search
_title
(webpage
)),
283 description
=(traverse_obj(webpage_metadata
, ('coverInfo', 'description'))
284 or self
._og
_search
_description
(webpage
)))
287 class WeTvBaseIE(TencentBaseIE
):
288 _VALID_URL_BASE
= r
'https?://(?:www\.)?wetv\.vip/(?:[^?#]+/)?play'
290 _API_URL
= 'https://play.wetv.vip/getvinfo'
291 _APP_VERSION
= '3.5.57'
292 _PLATFORM
= '4830201'
294 _REFERER
= 'wetv.vip'
296 def _get_webpage_metadata(self
, webpage
, video_id
):
297 return self
._parse
_json
(
298 traverse_obj(self
._search
_nextjs
_data
(webpage
, video_id
), ('props', 'pageProps', 'data')),
299 video_id
, fatal
=False)
301 def _extract_episode(self
, url
):
302 video_id
, series_id
= self
._match
_valid
_url
(url
).group('id', 'series_id')
303 webpage
= self
._download
_webpage
(url
, video_id
)
304 webpage_metadata
= self
._get
_webpage
_metadata
(webpage
, video_id
)
306 formats
, subtitles
= self
._extract
_all
_video
_formats
_and
_subtitles
(url
, video_id
, series_id
)
309 'title': self
._get
_clean
_title
(self
._og
_search
_title
(webpage
)
310 or traverse_obj(webpage_metadata
, ('coverInfo', 'title'))),
311 'description': (traverse_obj(webpage_metadata
, ('coverInfo', 'description'))
312 or self
._og
_search
_description
(webpage
)),
314 'subtitles': subtitles
,
315 'thumbnail': self
._og
_search
_thumbnail
(webpage
),
316 'duration': int_or_none(traverse_obj(webpage_metadata
, ('videoInfo', 'duration'))),
317 'series': traverse_obj(webpage_metadata
, ('coverInfo', 'title')),
318 'episode_number': int_or_none(traverse_obj(webpage_metadata
, ('videoInfo', 'episode'))),
321 def _extract_series(self
, url
, ie
):
322 series_id
= self
._match
_id
(url
)
323 webpage
= self
._download
_webpage
(url
, series_id
)
324 webpage_metadata
= self
._get
_webpage
_metadata
(webpage
, series_id
)
326 episode_paths
= ([f
'/play/{series_id}/{episode["vid"]}' for episode
in webpage_metadata
.get('videoList')]
327 or re
.findall(r
'<a[^>]+class="play-video__link"[^>]+href="(?P<path>[^"]+)', webpage
))
329 return self
.playlist_from_matches(
330 episode_paths
, series_id
, ie
=ie
, getter
=urljoin(url
),
331 title
=self
._get
_clean
_title
(traverse_obj(webpage_metadata
, ('coverInfo', 'title'))
332 or self
._og
_search
_title
(webpage
)),
333 description
=(traverse_obj(webpage_metadata
, ('coverInfo', 'description'))
334 or self
._og
_search
_description
(webpage
)))
337 class WeTvEpisodeIE(WeTvBaseIE
):
338 IE_NAME
= 'wetv:episode'
339 _VALID_URL
= WeTvBaseIE
._VALID
_URL
_BASE
+ r
'/(?P<series_id>\w+)(?:-[^?#]+)?/(?P<id>\w+)(?:-[^?#]+)?'
342 'url': 'https://wetv.vip/en/play/air11ooo2rdsdi3-Cute-Programmer/v0040pr89t9-EP1-Cute-Programmer',
343 'md5': '0c70fdfaa5011ab022eebc598e64bbbe',
347 'title': 'EP1: Cute Programmer',
348 'description': 'md5:e87beab3bf9f392d6b9e541a63286343',
349 'thumbnail': r
're:^https?://[^?#]+air11ooo2rdsdi3',
350 'series': 'Cute Programmer',
351 'episode': 'Episode 1',
354 'format_id': r
're:^shd',
357 'url': 'https://wetv.vip/en/play/u37kgfnfzs73kiu/p0039b9nvik',
358 'md5': '3b3c15ca4b9a158d8d28d5aa9d7c0a49',
362 'title': 'EP1: You Are My Glory',
363 'description': 'md5:831363a4c3b4d7615e1f3854be3a123b',
364 'thumbnail': r
're:^https?://[^?#]+u37kgfnfzs73kiu',
365 'series': 'You Are My Glory',
366 'episode': 'Episode 1',
369 'format_id': r
're:^shd',
372 'url': 'https://wetv.vip/en/play/lcxgwod5hapghvw-WeTV-PICK-A-BOO/i0042y00lxp-Zhao-Lusi-Describes-The-First-Experiences-She-Had-In-Who-Rules-The-World-%7C-WeTV-PICK-A-BOO',
373 'md5': '71133f5c2d5d6cad3427e1b010488280',
377 'title': 'md5:f7a0857dbe5fbbe2e7ad630b92b54e6a',
378 'description': 'md5:76260cb9cdc0ef76826d7ca9d92fadfa',
379 'thumbnail': r
're:^https?://[^?#]+i0042y00lxp',
380 'series': 'WeTV PICK-A-BOO',
381 'episode': 'Episode 0',
384 'format_id': r
're:^shd',
388 def _real_extract(self
, url
):
389 return self
._extract
_episode
(url
)
392 class WeTvSeriesIE(WeTvBaseIE
):
393 _VALID_URL
= WeTvBaseIE
._VALID
_URL
_BASE
+ r
'/(?P<id>\w+)(?:-[^/?#]+)?/?(?:[?#]|$)'
396 'url': 'https://wetv.vip/play/air11ooo2rdsdi3-Cute-Programmer',
398 'id': 'air11ooo2rdsdi3',
399 'title': 'Cute Programmer',
400 'description': 'md5:e87beab3bf9f392d6b9e541a63286343',
402 'playlist_count': 30,
404 'url': 'https://wetv.vip/en/play/u37kgfnfzs73kiu-You-Are-My-Glory',
406 'id': 'u37kgfnfzs73kiu',
407 'title': 'You Are My Glory',
408 'description': 'md5:831363a4c3b4d7615e1f3854be3a123b',
410 'playlist_count': 32,
413 def _real_extract(self
, url
):
414 return self
._extract
_series
(url
, WeTvEpisodeIE
)
417 class IflixBaseIE(WeTvBaseIE
):
418 _VALID_URL_BASE
= r
'https?://(?:www\.)?iflix\.com/(?:[^?#]+/)?play'
420 _API_URL
= 'https://vplay.iflix.com/getvinfo'
421 _APP_VERSION
= '3.5.57'
423 _HOST
= 'www.iflix.com'
424 _REFERER
= 'www.iflix.com'
427 class IflixEpisodeIE(IflixBaseIE
):
428 IE_NAME
= 'iflix:episode'
429 _VALID_URL
= IflixBaseIE
._VALID
_URL
_BASE
+ r
'/(?P<series_id>\w+)(?:-[^?#]+)?/(?P<id>\w+)(?:-[^?#]+)?'
432 'url': 'https://www.iflix.com/en/play/daijrxu03yypu0s/a0040kvgaza',
433 'md5': '9740f9338c3a2105290d16b68fb3262f',
437 'title': 'EP1: Put Your Head On My Shoulder 2021',
438 'description': 'md5:c095a742d3b7da6dfedd0c8170727a42',
439 'thumbnail': r
're:^https?://[^?#]+daijrxu03yypu0s',
440 'series': 'Put Your Head On My Shoulder 2021',
441 'episode': 'Episode 1',
444 'format_id': r
're:^shd',
447 'url': 'https://www.iflix.com/en/play/fvvrcc3ra9lbtt1-Take-My-Brother-Away/i0029sd3gm1-EP1%EF%BC%9ATake-My-Brother-Away',
448 'md5': '375c9b8478fdedca062274b2c2f53681',
452 'title': 'EP1:Take My Brother Away',
453 'description': 'md5:f0f7be1606af51cd94d5627de96b0c76',
454 'thumbnail': r
're:^https?://[^?#]+fvvrcc3ra9lbtt1',
455 'series': 'Take My Brother Away',
456 'episode': 'Episode 1',
459 'format_id': r
're:^shd',
463 def _real_extract(self
, url
):
464 return self
._extract
_episode
(url
)
467 class IflixSeriesIE(IflixBaseIE
):
468 _VALID_URL
= IflixBaseIE
._VALID
_URL
_BASE
+ r
'/(?P<id>\w+)(?:-[^/?#]+)?/?(?:[?#]|$)'
471 'url': 'https://www.iflix.com/en/play/g21a6qk4u1s9x22-You-Are-My-Hero',
473 'id': 'g21a6qk4u1s9x22',
474 'title': 'You Are My Hero',
475 'description': 'md5:9c4d844bc0799cd3d2b5aed758a2050a',
477 'playlist_count': 40,
479 'url': 'https://www.iflix.com/play/0s682hc45t0ohll',
481 'id': '0s682hc45t0ohll',
482 'title': 'Miss Gu Who Is Silent',
483 'description': 'md5:a9651d0236f25af06435e845fa2f8c78',
485 'playlist_count': 20,
488 def _real_extract(self
, url
):
489 return self
._extract
_series
(url
, IflixEpisodeIE
)