]>
Commit | Line | Data |
---|---|---|
22979993 | 1 | # coding: utf-8 |
1fe8fb8c | 2 | from __future__ import unicode_literals |
1fe8fb8c | 3 | |
0a477f87 | 4 | import re |
b811b4c9 RA |
5 | import time |
6 | import hashlib | |
7 | import json | |
86c8cfc5 | 8 | import random |
0a477f87 | 9 | |
b811b4c9 | 10 | from .adobepass import AdobePassIE |
5113b691 | 11 | from .youtube import YoutubeIE |
1fe8fb8c | 12 | from .common import InfoExtractor |
86c8cfc5 S |
13 | from ..compat import ( |
14 | compat_HTTPError, | |
15 | compat_str, | |
16 | ) | |
b811b4c9 | 17 | from ..utils import ( |
86c8cfc5 | 18 | ExtractorError, |
b811b4c9 RA |
19 | int_or_none, |
20 | parse_age_limit, | |
21 | str_or_none, | |
86c8cfc5 | 22 | try_get, |
b811b4c9 | 23 | ) |
1fe8fb8c JMF |
24 | |
25 | ||
86c8cfc5 S |
26 | class ViceIE(AdobePassIE): |
27 | IE_NAME = 'vice' | |
28 | _VALID_URL = r'https?://(?:(?:video|vms)\.vice|(?:www\.)?viceland)\.com/(?P<locale>[^/]+)/(?:video/[^/]+|embed)/(?P<id>[\da-f]+)' | |
29 | _TESTS = [{ | |
30 | 'url': 'https://video.vice.com/en_us/video/pet-cremator/58c69e38a55424f1227dc3f7', | |
31 | 'info_dict': { | |
32 | 'id': '5e647f0125e145c9aef2069412c0cbde', | |
33 | 'ext': 'mp4', | |
34 | 'title': '10 Questions You Always Wanted To Ask: Pet Cremator', | |
35 | 'description': 'md5:fe856caacf61fe0e74fab15ce2b07ca5', | |
36 | 'uploader': 'vice', | |
37 | 'uploader_id': '57a204088cb727dec794c67b', | |
38 | 'timestamp': 1489664942, | |
39 | 'upload_date': '20170316', | |
40 | 'age_limit': 14, | |
41 | }, | |
42 | 'params': { | |
43 | # m3u8 download | |
44 | 'skip_download': True, | |
45 | }, | |
46 | 'add_ie': ['UplynkPreplay'], | |
47 | }, { | |
48 | # geo restricted to US | |
49 | 'url': 'https://video.vice.com/en_us/video/the-signal-from-tolva/5816510690b70e6c5fd39a56', | |
50 | 'info_dict': { | |
51 | 'id': '930c0ad1f47141cc955087eecaddb0e2', | |
52 | 'ext': 'mp4', | |
53 | 'uploader': 'waypoint', | |
54 | 'title': 'The Signal From Tölva', | |
55 | 'description': 'md5:3927e3c79f9e8094606a2b3c5b5e55d5', | |
56 | 'uploader_id': '57f7d621e05ca860fa9ccaf9', | |
57 | 'timestamp': 1477941983, | |
58 | 'upload_date': '20161031', | |
59 | }, | |
60 | 'params': { | |
61 | # m3u8 download | |
62 | 'skip_download': True, | |
63 | }, | |
64 | 'add_ie': ['UplynkPreplay'], | |
65 | }, { | |
66 | 'url': 'https://video.vice.com/alps/video/ulfs-wien-beruchtigste-grafitti-crew-part-1/581b12b60a0e1f4c0fb6ea2f', | |
67 | 'info_dict': { | |
68 | 'id': '581b12b60a0e1f4c0fb6ea2f', | |
69 | 'ext': 'mp4', | |
70 | 'title': 'ULFs - Wien berüchtigste Grafitti Crew - Part 1', | |
71 | 'description': '<p>Zwischen Hinterzimmer-Tattoos und U-Bahnschächten erzählen uns die Ulfs, wie es ist, "süchtig nach Sachbeschädigung" zu sein.</p>', | |
72 | 'uploader': 'VICE', | |
73 | 'uploader_id': '57a204088cb727dec794c67b', | |
74 | 'timestamp': 1485368119, | |
75 | 'upload_date': '20170125', | |
76 | 'age_limit': 14, | |
77 | }, | |
78 | 'params': { | |
79 | # AES-encrypted m3u8 | |
80 | 'skip_download': True, | |
81 | 'proxy': '127.0.0.1:8118', | |
82 | }, | |
83 | 'add_ie': ['UplynkPreplay'], | |
84 | }, { | |
85 | 'url': 'https://video.vice.com/en_us/video/pizza-show-trailer/56d8c9a54d286ed92f7f30e4', | |
86 | 'only_matching': True, | |
87 | }, { | |
88 | 'url': 'https://video.vice.com/en_us/embed/57f41d3556a0a80f54726060', | |
89 | 'only_matching': True, | |
90 | }, { | |
91 | 'url': 'https://vms.vice.com/en_us/video/preplay/58c69e38a55424f1227dc3f7', | |
92 | 'only_matching': True, | |
93 | }, { | |
94 | 'url': 'https://www.viceland.com/en_us/video/thursday-march-1-2018/5a8f2d7ff1cdb332dd446ec1', | |
95 | 'only_matching': True, | |
96 | }] | |
97 | _PREPLAY_HOST = 'vms.vice' | |
98 | ||
99 | @staticmethod | |
100 | def _extract_urls(webpage): | |
101 | return re.findall( | |
102 | r'<iframe\b[^>]+\bsrc=["\']((?:https?:)?//video\.vice\.com/[^/]+/embed/[\da-f]+)', | |
103 | webpage) | |
104 | ||
105 | @staticmethod | |
106 | def _extract_url(webpage): | |
107 | urls = ViceIE._extract_urls(webpage) | |
108 | return urls[0] if urls else None | |
109 | ||
110 | def _real_extract(self, url): | |
111 | locale, video_id = re.match(self._VALID_URL, url).groups() | |
112 | ||
113 | webpage = self._download_webpage( | |
114 | 'https://video.vice.com/%s/embed/%s' % (locale, video_id), | |
115 | video_id) | |
116 | ||
117 | video = self._parse_json( | |
118 | self._search_regex( | |
119 | r'PREFETCH_DATA\s*=\s*({.+?})\s*;\s*\n', webpage, | |
120 | 'app state'), video_id)['video'] | |
121 | video_id = video.get('vms_id') or video.get('id') or video_id | |
122 | title = video['title'] | |
123 | is_locked = video.get('locked') | |
124 | rating = video.get('rating') | |
125 | thumbnail = video.get('thumbnail_url') | |
126 | duration = int_or_none(video.get('duration')) | |
127 | series = try_get( | |
128 | video, lambda x: x['episode']['season']['show']['title'], | |
129 | compat_str) | |
130 | episode_number = try_get( | |
131 | video, lambda x: x['episode']['episode_number']) | |
132 | season_number = try_get( | |
133 | video, lambda x: x['episode']['season']['season_number']) | |
134 | uploader = None | |
b811b4c9 RA |
135 | |
136 | query = {} | |
b811b4c9 RA |
137 | if is_locked: |
138 | resource = self._get_mvpd_resource( | |
86c8cfc5 | 139 | 'VICELAND', title, video_id, rating) |
1d9e0a4f RA |
140 | query['tvetoken'] = self._extract_mvpd_auth( |
141 | url, video_id, 'VICELAND', resource) | |
b811b4c9 RA |
142 | |
143 | # signature generation algorithm is reverse engineered from signatureGenerator in | |
144 | # webpack:///../shared/~/vice-player/dist/js/vice-player.js in | |
145 | # https://www.viceland.com/assets/common/js/web.vendor.bundle.js | |
86c8cfc5 S |
146 | # new JS is located here https://vice-web-statics-cdn.vice.com/vice-player/player-embed.js |
147 | exp = int(time.time()) + 1440 | |
148 | ||
b811b4c9 RA |
149 | query.update({ |
150 | 'exp': exp, | |
151 | 'sign': hashlib.sha512(('%s:GET:%d' % (video_id, exp)).encode()).hexdigest(), | |
86c8cfc5 S |
152 | '_ad_blocked': None, |
153 | '_ad_unit': '', | |
154 | '_debug': '', | |
155 | 'platform': 'desktop', | |
156 | 'rn': random.randint(10000, 100000), | |
157 | 'fbprebidtoken': '', | |
b811b4c9 RA |
158 | }) |
159 | ||
160 | try: | |
161 | host = 'www.viceland' if is_locked else self._PREPLAY_HOST | |
1d9e0a4f | 162 | preplay = self._download_json( |
86c8cfc5 | 163 | 'https://%s.com/%s/video/preplay/%s' % (host, locale, video_id), |
1d9e0a4f | 164 | video_id, query=query) |
b811b4c9 | 165 | except ExtractorError as e: |
86c8cfc5 | 166 | if isinstance(e.cause, compat_HTTPError) and e.cause.code in (400, 401): |
b811b4c9 | 167 | error = json.loads(e.cause.read().decode()) |
86c8cfc5 | 168 | error_message = error.get('error_description') or error['details'] |
1d9e0a4f | 169 | raise ExtractorError('%s said: %s' % ( |
86c8cfc5 | 170 | self.IE_NAME, error_message), expected=True) |
b811b4c9 RA |
171 | raise |
172 | ||
173 | video_data = preplay['video'] | |
174 | base = video_data['base'] | |
175 | uplynk_preplay_url = preplay['preplayURL'] | |
176 | episode = video_data.get('episode', {}) | |
177 | channel = video_data.get('channel', {}) | |
178 | ||
179 | subtitles = {} | |
180 | cc_url = preplay.get('ccURL') | |
181 | if cc_url: | |
182 | subtitles['en'] = [{ | |
183 | 'url': cc_url, | |
184 | }] | |
185 | ||
186 | return { | |
187 | '_type': 'url_transparent', | |
188 | 'url': uplynk_preplay_url, | |
189 | 'id': video_id, | |
190 | 'title': title, | |
70bcc444 | 191 | 'description': base.get('body') or base.get('display_body'), |
86c8cfc5 S |
192 | 'thumbnail': thumbnail, |
193 | 'duration': int_or_none(video_data.get('video_duration')) or duration, | |
70bcc444 | 194 | 'timestamp': int_or_none(video_data.get('created_at'), 1000), |
b811b4c9 | 195 | 'age_limit': parse_age_limit(video_data.get('video_rating')), |
86c8cfc5 S |
196 | 'series': video_data.get('show_title') or series, |
197 | 'episode_number': int_or_none(episode.get('episode_number') or episode_number), | |
b811b4c9 | 198 | 'episode_id': str_or_none(episode.get('id') or video_data.get('episode_id')), |
86c8cfc5 | 199 | 'season_number': int_or_none(season_number), |
b811b4c9 | 200 | 'season_id': str_or_none(episode.get('season_id')), |
86c8cfc5 | 201 | 'uploader': channel.get('base', {}).get('title') or channel.get('name') or uploader, |
b811b4c9 RA |
202 | 'uploader_id': str_or_none(channel.get('id')), |
203 | 'subtitles': subtitles, | |
204 | 'ie_key': 'UplynkPreplay', | |
205 | } | |
206 | ||
207 | ||
0a477f87 | 208 | class ViceShowIE(InfoExtractor): |
1d9e0a4f | 209 | IE_NAME = 'vice:show' |
0a477f87 S |
210 | _VALID_URL = r'https?://(?:.+?\.)?vice\.com/(?:[^/]+/)?show/(?P<id>[^/?#&]+)' |
211 | ||
212 | _TEST = { | |
213 | 'url': 'https://munchies.vice.com/en/show/fuck-thats-delicious-2', | |
214 | 'info_dict': { | |
215 | 'id': 'fuck-thats-delicious-2', | |
216 | 'title': "Fuck, That's Delicious", | |
217 | 'description': 'Follow the culinary adventures of rapper Action Bronson during his ongoing world tour.', | |
218 | }, | |
219 | 'playlist_count': 17, | |
220 | } | |
221 | ||
222 | def _real_extract(self, url): | |
223 | show_id = self._match_id(url) | |
224 | webpage = self._download_webpage(url, show_id) | |
225 | ||
226 | entries = [ | |
227 | self.url_result(video_url, ViceIE.ie_key()) | |
228 | for video_url, _ in re.findall( | |
229 | r'<h2[^>]+class="article-title"[^>]+data-id="\d+"[^>]*>\s*<a[^>]+href="(%s.*?)"' | |
230 | % ViceIE._VALID_URL, webpage)] | |
231 | ||
232 | title = self._search_regex( | |
233 | r'<title>(.+?)</title>', webpage, 'title', default=None) | |
234 | if title: | |
235 | title = re.sub(r'(.+)\s*\|\s*.+$', r'\1', title).strip() | |
1d9e0a4f RA |
236 | description = self._html_search_meta( |
237 | 'description', webpage, 'description') | |
0a477f87 S |
238 | |
239 | return self.playlist_result(entries, show_id, title, description) | |
4ac6dc37 YCH |
240 | |
241 | ||
242 | class ViceArticleIE(InfoExtractor): | |
1d9e0a4f | 243 | IE_NAME = 'vice:article' |
197224b7 | 244 | _VALID_URL = r'https://www\.vice\.com/[^/]+/article/(?P<id>[^?#]+)' |
4ac6dc37 YCH |
245 | |
246 | _TESTS = [{ | |
247 | 'url': 'https://www.vice.com/en_us/article/on-set-with-the-woman-making-mormon-porn-in-utah', | |
248 | 'info_dict': { | |
86c8cfc5 | 249 | 'id': '41eae2a47b174a1398357cec55f1f6fc', |
4ac6dc37 YCH |
250 | 'ext': 'mp4', |
251 | 'title': 'Mormon War on Porn ', | |
86c8cfc5 S |
252 | 'description': 'md5:6394a8398506581d0346b9ab89093fef', |
253 | 'uploader': 'vice', | |
254 | 'uploader_id': '57a204088cb727dec794c67b', | |
255 | 'timestamp': 1491883129, | |
256 | 'upload_date': '20170411', | |
257 | 'age_limit': 17, | |
4ac6dc37 YCH |
258 | }, |
259 | 'params': { | |
260 | # AES-encrypted m3u8 | |
261 | 'skip_download': True, | |
262 | }, | |
1d9e0a4f | 263 | 'add_ie': ['UplynkPreplay'], |
4ac6dc37 | 264 | }, { |
1d9e0a4f | 265 | 'url': 'https://www.vice.com/en_us/article/how-to-hack-a-car', |
86c8cfc5 | 266 | 'md5': '7fe8ebc4fa3323efafc127b82bd821d9', |
4ac6dc37 YCH |
267 | 'info_dict': { |
268 | 'id': '3jstaBeXgAs', | |
269 | 'ext': 'mp4', | |
270 | 'title': 'How to Hack a Car: Phreaked Out (Episode 2)', | |
271 | 'description': 'md5:ee95453f7ff495db8efe14ae8bf56f30', | |
4ac6dc37 | 272 | 'uploader': 'Motherboard', |
86c8cfc5 | 273 | 'uploader_id': 'MotherboardTV', |
4ac6dc37 YCH |
274 | 'upload_date': '20140529', |
275 | }, | |
276 | 'add_ie': ['Youtube'], | |
86c8cfc5 S |
277 | }, { |
278 | 'url': 'https://www.vice.com/en_us/article/znm9dx/karley-sciortino-slutever-reloaded', | |
279 | 'md5': 'a7ecf64ee4fa19b916c16f4b56184ae2', | |
280 | 'info_dict': { | |
281 | 'id': 'e2ed435eb67e43efb66e6ef9a6930a88', | |
282 | 'ext': 'mp4', | |
283 | 'title': "Making The World's First Male Sex Doll", | |
284 | 'description': 'md5:916078ef0e032d76343116208b6cc2c4', | |
285 | 'uploader': 'vice', | |
286 | 'uploader_id': '57a204088cb727dec794c67b', | |
287 | 'timestamp': 1476919911, | |
288 | 'upload_date': '20161019', | |
289 | 'age_limit': 17, | |
290 | }, | |
291 | 'params': { | |
292 | 'skip_download': True, | |
293 | }, | |
294 | 'add_ie': [ViceIE.ie_key()], | |
1d9e0a4f RA |
295 | }, { |
296 | 'url': 'https://www.vice.com/en_us/article/cowboy-capitalists-part-1', | |
297 | 'only_matching': True, | |
298 | }, { | |
299 | 'url': 'https://www.vice.com/ru/article/big-night-out-ibiza-clive-martin-229', | |
300 | 'only_matching': True, | |
4ac6dc37 YCH |
301 | }] |
302 | ||
303 | def _real_extract(self, url): | |
304 | display_id = self._match_id(url) | |
305 | ||
306 | webpage = self._download_webpage(url, display_id) | |
307 | ||
308 | prefetch_data = self._parse_json(self._search_regex( | |
86c8cfc5 S |
309 | r'__APP_STATE\s*=\s*({.+?})(?:\s*\|\|\s*{}\s*)?;\s*\n', |
310 | webpage, 'app state'), display_id)['pageData'] | |
4ac6dc37 | 311 | body = prefetch_data['body'] |
1d9e0a4f RA |
312 | |
313 | def _url_res(video_url, ie_key): | |
4ac6dc37 YCH |
314 | return { |
315 | '_type': 'url_transparent', | |
1d9e0a4f | 316 | 'url': video_url, |
4ac6dc37 | 317 | 'display_id': display_id, |
1d9e0a4f | 318 | 'ie_key': ie_key, |
4ac6dc37 YCH |
319 | } |
320 | ||
86c8cfc5 S |
321 | vice_url = ViceIE._extract_url(webpage) |
322 | if vice_url: | |
323 | return _url_res(vice_url, ViceIE.ie_key()) | |
324 | ||
1d9e0a4f RA |
325 | embed_code = self._search_regex( |
326 | r'embedCode=([^&\'"]+)', body, | |
327 | 'ooyala embed code', default=None) | |
328 | if embed_code: | |
329 | return _url_res('ooyala:%s' % embed_code, 'Ooyala') | |
330 | ||
5113b691 | 331 | youtube_url = YoutubeIE._extract_url(body) |
1d9e0a4f | 332 | if youtube_url: |
5113b691 | 333 | return _url_res(youtube_url, YoutubeIE.ie_key()) |
1d9e0a4f | 334 | |
4ac6dc37 | 335 | video_url = self._html_search_regex( |
1d9e0a4f RA |
336 | r'data-video-url="([^"]+)"', |
337 | prefetch_data['embed_code'], 'video URL') | |
4ac6dc37 | 338 | |
1d9e0a4f | 339 | return _url_res(video_url, ViceIE.ie_key()) |