]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/la7.py
[extractor/youtube] Fix continuation loop with no comments (#7148)
[yt-dlp.git] / yt_dlp / extractor / la7.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 float_or_none,
6 HEADRequest,
7 int_or_none,
8 parse_duration,
9 unified_strdate,
10 )
11
12
13 class LA7IE(InfoExtractor):
14 IE_NAME = 'la7.it'
15 _VALID_URL = r'''(?x)https?://(?:
16 (?:www\.)?la7\.it/([^/]+)/(?:rivedila7|video|news)/|
17 tg\.la7\.it/repliche-tgla7\?id=
18 )(?P<id>.+)'''
19
20 _TESTS = [{
21 # single quality video
22 'url': 'http://www.la7.it/crozza/video/inccool8-02-10-2015-163722',
23 'md5': '8b613ffc0c4bf9b9e377169fc19c214c',
24 'info_dict': {
25 'id': 'inccool8-02-10-2015-163722',
26 'ext': 'mp4',
27 'title': 'Inc.Cool8',
28 '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',
29 'thumbnail': 're:^https?://.*',
30 'upload_date': '20151002',
31 'formats': 'count:4',
32 },
33 }, {
34 # multiple quality video
35 'url': 'https://www.la7.it/calcio-femminile/news/il-gol-di-lindsey-thomas-fiorentina-vs-milan-serie-a-calcio-femminile-26-11-2022-461736',
36 'md5': 'd2370e78f75e8d1238cb3a0db9a2eda3',
37 'info_dict': {
38 'id': 'il-gol-di-lindsey-thomas-fiorentina-vs-milan-serie-a-calcio-femminile-26-11-2022-461736',
39 'ext': 'mp4',
40 'title': 'Il gol di Lindsey Thomas | Fiorentina vs Milan | Serie A Calcio Femminile',
41 'description': 'Il gol di Lindsey Thomas | Fiorentina vs Milan | Serie A Calcio Femminile',
42 'thumbnail': 're:^https?://.*',
43 'upload_date': '20221126',
44 'formats': 'count:8',
45 },
46 }, {
47 'url': 'http://www.la7.it/omnibus/rivedila7/omnibus-news-02-07-2016-189077',
48 'only_matching': True,
49 }]
50 _HOST = 'https://awsvodpkg.iltrovatore.it'
51
52 def _generate_mp4_url(self, quality, m3u8_formats):
53 for f in m3u8_formats:
54 if f['vcodec'] != 'none' and quality in f['url']:
55 http_url = f'{self._HOST}{quality}.mp4'
56
57 urlh = self._request_webpage(
58 HEADRequest(http_url), quality,
59 note='Check filesize', fatal=False)
60 if urlh:
61 http_f = f.copy()
62 del http_f['manifest_url']
63 http_f.update({
64 'format_id': http_f['format_id'].replace('hls-', 'https-'),
65 'url': http_url,
66 'protocol': 'https',
67 'filesize_approx': int_or_none(urlh.headers.get('Content-Length', None)),
68 })
69 return http_f
70 return None
71
72 def _real_extract(self, url):
73 video_id = self._match_id(url)
74 webpage = self._download_webpage(url, video_id)
75
76 if re.search(r'(?i)(drmsupport\s*:\s*true)\s*', webpage):
77 self.report_drm(video_id)
78
79 video_path = self._search_regex(
80 r'(/content/[\w/,]+?)\.mp4(?:\.csmil)?/master\.m3u8', webpage, 'video_path')
81
82 formats = self._extract_mpd_formats(
83 f'{self._HOST}/local/dash/,{video_path}.mp4.urlset/manifest.mpd',
84 video_id, mpd_id='dash', fatal=False)
85 m3u8_formats = self._extract_m3u8_formats(
86 f'{self._HOST}/local/hls/,{video_path}.mp4.urlset/master.m3u8',
87 video_id, 'mp4', m3u8_id='hls', fatal=False)
88 formats.extend(m3u8_formats)
89
90 for q in filter(None, video_path.split(',')):
91 http_f = self._generate_mp4_url(q, m3u8_formats)
92 if http_f:
93 formats.append(http_f)
94
95 return {
96 'id': video_id,
97 'title': self._og_search_title(webpage, default=None),
98 'description': self._og_search_description(webpage, default=None),
99 'thumbnail': self._og_search_thumbnail(webpage, default=None),
100 'formats': formats,
101 'upload_date': unified_strdate(self._search_regex(r'datetime="(.+?)"', webpage, 'upload_date', fatal=False))
102 }
103
104
105 class LA7PodcastEpisodeIE(InfoExtractor):
106 IE_NAME = 'la7.it:pod:episode'
107 _VALID_URL = r'https?://(?:www\.)?la7\.it/[^/]+/podcast/([^/]+-)?(?P<id>\d+)'
108
109 _TESTS = [{
110 'url': 'https://www.la7.it/voicetown/podcast/la-carezza-delle-memoria-di-carlo-verdone-23-03-2021-371497',
111 'md5': '7737d4d79b3c1a34b3de3e16297119ed',
112 'info_dict': {
113 'id': '371497',
114 'ext': 'mp3',
115 'title': '"La carezza delle memoria" di Carlo Verdone',
116 'description': 'md5:5abf07c3c551a687db80af3f9ceb7d52',
117 'thumbnail': 'https://www.la7.it/sites/default/files/podcast/371497.jpg',
118 'upload_date': '20210323',
119 },
120 }, {
121 # embed url
122 'url': 'https://www.la7.it/embed/podcast/371497',
123 'only_matching': True,
124 }, {
125 # date already in the title
126 'url': 'https://www.la7.it/propagandalive/podcast/lintervista-di-diego-bianchi-ad-annalisa-cuzzocrea-puntata-del-1932021-20-03-2021-371130',
127 'only_matching': True,
128 }, {
129 # title same as show_title
130 'url': 'https://www.la7.it/otto-e-mezzo/podcast/otto-e-mezzo-26-03-2021-372340',
131 'only_matching': True,
132 }]
133
134 def _extract_info(self, webpage, video_id=None, ppn=None):
135 if not video_id:
136 video_id = self._search_regex(
137 r'data-nid=([\'"])(?P<vid>\d+)\1',
138 webpage, 'video_id', group='vid')
139
140 media_url = self._search_regex(
141 (r'src\s*:\s*([\'"])(?P<url>\S+?mp3.+?)\1',
142 r'data-podcast\s*=\s*([\'"])(?P<url>\S+?mp3.+?)\1'),
143 webpage, 'media_url', group='url')
144 formats = [{
145 'url': media_url,
146 'format_id': 'http-mp3',
147 'ext': 'mp3',
148 'acodec': 'mp3',
149 'vcodec': 'none',
150 }]
151
152 title = self._html_search_regex(
153 (r'<div class="title">(?P<title>.+?)</',
154 r'<title>(?P<title>[^<]+)</title>',
155 r'title:\s*([\'"])(?P<title>.+?)\1'),
156 webpage, 'title', group='title')
157
158 description = (
159 self._html_search_regex(
160 (r'<div class="description">(.+?)</div>',
161 r'<div class="description-mobile">(.+?)</div>',
162 r'<div class="box-txt">([^<]+?)</div>',
163 r'<div class="field-content"><p>(.+?)</p></div>'),
164 webpage, 'description', default=None)
165 or self._html_search_meta('description', webpage))
166
167 thumb = self._html_search_regex(
168 (r'<div class="podcast-image"><img src="(.+?)"></div>',
169 r'<div class="container-embed"[^<]+url\((.+?)\);">',
170 r'<div class="field-content"><img src="(.+?)"'),
171 webpage, 'thumbnail', fatal=False, default=None)
172
173 duration = parse_duration(self._html_search_regex(
174 r'<span class="(?:durata|duration)">([\d:]+)</span>',
175 webpage, 'duration', fatal=False, default=None))
176
177 date = self._html_search_regex(
178 r'class="data">\s*(?:<span>)?([\d\.]+)\s*</',
179 webpage, 'date', default=None)
180
181 date_alt = self._search_regex(
182 r'(\d+[\./]\d+[\./]\d+)', title, 'date_alt', default=None)
183 ppn = ppn or self._search_regex(
184 r'ppN:\s*([\'"])(?P<ppn>.+?)\1',
185 webpage, 'ppn', group='ppn', default=None)
186 # if the date is not in the title
187 # and title is the same as the show_title
188 # add the date to the title
189 if date and not date_alt and ppn and ppn.lower() == title.lower():
190 title = f'{title} del {date}'
191 return {
192 'id': video_id,
193 'title': title,
194 'description': description,
195 'duration': float_or_none(duration),
196 'formats': formats,
197 'thumbnail': thumb,
198 'upload_date': unified_strdate(date),
199 }
200
201 def _real_extract(self, url):
202 video_id = self._match_id(url)
203 webpage = self._download_webpage(url, video_id)
204
205 return self._extract_info(webpage, video_id)
206
207
208 class LA7PodcastIE(LA7PodcastEpisodeIE): # XXX: Do not subclass from concrete IE
209 IE_NAME = 'la7.it:podcast'
210 _VALID_URL = r'https?://(?:www\.)?la7\.it/(?P<id>[^/]+)/podcast/?(?:$|[#?])'
211
212 _TESTS = [{
213 'url': 'https://www.la7.it/propagandalive/podcast',
214 'info_dict': {
215 'id': 'propagandalive',
216 'title': "Propaganda Live",
217 },
218 'playlist_count_min': 10,
219 }]
220
221 def _real_extract(self, url):
222 playlist_id = self._match_id(url)
223 webpage = self._download_webpage(url, playlist_id)
224
225 title = (
226 self._html_search_regex(
227 r'<h1.*?>(.+?)</h1>', webpage, 'title', fatal=False, default=None)
228 or self._og_search_title(webpage))
229 ppn = self._search_regex(
230 r'window\.ppN\s*=\s*([\'"])(?P<ppn>.+?)\1',
231 webpage, 'ppn', group='ppn', default=None)
232
233 entries = []
234 for episode in re.finditer(
235 r'<div class="container-podcast-property">([\s\S]+?)(?:</div>\s*){3}',
236 webpage):
237 entries.append(self._extract_info(episode.group(1), ppn=ppn))
238
239 return self.playlist_result(entries, playlist_id, title)