]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/wetv.py
5 from .common
import InfoExtractor
6 from ..aes
import aes_cbc_encrypt_bytes
7 from ..utils
import determine_ext
, int_or_none
, traverse_obj
, urljoin
10 class WeTvBaseIE(InfoExtractor
):
11 _VALID_URL_BASE
= r
'https?://(?:www\.)?wetv\.vip/(?:[^?#]+/)?play'
13 def _get_ckey(self
, video_id
, url
, app_version
, platform
):
14 ua
= self
.get_param('http_headers')['User-Agent']
16 payload
= (f
'{video_id}|{int(time.time())}|mg3c3b04ba|{app_version}|0000000000000000|'
17 f
'{platform}|{url[:48]}|{ua.lower()[:48]}||Mozilla|Netscape|Win32|00|')
19 return aes_cbc_encrypt_bytes(
20 bytes(f
'|{sum(map(ord, payload))}|{payload}', 'utf-8'),
21 b
'Ok\xda\xa3\x9e/\x8c\xb0\x7f^r-\x9e\xde\xf3\x14',
22 b
'\x01PJ\xf3V\xe6\x19\xcf.B\xbb\xa6\x8c?p\xf9',
23 padding_mode
='whitespace').hex()
25 def _get_video_api_response(self
, video_url
, video_id
, series_id
, subtitle_format
, video_format
, video_quality
):
26 app_version
= '3.5.57'
29 ckey
= self
._get
_ckey
(video_id
, video_url
, app_version
, platform
)
35 'spcaptiontype': '1' if subtitle_format
== 'vtt' else '0', # 0 - SRT, 1 - VTT
36 'sphls': '1' if video_format
== 'hls' else '0', # 0 - MP4, 1 - HLS
37 'defn': video_quality
, # '': 480p, 'shd': 720p, 'fhd': 1080p
38 'spsrt': '1', # Enable subtitles
39 'sphttps': '1', # Enable HTTPS
40 'otype': 'json', # Response format: xml, json,
43 'host': 'wetv.vip', # These three values are needed for SHD
44 'referer': 'wetv.vip',
46 'appVer': app_version
,
50 return self
._search
_json
(r
'QZOutputJson=', self
._download
_webpage
(
51 'https://play.wetv.vip/getvinfo', video_id
, query
=query
), 'api_response', video_id
)
53 def _get_webpage_metadata(self
, webpage
, video_id
):
54 return self
._parse
_json
(
55 traverse_obj(self
._search
_nextjs
_data
(webpage
, video_id
), ('props', 'pageProps', 'data')),
56 video_id
, fatal
=False)
59 class WeTvEpisodeIE(WeTvBaseIE
):
60 IE_NAME
= 'wetv:episode'
61 _VALID_URL
= WeTvBaseIE
._VALID
_URL
_BASE
+ r
'/(?P<series_id>\w+)(?:-[^?#]+)?/(?P<id>\w+)(?:-[^?#]+)?'
64 'url': 'https://wetv.vip/en/play/air11ooo2rdsdi3-Cute-Programmer/v0040pr89t9-EP1-Cute-Programmer',
65 'md5': 'a046f565c9dce9b263a0465a422cd7bf',
69 'title': 'EP1: Cute Programmer',
70 'description': 'md5:e87beab3bf9f392d6b9e541a63286343',
71 'thumbnail': r
're:^https?://[^?#]+air11ooo2rdsdi3',
72 'series': 'Cute Programmer',
73 'episode': 'Episode 1',
78 'url': 'https://wetv.vip/en/play/u37kgfnfzs73kiu/p0039b9nvik',
79 'md5': '4d9d69bcfd11da61f4aae64fc6b316b3',
83 'title': 'EP1: You Are My Glory',
84 'description': 'md5:831363a4c3b4d7615e1f3854be3a123b',
85 'thumbnail': r
're:^https?://[^?#]+u37kgfnfzs73kiu',
86 'series': 'You Are My Glory',
87 'episode': 'Episode 1',
92 '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',
93 'md5': '71133f5c2d5d6cad3427e1b010488280',
97 'title': 'md5:f7a0857dbe5fbbe2e7ad630b92b54e6a',
98 'description': 'md5:76260cb9cdc0ef76826d7ca9d92fadfa',
99 'thumbnail': r
're:^https?://[^?#]+lcxgwod5hapghvw',
100 'series': 'WeTV PICK-A-BOO',
101 'episode': 'Episode 0',
107 def _extract_video_formats_and_subtitles(self
, api_response
, video_id
, video_quality
):
108 video_response
= api_response
['vl']['vi'][0]
109 video_width
= video_response
.get('vw')
110 video_height
= video_response
.get('vh')
112 formats
, subtitles
= [], {}
113 for video_format
in video_response
['ul']['ui']:
114 if video_format
.get('hls'):
115 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
116 video_format
['url'] + video_format
['hls']['pname'], video_id
, 'mp4', fatal
=False)
118 f
['width'] = video_width
119 f
['height'] = video_height
122 self
._merge
_subtitles
(subs
, target
=subtitles
)
125 'url': f
'{video_format["url"]}{video_response["fn"]}?vkey={video_response["fvkey"]}',
126 'width': video_width
,
127 'height': video_height
,
131 return formats
, subtitles
133 def _extract_video_subtitles(self
, api_response
, subtitles_format
):
135 for subtitle
in traverse_obj(api_response
, ('sfl', 'fi')):
136 subtitles
.setdefault(subtitle
['lang'].lower(), []).append({
137 'url': subtitle
['url'],
138 'ext': subtitles_format
,
139 'protocol': 'm3u8_native' if determine_ext(subtitle
['url']) == 'm3u8' else 'http',
144 def _real_extract(self
, url
):
145 video_id
, series_id
= self
._match
_valid
_url
(url
).group('id', 'series_id')
146 webpage
= self
._download
_webpage
(url
, video_id
)
148 formats
, subtitles
= [], {}
149 for video_format
, subtitle_format
, video_quality
in (('mp4', 'srt', ''), ('hls', 'vtt', 'shd'), ('hls', 'vtt', 'fhd')):
150 api_response
= self
._get
_video
_api
_response
(url
, video_id
, series_id
, subtitle_format
, video_format
, video_quality
)
152 fmts
, subs
= self
._extract
_video
_formats
_and
_subtitles
(api_response
, video_id
, video_quality
)
153 native_subtitles
= self
._extract
_video
_subtitles
(api_response
, subtitle_format
)
156 self
._merge
_subtitles
(subs
, native_subtitles
, target
=subtitles
)
158 self
._sort
_formats
(formats
)
159 webpage_metadata
= self
._get
_webpage
_metadata
(webpage
, video_id
)
163 'title': (self
._og
_search
_title
(webpage
)
164 or traverse_obj(webpage_metadata
, ('coverInfo', 'description'))),
165 'description': (self
._og
_search
_description
(webpage
)
166 or traverse_obj(webpage_metadata
, ('coverInfo', 'description'))),
168 'subtitles': subtitles
,
169 'thumbnail': self
._og
_search
_thumbnail
(webpage
),
170 'duration': int_or_none(traverse_obj(webpage_metadata
, ('videoInfo', 'duration'))),
171 'series': traverse_obj(webpage_metadata
, ('coverInfo', 'title')),
172 'episode_number': int_or_none(traverse_obj(webpage_metadata
, ('videoInfo', 'episode'))),
176 class WeTvSeriesIE(WeTvBaseIE
):
177 _VALID_URL
= WeTvBaseIE
._VALID
_URL
_BASE
+ r
'/(?P<id>\w+)(?:-[^/?#]+)?/?(?:[?#]|$)'
180 'url': 'https://wetv.vip/play/air11ooo2rdsdi3-Cute-Programmer',
182 'id': 'air11ooo2rdsdi3',
183 'title': 'Cute Programmer',
184 'description': 'md5:e87beab3bf9f392d6b9e541a63286343',
186 'playlist_count': 30,
188 'url': 'https://wetv.vip/en/play/u37kgfnfzs73kiu-You-Are-My-Glory',
190 'id': 'u37kgfnfzs73kiu',
191 'title': 'You Are My Glory',
192 'description': 'md5:831363a4c3b4d7615e1f3854be3a123b',
194 'playlist_count': 32,
197 def _real_extract(self
, url
):
198 series_id
= self
._match
_id
(url
)
199 webpage
= self
._download
_webpage
(url
, series_id
)
200 webpage_metadata
= self
._get
_webpage
_metadata
(webpage
, series_id
)
202 episode_paths
= (re
.findall(r
'<a[^>]+class="play-video__link"[^>]+href="(?P<path>[^"]+)', webpage
)
203 or [f
'/{series_id}/{episode["vid"]}' for episode
in webpage_metadata
.get('videoList')])
205 return self
.playlist_from_matches(
206 episode_paths
, series_id
, ie
=WeTvEpisodeIE
, getter
=functools
.partial(urljoin
, url
),
207 title
=traverse_obj(webpage_metadata
, ('coverInfo', 'title')) or self
._og
_search
_title
(webpage
),
208 description
=traverse_obj(webpage_metadata
, ('coverInfo', 'description')) or self
._og
_search
_description
(webpage
))