]>
Commit | Line | Data |
---|---|---|
1 | import re | |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | base_url, | |
6 | determine_ext, | |
7 | int_or_none, | |
8 | url_basename, | |
9 | urljoin, | |
10 | ) | |
11 | ||
12 | ||
13 | class GediDigitalIE(InfoExtractor): | |
14 | _VALID_URL = r'''(?x:(?P<base_url>(?:https?:)//video\. | |
15 | (?: | |
16 | (?: | |
17 | (?:espresso\.)?repubblica | |
18 | |lastampa | |
19 | |ilsecoloxix | |
20 | |huffingtonpost | |
21 | )| | |
22 | (?: | |
23 | iltirreno | |
24 | |messaggeroveneto | |
25 | |ilpiccolo | |
26 | |gazzettadimantova | |
27 | |mattinopadova | |
28 | |laprovinciapavese | |
29 | |tribunatreviso | |
30 | |nuovavenezia | |
31 | |gazzettadimodena | |
32 | |lanuovaferrara | |
33 | |corrierealpi | |
34 | |lasentinella | |
35 | )\.gelocal | |
36 | )\.it(?:/[^/]+){2,4}/(?P<id>\d+))(?:$|[?&].*))''' | |
37 | _EMBED_REGEX = [rf'''(?x) | |
38 | (?: | |
39 | data-frame-src=| | |
40 | <iframe[^\n]+src= | |
41 | ) | |
42 | (["'])(?P<url>{_VALID_URL})\1'''] | |
43 | _TESTS = [{ | |
44 | 'url': 'https://video.lastampa.it/politica/il-paradosso-delle-regionali-la-lega-vince-ma-sembra-aver-perso/121559/121683', | |
45 | 'md5': '84658d7fb9e55a6e57ecc77b73137494', | |
46 | 'info_dict': { | |
47 | 'id': '121683', | |
48 | 'ext': 'mp4', | |
49 | 'title': 'Il paradosso delle Regionali: ecco perché la Lega vince ma sembra aver perso', | |
50 | 'description': 'md5:de7f4d6eaaaf36c153b599b10f8ce7ca', | |
51 | 'thumbnail': r're:^https://www\.repstatic\.it/video/photo/.+?-thumb-full-.+?\.jpg$', | |
52 | 'duration': 125, | |
53 | }, | |
54 | }, { | |
55 | 'url': 'https://video.huffingtonpost.it/embed/politica/cotticelli-non-so-cosa-mi-sia-successo-sto-cercando-di-capire-se-ho-avuto-un-malore/29312/29276?responsive=true&el=video971040871621586700', | |
56 | 'only_matching': True, | |
57 | }, { | |
58 | 'url': 'https://video.espresso.repubblica.it/embed/tutti-i-video/01-ted-villa/14772/14870&width=640&height=360', | |
59 | 'only_matching': True, | |
60 | }, { | |
61 | 'url': 'https://video.repubblica.it/motori/record-della-pista-a-spa-francorchamps-la-pagani-huayra-roadster-bc-stupisce/367415/367963', | |
62 | 'only_matching': True, | |
63 | }, { | |
64 | 'url': 'https://video.ilsecoloxix.it/sport/cassani-e-i-brividi-azzurri-ai-mondiali-di-imola-qui-mi-sono-innamorato-del-ciclismo-da-ragazzino-incredibile-tornarci-da-ct/66184/66267', | |
65 | 'only_matching': True, | |
66 | }, { | |
67 | 'url': 'https://video.iltirreno.gelocal.it/sport/dentro-la-notizia-ferrari-cosa-succede-a-maranello/141059/142723', | |
68 | 'only_matching': True, | |
69 | }, { | |
70 | 'url': 'https://video.messaggeroveneto.gelocal.it/locale/maria-giovanna-elmi-covid-vaccino/138155/139268', | |
71 | 'only_matching': True, | |
72 | }, { | |
73 | 'url': 'https://video.ilpiccolo.gelocal.it/dossier/big-john/dinosauro-big-john-al-via-le-visite-guidate-a-trieste/135226/135751', | |
74 | 'only_matching': True, | |
75 | }, { | |
76 | 'url': 'https://video.gazzettadimantova.gelocal.it/locale/dal-ponte-visconteo-di-valeggio-l-and-8217sos-dei-ristoratori-aprire-anche-a-cena/137310/137818', | |
77 | 'only_matching': True, | |
78 | }, { | |
79 | 'url': 'https://video.mattinopadova.gelocal.it/dossier/coronavirus-in-veneto/covid-a-vo-un-anno-dopo-un-cuore-tricolore-per-non-dimenticare/138402/138964', | |
80 | 'only_matching': True, | |
81 | }, { | |
82 | 'url': 'https://video.laprovinciapavese.gelocal.it/locale/mede-zona-rossa-via-alle-vaccinazioni-per-gli-over-80/137545/138120', | |
83 | 'only_matching': True, | |
84 | }, { | |
85 | 'url': 'https://video.tribunatreviso.gelocal.it/dossier/coronavirus-in-veneto/ecco-le-prima-vaccinazioni-di-massa-nella-marca/134485/135024', | |
86 | 'only_matching': True, | |
87 | }, { | |
88 | 'url': 'https://video.nuovavenezia.gelocal.it/locale/camion-troppo-alto-per-il-ponte-ferroviario-perde-il-carico/135734/136266', | |
89 | 'only_matching': True, | |
90 | }, { | |
91 | 'url': 'https://video.gazzettadimodena.gelocal.it/locale/modena-scoperta-la-proteina-che-predice-il-livello-di-gravita-del-covid/139109/139796', | |
92 | 'only_matching': True, | |
93 | }, { | |
94 | 'url': 'https://video.lanuovaferrara.gelocal.it/locale/due-bombole-di-gpl-aperte-e-abbandonate-i-vigili-bruciano-il-gas/134391/134957', | |
95 | 'only_matching': True, | |
96 | }, { | |
97 | 'url': 'https://video.corrierealpi.gelocal.it/dossier/cortina-2021-i-mondiali-di-sci-alpino/mondiali-di-sci-il-timelapse-sulla-splendida-olympia/133760/134331', | |
98 | 'only_matching': True, | |
99 | }, { | |
100 | 'url': 'https://video.lasentinella.gelocal.it/locale/vestigne-centra-un-auto-e-si-ribalta/138931/139466', | |
101 | 'only_matching': True, | |
102 | }, { | |
103 | 'url': 'https://video.espresso.repubblica.it/tutti-i-video/01-ted-villa/14772', | |
104 | 'only_matching': True, | |
105 | }] | |
106 | ||
107 | @staticmethod | |
108 | def _sanitize_urls(urls): | |
109 | # add protocol if missing | |
110 | for i, e in enumerate(urls): | |
111 | if e.startswith('//'): | |
112 | urls[i] = f'https:{e}' | |
113 | # clean iframes urls | |
114 | for i, e in enumerate(urls): | |
115 | urls[i] = urljoin(base_url(e), url_basename(e)) | |
116 | return urls | |
117 | ||
118 | @classmethod | |
119 | def _extract_embed_urls(cls, url, webpage): | |
120 | return cls._sanitize_urls(tuple(super()._extract_embed_urls(url, webpage))) | |
121 | ||
122 | @staticmethod | |
123 | def _clean_formats(formats): | |
124 | format_urls = set() | |
125 | clean_formats = [] | |
126 | for f in formats: | |
127 | if f['url'] not in format_urls: | |
128 | if f.get('audio_ext') != 'none' and not f.get('acodec'): | |
129 | continue | |
130 | format_urls.add(f['url']) | |
131 | clean_formats.append(f) | |
132 | formats[:] = clean_formats | |
133 | ||
134 | def _real_extract(self, url): | |
135 | video_id, url = self._match_valid_url(url).group('id', 'base_url') | |
136 | webpage = self._download_webpage(url, video_id) | |
137 | title = self._html_search_meta( | |
138 | ['twitter:title', 'og:title'], webpage, fatal=True) | |
139 | player_data = re.findall( | |
140 | r"PlayerFactory\.setParam\('(?P<type>format|param)',\s*'(?P<name>[^']+)',\s*'(?P<val>[^']+)'\);", | |
141 | webpage) | |
142 | ||
143 | formats = [] | |
144 | duration = thumb = None | |
145 | for t, n, v in player_data: | |
146 | if t == 'format': | |
147 | if n in ('video-hds-vod-ec', 'video-hls-vod-ec', 'video-viralize', 'video-youtube-pfp'): | |
148 | continue | |
149 | elif n.endswith('-vod-ak'): | |
150 | formats.extend(self._extract_akamai_formats( | |
151 | v, video_id, {'http': 'media.gedidigital.it'})) | |
152 | else: | |
153 | ext = determine_ext(v) | |
154 | if ext == 'm3u8': | |
155 | formats.extend(self._extract_m3u8_formats( | |
156 | v, video_id, 'mp4', 'm3u8_native', m3u8_id=n, fatal=False)) | |
157 | continue | |
158 | f = { | |
159 | 'format_id': n, | |
160 | 'url': v, | |
161 | } | |
162 | if ext == 'mp3': | |
163 | abr = int_or_none(self._search_regex( | |
164 | r'-mp3-audio-(\d+)', v, 'abr', default=None)) | |
165 | f.update({ | |
166 | 'abr': abr, | |
167 | 'tbr': abr, | |
168 | 'acodec': ext, | |
169 | 'vcodec': 'none', | |
170 | }) | |
171 | else: | |
172 | mobj = re.match(r'^video-rrtv-(\d+)(?:-(\d+))?$', n) | |
173 | if mobj: | |
174 | f.update({ | |
175 | 'height': int(mobj.group(1)), | |
176 | 'vbr': int_or_none(mobj.group(2)), | |
177 | }) | |
178 | if not f.get('vbr'): | |
179 | f['vbr'] = int_or_none(self._search_regex( | |
180 | r'-video-rrtv-(\d+)', v, 'abr', default=None)) | |
181 | formats.append(f) | |
182 | elif t == 'param': | |
183 | if n in ['image_full', 'image']: | |
184 | thumb = v | |
185 | elif n == 'videoDuration': | |
186 | duration = int_or_none(v) | |
187 | ||
188 | self._clean_formats(formats) | |
189 | ||
190 | return { | |
191 | 'id': video_id, | |
192 | 'title': title, | |
193 | 'description': self._html_search_meta( | |
194 | ['twitter:description', 'og:description', 'description'], webpage), | |
195 | 'thumbnail': thumb or self._og_search_thumbnail(webpage), | |
196 | 'formats': formats, | |
197 | 'duration': duration, | |
198 | } |