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,
99 def _extract_urls(webpage):
101 r'<iframe\b[^>]+\bsrc=["\']((?:https?:)?//video\.vice\.com/[^/]+/embed/[\da-f]+)',
105 def _extract_url(webpage):
106 urls = ViceIE._extract_urls(webpage)
107 return urls[0] if urls else None
109 def _real_extract(self, url):
110 locale, video_id = re.match(self._VALID_URL, url).groups()
112 webpage = self._download_webpage(
113 'https://video.vice.com/%s/embed/%s' % (locale, video_id),
116 video = self._parse_json(
118 r'PREFETCH_DATA\s*=\s*({.+?})\s*;\s*\n', webpage,
119 'app state'), video_id)['video']
120 video_id = video.get('vms_id') or video.get('id') or video_id
121 title = video['title']
122 is_locked = video.get('locked')
123 rating = video.get('rating')
124 thumbnail = video.get('thumbnail_url')
125 duration = int_or_none(video.get('duration'))
127 video, lambda x: x['episode']['season']['show']['title'],
129 episode_number = try_get(
130 video, lambda x: x['episode']['episode_number'])
131 season_number = try_get(
132 video, lambda x: x['episode']['season']['season_number'])
137 resource = self._get_mvpd_resource(
138 'VICELAND', title, video_id, rating)
139 query['tvetoken'] = self._extract_mvpd_auth(
140 url, video_id, 'VICELAND', resource)
142 # signature generation algorithm is reverse engineered from signatureGenerator in
143 # webpack:///../shared/~/vice-player/dist/js/vice-player.js in
144 # https://www.viceland.com/assets/common/js/web.vendor.bundle.js
145 # new JS is located here https://vice-web-statics-cdn.vice.com/vice-player/player-embed.js
146 exp = int(time.time()) + 1440
150 'sign': hashlib.sha512(('%s:GET:%d' % (video_id, exp)).encode()).hexdigest(),
154 'platform': 'desktop',
155 'rn': random.randint(10000, 100000),
160 preplay = self._download_json(
161 'https://vms.vice.com/%s/video/preplay/%s' % (locale, video_id),
162 video_id, query=query)
163 except ExtractorError as e:
164 if isinstance(e.cause, compat_HTTPError) and e.cause.code in (400, 401):
165 error = json.loads(e.cause.read().decode())
166 error_message = error.get('error_description') or error['details']
167 raise ExtractorError('%s said: %s' % (
168 self.IE_NAME, error_message), expected=True)
171 video_data = preplay['video']
172 base = video_data['base']
173 uplynk_preplay_url = preplay['preplayURL']
174 episode = video_data.get('episode', {})
175 channel = video_data.get('channel', {})
178 cc_url = preplay.get('ccURL')
185 '_type': 'url_transparent',
186 'url': uplynk_preplay_url,
189 'description': base.get('body') or base.get('display_body'),
190 'thumbnail': thumbnail,
191 'duration': int_or_none(video_data.get('video_duration')) or duration,
192 'timestamp': int_or_none(video_data.get('created_at'), 1000),
193 'age_limit': parse_age_limit(video_data.get('video_rating')),
194 'series': video_data.get('show_title') or series,
195 'episode_number': int_or_none(episode.get('episode_number') or episode_number),
196 'episode_id': str_or_none(episode.get('id') or video_data.get('episode_id')),
197 'season_number': int_or_none(season_number),
198 'season_id': str_or_none(episode.get('season_id')),
199 'uploader': channel.get('base', {}).get('title') or channel.get('name') or uploader,
200 'uploader_id': str_or_none(channel.get('id')),
201 'subtitles': subtitles,
202 'ie_key': 'UplynkPreplay',
206 class ViceShowIE(InfoExtractor):
207 IE_NAME = 'vice:show'
208 _VALID_URL = r'https?://(?:.+?\.)?vice\.com/(?:[^/]+/)?show/(?P<id>[^/?#&]+)'
211 'url': 'https://munchies.vice.com/en/show/fuck-thats-delicious-2',
213 'id': 'fuck-thats-delicious-2',
214 'title': "Fuck, That's Delicious",
215 'description': 'Follow the culinary adventures of rapper Action Bronson during his ongoing world tour.',
217 'playlist_count': 17,
220 def _real_extract(self, url):
221 show_id = self._match_id(url)
222 webpage = self._download_webpage(url, show_id)
225 self.url_result(video_url, ViceIE.ie_key())
226 for video_url, _ in re.findall(
227 r'<h2[^>]+class="article-title"[^>]+data-id="\d+"[^>]*>\s*<a[^>]+href="(%s.*?)"'
228 % ViceIE._VALID_URL, webpage)]
230 title = self._search_regex(
231 r'<title>(.+?)</title>', webpage, 'title', default=None)
233 title = re.sub(r'(.+)\s*\|\s*.+$', r'\1', title).strip()
234 description = self._html_search_meta(
235 'description', webpage, 'description')
237 return self.playlist_result(entries, show_id, title, description)
240 class ViceArticleIE(InfoExtractor):
241 IE_NAME = 'vice:article'
242 _VALID_URL = r'https://www\.vice\.com/[^/]+/article/(?P<id>[^?#]+)'
245 'url': 'https://www.vice.com/en_us/article/on-set-with-the-woman-making-mormon-porn-in-utah',
247 'id': '41eae2a47b174a1398357cec55f1f6fc',
249 'title': 'Mormon War on Porn ',
250 'description': 'md5:6394a8398506581d0346b9ab89093fef',
252 'uploader_id': '57a204088cb727dec794c67b',
253 'timestamp': 1491883129,
254 'upload_date': '20170411',
259 'skip_download': True,
261 'add_ie': ['UplynkPreplay'],
263 'url': 'https://www.vice.com/en_us/article/how-to-hack-a-car',
264 'md5': '7fe8ebc4fa3323efafc127b82bd821d9',
268 'title': 'How to Hack a Car: Phreaked Out (Episode 2)',
269 'description': 'md5:ee95453f7ff495db8efe14ae8bf56f30',
270 'uploader': 'Motherboard',
271 'uploader_id': 'MotherboardTV',
272 'upload_date': '20140529',
274 'add_ie': ['Youtube'],
276 'url': 'https://www.vice.com/en_us/article/znm9dx/karley-sciortino-slutever-reloaded',
277 'md5': 'a7ecf64ee4fa19b916c16f4b56184ae2',
279 'id': 'e2ed435eb67e43efb66e6ef9a6930a88',
281 'title': "Making The World's First Male Sex Doll",
282 'description': 'md5:916078ef0e032d76343116208b6cc2c4',
284 'uploader_id': '57a204088cb727dec794c67b',
285 'timestamp': 1476919911,
286 'upload_date': '20161019',
290 'skip_download': True,
292 'add_ie': [ViceIE.ie_key()],
294 'url': 'https://www.vice.com/en_us/article/cowboy-capitalists-part-1',
295 'only_matching': True,
297 'url': 'https://www.vice.com/ru/article/big-night-out-ibiza-clive-martin-229',
298 'only_matching': True,
301 def _real_extract(self, url):
302 display_id = self._match_id(url)
304 webpage = self._download_webpage(url, display_id)
306 prefetch_data = self._parse_json(self._search_regex(
307 r'__APP_STATE\s*=\s*({.+?})(?:\s*\|\|\s*{}\s*)?;\s*\n',
308 webpage, 'app state'), display_id)['pageData']
309 body = prefetch_data['body']
311 def _url_res(video_url, ie_key):
313 '_type': 'url_transparent',
315 'display_id': display_id,
319 vice_url = ViceIE._extract_url(webpage)
321 return _url_res(vice_url, ViceIE.ie_key())
323 embed_code = self._search_regex(
324 r'embedCode=([^&\'"]+)', body,
325 'ooyala embed code', default=None)
327 return _url_res('ooyala:%s' % embed_code, 'Ooyala')
329 youtube_url = YoutubeIE._extract_url(body)
331 return _url_res(youtube_url, YoutubeIE.ie_key())
333 video_url = self._html_search_regex(
334 r'data-video-url="([^"]+)"',
335 prefetch_data['embed_code'], 'video URL')
337 return _url_res(video_url, ViceIE.ie_key())