7 from .common
import InfoExtractor
8 from ..aes
import aes_cbc_encrypt_bytes
19 class TencentBaseIE(InfoExtractor
):
20 """Subclasses must set _API_URL, _APP_VERSION, _PLATFORM, _HOST, _REFERER"""
22 def _get_ckey(self
, video_id
, url
, guid
):
23 ua
= self
.get_param('http_headers')['User-Agent']
25 payload
= (f
'{video_id}|{int(time.time())}|mg3c3b04ba|{self._APP_VERSION}|{guid}|'
26 f
'{self._PLATFORM}|{url[:48]}|{ua.lower()[:48]}||Mozilla|Netscape|Windows x86_64|00|')
28 return aes_cbc_encrypt_bytes(
29 bytes(f
'|{sum(map(ord, payload))}|{payload}', 'utf-8'),
30 b
'Ok\xda\xa3\x9e/\x8c\xb0\x7f^r-\x9e\xde\xf3\x14',
31 b
'\x01PJ\xf3V\xe6\x19\xcf.B\xbb\xa6\x8c?p\xf9',
32 padding_mode
='whitespace').hex().upper()
34 def _get_video_api_response(self
, video_url
, video_id
, series_id
, subtitle_format
, video_format
, video_quality
):
35 guid
= ''.join([random
.choice(string
.digits
+ string
.ascii_lowercase
) for _
in range(16)])
36 ckey
= self
._get
_ckey
(video_id
, video_url
, guid
)
42 'spcaptiontype': '1' if subtitle_format
== 'vtt' else '0',
43 'sphls': '2' if video_format
== 'hls' else '0',
44 'dtype': '3' if video_format
== 'hls' else '0',
45 'defn': video_quality
,
46 'spsrt': '2', # Enable subtitles
47 'sphttps': '1', # Enable HTTPS
52 'referer': self
._REFERER
,
54 'appVer': self
._APP
_VERSION
,
55 'platform': self
._PLATFORM
,
58 'flowid': ''.join(random
.choice(string
.digits
+ string
.ascii_lowercase
) for _
in range(32)),
61 return self
._search
_json
(r
'QZOutputJson=', self
._download
_webpage
(
62 self
._API
_URL
, video_id
, query
=query
), 'api_response', video_id
)
64 def _extract_video_formats_and_subtitles(self
, api_response
, video_id
):
65 video_response
= api_response
['vl']['vi'][0]
66 video_width
, video_height
= video_response
.get('vw'), video_response
.get('vh')
68 formats
, subtitles
= [], {}
69 for video_format
in video_response
['ul']['ui']:
70 if video_format
.get('hls') or determine_ext(video_format
['url']) == 'm3u8':
71 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
72 video_format
['url'] + traverse_obj(video_format
, ('hls', 'pt'), default
=''),
73 video_id
, 'mp4', fatal
=False)
75 f
.update({'width': video_width, 'height': video_height}
)
78 self
._merge
_subtitles
(subs
, target
=subtitles
)
81 'url': f
'{video_format["url"]}{video_response["fn"]}?vkey={video_response["fvkey"]}',
83 'height': video_height
,
87 return formats
, subtitles
89 def _extract_video_native_subtitles(self
, api_response
, subtitles_format
):
91 for subtitle
in traverse_obj(api_response
, ('sfl', 'fi')) or ():
92 subtitles
.setdefault(subtitle
['lang'].lower(), []).append({
93 'url': subtitle
['url'],
94 'ext': subtitles_format
,
95 'protocol': 'm3u8_native' if determine_ext(subtitle
['url']) == 'm3u8' else 'http',
100 def _extract_all_video_formats_and_subtitles(self
, url
, video_id
, series_id
):
101 formats
, subtitles
= [], {}
102 for video_format
, subtitle_format
, video_quality
in (
103 # '': 480p, 'shd': 720p, 'fhd': 1080p
104 ('mp4', 'srt', ''), ('hls', 'vtt', 'shd'), ('hls', 'vtt', 'fhd')):
105 api_response
= self
._get
_video
_api
_response
(
106 url
, video_id
, series_id
, subtitle_format
, video_format
, video_quality
)
108 if api_response
.get('em') != 0 and api_response
.get('exem') != 0:
109 if '您所在区域暂无此内容版权' in api_response
.get('msg'):
110 self
.raise_geo_restricted()
111 raise ExtractorError(f
'Tencent said: {api_response.get("msg")}')
113 fmts
, subs
= self
._extract
_video
_formats
_and
_subtitles
(api_response
, video_id
)
114 native_subtitles
= self
._extract
_video
_native
_subtitles
(api_response
, subtitle_format
)
117 self
._merge
_subtitles
(subs
, native_subtitles
, target
=subtitles
)
119 return formats
, subtitles
121 def _get_clean_title(self
, title
):
123 r
'\s*[_\-]\s*(?:Watch online|腾讯视频|(?:高清)?1080P在线观看平台).*?$',
124 '', title
or '').strip() or None
127 class VQQBaseIE(TencentBaseIE
):
128 _VALID_URL_BASE
= r
'https?://v\.qq\.com'
130 _API_URL
= 'https://h5vv6.video.qq.com/getvinfo'
131 _APP_VERSION
= '3.5.57'
134 _REFERER
= 'v.qq.com'
136 def _get_webpage_metadata(self
, webpage
, video_id
):
137 return self
._parse
_json
(
139 r
'(?s)<script[^>]*>[^<]*window\.__pinia\s*=\s*([^<]+)</script>',
140 webpage
, 'pinia data', fatal
=False),
141 video_id
, transform_source
=js_to_json
, fatal
=False)
144 class VQQVideoIE(VQQBaseIE
):
145 IE_NAME
= 'vqq:video'
146 _VALID_URL
= VQQBaseIE
._VALID
_URL
_BASE
+ r
'/x/(?:page|cover/(?P<series_id>\w+))/(?P<id>\w+)'
149 'url': 'https://v.qq.com/x/page/q326831cny0.html',
150 'md5': '826ef93682df09e3deac4a6e6e8cdb6e',
154 'title': '我是选手:雷霆裂阵,终极时刻',
155 'description': 'md5:e7ed70be89244017dac2a835a10aeb1e',
156 'thumbnail': r
're:^https?://[^?#]+q326831cny0',
159 'url': 'https://v.qq.com/x/page/o3013za7cse.html',
160 'md5': 'b91cbbeada22ef8cc4b06df53e36fa21',
165 'description': 'md5:29fe847497a98e04a8c3826e499edd2e',
166 'thumbnail': r
're:^https?://[^?#]+o3013za7cse',
169 'url': 'https://v.qq.com/x/cover/7ce5noezvafma27/a00269ix3l8.html',
170 'md5': '71459c5375c617c265a22f083facce67',
174 'title': '鸡毛飞上天 第01集',
175 'description': 'md5:8cae3534327315b3872fbef5e51b5c5b',
176 'thumbnail': r
're:^https?://[^?#]+7ce5noezvafma27',
180 'url': 'https://v.qq.com/x/cover/mzc00200p29k31e/s0043cwsgj0.html',
181 'md5': '96b9fd4a189fdd4078c111f21d7ac1bc',
185 'title': '第1集:如何快乐吃糖?',
186 'description': 'md5:1d8c3a0b8729ae3827fa5b2d3ebd5213',
187 'thumbnail': r
're:^https?://[^?#]+s0043cwsgj0',
188 'series': '青年理工工作者生活研究所',
191 # Geo-restricted to China
192 'url': 'https://v.qq.com/x/cover/mcv8hkc8zk8lnov/x0036x5qqsr.html',
193 'only_matching': True,
196 def _real_extract(self
, url
):
197 video_id
, series_id
= self
._match
_valid
_url
(url
).group('id', 'series_id')
198 webpage
= self
._download
_webpage
(url
, video_id
)
199 webpage_metadata
= self
._get
_webpage
_metadata
(webpage
, video_id
)
201 formats
, subtitles
= self
._extract
_all
_video
_formats
_and
_subtitles
(url
, video_id
, series_id
)
204 'title': self
._get
_clean
_title
(self
._og
_search
_title
(webpage
)
205 or traverse_obj(webpage_metadata
, ('global', 'videoInfo', 'title'))),
206 'description': (self
._og
_search
_description
(webpage
)
207 or traverse_obj(webpage_metadata
, ('global', 'videoInfo', 'desc'))),
209 'subtitles': subtitles
,
210 'thumbnail': (self
._og
_search
_thumbnail
(webpage
)
211 or traverse_obj(webpage_metadata
, ('global', 'videoInfo', 'pic160x90'))),
212 'series': traverse_obj(webpage_metadata
, ('global', 'coverInfo', 'title')),
216 class VQQSeriesIE(VQQBaseIE
):
217 IE_NAME
= 'vqq:series'
218 _VALID_URL
= VQQBaseIE
._VALID
_URL
_BASE
+ r
'/x/cover/(?P<id>\w+)\.html/?(?:[?#]|$)'
221 'url': 'https://v.qq.com/x/cover/7ce5noezvafma27.html',
223 'id': '7ce5noezvafma27',
225 'description': 'md5:8cae3534327315b3872fbef5e51b5c5b',
227 'playlist_count': 55,
229 'url': 'https://v.qq.com/x/cover/oshd7r0vy9sfq8e.html',
231 'id': 'oshd7r0vy9sfq8e',
233 'description': 'md5:9d8a2245679f71ca828534b0f95d2a03',
235 'playlist_count': 12,
238 def _real_extract(self
, url
):
239 series_id
= self
._match
_id
(url
)
240 webpage
= self
._download
_webpage
(url
, series_id
)
241 webpage_metadata
= self
._get
_webpage
_metadata
(webpage
, series_id
)
243 episode_paths
= [f
'/x/cover/{series_id}/{video_id}.html' for video_id
in re
.findall(
244 r
'<div[^>]+data-vid="(?P<video_id>[^"]+)"[^>]+class="[^"]+episode-item-rect--number',
247 return self
.playlist_from_matches(
248 episode_paths
, series_id
, ie
=VQQVideoIE
, getter
=functools
.partial(urljoin
, url
),
249 title
=self
._get
_clean
_title
(traverse_obj(webpage_metadata
, ('coverInfo', 'title'))
250 or self
._og
_search
_title
(webpage
)),
251 description
=(traverse_obj(webpage_metadata
, ('coverInfo', 'description'))
252 or self
._og
_search
_description
(webpage
)))
255 class WeTvBaseIE(TencentBaseIE
):
256 _VALID_URL_BASE
= r
'https?://(?:www\.)?wetv\.vip/(?:[^?#]+/)?play'
258 _API_URL
= 'https://play.wetv.vip/getvinfo'
259 _APP_VERSION
= '3.5.57'
260 _PLATFORM
= '4830201'
262 _REFERER
= 'wetv.vip'
264 def _get_webpage_metadata(self
, webpage
, video_id
):
265 return self
._parse
_json
(
266 traverse_obj(self
._search
_nextjs
_data
(webpage
, video_id
), ('props', 'pageProps', 'data')),
267 video_id
, fatal
=False)
269 def _extract_episode(self
, url
):
270 video_id
, series_id
= self
._match
_valid
_url
(url
).group('id', 'series_id')
271 webpage
= self
._download
_webpage
(url
, video_id
)
272 webpage_metadata
= self
._get
_webpage
_metadata
(webpage
, video_id
)
274 formats
, subtitles
= self
._extract
_all
_video
_formats
_and
_subtitles
(url
, video_id
, series_id
)
277 'title': self
._get
_clean
_title
(self
._og
_search
_title
(webpage
)
278 or traverse_obj(webpage_metadata
, ('coverInfo', 'title'))),
279 'description': (traverse_obj(webpage_metadata
, ('coverInfo', 'description'))
280 or self
._og
_search
_description
(webpage
)),
282 'subtitles': subtitles
,
283 'thumbnail': self
._og
_search
_thumbnail
(webpage
),
284 'duration': int_or_none(traverse_obj(webpage_metadata
, ('videoInfo', 'duration'))),
285 'series': traverse_obj(webpage_metadata
, ('coverInfo', 'title')),
286 'episode_number': int_or_none(traverse_obj(webpage_metadata
, ('videoInfo', 'episode'))),
289 def _extract_series(self
, url
, ie
):
290 series_id
= self
._match
_id
(url
)
291 webpage
= self
._download
_webpage
(url
, series_id
)
292 webpage_metadata
= self
._get
_webpage
_metadata
(webpage
, series_id
)
294 episode_paths
= ([f
'/play/{series_id}/{episode["vid"]}' for episode
in webpage_metadata
.get('videoList')]
295 or re
.findall(r
'<a[^>]+class="play-video__link"[^>]+href="(?P<path>[^"]+)', webpage
))
297 return self
.playlist_from_matches(
298 episode_paths
, series_id
, ie
=ie
, getter
=functools
.partial(urljoin
, url
),
299 title
=self
._get
_clean
_title
(traverse_obj(webpage_metadata
, ('coverInfo', 'title'))
300 or self
._og
_search
_title
(webpage
)),
301 description
=(traverse_obj(webpage_metadata
, ('coverInfo', 'description'))
302 or self
._og
_search
_description
(webpage
)))
305 class WeTvEpisodeIE(WeTvBaseIE
):
306 IE_NAME
= 'wetv:episode'
307 _VALID_URL
= WeTvBaseIE
._VALID
_URL
_BASE
+ r
'/(?P<series_id>\w+)(?:-[^?#]+)?/(?P<id>\w+)(?:-[^?#]+)?'
310 'url': 'https://wetv.vip/en/play/air11ooo2rdsdi3-Cute-Programmer/v0040pr89t9-EP1-Cute-Programmer',
311 'md5': '0c70fdfaa5011ab022eebc598e64bbbe',
315 'title': 'EP1: Cute Programmer',
316 'description': 'md5:e87beab3bf9f392d6b9e541a63286343',
317 'thumbnail': r
're:^https?://[^?#]+air11ooo2rdsdi3',
318 'series': 'Cute Programmer',
319 'episode': 'Episode 1',
324 'url': 'https://wetv.vip/en/play/u37kgfnfzs73kiu/p0039b9nvik',
325 'md5': '3b3c15ca4b9a158d8d28d5aa9d7c0a49',
329 'title': 'EP1: You Are My Glory',
330 'description': 'md5:831363a4c3b4d7615e1f3854be3a123b',
331 'thumbnail': r
're:^https?://[^?#]+u37kgfnfzs73kiu',
332 'series': 'You Are My Glory',
333 'episode': 'Episode 1',
338 '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',
339 'md5': '71133f5c2d5d6cad3427e1b010488280',
343 'title': 'md5:f7a0857dbe5fbbe2e7ad630b92b54e6a',
344 'description': 'md5:76260cb9cdc0ef76826d7ca9d92fadfa',
345 'thumbnail': r
're:^https?://[^?#]+lcxgwod5hapghvw',
346 'series': 'WeTV PICK-A-BOO',
347 'episode': 'Episode 0',
353 def _real_extract(self
, url
):
354 return self
._extract
_episode
(url
)
357 class WeTvSeriesIE(WeTvBaseIE
):
358 _VALID_URL
= WeTvBaseIE
._VALID
_URL
_BASE
+ r
'/(?P<id>\w+)(?:-[^/?#]+)?/?(?:[?#]|$)'
361 'url': 'https://wetv.vip/play/air11ooo2rdsdi3-Cute-Programmer',
363 'id': 'air11ooo2rdsdi3',
364 'title': 'Cute Programmer',
365 'description': 'md5:e87beab3bf9f392d6b9e541a63286343',
367 'playlist_count': 30,
369 'url': 'https://wetv.vip/en/play/u37kgfnfzs73kiu-You-Are-My-Glory',
371 'id': 'u37kgfnfzs73kiu',
372 'title': 'You Are My Glory',
373 'description': 'md5:831363a4c3b4d7615e1f3854be3a123b',
375 'playlist_count': 32,
378 def _real_extract(self
, url
):
379 return self
._extract
_series
(url
, WeTvEpisodeIE
)
382 class IflixBaseIE(WeTvBaseIE
):
383 _VALID_URL_BASE
= r
'https?://(?:www\.)?iflix\.com/(?:[^?#]+/)?play'
385 _API_URL
= 'https://vplay.iflix.com/getvinfo'
386 _APP_VERSION
= '3.5.57'
388 _HOST
= 'www.iflix.com'
389 _REFERER
= 'www.iflix.com'
392 class IflixEpisodeIE(IflixBaseIE
):
393 IE_NAME
= 'iflix:episode'
394 _VALID_URL
= IflixBaseIE
._VALID
_URL
_BASE
+ r
'/(?P<series_id>\w+)(?:-[^?#]+)?/(?P<id>\w+)(?:-[^?#]+)?'
397 'url': 'https://www.iflix.com/en/play/daijrxu03yypu0s/a0040kvgaza',
398 'md5': '9740f9338c3a2105290d16b68fb3262f',
402 'title': 'EP1: Put Your Head On My Shoulder 2021',
403 'description': 'md5:c095a742d3b7da6dfedd0c8170727a42',
404 'thumbnail': r
're:^https?://[^?#]+daijrxu03yypu0s',
405 'series': 'Put Your Head On My Shoulder 2021',
406 'episode': 'Episode 1',
411 'url': 'https://www.iflix.com/en/play/fvvrcc3ra9lbtt1-Take-My-Brother-Away/i0029sd3gm1-EP1%EF%BC%9ATake-My-Brother-Away',
412 'md5': '375c9b8478fdedca062274b2c2f53681',
416 'title': 'EP1:Take My Brother Away',
417 'description': 'md5:f0f7be1606af51cd94d5627de96b0c76',
418 'thumbnail': r
're:^https?://[^?#]+fvvrcc3ra9lbtt1',
419 'series': 'Take My Brother Away',
420 'episode': 'Episode 1',
426 def _real_extract(self
, url
):
427 return self
._extract
_episode
(url
)
430 class IflixSeriesIE(IflixBaseIE
):
431 _VALID_URL
= IflixBaseIE
._VALID
_URL
_BASE
+ r
'/(?P<id>\w+)(?:-[^/?#]+)?/?(?:[?#]|$)'
434 'url': 'https://www.iflix.com/en/play/g21a6qk4u1s9x22-You-Are-My-Hero',
436 'id': 'g21a6qk4u1s9x22',
437 'title': 'You Are My Hero',
438 'description': 'md5:9c4d844bc0799cd3d2b5aed758a2050a',
440 'playlist_count': 40,
442 'url': 'https://www.iflix.com/play/0s682hc45t0ohll',
444 'id': '0s682hc45t0ohll',
445 'title': 'Miss Gu Who Is Silent',
446 'description': 'md5:a9651d0236f25af06435e845fa2f8c78',
448 'playlist_count': 20,
451 def _real_extract(self
, url
):
452 return self
._extract
_series
(url
, IflixEpisodeIE
)