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