]>
Commit | Line | Data |
---|---|---|
a85e131b | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
8 | clean_html, | |
9 | ExtractorError, | |
10 | js_to_json, | |
11 | base_url, | |
12 | url_basename, | |
13 | urljoin, | |
14 | ) | |
15 | ||
16 | ||
17 | class RCSIE(InfoExtractor): | |
18 | _ALL_REPLACE = { | |
19 | 'media2vam.corriere.it.edgesuite.net': | |
20 | 'media2vam-corriere-it.akamaized.net', | |
21 | 'media.youreporter.it.edgesuite.net': | |
22 | 'media-youreporter-it.akamaized.net', | |
23 | 'corrierepmd.corriere.it.edgesuite.net': | |
24 | 'corrierepmd-corriere-it.akamaized.net', | |
25 | 'media2vam-corriere-it.akamaized.net/fcs.quotidiani/vr/videos/': | |
26 | 'video.corriere.it/vr360/videos/', | |
27 | '.net//': '.net/', | |
28 | } | |
29 | _MP4_REPLACE = { | |
30 | 'media2vam.corbologna.corriere.it.edgesuite.net': | |
31 | 'media2vam-bologna-corriere-it.akamaized.net', | |
32 | 'media2vam.corfiorentino.corriere.it.edgesuite.net': | |
33 | 'media2vam-fiorentino-corriere-it.akamaized.net', | |
34 | 'media2vam.cormezzogiorno.corriere.it.edgesuite.net': | |
35 | 'media2vam-mezzogiorno-corriere-it.akamaized.net', | |
36 | 'media2vam.corveneto.corriere.it.edgesuite.net': | |
37 | 'media2vam-veneto-corriere-it.akamaized.net', | |
38 | 'media2.oggi.it.edgesuite.net': | |
39 | 'media2-oggi-it.akamaized.net', | |
40 | 'media2.quimamme.it.edgesuite.net': | |
41 | 'media2-quimamme-it.akamaized.net', | |
42 | 'media2.amica.it.edgesuite.net': | |
43 | 'media2-amica-it.akamaized.net', | |
44 | 'media2.living.corriere.it.edgesuite.net': | |
45 | 'media2-living-corriere-it.akamaized.net', | |
46 | 'media2.style.corriere.it.edgesuite.net': | |
47 | 'media2-style-corriere-it.akamaized.net', | |
48 | 'media2.iodonna.it.edgesuite.net': | |
49 | 'media2-iodonna-it.akamaized.net', | |
50 | 'media2.leitv.it.edgesuite.net': | |
51 | 'media2-leitv-it.akamaized.net', | |
52 | } | |
53 | _MIGRATION_MAP = { | |
54 | 'videoamica-vh.akamaihd': 'amica', | |
55 | 'media2-amica-it.akamaized': 'amica', | |
56 | 'corrierevam-vh.akamaihd': 'corriere', | |
57 | 'media2vam-corriere-it.akamaized': 'corriere', | |
58 | 'cormezzogiorno-vh.akamaihd': 'corrieredelmezzogiorno', | |
59 | 'media2vam-mezzogiorno-corriere-it.akamaized': 'corrieredelmezzogiorno', | |
60 | 'corveneto-vh.akamaihd': 'corrieredelveneto', | |
61 | 'media2vam-veneto-corriere-it.akamaized': 'corrieredelveneto', | |
62 | 'corbologna-vh.akamaihd': 'corrieredibologna', | |
63 | 'media2vam-bologna-corriere-it.akamaized': 'corrieredibologna', | |
64 | 'corfiorentino-vh.akamaihd': 'corrierefiorentino', | |
65 | 'media2vam-fiorentino-corriere-it.akamaized': 'corrierefiorentino', | |
66 | 'corinnovazione-vh.akamaihd': 'corriereinnovazione', | |
67 | 'media2-gazzanet-gazzetta-it.akamaized': 'gazzanet', | |
68 | 'videogazzanet-vh.akamaihd': 'gazzanet', | |
69 | 'videogazzaworld-vh.akamaihd': 'gazzaworld', | |
70 | 'gazzettavam-vh.akamaihd': 'gazzetta', | |
71 | 'media2vam-gazzetta-it.akamaized': 'gazzetta', | |
72 | 'videoiodonna-vh.akamaihd': 'iodonna', | |
73 | 'media2-leitv-it.akamaized': 'leitv', | |
74 | 'videoleitv-vh.akamaihd': 'leitv', | |
75 | 'videoliving-vh.akamaihd': 'living', | |
76 | 'media2-living-corriere-it.akamaized': 'living', | |
77 | 'media2-oggi-it.akamaized': 'oggi', | |
78 | 'videooggi-vh.akamaihd': 'oggi', | |
79 | 'media2-quimamme-it.akamaized': 'quimamme', | |
80 | 'quimamme-vh.akamaihd': 'quimamme', | |
81 | 'videorunning-vh.akamaihd': 'running', | |
82 | 'media2-style-corriere-it.akamaized': 'style', | |
83 | 'style-vh.akamaihd': 'style', | |
84 | 'videostyle-vh.akamaihd': 'style', | |
85 | 'media2-stylepiccoli-it.akamaized': 'stylepiccoli', | |
86 | 'stylepiccoli-vh.akamaihd': 'stylepiccoli', | |
87 | 'doveviaggi-vh.akamaihd': 'viaggi', | |
88 | 'media2-doveviaggi-it.akamaized': 'viaggi', | |
89 | 'media2-vivimilano-corriere-it.akamaized': 'vivimilano', | |
90 | 'vivimilano-vh.akamaihd': 'vivimilano', | |
91 | 'media2-youreporter-it.akamaized': 'youreporter' | |
92 | } | |
93 | _MIGRATION_MEDIA = { | |
94 | 'advrcs-vh.akamaihd': '', | |
95 | 'corriere-f.akamaihd': '', | |
96 | 'corrierepmd-corriere-it.akamaized': '', | |
97 | 'corrprotetto-vh.akamaihd': '', | |
98 | 'gazzetta-f.akamaihd': '', | |
99 | 'gazzettapmd-gazzetta-it.akamaized': '', | |
100 | 'gazzprotetto-vh.akamaihd': '', | |
101 | 'periodici-f.akamaihd': '', | |
102 | 'periodicisecure-vh.akamaihd': '', | |
103 | 'videocoracademy-vh.akamaihd': '' | |
104 | } | |
105 | ||
106 | def _get_video_src(self, video): | |
107 | mediaFiles = video['mediaProfile']['mediaFile'] | |
108 | src = {} | |
109 | # audio | |
110 | if video['mediaType'] == 'AUDIO': | |
111 | for aud in mediaFiles: | |
112 | # todo: check | |
113 | src['mp3'] = aud['value'] | |
114 | # video | |
115 | else: | |
116 | for vid in mediaFiles: | |
117 | if vid['mimeType'] == 'application/vnd.apple.mpegurl': | |
118 | src['m3u8'] = vid['value'] | |
119 | if vid['mimeType'] == 'video/mp4': | |
120 | src['mp4'] = vid['value'] | |
121 | ||
122 | # replace host | |
123 | for t in src: | |
124 | for s, r in self._ALL_REPLACE.items(): | |
125 | src[t] = src[t].replace(s, r) | |
126 | for s, r in self._MP4_REPLACE.items(): | |
127 | src[t] = src[t].replace(s, r) | |
128 | ||
129 | # switch cdn | |
130 | if 'mp4' in src and 'm3u8' in src: | |
131 | if '-lh.akamaihd' not in src['m3u8'] and 'akamai' in src['mp4']: | |
132 | if 'm3u8' in src: | |
133 | matches = re.search(r'(?:https*:)?\/\/(?P<host>.*)\.net\/i(?P<path>.*)$', src['m3u8']) | |
134 | src['m3u8'] = 'https://vod.rcsobjects.it/hls/%s%s' % ( | |
135 | self._MIGRATION_MAP[matches.group('host')], | |
136 | matches.group('path').replace( | |
137 | '///', '/').replace( | |
138 | '//', '/').replace( | |
139 | '.csmil', '.urlset' | |
140 | ) | |
141 | ) | |
142 | if 'mp4' in src: | |
143 | matches = re.search(r'(?:https*:)?\/\/(?P<host>.*)\.net\/i(?P<path>.*)$', src['mp4']) | |
144 | if matches: | |
145 | if matches.group('host') in self._MIGRATION_MEDIA: | |
146 | vh_stream = 'https://media2.corriereobjects.it' | |
147 | if src['mp4'].find('fcs.quotidiani_!'): | |
148 | vh_stream = 'https://media2-it.corriereobjects.it' | |
149 | src['mp4'] = '%s%s' % ( | |
150 | vh_stream, | |
151 | matches.group('path').replace( | |
152 | '///', '/').replace( | |
153 | '//', '/').replace( | |
154 | '/fcs.quotidiani/mediacenter', '').replace( | |
155 | '/fcs.quotidiani_!/mediacenter', '').replace( | |
156 | 'corriere/content/mediacenter/', '').replace( | |
157 | 'gazzetta/content/mediacenter/', '') | |
158 | ) | |
159 | else: | |
160 | src['mp4'] = 'https://vod.rcsobjects.it/%s%s' % ( | |
161 | self._MIGRATION_MAP[matches.group('host')], | |
162 | matches.group('path').replace('///', '/').replace('//', '/') | |
163 | ) | |
164 | ||
165 | if 'mp3' in src: | |
166 | src['mp3'] = src['mp3'].replace( | |
167 | 'media2vam-corriere-it.akamaized.net', | |
168 | 'vod.rcsobjects.it/corriere') | |
169 | if 'mp4' in src: | |
170 | if src['mp4'].find('fcs.quotidiani_!'): | |
171 | src['mp4'] = src['mp4'].replace('vod.rcsobjects', 'vod-it.rcsobjects') | |
172 | if 'm3u8' in src: | |
173 | if src['m3u8'].find('fcs.quotidiani_!'): | |
174 | src['m3u8'] = src['m3u8'].replace('vod.rcsobjects', 'vod-it.rcsobjects') | |
175 | ||
176 | if 'geoblocking' in video['mediaProfile']: | |
177 | if 'm3u8' in src: | |
178 | src['m3u8'] = src['m3u8'].replace('vod.rcsobjects', 'vod-it.rcsobjects') | |
179 | if 'mp4' in src: | |
180 | src['mp4'] = src['mp4'].replace('vod.rcsobjects', 'vod-it.rcsobjects') | |
181 | if 'm3u8' in src: | |
182 | if src['m3u8'].find('csmil') and src['m3u8'].find('vod'): | |
183 | src['m3u8'] = src['m3u8'].replace('.csmil', '.urlset') | |
184 | ||
185 | return src | |
186 | ||
187 | def _create_formats(self, urls, video_id): | |
188 | formats = [] | |
189 | formats = self._extract_m3u8_formats( | |
190 | urls['m3u8'], video_id, 'mp4', entry_protocol='m3u8_native', | |
191 | m3u8_id='hls', fatal=False) | |
192 | ||
193 | if not formats: | |
194 | formats.append({ | |
195 | 'format_id': 'http-mp4', | |
196 | 'url': urls['mp4'] | |
197 | }) | |
198 | self._sort_formats(formats) | |
199 | return formats | |
200 | ||
201 | def _real_extract(self, url): | |
202 | video_id = self._match_id(url) | |
203 | mobj = re.search(self._VALID_URL, url).groupdict() | |
204 | ||
205 | if not mobj['cdn']: | |
206 | raise ExtractorError('CDN not found in url: %s' % url) | |
207 | ||
208 | # for leitv/youreporter/viaggi don't use the embed page | |
209 | if (mobj['cdn'] not in ['leitv.it', 'youreporter.it']) and (mobj['vid'] == 'video'): | |
210 | url = 'https://video.%s/video-embed/%s' % (mobj['cdn'], video_id) | |
211 | ||
212 | page = self._download_webpage(url, video_id) | |
213 | ||
214 | video_data = None | |
215 | # look for json video data url | |
216 | json = self._search_regex( | |
217 | r'''var url\s*=\s*["']((?:https?:)?//video\.rcs\.it/fragment-includes/video-includes/.+?\.json)["'];''', | |
218 | page, video_id, default=None) | |
219 | if json: | |
220 | if json.startswith('//'): | |
221 | json = 'https:%s' % json | |
222 | video_data = self._download_json(json, video_id) | |
223 | ||
224 | # if url not found, look for json video data directly in the page | |
225 | else: | |
226 | json = self._search_regex( | |
227 | r'[\s;]video\s*=\s*({[\s\S]+?})(?:;|,playlist=)', | |
228 | page, video_id, default=None) | |
229 | if json: | |
230 | video_data = self._parse_json( | |
231 | json, video_id, transform_source=js_to_json) | |
232 | else: | |
233 | # if no video data found try search for iframes | |
234 | emb = RCSEmbedsIE._extract_url(page) | |
235 | if emb: | |
236 | return self._real_extract(emb) | |
237 | ||
238 | if not video_data: | |
239 | raise ExtractorError('Video data not found in the page') | |
240 | ||
241 | formats = self._create_formats( | |
242 | self._get_video_src(video_data), video_id) | |
243 | ||
244 | return { | |
245 | 'id': video_id, | |
246 | 'title': video_data['title'], | |
247 | 'description': video_data['description'] or clean_html(video_data['htmlDescription']), | |
248 | 'uploader': video_data['provider'] if video_data['provider'] else mobj['cdn'], | |
249 | 'formats': formats | |
250 | } | |
251 | ||
252 | ||
253 | class RCSEmbedsIE(RCSIE): | |
254 | IE_NAME = 'rcs:rcs' | |
255 | _VALID_URL = r'''(?x) | |
256 | https?://(?P<vid>video)\. | |
257 | (?P<cdn> | |
258 | (?: | |
259 | rcs| | |
260 | (?:corriere\w+\.)?corriere| | |
261 | (?:gazzanet\.)?gazzetta | |
262 | )\.it) | |
263 | /video-embed/(?P<id>[^/=&\?]+?)(?:$|\?)''' | |
264 | _TESTS = [{ | |
265 | 'url': 'https://video.rcs.it/video-embed/iodonna-0001585037', | |
266 | 'md5': '623ecc8ffe7299b2d0c1046d8331a9df', | |
267 | 'info_dict': { | |
268 | 'id': 'iodonna-0001585037', | |
269 | 'ext': 'mp4', | |
270 | 'title': 'Sky Arte racconta Madonna nella serie "Artist to icon"', | |
271 | 'description': 'md5:65b09633df9ffee57f48b39e34c9e067', | |
272 | 'uploader': 'rcs.it', | |
273 | } | |
274 | }, { | |
275 | 'url': 'https://video.corriere.it/video-embed/b727632a-f9d0-11ea-91b0-38d50a849abb?player', | |
276 | 'match_only': True | |
277 | }, { | |
278 | 'url': 'https://video.gazzetta.it/video-embed/49612410-00ca-11eb-bcd8-30d4253e0140', | |
279 | 'match_only': True | |
280 | }] | |
281 | ||
282 | @staticmethod | |
283 | def _sanitize_urls(urls): | |
284 | # add protocol if missing | |
285 | for i, e in enumerate(urls): | |
286 | if e.startswith('//'): | |
287 | urls[i] = 'https:%s' % e | |
288 | # clean iframes urls | |
289 | for i, e in enumerate(urls): | |
290 | urls[i] = urljoin(base_url(e), url_basename(e)) | |
291 | return urls | |
292 | ||
293 | @staticmethod | |
294 | def _extract_urls(webpage): | |
295 | entries = [ | |
296 | mobj.group('url') | |
297 | for mobj in re.finditer(r'''(?x) | |
298 | (?: | |
299 | data-frame-src=| | |
300 | <iframe[^\n]+src= | |
301 | ) | |
302 | (["']) | |
303 | (?P<url>(?:https?:)?//video\. | |
304 | (?: | |
305 | rcs| | |
306 | (?:corriere\w+\.)?corriere| | |
307 | (?:gazzanet\.)?gazzetta | |
308 | ) | |
309 | \.it/video-embed/.+?) | |
310 | \1''', webpage)] | |
311 | return RCSEmbedsIE._sanitize_urls(entries) | |
312 | ||
313 | @staticmethod | |
314 | def _extract_url(webpage): | |
315 | urls = RCSEmbedsIE._extract_urls(webpage) | |
316 | return urls[0] if urls else None | |
317 | ||
318 | ||
319 | class CorriereIE(RCSIE): | |
320 | IE_NAME = 'rcs:corriere' | |
321 | _VALID_URL = r'''(?x)https?://(?P<vid>video|viaggi)\. | |
322 | (?P<cdn> | |
323 | (?: | |
324 | corrieredelmezzogiorno\.| | |
325 | corrieredelveneto\.| | |
326 | corrieredibologna\.| | |
327 | corrierefiorentino\. | |
328 | )? | |
329 | corriere\.it)/.+?/(?P<id>[^/]+)(?=\?|/$|$)''' | |
330 | _TESTS = [{ | |
331 | 'url': 'https://video.corriere.it/sport/formula-1/vettel-guida-ferrari-sf90-mugello-suo-fianco-c-elecrerc-bendato-video-esilarante/b727632a-f9d0-11ea-91b0-38d50a849abb', | |
332 | 'md5': '0f4ededc202b0f00b6e509d831e2dcda', | |
333 | 'info_dict': { | |
334 | 'id': 'b727632a-f9d0-11ea-91b0-38d50a849abb', | |
335 | 'ext': 'mp4', | |
336 | 'title': 'Vettel guida la Ferrari SF90 al Mugello e al suo fianco c\'è Leclerc (bendato): il video è esilarante', | |
337 | 'description': 'md5:93b51c9161ac8a64fb2f997b054d0152', | |
338 | 'uploader': 'Corriere Tv', | |
339 | } | |
340 | }, { | |
341 | 'url': 'https://viaggi.corriere.it/video/norvegia-il-nuovo-ponte-spettacolare-sopra-la-cascata-di-voringsfossen/', | |
342 | 'md5': 'da378e4918d2afbf7d61c35abb948d4c', | |
343 | 'info_dict': { | |
344 | 'id': '5b7cd134-e2c1-11ea-89b3-b56dd0df2aa2', | |
345 | 'ext': 'mp4', | |
346 | 'title': 'La nuova spettacolare attrazione in Norvegia: il ponte sopra Vøringsfossen', | |
347 | 'description': 'md5:18b35a291f6746c0c8dacd16e5f5f4f8', | |
348 | 'uploader': 'DOVE Viaggi', | |
349 | } | |
350 | }, { | |
351 | 'url': 'https://video.corriere.it/video-embed/b727632a-f9d0-11ea-91b0-38d50a849abb?player', | |
352 | 'match_only': True | |
353 | }, { | |
354 | 'url': 'https://video.corriere.it/video-360/metro-copenaghen-tutta-italiana/a248a7f0-e2db-11e9-9830-af2de6b1f945', | |
355 | 'match_only': True | |
356 | }] | |
357 | ||
358 | ||
359 | class GazzettaIE(RCSIE): | |
360 | IE_NAME = 'rcs:gazzetta' | |
361 | _VALID_URL = r'https?://(?P<vid>video)\.(?P<cdn>(?:gazzanet\.)?gazzetta\.it)/.+?/(?P<id>[^/]+?)(?:$|\?)' | |
362 | _TESTS = [{ | |
363 | 'url': 'https://video.gazzetta.it/video-motogp-catalogna-cadute-dovizioso-vale-rossi/49612410-00ca-11eb-bcd8-30d4253e0140?vclk=Videobar', | |
364 | 'md5': 'eedc1b5defd18e67383afef51ff7bdf9', | |
365 | 'info_dict': { | |
366 | 'id': '49612410-00ca-11eb-bcd8-30d4253e0140', | |
367 | 'ext': 'mp4', | |
368 | 'title': 'Dovizioso, il contatto con Zarco e la caduta. E anche Vale finisce a terra', | |
369 | 'description': 'md5:8c6e905dc3b9413218beca11ebd69778', | |
370 | 'uploader': 'AMorici', | |
371 | } | |
372 | }, { | |
373 | 'url': 'https://video.gazzetta.it/video-embed/49612410-00ca-11eb-bcd8-30d4253e0140', | |
374 | 'match_only': True | |
375 | }, { | |
376 | 'url': 'https://video.gazzanet.gazzetta.it/video-embed/gazzanet-mo05-0000260789', | |
377 | 'match_only': True | |
378 | }] | |
379 | ||
380 | ||
381 | class RCSVariousIE(RCSIE): | |
382 | IE_NAME = 'rcs:various' | |
383 | _VALID_URL = r'''(?x)https?://www\. | |
384 | (?P<cdn> | |
385 | leitv\.it| | |
386 | youreporter\.it | |
387 | )/(?:video/)?(?P<id>[^/]+?)(?:$|\?|/)''' | |
388 | _TESTS = [{ | |
389 | 'url': 'https://www.leitv.it/video/marmellata-di-ciliegie-fatta-in-casa/', | |
390 | 'md5': '618aaabac32152199c1af86784d4d554', | |
391 | 'info_dict': { | |
392 | 'id': 'marmellata-di-ciliegie-fatta-in-casa', | |
393 | 'ext': 'mp4', | |
394 | 'title': 'Marmellata di ciliegie fatta in casa', | |
395 | 'description': 'md5:89133864d6aad456dbcf6e7a29f86263', | |
396 | 'uploader': 'leitv.it', | |
397 | } | |
398 | }, { | |
399 | 'url': 'https://www.youreporter.it/fiume-sesia-3-ottobre-2020/', | |
400 | 'md5': '8dccd436b47a830bab5b4a88232f391a', | |
401 | 'info_dict': { | |
402 | 'id': 'fiume-sesia-3-ottobre-2020', | |
403 | 'ext': 'mp4', | |
404 | 'title': 'Fiume Sesia 3 ottobre 2020', | |
405 | 'description': 'md5:0070eef1cc884d13c970a4125063de55', | |
406 | 'uploader': 'youreporter.it', | |
407 | } | |
408 | }] |