gedidigital.py 8.3 KB

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