]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/wetv.py
4 from .common
import InfoExtractor
5 from ..aes
import aes_cbc_encrypt
6 from ..utils
import bytes_to_intlist
, determine_ext
, intlist_to_bytes
, int_or_none
, traverse_obj
9 class WeTvBaseIE(InfoExtractor
):
10 _VALID_URL_BASE
= r
'https?://(?:www\.)?wetv\.vip/(?:[^?#]+/)?play'
12 def _get_ckey(self
, video_id
, url
, app_version
, platform
):
13 ua
= self
.get_param('http_headers')['User-Agent']
15 payload
= (f
'{video_id}|{int(time.time())}|mg3c3b04ba|{app_version}|0000000000000000|'
16 f
'{platform}|{url[:48]}|{ua.lower()[:48]}||Mozilla|Netscape|Win32|00|')
18 ciphertext_int_bytes
= aes_cbc_encrypt(
19 bytes_to_intlist(bytes(f
'|{sum(map(ord, payload))}|{payload}', 'utf-8')),
20 bytes_to_intlist(b
'Ok\xda\xa3\x9e/\x8c\xb0\x7f^r-\x9e\xde\xf3\x14'),
21 bytes_to_intlist(b
'\x01PJ\xf3V\xe6\x19\xcf.B\xbb\xa6\x8c?p\xf9'),
24 return intlist_to_bytes(ciphertext_int_bytes
).hex()
26 def _get_video_api_response(self
, video_url
, video_id
, series_id
, subtitle_format
, video_format
, video_quality
):
27 app_version
= '3.5.57'
30 ckey
= self
._get
_ckey
(video_id
, video_url
, app_version
, platform
)
36 'spcaptiontype': '1' if subtitle_format
== 'vtt' else '0', # 0 - SRT, 1 - VTT
37 'sphls': '1' if video_format
== 'hls' else '0', # 0 - MP4, 1 - HLS
38 'defn': video_quality
, # '': 480p, 'shd': 720p, 'fhd': 1080p
39 'spsrt': '1', # Enable subtitles
40 'sphttps': '1', # Enable HTTPS
41 'otype': 'json', # Response format: xml, json,
44 'host': 'wetv.vip', # These three values are needed for SHD
45 'referer': 'wetv.vip',
47 'appVer': app_version
,
51 return self
._search
_json
(r
'QZOutputJson=', self
._download
_webpage
(
52 'https://play.wetv.vip/getvinfo', video_id
, query
=query
), 'api_response', video_id
)
54 def _get_webpage_metadata(self
, webpage
, video_id
):
55 return self
._parse
_json
(
56 traverse_obj(self
._search
_nextjs
_data
(webpage
, video_id
), ('props', 'pageProps', 'data')),
57 video_id
, fatal
=False)
60 class WeTvEpisodeIE(WeTvBaseIE
):
61 IE_NAME
= 'wetv:episode'
62 _VALID_URL
= WeTvBaseIE
._VALID
_URL
_BASE
+ r
'/(?P<series_id>\w+)(?:-[^?#]+)?/(?P<id>\w+)(?:-[^?#]+)?'
65 'url': 'https://wetv.vip/en/play/air11ooo2rdsdi3-Cute-Programmer/v0040pr89t9-EP1-Cute-Programmer',
66 'md5': 'a046f565c9dce9b263a0465a422cd7bf',
70 'title': 'EP1: Cute Programmer',
71 'description': 'md5:e87beab3bf9f392d6b9e541a63286343',
72 'thumbnail': r
're:^https?://[^?#]+air11ooo2rdsdi3',
73 'series': 'Cute Programmer',
74 'episode': 'Episode 1',
79 'url': 'https://wetv.vip/en/play/u37kgfnfzs73kiu/p0039b9nvik',
80 'md5': '4d9d69bcfd11da61f4aae64fc6b316b3',
84 'title': 'EP1: You Are My Glory',
85 'description': 'md5:831363a4c3b4d7615e1f3854be3a123b',
86 'thumbnail': r
're:^https?://[^?#]+u37kgfnfzs73kiu',
87 'series': 'You Are My Glory',
88 'episode': 'Episode 1',
93 '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',
94 'md5': '71133f5c2d5d6cad3427e1b010488280',
98 'title': 'md5:f7a0857dbe5fbbe2e7ad630b92b54e6a',
99 'description': 'md5:76260cb9cdc0ef76826d7ca9d92fadfa',
100 'thumbnail': r
're:^https?://[^?#]+lcxgwod5hapghvw',
101 'series': 'WeTV PICK-A-BOO',
102 'episode': 'Episode 0',
108 def _extract_video_formats_and_subtitles(self
, api_response
, video_id
, video_quality
):
109 video_response
= api_response
['vl']['vi'][0]
110 video_width
= video_response
.get('vw')
111 video_height
= video_response
.get('vh')
113 formats
, subtitles
= [], {}
114 for video_format
in video_response
['ul']['ui']:
115 if video_format
.get('hls'):
116 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
117 video_format
['url'] + video_format
['hls']['pname'], video_id
, 'mp4', fatal
=False)
119 f
['width'] = video_width
120 f
['height'] = video_height
123 self
._merge
_subtitles
(subs
, target
=subtitles
)
126 'url': f
'{video_format["url"]}{video_response["fn"]}?vkey={video_response["fvkey"]}',
127 'width': video_width
,
128 'height': video_height
,
132 return formats
, subtitles
134 def _extract_video_subtitles(self
, api_response
, subtitles_format
):
136 for subtitle
in traverse_obj(api_response
, ('sfl', 'fi')):
137 subtitles
.setdefault(subtitle
['lang'].lower(), []).append({
138 'url': subtitle
['url'],
139 'ext': subtitles_format
,
140 'protocol': 'm3u8_native' if determine_ext(subtitle
['url']) == 'm3u8' else 'http',
145 def _real_extract(self
, url
):
146 video_id
, series_id
= self
._match
_valid
_url
(url
).group('id', 'series_id')
147 webpage
= self
._download
_webpage
(url
, video_id
)
149 formats
, subtitles
= [], {}
150 for video_format
, subtitle_format
, video_quality
in (('mp4', 'srt', ''), ('hls', 'vtt', 'shd'), ('hls', 'vtt', 'fhd')):
151 api_response
= self
._get
_video
_api
_response
(url
, video_id
, series_id
, subtitle_format
, video_format
, video_quality
)
153 fmts
, subs
= self
._extract
_video
_formats
_and
_subtitles
(api_response
, video_id
, video_quality
)
154 native_subtitles
= self
._extract
_video
_subtitles
(api_response
, subtitle_format
)
157 self
._merge
_subtitles
(subs
, native_subtitles
, target
=subtitles
)
159 self
._sort
_formats
(formats
)
160 webpage_metadata
= self
._get
_webpage
_metadata
(webpage
, video_id
)
164 'title': (self
._og
_search
_title
(webpage
)
165 or traverse_obj(webpage_metadata
, ('coverInfo', 'description'))),
166 'description': (self
._og
_search
_description
(webpage
)
167 or traverse_obj(webpage_metadata
, ('coverInfo', 'description'))),
169 'subtitles': subtitles
,
170 'thumbnail': self
._og
_search
_thumbnail
(webpage
),
171 'duration': int_or_none(traverse_obj(webpage_metadata
, ('videoInfo', 'duration'))),
172 'series': traverse_obj(webpage_metadata
, ('coverInfo', 'title')),
173 'episode_number': int_or_none(traverse_obj(webpage_metadata
, ('videoInfo', 'episode'))),
177 class WeTvSeriesIE(WeTvBaseIE
):
178 _VALID_URL
= WeTvBaseIE
._VALID
_URL
_BASE
+ r
'/(?P<id>\w+)(?:-[^/?#]+)?/?(?:[?#]|$)'
181 'url': 'https://wetv.vip/play/air11ooo2rdsdi3-Cute-Programmer',
183 'id': 'air11ooo2rdsdi3',
184 'title': 'Cute Programmer',
185 'description': 'md5:e87beab3bf9f392d6b9e541a63286343',
187 'playlist_count': 30,
189 'url': 'https://wetv.vip/en/play/u37kgfnfzs73kiu-You-Are-My-Glory',
191 'id': 'u37kgfnfzs73kiu',
192 'title': 'You Are My Glory',
193 'description': 'md5:831363a4c3b4d7615e1f3854be3a123b',
195 'playlist_count': 32,
198 def _real_extract(self
, url
):
199 series_id
= self
._match
_id
(url
)
200 webpage
= self
._download
_webpage
(url
, series_id
)
201 webpage_metadata
= self
._get
_webpage
_metadata
(webpage
, series_id
)
203 episode_paths
= (re
.findall(r
'<a[^>]+class="play-video__link"[^>]+href="(?P<path>[^"]+)', webpage
)
204 or [f
'/{series_id}/{episode["vid"]}' for episode
in webpage_metadata
.get('videoList')])
206 return self
.playlist_from_matches(
207 episode_paths
, series_id
, ie
=WeTvEpisodeIE
,
208 title
=traverse_obj(webpage_metadata
, ('coverInfo', 'title')) or self
._og
_search
_title
(webpage
),
209 description
=traverse_obj(webpage_metadata
, ('coverInfo', 'description')) or self
._og
_search
_description
(webpage
))