gedidigital.py (7100B)
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 determine_ext, 9 int_or_none, 10 ) 11 12 13 class GediDigitalIE(InfoExtractor): 14 _VALID_URL = r'''(?x)https?://video\. 15 (?: 16 (?: 17 (?:espresso\.)?repubblica 18 |lastampa 19 |ilsecoloxix 20 )| 21 (?: 22 iltirreno 23 |messaggeroveneto 24 |ilpiccolo 25 |gazzettadimantova 26 |mattinopadova 27 |laprovinciapavese 28 |tribunatreviso 29 |nuovavenezia 30 |gazzettadimodena 31 |lanuovaferrara 32 |corrierealpi 33 |lasentinella 34 )\.gelocal 35 )\.it(?:/[^/]+){2,3}?/(?P<id>\d+)(?:[/?&#]|$)''' 36 _TESTS = [{ 37 'url': 'https://video.lastampa.it/politica/il-paradosso-delle-regionali-la-lega-vince-ma-sembra-aver-perso/121559/121683', 38 'md5': '84658d7fb9e55a6e57ecc77b73137494', 39 'info_dict': { 40 'id': '121559', 41 'ext': 'mp4', 42 'title': 'Il paradosso delle Regionali: ecco perché la Lega vince ma sembra aver perso', 43 'description': 'md5:de7f4d6eaaaf36c153b599b10f8ce7ca', 44 'thumbnail': r're:^https://www\.repstatic\.it/video/photo/.+?-thumb-full-.+?\.jpg$', 45 'duration': 125, 46 }, 47 }, { 48 'url': 'https://video.espresso.repubblica.it/embed/tutti-i-video/01-ted-villa/14772/14870&width=640&height=360', 49 'only_matching': True, 50 }, { 51 'url': 'https://video.repubblica.it/motori/record-della-pista-a-spa-francorchamps-la-pagani-huayra-roadster-bc-stupisce/367415/367963', 52 'only_matching': True, 53 }, { 54 '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', 55 'only_matching': True, 56 }, { 57 'url': 'https://video.iltirreno.gelocal.it/sport/dentro-la-notizia-ferrari-cosa-succede-a-maranello/141059/142723', 58 'only_matching': True, 59 }, { 60 'url': 'https://video.messaggeroveneto.gelocal.it/locale/maria-giovanna-elmi-covid-vaccino/138155/139268', 61 'only_matching': True, 62 }, { 63 'url': 'https://video.ilpiccolo.gelocal.it/dossier/big-john/dinosauro-big-john-al-via-le-visite-guidate-a-trieste/135226/135751', 64 'only_matching': True, 65 }, { 66 'url': 'https://video.gazzettadimantova.gelocal.it/locale/dal-ponte-visconteo-di-valeggio-l-and-8217sos-dei-ristoratori-aprire-anche-a-cena/137310/137818', 67 'only_matching': True, 68 }, { 69 'url': 'https://video.mattinopadova.gelocal.it/dossier/coronavirus-in-veneto/covid-a-vo-un-anno-dopo-un-cuore-tricolore-per-non-dimenticare/138402/138964', 70 'only_matching': True, 71 }, { 72 'url': 'https://video.laprovinciapavese.gelocal.it/locale/mede-zona-rossa-via-alle-vaccinazioni-per-gli-over-80/137545/138120', 73 'only_matching': True, 74 }, { 75 'url': 'https://video.tribunatreviso.gelocal.it/dossier/coronavirus-in-veneto/ecco-le-prima-vaccinazioni-di-massa-nella-marca/134485/135024', 76 'only_matching': True, 77 }, { 78 'url': 'https://video.nuovavenezia.gelocal.it/locale/camion-troppo-alto-per-il-ponte-ferroviario-perde-il-carico/135734/136266', 79 'only_matching': True, 80 }, { 81 'url': 'https://video.gazzettadimodena.gelocal.it/locale/modena-scoperta-la-proteina-che-predice-il-livello-di-gravita-del-covid/139109/139796', 82 'only_matching': True, 83 }, { 84 'url': 'https://video.lanuovaferrara.gelocal.it/locale/due-bombole-di-gpl-aperte-e-abbandonate-i-vigili-bruciano-il-gas/134391/134957', 85 'only_matching': True, 86 }, { 87 'url': 'https://video.corrierealpi.gelocal.it/dossier/cortina-2021-i-mondiali-di-sci-alpino/mondiali-di-sci-il-timelapse-sulla-splendida-olympia/133760/134331', 88 'only_matching': True, 89 }, { 90 'url': 'https://video.lasentinella.gelocal.it/locale/vestigne-centra-un-auto-e-si-ribalta/138931/139466', 91 'only_matching': True, 92 }, { 93 'url': 'https://video.espresso.repubblica.it/tutti-i-video/01-ted-villa/14772', 94 'only_matching': True, 95 }] 96 97 def _real_extract(self, url): 98 video_id = self._match_id(url) 99 100 webpage = self._download_webpage(url, video_id) 101 title = self._html_search_meta( 102 ['twitter:title', 'og:title'], webpage, fatal=True) 103 player_data = re.findall( 104 r"PlayerFactory\.setParam\('(?P<type>format|param)',\s*'(?P<name>[^']+)',\s*'(?P<val>[^']+)'\);", 105 webpage) 106 107 formats = [] 108 duration = thumb = None 109 for t, n, v in player_data: 110 if t == 'format': 111 if n in ('video-hds-vod-ec', 'video-hls-vod-ec', 'video-viralize', 'video-youtube-pfp'): 112 continue 113 elif n.endswith('-vod-ak'): 114 formats.extend(self._extract_akamai_formats( 115 v, video_id, {'http': 'media.gedidigital.it'})) 116 else: 117 ext = determine_ext(v) 118 if ext == 'm3u8': 119 formats.extend(self._extract_m3u8_formats( 120 v, video_id, 'mp4', 'm3u8_native', m3u8_id=n, fatal=False)) 121 continue 122 f = { 123 'format_id': n, 124 'url': v, 125 } 126 if ext == 'mp3': 127 abr = int_or_none(self._search_regex( 128 r'-mp3-audio-(\d+)', v, 'abr', default=None)) 129 f.update({ 130 'abr': abr, 131 'tbr': abr, 132 'vcodec': 'none' 133 }) 134 else: 135 mobj = re.match(r'^video-rrtv-(\d+)(?:-(\d+))?$', n) 136 if mobj: 137 f.update({ 138 'height': int(mobj.group(1)), 139 'vbr': int_or_none(mobj.group(2)), 140 }) 141 if not f.get('vbr'): 142 f['vbr'] = int_or_none(self._search_regex( 143 r'-video-rrtv-(\d+)', v, 'abr', default=None)) 144 formats.append(f) 145 elif t == 'param': 146 if n in ['image_full', 'image']: 147 thumb = v 148 elif n == 'videoDuration': 149 duration = int_or_none(v) 150 151 self._sort_formats(formats) 152 153 return { 154 'id': video_id, 155 'title': title, 156 'description': self._html_search_meta( 157 ['twitter:description', 'og:description', 'description'], webpage), 158 'thumbnail': thumb or self._og_search_thumbnail(webpage), 159 'formats': formats, 160 'duration': duration, 161 }