2 from __future__ import unicode_literals
10 from .adobepass import AdobePassIE
11 from .youtube import YoutubeIE
12 from .common import InfoExtractor
13 from ..compat import (
26 class ViceIE(AdobePassIE):
28 _VALID_URL = r'https?://(?:(?:video|vms)\.vice|(?:www\.)?viceland)\.com/(?P<locale>[^/]+)/(?:video/[^/]+|embed)/(?P<id>[\da-f]+)'
30 'url': 'https://video.vice.com/en_us/video/pet-cremator/58c69e38a55424f1227dc3f7',
32 'id': '5e647f0125e145c9aef2069412c0cbde',
34 'title': '10 Questions You Always Wanted To Ask: Pet Cremator',
35 'description': 'md5:fe856caacf61fe0e74fab15ce2b07ca5',
37 'uploader_id': '57a204088cb727dec794c67b',
38 'timestamp': 1489664942,
39 'upload_date': '20170316',
44 'skip_download': True,
46 'add_ie': ['UplynkPreplay'],
48 # geo restricted to US
49 'url': 'https://video.vice.com/en_us/video/the-signal-from-tolva/5816510690b70e6c5fd39a56',
51 'id': '930c0ad1f47141cc955087eecaddb0e2',
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',
62 'skip_download': True,
64 'add_ie': ['UplynkPreplay'],
66 'url': 'https://video.vice.com/alps/video/ulfs-wien-beruchtigste-grafitti-crew-part-1/581b12b60a0e1f4c0fb6ea2f',
68 'id': '581b12b60a0e1f4c0fb6ea2f',
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>',
73 'uploader_id': '57a204088cb727dec794c67b',
74 'timestamp': 1485368119,
75 'upload_date': '20170125',
80 'skip_download': True,
81 'proxy': '127.0.0.1:8118',
83 'add_ie': ['UplynkPreplay'],
85 'url': 'https://video.vice.com/en_us/video/pizza-show-trailer/56d8c9a54d286ed92f7f30e4',
86 'only_matching': True,
88 'url': 'https://video.vice.com/en_us/embed/57f41d3556a0a80f54726060',
89 'only_matching': True,
91 'url': 'https://vms.vice.com/en_us/video/preplay/58c69e38a55424f1227dc3f7',
92 'only_matching': True,
94 'url': 'https://www.viceland.com/en_us/video/thursday-march-1-2018/5a8f2d7ff1cdb332dd446ec1',
95 'only_matching': True,
97 _PREPLAY_HOST = 'vms.vice'
100 def _extract_urls(webpage):
102 r'<iframe\b[^>]+\bsrc=["\']((?:https?:)?//video\.vice\.com/[^/]+/embed/[\da-f]+)',
106 def _extract_url(webpage):
107 urls = ViceIE._extract_urls(webpage)
108 return urls[0] if urls else None
110 def _real_extract(self, url):
111 locale, video_id = re.match(self._VALID_URL, url).groups()
113 webpage = self._download_webpage(
114 'https://video.vice.com/%s/embed/%s' % (locale, video_id),
117 video = self._parse_json(
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'))
128 video, lambda x: x['episode']['season']['show']['title'],
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'])
138 resource = self._get_mvpd_resource(
139 'VICELAND', title, video_id, rating)
140 query['tvetoken'] = self._extract_mvpd_auth(
141 url, video_id, 'VICELAND', resource)
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
146 # new JS is located here https://vice-web-statics-cdn.vice.com/vice-player/player-embed.js
147 exp = int(time.time()) + 1440
151 'sign': hashlib.sha512(('%s:GET:%d' % (video_id, exp)).encode()).hexdigest(),
155 'platform': 'desktop',
156 'rn': random.randint(10000, 100000),
161 host = 'www.viceland' if is_locked else self._PREPLAY_HOST
162 preplay = self._download_json(
163 'https://%s.com/%s/video/preplay/%s' % (host, locale, video_id),
164 video_id, query=query)
165 except ExtractorError as e:
166 if isinstance(e.cause, compat_HTTPError) and e.cause.code in (400, 401):
167 error = json.loads(e.cause.read().decode())
168 error_message = error.get('error_description') or error['details']
169 raise ExtractorError('%s said: %s' % (
170 self.IE_NAME, error_message), expected=True)
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', {})
180 cc_url = preplay.get('ccURL')
187 '_type': 'url_transparent',
188 'url': uplynk_preplay_url,
191 'description': base.get('body') or base.get('display_body'),
192 'thumbnail': thumbnail,
193 'duration': int_or_none(video_data.get('video_duration')) or duration,
194 'timestamp': int_or_none(video_data.get('created_at'), 1000),
195 'age_limit': parse_age_limit(video_data.get('video_rating')),
196 'series': video_data.get('show_title') or series,
197 'episode_number': int_or_none(episode.get('episode_number') or episode_number),
198 'episode_id': str_or_none(episode.get('id') or video_data.get('episode_id')),
199 'season_number': int_or_none(season_number),
200 'season_id': str_or_none(episode.get('season_id')),
201 'uploader': channel.get('base', {}).get('title') or channel.get('name') or uploader,
202 'uploader_id': str_or_none(channel.get('id')),
203 'subtitles': subtitles,
204 'ie_key': 'UplynkPreplay',
208 class ViceShowIE(InfoExtractor):
209 IE_NAME = 'vice:show'
210 _VALID_URL = r'https?://(?:.+?\.)?vice\.com/(?:[^/]+/)?show/(?P<id>[^/?#&]+)'
213 'url': 'https://munchies.vice.com/en/show/fuck-thats-delicious-2',
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.',
219 'playlist_count': 17,
222 def _real_extract(self, url):
223 show_id = self._match_id(url)
224 webpage = self._download_webpage(url, show_id)
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)]
232 title = self._search_regex(
233 r'<title>(.+?)</title>', webpage, 'title', default=None)
235 title = re.sub(r'(.+)\s*\|\s*.+$', r'\1', title).strip()
236 description = self._html_search_meta(
237 'description', webpage, 'description')
239 return self.playlist_result(entries, show_id, title, description)
242 class ViceArticleIE(InfoExtractor):
243 IE_NAME = 'vice:article'
244 _VALID_URL = r'https://www\.vice\.com/[^/]+/article/(?P<id>[^?#]+)'
247 'url': 'https://www.vice.com/en_us/article/on-set-with-the-woman-making-mormon-porn-in-utah',
249 'id': '41eae2a47b174a1398357cec55f1f6fc',
251 'title': 'Mormon War on Porn ',
252 'description': 'md5:6394a8398506581d0346b9ab89093fef',
254 'uploader_id': '57a204088cb727dec794c67b',
255 'timestamp': 1491883129,
256 'upload_date': '20170411',
261 'skip_download': True,
263 'add_ie': ['UplynkPreplay'],
265 'url': 'https://www.vice.com/en_us/article/how-to-hack-a-car',
266 'md5': '7fe8ebc4fa3323efafc127b82bd821d9',
270 'title': 'How to Hack a Car: Phreaked Out (Episode 2)',
271 'description': 'md5:ee95453f7ff495db8efe14ae8bf56f30',
272 'uploader': 'Motherboard',
273 'uploader_id': 'MotherboardTV',
274 'upload_date': '20140529',
276 'add_ie': ['Youtube'],
278 'url': 'https://www.vice.com/en_us/article/znm9dx/karley-sciortino-slutever-reloaded',
279 'md5': 'a7ecf64ee4fa19b916c16f4b56184ae2',
281 'id': 'e2ed435eb67e43efb66e6ef9a6930a88',
283 'title': "Making The World's First Male Sex Doll",
284 'description': 'md5:916078ef0e032d76343116208b6cc2c4',
286 'uploader_id': '57a204088cb727dec794c67b',
287 'timestamp': 1476919911,
288 'upload_date': '20161019',
292 'skip_download': True,
294 'add_ie': [ViceIE.ie_key()],
296 'url': 'https://www.vice.com/en_us/article/cowboy-capitalists-part-1',
297 'only_matching': True,
299 'url': 'https://www.vice.com/ru/article/big-night-out-ibiza-clive-martin-229',
300 'only_matching': True,
303 def _real_extract(self, url):
304 display_id = self._match_id(url)
306 webpage = self._download_webpage(url, display_id)
308 prefetch_data = self._parse_json(self._search_regex(
309 r'__APP_STATE\s*=\s*({.+?})(?:\s*\|\|\s*{}\s*)?;\s*\n',
310 webpage, 'app state'), display_id)['pageData']
311 body = prefetch_data['body']
313 def _url_res(video_url, ie_key):
315 '_type': 'url_transparent',
317 'display_id': display_id,
321 vice_url = ViceIE._extract_url(webpage)
323 return _url_res(vice_url, ViceIE.ie_key())
325 embed_code = self._search_regex(
326 r'embedCode=([^&\'"]+)', body,
327 'ooyala embed code', default=None)
329 return _url_res('ooyala:%s' % embed_code, 'Ooyala')
331 youtube_url = YoutubeIE._extract_url(body)
333 return _url_res(youtube_url, YoutubeIE.ie_key())
335 video_url = self._html_search_regex(
336 r'data-video-url="([^"]+)"',
337 prefetch_data['embed_code'], 'video URL')
339 return _url_res(video_url, ViceIE.ie_key())