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