]>
Commit | Line | Data |
---|---|---|
ce7f6aa6 | 1 | import functools |
2aab569f E |
2 | import re |
3 | import time | |
4 | ||
5 | from .common import InfoExtractor | |
c6e07cf1 | 6 | from ..aes import aes_cbc_encrypt_bytes |
7 | from ..utils import determine_ext, 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 | ||
c6e07cf1 | 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() | |
2aab569f E |
24 | |
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' | |
27 | platform = '4830201' | |
28 | ||
29 | ckey = self._get_ckey(video_id, video_url, app_version, platform) | |
30 | query = { | |
31 | 'vid': video_id, | |
32 | 'cid': series_id, | |
33 | 'cKey': ckey, | |
34 | 'encryptVer': '8.1', | |
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, | |
41 | 'dtype': '1', | |
42 | 'spwm': '1', | |
43 | 'host': 'wetv.vip', # These three values are needed for SHD | |
44 | 'referer': 'wetv.vip', | |
45 | 'ehost': video_url, | |
46 | 'appVer': app_version, | |
47 | 'platform': platform, | |
48 | } | |
49 | ||
50 | return self._search_json(r'QZOutputJson=', self._download_webpage( | |
51 | 'https://play.wetv.vip/getvinfo', video_id, query=query), 'api_response', video_id) | |
52 | ||
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) | |
57 | ||
58 | ||
59 | class WeTvEpisodeIE(WeTvBaseIE): | |
60 | IE_NAME = 'wetv:episode' | |
61 | _VALID_URL = WeTvBaseIE._VALID_URL_BASE + r'/(?P<series_id>\w+)(?:-[^?#]+)?/(?P<id>\w+)(?:-[^?#]+)?' | |
62 | ||
63 | _TESTS = [{ | |
64 | 'url': 'https://wetv.vip/en/play/air11ooo2rdsdi3-Cute-Programmer/v0040pr89t9-EP1-Cute-Programmer', | |
65 | 'md5': 'a046f565c9dce9b263a0465a422cd7bf', | |
66 | 'info_dict': { | |
67 | 'id': 'v0040pr89t9', | |
68 | 'ext': 'mp4', | |
69 | 'title': 'EP1: Cute Programmer', | |
70 | 'description': 'md5:e87beab3bf9f392d6b9e541a63286343', | |
71 | 'thumbnail': r're:^https?://[^?#]+air11ooo2rdsdi3', | |
72 | 'series': 'Cute Programmer', | |
73 | 'episode': 'Episode 1', | |
74 | 'episode_number': 1, | |
75 | 'duration': 2835, | |
76 | }, | |
77 | }, { | |
78 | 'url': 'https://wetv.vip/en/play/u37kgfnfzs73kiu/p0039b9nvik', | |
79 | 'md5': '4d9d69bcfd11da61f4aae64fc6b316b3', | |
80 | 'info_dict': { | |
81 | 'id': 'p0039b9nvik', | |
82 | 'ext': 'mp4', | |
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', | |
88 | 'episode_number': 1, | |
89 | 'duration': 2454, | |
90 | }, | |
91 | }, { | |
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', | |
94 | 'info_dict': { | |
95 | 'id': 'i0042y00lxp', | |
96 | 'ext': 'mp4', | |
97 | 'title': 'md5:f7a0857dbe5fbbe2e7ad630b92b54e6a', | |
98 | 'description': 'md5:76260cb9cdc0ef76826d7ca9d92fadfa', | |
99 | 'thumbnail': r're:^https?://[^?#]+lcxgwod5hapghvw', | |
100 | 'series': 'WeTV PICK-A-BOO', | |
101 | 'episode': 'Episode 0', | |
102 | 'episode_number': 0, | |
103 | 'duration': 442, | |
104 | }, | |
105 | }] | |
106 | ||
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') | |
111 | ||
112 | formats, subtitles = [], {} | |
113 | for video_format in video_response['ul']['ui']: | |
114 | if video_format.get('hls'): | |
115 | fmts, subs = self._extract_m3u8_formats_and_subtitles( | |
116 | video_format['url'] + video_format['hls']['pname'], video_id, 'mp4', fatal=False) | |
117 | for f in fmts: | |
118 | f['width'] = video_width | |
119 | f['height'] = video_height | |
120 | ||
121 | formats.extend(fmts) | |
122 | self._merge_subtitles(subs, target=subtitles) | |
123 | else: | |
124 | formats.append({ | |
125 | 'url': f'{video_format["url"]}{video_response["fn"]}?vkey={video_response["fvkey"]}', | |
126 | 'width': video_width, | |
127 | 'height': video_height, | |
128 | 'ext': 'mp4', | |
129 | }) | |
130 | ||
131 | return formats, subtitles | |
132 | ||
133 | def _extract_video_subtitles(self, api_response, subtitles_format): | |
134 | subtitles = {} | |
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', | |
140 | }) | |
141 | ||
142 | return subtitles | |
143 | ||
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) | |
147 | ||
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) | |
151 | ||
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) | |
154 | ||
155 | formats.extend(fmts) | |
156 | self._merge_subtitles(subs, native_subtitles, target=subtitles) | |
157 | ||
158 | self._sort_formats(formats) | |
159 | webpage_metadata = self._get_webpage_metadata(webpage, video_id) | |
160 | ||
161 | return { | |
162 | 'id': 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'))), | |
167 | 'formats': formats, | |
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'))), | |
173 | } | |
174 | ||
175 | ||
176 | class WeTvSeriesIE(WeTvBaseIE): | |
177 | _VALID_URL = WeTvBaseIE._VALID_URL_BASE + r'/(?P<id>\w+)(?:-[^/?#]+)?/?(?:[?#]|$)' | |
178 | ||
179 | _TESTS = [{ | |
180 | 'url': 'https://wetv.vip/play/air11ooo2rdsdi3-Cute-Programmer', | |
181 | 'info_dict': { | |
182 | 'id': 'air11ooo2rdsdi3', | |
183 | 'title': 'Cute Programmer', | |
184 | 'description': 'md5:e87beab3bf9f392d6b9e541a63286343', | |
185 | }, | |
186 | 'playlist_count': 30, | |
187 | }, { | |
188 | 'url': 'https://wetv.vip/en/play/u37kgfnfzs73kiu-You-Are-My-Glory', | |
189 | 'info_dict': { | |
190 | 'id': 'u37kgfnfzs73kiu', | |
191 | 'title': 'You Are My Glory', | |
192 | 'description': 'md5:831363a4c3b4d7615e1f3854be3a123b', | |
193 | }, | |
194 | 'playlist_count': 32, | |
195 | }] | |
196 | ||
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) | |
201 | ||
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')]) | |
204 | ||
205 | return self.playlist_from_matches( | |
ce7f6aa6 | 206 | episode_paths, series_id, ie=WeTvEpisodeIE, getter=functools.partial(urljoin, url), |
2aab569f E |
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)) |