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