]>
Commit | Line | Data |
---|---|---|
ce7f6aa6 | 1 | import functools |
2aab569f E |
2 | import re |
3 | import time | |
4 | ||
5 | from .common import InfoExtractor | |
6 | from ..aes import aes_cbc_encrypt | |
ce7f6aa6 | 7 | from ..utils import bytes_to_intlist, determine_ext, intlist_to_bytes, int_or_none, traverse_obj, urljoin |
2aab569f E |
8 | |
9 | ||
10 | class WeTvBaseIE(InfoExtractor): | |
11 | _VALID_URL_BASE = r'https?://(?:www\.)?wetv\.vip/(?:[^?#]+/)?play' | |
12 | ||
13 | def _get_ckey(self, video_id, url, app_version, platform): | |
14 | ua = self.get_param('http_headers')['User-Agent'] | |
15 | ||
16 | payload = (f'{video_id}|{int(time.time())}|mg3c3b04ba|{app_version}|0000000000000000|' | |
17 | f'{platform}|{url[:48]}|{ua.lower()[:48]}||Mozilla|Netscape|Win32|00|') | |
18 | ||
19 | ciphertext_int_bytes = aes_cbc_encrypt( | |
20 | bytes_to_intlist(bytes(f'|{sum(map(ord, payload))}|{payload}', 'utf-8')), | |
21 | bytes_to_intlist(b'Ok\xda\xa3\x9e/\x8c\xb0\x7f^r-\x9e\xde\xf3\x14'), | |
22 | bytes_to_intlist(b'\x01PJ\xf3V\xe6\x19\xcf.B\xbb\xa6\x8c?p\xf9'), | |
23 | 'whitespace') | |
24 | ||
25 | return intlist_to_bytes(ciphertext_int_bytes).hex() | |
26 | ||
27 | def _get_video_api_response(self, video_url, video_id, series_id, subtitle_format, video_format, video_quality): | |
28 | app_version = '3.5.57' | |
29 | platform = '4830201' | |
30 | ||
31 | ckey = self._get_ckey(video_id, video_url, app_version, platform) | |
32 | query = { | |
33 | 'vid': video_id, | |
34 | 'cid': series_id, | |
35 | 'cKey': ckey, | |
36 | 'encryptVer': '8.1', | |
37 | 'spcaptiontype': '1' if subtitle_format == 'vtt' else '0', # 0 - SRT, 1 - VTT | |
38 | 'sphls': '1' if video_format == 'hls' else '0', # 0 - MP4, 1 - HLS | |
39 | 'defn': video_quality, # '': 480p, 'shd': 720p, 'fhd': 1080p | |
40 | 'spsrt': '1', # Enable subtitles | |
41 | 'sphttps': '1', # Enable HTTPS | |
42 | 'otype': 'json', # Response format: xml, json, | |
43 | 'dtype': '1', | |
44 | 'spwm': '1', | |
45 | 'host': 'wetv.vip', # These three values are needed for SHD | |
46 | 'referer': 'wetv.vip', | |
47 | 'ehost': video_url, | |
48 | 'appVer': app_version, | |
49 | 'platform': platform, | |
50 | } | |
51 | ||
52 | return self._search_json(r'QZOutputJson=', self._download_webpage( | |
53 | 'https://play.wetv.vip/getvinfo', video_id, query=query), 'api_response', video_id) | |
54 | ||
55 | def _get_webpage_metadata(self, webpage, video_id): | |
56 | return self._parse_json( | |
57 | traverse_obj(self._search_nextjs_data(webpage, video_id), ('props', 'pageProps', 'data')), | |
58 | video_id, fatal=False) | |
59 | ||
60 | ||
61 | class WeTvEpisodeIE(WeTvBaseIE): | |
62 | IE_NAME = 'wetv:episode' | |
63 | _VALID_URL = WeTvBaseIE._VALID_URL_BASE + r'/(?P<series_id>\w+)(?:-[^?#]+)?/(?P<id>\w+)(?:-[^?#]+)?' | |
64 | ||
65 | _TESTS = [{ | |
66 | 'url': 'https://wetv.vip/en/play/air11ooo2rdsdi3-Cute-Programmer/v0040pr89t9-EP1-Cute-Programmer', | |
67 | 'md5': 'a046f565c9dce9b263a0465a422cd7bf', | |
68 | 'info_dict': { | |
69 | 'id': 'v0040pr89t9', | |
70 | 'ext': 'mp4', | |
71 | 'title': 'EP1: Cute Programmer', | |
72 | 'description': 'md5:e87beab3bf9f392d6b9e541a63286343', | |
73 | 'thumbnail': r're:^https?://[^?#]+air11ooo2rdsdi3', | |
74 | 'series': 'Cute Programmer', | |
75 | 'episode': 'Episode 1', | |
76 | 'episode_number': 1, | |
77 | 'duration': 2835, | |
78 | }, | |
79 | }, { | |
80 | 'url': 'https://wetv.vip/en/play/u37kgfnfzs73kiu/p0039b9nvik', | |
81 | 'md5': '4d9d69bcfd11da61f4aae64fc6b316b3', | |
82 | 'info_dict': { | |
83 | 'id': 'p0039b9nvik', | |
84 | 'ext': 'mp4', | |
85 | 'title': 'EP1: You Are My Glory', | |
86 | 'description': 'md5:831363a4c3b4d7615e1f3854be3a123b', | |
87 | 'thumbnail': r're:^https?://[^?#]+u37kgfnfzs73kiu', | |
88 | 'series': 'You Are My Glory', | |
89 | 'episode': 'Episode 1', | |
90 | 'episode_number': 1, | |
91 | 'duration': 2454, | |
92 | }, | |
93 | }, { | |
94 | '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', | |
95 | 'md5': '71133f5c2d5d6cad3427e1b010488280', | |
96 | 'info_dict': { | |
97 | 'id': 'i0042y00lxp', | |
98 | 'ext': 'mp4', | |
99 | 'title': 'md5:f7a0857dbe5fbbe2e7ad630b92b54e6a', | |
100 | 'description': 'md5:76260cb9cdc0ef76826d7ca9d92fadfa', | |
101 | 'thumbnail': r're:^https?://[^?#]+lcxgwod5hapghvw', | |
102 | 'series': 'WeTV PICK-A-BOO', | |
103 | 'episode': 'Episode 0', | |
104 | 'episode_number': 0, | |
105 | 'duration': 442, | |
106 | }, | |
107 | }] | |
108 | ||
109 | def _extract_video_formats_and_subtitles(self, api_response, video_id, video_quality): | |
110 | video_response = api_response['vl']['vi'][0] | |
111 | video_width = video_response.get('vw') | |
112 | video_height = video_response.get('vh') | |
113 | ||
114 | formats, subtitles = [], {} | |
115 | for video_format in video_response['ul']['ui']: | |
116 | if video_format.get('hls'): | |
117 | fmts, subs = self._extract_m3u8_formats_and_subtitles( | |
118 | video_format['url'] + video_format['hls']['pname'], video_id, 'mp4', fatal=False) | |
119 | for f in fmts: | |
120 | f['width'] = video_width | |
121 | f['height'] = video_height | |
122 | ||
123 | formats.extend(fmts) | |
124 | self._merge_subtitles(subs, target=subtitles) | |
125 | else: | |
126 | formats.append({ | |
127 | 'url': f'{video_format["url"]}{video_response["fn"]}?vkey={video_response["fvkey"]}', | |
128 | 'width': video_width, | |
129 | 'height': video_height, | |
130 | 'ext': 'mp4', | |
131 | }) | |
132 | ||
133 | return formats, subtitles | |
134 | ||
135 | def _extract_video_subtitles(self, api_response, subtitles_format): | |
136 | subtitles = {} | |
137 | for subtitle in traverse_obj(api_response, ('sfl', 'fi')): | |
138 | subtitles.setdefault(subtitle['lang'].lower(), []).append({ | |
139 | 'url': subtitle['url'], | |
140 | 'ext': subtitles_format, | |
141 | 'protocol': 'm3u8_native' if determine_ext(subtitle['url']) == 'm3u8' else 'http', | |
142 | }) | |
143 | ||
144 | return subtitles | |
145 | ||
146 | def _real_extract(self, url): | |
147 | video_id, series_id = self._match_valid_url(url).group('id', 'series_id') | |
148 | webpage = self._download_webpage(url, video_id) | |
149 | ||
150 | formats, subtitles = [], {} | |
151 | for video_format, subtitle_format, video_quality in (('mp4', 'srt', ''), ('hls', 'vtt', 'shd'), ('hls', 'vtt', 'fhd')): | |
152 | api_response = self._get_video_api_response(url, video_id, series_id, subtitle_format, video_format, video_quality) | |
153 | ||
154 | fmts, subs = self._extract_video_formats_and_subtitles(api_response, video_id, video_quality) | |
155 | native_subtitles = self._extract_video_subtitles(api_response, subtitle_format) | |
156 | ||
157 | formats.extend(fmts) | |
158 | self._merge_subtitles(subs, native_subtitles, target=subtitles) | |
159 | ||
160 | self._sort_formats(formats) | |
161 | webpage_metadata = self._get_webpage_metadata(webpage, video_id) | |
162 | ||
163 | return { | |
164 | 'id': video_id, | |
165 | 'title': (self._og_search_title(webpage) | |
166 | or traverse_obj(webpage_metadata, ('coverInfo', 'description'))), | |
167 | 'description': (self._og_search_description(webpage) | |
168 | or traverse_obj(webpage_metadata, ('coverInfo', 'description'))), | |
169 | 'formats': formats, | |
170 | 'subtitles': subtitles, | |
171 | 'thumbnail': self._og_search_thumbnail(webpage), | |
172 | 'duration': int_or_none(traverse_obj(webpage_metadata, ('videoInfo', 'duration'))), | |
173 | 'series': traverse_obj(webpage_metadata, ('coverInfo', 'title')), | |
174 | 'episode_number': int_or_none(traverse_obj(webpage_metadata, ('videoInfo', 'episode'))), | |
175 | } | |
176 | ||
177 | ||
178 | class WeTvSeriesIE(WeTvBaseIE): | |
179 | _VALID_URL = WeTvBaseIE._VALID_URL_BASE + r'/(?P<id>\w+)(?:-[^/?#]+)?/?(?:[?#]|$)' | |
180 | ||
181 | _TESTS = [{ | |
182 | 'url': 'https://wetv.vip/play/air11ooo2rdsdi3-Cute-Programmer', | |
183 | 'info_dict': { | |
184 | 'id': 'air11ooo2rdsdi3', | |
185 | 'title': 'Cute Programmer', | |
186 | 'description': 'md5:e87beab3bf9f392d6b9e541a63286343', | |
187 | }, | |
188 | 'playlist_count': 30, | |
189 | }, { | |
190 | 'url': 'https://wetv.vip/en/play/u37kgfnfzs73kiu-You-Are-My-Glory', | |
191 | 'info_dict': { | |
192 | 'id': 'u37kgfnfzs73kiu', | |
193 | 'title': 'You Are My Glory', | |
194 | 'description': 'md5:831363a4c3b4d7615e1f3854be3a123b', | |
195 | }, | |
196 | 'playlist_count': 32, | |
197 | }] | |
198 | ||
199 | def _real_extract(self, url): | |
200 | series_id = self._match_id(url) | |
201 | webpage = self._download_webpage(url, series_id) | |
202 | webpage_metadata = self._get_webpage_metadata(webpage, series_id) | |
203 | ||
204 | episode_paths = (re.findall(r'<a[^>]+class="play-video__link"[^>]+href="(?P<path>[^"]+)', webpage) | |
205 | or [f'/{series_id}/{episode["vid"]}' for episode in webpage_metadata.get('videoList')]) | |
206 | ||
207 | return self.playlist_from_matches( | |
ce7f6aa6 | 208 | episode_paths, series_id, ie=WeTvEpisodeIE, getter=functools.partial(urljoin, url), |
2aab569f E |
209 | title=traverse_obj(webpage_metadata, ('coverInfo', 'title')) or self._og_search_title(webpage), |
210 | description=traverse_obj(webpage_metadata, ('coverInfo', 'description')) or self._og_search_description(webpage)) |