la7.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. determine_ext,
  5. float_or_none,
  6. HEADRequest,
  7. int_or_none,
  8. parse_duration,
  9. unified_strdate,
  10. )
  11. class LA7IE(InfoExtractor):
  12. IE_NAME = 'la7.it'
  13. _VALID_URL = r'''(?x)(https?://)?(?:
  14. (?:www\.)?la7\.it/([^/]+)/(?:rivedila7|video)/|
  15. tg\.la7\.it/repliche-tgla7\?id=
  16. )(?P<id>.+)'''
  17. _TESTS = [{
  18. # 'src' is a plain URL
  19. 'url': 'http://www.la7.it/crozza/video/inccool8-02-10-2015-163722',
  20. 'md5': '8b613ffc0c4bf9b9e377169fc19c214c',
  21. 'info_dict': {
  22. 'id': 'inccool8-02-10-2015-163722',
  23. 'ext': 'mp4',
  24. 'title': 'Inc.Cool8',
  25. 'description': 'Benvenuti nell\'incredibile mondo della INC. COOL. 8. dove “INC.” sta per “Incorporated” “COOL” sta per “fashion” ed Eight sta per il gesto atletico',
  26. 'thumbnail': 're:^https?://.*',
  27. 'upload_date': '20151002',
  28. },
  29. }, {
  30. 'url': 'http://www.la7.it/omnibus/rivedila7/omnibus-news-02-07-2016-189077',
  31. 'only_matching': True,
  32. }]
  33. _HOST = 'https://awsvodpkg.iltrovatore.it'
  34. def _generate_mp4_url(self, quality, m3u8_formats):
  35. for f in m3u8_formats:
  36. if f['vcodec'] != 'none' and quality in f['url']:
  37. http_url = '%s%s.mp4' % (self._HOST, quality)
  38. urlh = self._request_webpage(
  39. HEADRequest(http_url), quality,
  40. note='Check filesize', fatal=False)
  41. if urlh:
  42. http_f = f.copy()
  43. del http_f['manifest_url']
  44. http_f.update({
  45. 'format_id': http_f['format_id'].replace('hls-', 'https-'),
  46. 'url': http_url,
  47. 'protocol': 'https',
  48. 'filesize_approx': int_or_none(urlh.headers.get('Content-Length', None)),
  49. })
  50. return http_f
  51. return None
  52. def _real_extract(self, url):
  53. video_id = self._match_id(url)
  54. if not url.startswith('http'):
  55. url = '%s//%s' % (self.http_scheme(), url)
  56. webpage = self._download_webpage(url, video_id)
  57. video_path = self._search_regex(r'(/content/.*?).mp4', webpage, 'video_path')
  58. formats = self._extract_mpd_formats(
  59. f'{self._HOST}/local/dash/,{video_path}.mp4.urlset/manifest.mpd',
  60. video_id, mpd_id='dash', fatal=False)
  61. m3u8_formats = self._extract_m3u8_formats(
  62. f'{self._HOST}/local/hls/,{video_path}.mp4.urlset/master.m3u8',
  63. video_id, 'mp4', m3u8_id='hls', fatal=False)
  64. formats.extend(m3u8_formats)
  65. for q in filter(None, video_path.split(',')):
  66. http_f = self._generate_mp4_url(q, m3u8_formats)
  67. if http_f:
  68. formats.append(http_f)
  69. return {
  70. 'id': video_id,
  71. 'title': self._og_search_title(webpage, default=None),
  72. 'description': self._og_search_description(webpage, default=None),
  73. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  74. 'formats': formats,
  75. 'upload_date': unified_strdate(self._search_regex(r'datetime="(.+?)"', webpage, 'upload_date', fatal=False))
  76. }
  77. class LA7PodcastEpisodeIE(InfoExtractor):
  78. IE_NAME = 'la7.it:pod:episode'
  79. _VALID_URL = r'''(?x)(https?://)?
  80. (?:www\.)?la7\.it/[^/]+/podcast/([^/]+-)?(?P<id>\d+)'''
  81. _TESTS = [{
  82. 'url': 'https://www.la7.it/voicetown/podcast/la-carezza-delle-memoria-di-carlo-verdone-23-03-2021-371497',
  83. 'md5': '7737d4d79b3c1a34b3de3e16297119ed',
  84. 'info_dict': {
  85. 'id': '371497',
  86. 'ext': 'mp3',
  87. 'title': '"La carezza delle memoria" di Carlo Verdone',
  88. 'description': 'md5:5abf07c3c551a687db80af3f9ceb7d52',
  89. 'thumbnail': 'https://www.la7.it/sites/default/files/podcast/371497.jpg',
  90. 'upload_date': '20210323',
  91. },
  92. }, {
  93. # embed url
  94. 'url': 'https://www.la7.it/embed/podcast/371497',
  95. 'only_matching': True,
  96. }, {
  97. # date already in the title
  98. 'url': 'https://www.la7.it/propagandalive/podcast/lintervista-di-diego-bianchi-ad-annalisa-cuzzocrea-puntata-del-1932021-20-03-2021-371130',
  99. 'only_matching': True,
  100. }, {
  101. # title same as show_title
  102. 'url': 'https://www.la7.it/otto-e-mezzo/podcast/otto-e-mezzo-26-03-2021-372340',
  103. 'only_matching': True,
  104. }]
  105. def _extract_info(self, webpage, video_id=None, ppn=None):
  106. if not video_id:
  107. video_id = self._search_regex(
  108. r'data-nid=([\'"])(?P<vid>\d+)\1',
  109. webpage, 'video_id', group='vid')
  110. media_url = self._search_regex(
  111. (r'src:\s*([\'"])(?P<url>.+?mp3.+?)\1',
  112. r'data-podcast=([\'"])(?P<url>.+?mp3.+?)\1'),
  113. webpage, 'media_url', group='url')
  114. ext = determine_ext(media_url)
  115. formats = [{
  116. 'url': media_url,
  117. 'format_id': ext,
  118. 'ext': ext,
  119. }]
  120. title = self._html_search_regex(
  121. (r'<div class="title">(?P<title>.+?)</',
  122. r'<title>(?P<title>[^<]+)</title>',
  123. r'title:\s*([\'"])(?P<title>.+?)\1'),
  124. webpage, 'title', group='title')
  125. description = (
  126. self._html_search_regex(
  127. (r'<div class="description">(.+?)</div>',
  128. r'<div class="description-mobile">(.+?)</div>',
  129. r'<div class="box-txt">([^<]+?)</div>',
  130. r'<div class="field-content"><p>(.+?)</p></div>'),
  131. webpage, 'description', default=None)
  132. or self._html_search_meta('description', webpage))
  133. thumb = self._html_search_regex(
  134. (r'<div class="podcast-image"><img src="(.+?)"></div>',
  135. r'<div class="container-embed"[^<]+url\((.+?)\);">',
  136. r'<div class="field-content"><img src="(.+?)"'),
  137. webpage, 'thumbnail', fatal=False, default=None)
  138. duration = parse_duration(self._html_search_regex(
  139. r'<span class="(?:durata|duration)">([\d:]+)</span>',
  140. webpage, 'duration', fatal=False, default=None))
  141. date = self._html_search_regex(
  142. r'class="data">\s*(?:<span>)?([\d\.]+)\s*</',
  143. webpage, 'date', default=None)
  144. date_alt = self._search_regex(
  145. r'(\d+[\./]\d+[\./]\d+)', title, 'date_alt', default=None)
  146. ppn = ppn or self._search_regex(
  147. r'ppN:\s*([\'"])(?P<ppn>.+?)\1',
  148. webpage, 'ppn', group='ppn', default=None)
  149. # if the date is not in the title
  150. # and title is the same as the show_title
  151. # add the date to the title
  152. if date and not date_alt and ppn and ppn.lower() == title.lower():
  153. title += ' del %s' % date
  154. return {
  155. 'id': video_id,
  156. 'title': title,
  157. 'description': description,
  158. 'duration': float_or_none(duration),
  159. 'formats': formats,
  160. 'thumbnail': thumb,
  161. 'upload_date': unified_strdate(date),
  162. }
  163. def _real_extract(self, url):
  164. video_id = self._match_id(url)
  165. webpage = self._download_webpage(url, video_id)
  166. return self._extract_info(webpage, video_id)
  167. class LA7PodcastIE(LA7PodcastEpisodeIE): # XXX: Do not subclass from concrete IE
  168. IE_NAME = 'la7.it:podcast'
  169. _VALID_URL = r'(https?://)?(www\.)?la7\.it/(?P<id>[^/]+)/podcast/?(?:$|[#?])'
  170. _TESTS = [{
  171. 'url': 'https://www.la7.it/propagandalive/podcast',
  172. 'info_dict': {
  173. 'id': 'propagandalive',
  174. 'title': "Propaganda Live",
  175. },
  176. 'playlist_count': 10,
  177. }]
  178. def _real_extract(self, url):
  179. playlist_id = self._match_id(url)
  180. webpage = self._download_webpage(url, playlist_id)
  181. title = (
  182. self._html_search_regex(
  183. r'<h1.*?>(.+?)</h1>', webpage, 'title', fatal=False, default=None)
  184. or self._og_search_title(webpage))
  185. ppn = self._search_regex(
  186. r'window\.ppN\s*=\s*([\'"])(?P<ppn>.+?)\1',
  187. webpage, 'ppn', group='ppn', default=None)
  188. entries = []
  189. for episode in re.finditer(
  190. r'<div class="container-podcast-property">([\s\S]+?)(?:</div>\s*){3}',
  191. webpage):
  192. entries.append(self._extract_info(episode.group(1), ppn=ppn))
  193. return self.playlist_result(entries, playlist_id, title)