]>
Commit | Line | Data |
---|---|---|
7b1e8079 RA |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
2181983a | 4 | from .youtube import YoutubeIE |
7b1e8079 RA |
5 | from ..utils import ( |
6 | ExtractorError, | |
7 | int_or_none, | |
8 | str_or_none, | |
9 | ) | |
10 | ||
11 | ||
12 | class VVVVIDIE(InfoExtractor): | |
29f7c58a | 13 | _VALID_URL_BASE = r'https?://(?:www\.)?vvvvid\.it/(?:#!)?(?:show|anime|film|series)/' |
14 | _VALID_URL = r'%s(?P<show_id>\d+)/[^/]+/(?P<season_id>\d+)/(?P<id>[0-9]+)' % _VALID_URL_BASE | |
7b1e8079 RA |
15 | _TESTS = [{ |
16 | # video_type == 'video/vvvvid' | |
17 | 'url': 'https://www.vvvvid.it/#!show/434/perche-dovrei-guardarlo-di-dario-moccia/437/489048/ping-pong', | |
18 | 'md5': 'b8d3cecc2e981adc3835adf07f6df91b', | |
19 | 'info_dict': { | |
20 | 'id': '489048', | |
21 | 'ext': 'mp4', | |
22 | 'title': 'Ping Pong', | |
29f7c58a | 23 | 'duration': 239, |
24 | 'series': '"Perché dovrei guardarlo?" di Dario Moccia', | |
25 | 'season_id': '437', | |
26 | 'episode': 'Ping Pong', | |
27 | 'episode_number': 1, | |
28 | 'episode_id': '3334', | |
29 | 'view_count': int, | |
30 | 'like_count': int, | |
31 | 'repost_count': int, | |
7b1e8079 | 32 | }, |
fb61b57d RA |
33 | 'params': { |
34 | 'skip_download': True, | |
35 | }, | |
7b1e8079 RA |
36 | }, { |
37 | # video_type == 'video/rcs' | |
38 | 'url': 'https://www.vvvvid.it/#!show/376/death-note-live-action/377/482493/episodio-01', | |
39 | 'md5': '33e0edfba720ad73a8782157fdebc648', | |
40 | 'info_dict': { | |
41 | 'id': '482493', | |
42 | 'ext': 'mp4', | |
43 | 'title': 'Episodio 01', | |
44 | }, | |
fb61b57d RA |
45 | 'params': { |
46 | 'skip_download': True, | |
47 | }, | |
2181983a | 48 | }, { |
49 | # video_type == 'video/youtube' | |
50 | 'url': 'https://www.vvvvid.it/show/404/one-punch-man/406/486683/trailer', | |
51 | 'md5': '33e0edfba720ad73a8782157fdebc648', | |
52 | 'info_dict': { | |
53 | 'id': 'RzmFKUDOUgw', | |
54 | 'ext': 'mp4', | |
55 | 'title': 'Trailer', | |
56 | 'upload_date': '20150906', | |
57 | 'description': 'md5:a5e802558d35247fee285875328c0b80', | |
58 | 'uploader_id': 'BandaiVisual', | |
59 | 'uploader': 'BANDAI NAMCO Arts Channel', | |
60 | }, | |
61 | 'params': { | |
62 | 'skip_download': True, | |
63 | }, | |
29f7c58a | 64 | }, { |
65 | 'url': 'https://www.vvvvid.it/show/434/perche-dovrei-guardarlo-di-dario-moccia/437/489048', | |
66 | 'only_matching': True | |
7b1e8079 RA |
67 | }] |
68 | _conn_id = None | |
69 | ||
70 | def _real_initialize(self): | |
dc1f3a9f RA |
71 | self._conn_id = self._download_json( |
72 | 'https://www.vvvvid.it/user/login', | |
73 | None, headers=self.geo_verification_headers())['data']['conn_id'] | |
7b1e8079 | 74 | |
ec5e77c5 | 75 | def _download_info(self, show_id, path, video_id, fatal=True, query=None): |
76 | q = { | |
77 | 'conn_id': self._conn_id, | |
78 | } | |
79 | if query: | |
80 | q.update(query) | |
7b1e8079 | 81 | response = self._download_json( |
29f7c58a | 82 | 'https://www.vvvvid.it/vvvvid/ondemand/%s/%s' % (show_id, path), |
ec5e77c5 | 83 | video_id, headers=self.geo_verification_headers(), query=q, fatal=fatal) |
29f7c58a | 84 | if not (response or fatal): |
85 | return | |
86 | if response.get('result') == 'error': | |
7b1e8079 RA |
87 | raise ExtractorError('%s said: %s' % ( |
88 | self.IE_NAME, response['message']), expected=True) | |
29f7c58a | 89 | return response['data'] |
90 | ||
91 | def _extract_common_video_info(self, video_data): | |
92 | return { | |
93 | 'thumbnail': video_data.get('thumbnail'), | |
94 | 'episode_id': str_or_none(video_data.get('id')), | |
95 | } | |
96 | ||
97 | def _real_extract(self, url): | |
5ad28e7f | 98 | show_id, season_id, video_id = self._match_valid_url(url).groups() |
29f7c58a | 99 | |
100 | response = self._download_info( | |
ec5e77c5 | 101 | show_id, 'season/%s' % season_id, |
102 | video_id, query={'video_id': video_id}) | |
7b1e8079 RA |
103 | |
104 | vid = int(video_id) | |
105 | video_data = list(filter( | |
29f7c58a | 106 | lambda episode: episode.get('video_id') == vid, response))[0] |
107 | title = video_data['title'] | |
7b1e8079 RA |
108 | formats = [] |
109 | ||
110 | # vvvvid embed_info decryption algorithm is reverse engineered from function $ds(h) at vvvvid.js | |
111 | def ds(h): | |
112 | g = "MNOPIJKL89+/4567UVWXQRSTEFGHABCDcdefYZabstuvopqr0123wxyzklmnghij" | |
113 | ||
114 | def f(m): | |
115 | l = [] | |
116 | o = 0 | |
117 | b = False | |
118 | m_len = len(m) | |
119 | while ((not b) and o < m_len): | |
120 | n = m[o] << 2 | |
121 | o += 1 | |
122 | k = -1 | |
123 | j = -1 | |
124 | if o < m_len: | |
125 | n += m[o] >> 4 | |
126 | o += 1 | |
127 | if o < m_len: | |
128 | k = (m[o - 1] << 4) & 255 | |
129 | k += m[o] >> 2 | |
130 | o += 1 | |
131 | if o < m_len: | |
132 | j = (m[o - 1] << 6) & 255 | |
133 | j += m[o] | |
134 | o += 1 | |
135 | else: | |
136 | b = True | |
137 | else: | |
138 | b = True | |
139 | else: | |
140 | b = True | |
141 | l.append(n) | |
142 | if k != -1: | |
143 | l.append(k) | |
144 | if j != -1: | |
145 | l.append(j) | |
146 | return l | |
147 | ||
148 | c = [] | |
149 | for e in h: | |
150 | c.append(g.index(e)) | |
151 | ||
152 | c_len = len(c) | |
153 | for e in range(c_len * 2 - 1, -1, -1): | |
154 | a = c[e % c_len] ^ c[(e + 1) % c_len] | |
155 | c[e % c_len] = a | |
156 | ||
157 | c = f(c) | |
158 | d = '' | |
159 | for e in c: | |
160 | d += chr(e) | |
161 | ||
162 | return d | |
163 | ||
29f7c58a | 164 | info = {} |
165 | ||
166 | def metadata_from_url(r_url): | |
167 | if not info and r_url: | |
168 | mobj = re.search(r'_(?:S(\d+))?Ep(\d+)', r_url) | |
169 | if mobj: | |
170 | info['episode_number'] = int(mobj.group(2)) | |
171 | season_number = mobj.group(1) | |
172 | if season_number: | |
173 | info['season_number'] = int(season_number) | |
174 | ||
2181983a | 175 | video_type = video_data.get('video_type') |
176 | is_youtube = False | |
177 | for quality in ('', '_sd'): | |
7b1e8079 RA |
178 | embed_code = video_data.get('embed_info' + quality) |
179 | if not embed_code: | |
180 | continue | |
181 | embed_code = ds(embed_code) | |
421a4595 | 182 | if video_type == 'video/kenc': |
183 | embed_code = re.sub(r'https?(://[^/]+)/z/', r'https\1/i/', embed_code).replace('/manifest.f4m', '/master.m3u8') | |
184 | kenc = self._download_json( | |
185 | 'https://www.vvvvid.it/kenc', video_id, query={ | |
186 | 'action': 'kt', | |
187 | 'conn_id': self._conn_id, | |
188 | 'url': embed_code, | |
189 | }, fatal=False) or {} | |
190 | kenc_message = kenc.get('message') | |
191 | if kenc_message: | |
192 | embed_code += '?' + ds(kenc_message) | |
193 | formats.extend(self._extract_m3u8_formats( | |
194 | embed_code, video_id, 'mp4', m3u8_id='hls', fatal=False)) | |
195 | elif video_type == 'video/rcs': | |
29f7c58a | 196 | formats.extend(self._extract_akamai_formats(embed_code, video_id)) |
2181983a | 197 | elif video_type == 'video/youtube': |
198 | info.update({ | |
199 | '_type': 'url_transparent', | |
200 | 'ie_key': YoutubeIE.ie_key(), | |
201 | 'url': embed_code, | |
202 | }) | |
203 | is_youtube = True | |
204 | break | |
7b1e8079 RA |
205 | else: |
206 | formats.extend(self._extract_wowza_formats( | |
207 | 'http://sb.top-ix.org/videomg/_definst_/mp4:%s/playlist.m3u8' % embed_code, video_id)) | |
29f7c58a | 208 | metadata_from_url(embed_code) |
209 | ||
2181983a | 210 | if not is_youtube: |
211 | self._sort_formats(formats) | |
212 | info['formats'] = formats | |
7b1e8079 | 213 | |
29f7c58a | 214 | metadata_from_url(video_data.get('thumbnail')) |
215 | info.update(self._extract_common_video_info(video_data)) | |
216 | info.update({ | |
7b1e8079 | 217 | 'id': video_id, |
29f7c58a | 218 | 'title': title, |
7b1e8079 RA |
219 | 'duration': int_or_none(video_data.get('length')), |
220 | 'series': video_data.get('show_title'), | |
221 | 'season_id': season_id, | |
29f7c58a | 222 | 'episode': title, |
7b1e8079 RA |
223 | 'view_count': int_or_none(video_data.get('views')), |
224 | 'like_count': int_or_none(video_data.get('video_likes')), | |
29f7c58a | 225 | 'repost_count': int_or_none(video_data.get('video_shares')), |
226 | }) | |
227 | return info | |
228 | ||
229 | ||
230 | class VVVVIDShowIE(VVVVIDIE): | |
231 | _VALID_URL = r'(?P<base_url>%s(?P<id>\d+)(?:/(?P<show_title>[^/?&#]+))?)/?(?:[?#&]|$)' % VVVVIDIE._VALID_URL_BASE | |
232 | _TESTS = [{ | |
233 | 'url': 'https://www.vvvvid.it/show/156/psyco-pass', | |
234 | 'info_dict': { | |
235 | 'id': '156', | |
236 | 'title': 'Psycho-Pass', | |
237 | 'description': 'md5:94d572c0bd85894b193b8aebc9a3a806', | |
238 | }, | |
239 | 'playlist_count': 46, | |
240 | }, { | |
241 | 'url': 'https://www.vvvvid.it/show/156', | |
242 | 'only_matching': True, | |
243 | }] | |
244 | ||
245 | def _real_extract(self, url): | |
5ad28e7f | 246 | base_url, show_id, show_title = self._match_valid_url(url).groups() |
29f7c58a | 247 | |
248 | seasons = self._download_info( | |
249 | show_id, 'seasons/', show_title) | |
250 | ||
251 | show_info = self._download_info( | |
252 | show_id, 'info/', show_title, fatal=False) | |
253 | ||
ec5e77c5 | 254 | if not show_title: |
255 | base_url += "/title" | |
256 | ||
29f7c58a | 257 | entries = [] |
258 | for season in (seasons or []): | |
259 | episodes = season.get('episodes') or [] | |
ec5e77c5 | 260 | playlist_title = season.get('name') or show_info.get('title') |
29f7c58a | 261 | for episode in episodes: |
262 | if episode.get('playable') is False: | |
263 | continue | |
264 | season_id = str_or_none(episode.get('season_id')) | |
265 | video_id = str_or_none(episode.get('video_id')) | |
266 | if not (season_id and video_id): | |
267 | continue | |
268 | info = self._extract_common_video_info(episode) | |
269 | info.update({ | |
ec5e77c5 | 270 | '_type': 'url_transparent', |
29f7c58a | 271 | 'ie_key': VVVVIDIE.ie_key(), |
272 | 'url': '/'.join([base_url, season_id, video_id]), | |
273 | 'title': episode.get('title'), | |
274 | 'description': episode.get('description'), | |
275 | 'season_id': season_id, | |
ec5e77c5 | 276 | 'playlist_title': playlist_title, |
29f7c58a | 277 | }) |
278 | entries.append(info) | |
279 | ||
280 | return self.playlist_result( | |
281 | entries, show_id, show_info.get('title'), show_info.get('description')) |