]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/skyit.py
[extractor/FranceCulture] Fix extractor (#3874)
[yt-dlp.git] / yt_dlp / extractor / skyit.py
CommitLineData
12300fa4
RA
1from .common import InfoExtractor
2from ..compat import (
12300fa4
RA
3 compat_parse_qs,
4 compat_urllib_parse_urlparse,
5)
6from ..utils import (
7 dict_get,
8 int_or_none,
9 parse_duration,
10 unified_timestamp,
11)
12
13
14class SkyItPlayerIE(InfoExtractor):
15 IE_NAME = 'player.sky.it'
16 _VALID_URL = r'https?://player\.sky\.it/player/(?:external|social)\.html\?.*?\bid=(?P<id>\d+)'
17 _GEO_BYPASS = False
18 _DOMAIN = 'sky'
19 _PLAYER_TMPL = 'https://player.sky.it/player/external.html?id=%s&domain=%s'
20 # http://static.sky.it/static/skyplayer/conf.json
21 _TOKEN_MAP = {
22 'cielo': 'Hh9O7M8ks5yi6nSROL7bKYz933rdf3GhwZlTLMgvy4Q',
23 'hotclub': 'kW020K2jq2lk2eKRJD2vWEg832ncx2EivZlTLQput2C',
24 'mtv8': 'A5Nn9GGb326CI7vP5e27d7E4PIaQjota',
25 'salesforce': 'C6D585FD1615272C98DE38235F38BD86',
26 'sitocommerciale': 'VJwfFuSGnLKnd9Phe9y96WkXgYDCguPMJ2dLhGMb2RE',
27 'sky': 'F96WlOd8yoFmLQgiqv6fNQRvHZcsWk5jDaYnDvhbiJk',
28 'skyacademy': 'A6LAn7EkO2Q26FRy0IAMBekX6jzDXYL3',
29 'skyarte': 'LWk29hfiU39NNdq87ePeRach3nzTSV20o0lTv2001Cd',
30 'theupfront': 'PRSGmDMsg6QMGc04Obpoy7Vsbn7i2Whp',
31 }
32
33 def _player_url_result(self, video_id):
34 return self.url_result(
35 self._PLAYER_TMPL % (video_id, self._DOMAIN),
36 SkyItPlayerIE.ie_key(), video_id)
37
38 def _parse_video(self, video, video_id):
39 title = video['title']
40 is_live = video.get('type') == 'live'
41 hls_url = video.get(('streaming' if is_live else 'hls') + '_url')
42 if not hls_url and video.get('geoblock' if is_live else 'geob'):
43 self.raise_geo_restricted(countries=['IT'])
44
45 if is_live:
46 formats = self._extract_m3u8_formats(hls_url, video_id, 'mp4')
47 else:
48 formats = self._extract_akamai_formats(
49 hls_url, video_id, {'http': 'videoplatform.sky.it'})
50 self._sort_formats(formats)
51
52 return {
53 'id': video_id,
39ca3b5c 54 'title': title,
12300fa4
RA
55 'formats': formats,
56 'thumbnail': dict_get(video, ('video_still', 'video_still_medium', 'thumb')),
57 'description': video.get('short_desc') or None,
58 'timestamp': unified_timestamp(video.get('create_date')),
59 'duration': int_or_none(video.get('duration_sec')) or parse_duration(video.get('duration')),
60 'is_live': is_live,
61 }
62
63 def _real_extract(self, url):
64 video_id = self._match_id(url)
65 domain = compat_parse_qs(compat_urllib_parse_urlparse(
66 url).query).get('domain', [None])[0]
67 token = dict_get(self._TOKEN_MAP, (domain, 'sky'))
68 video = self._download_json(
69 'https://apid.sky.it/vdp/v1/getVideoData',
70 video_id, query={
71 'caller': 'sky',
72 'id': video_id,
73 'token': token
74 }, headers=self.geo_verification_headers())
75 return self._parse_video(video, video_id)
76
77
78class SkyItVideoIE(SkyItPlayerIE):
79 IE_NAME = 'video.sky.it'
80 _VALID_URL = r'https?://(?:masterchef|video|xfactor)\.sky\.it(?:/[^/]+)*/video/[0-9a-z-]+-(?P<id>\d+)'
81 _TESTS = [{
82 'url': 'https://video.sky.it/news/mondo/video/uomo-ucciso-da-uno-squalo-in-australia-631227',
83 'md5': 'fe5c91e59a84a3437eaa0bca6e134ccd',
84 'info_dict': {
85 'id': '631227',
86 'ext': 'mp4',
87 'title': 'Uomo ucciso da uno squalo in Australia',
88 'timestamp': 1606036192,
89 'upload_date': '20201122',
90 }
91 }, {
92 'url': 'https://xfactor.sky.it/video/x-factor-2020-replay-audizioni-1-615820',
93 'only_matching': True,
94 }, {
95 'url': 'https://masterchef.sky.it/video/masterchef-9-cosa-e-successo-nella-prima-puntata-562831',
96 'only_matching': True,
97 }]
98
99 def _real_extract(self, url):
100 video_id = self._match_id(url)
101 return self._player_url_result(video_id)
102
103
104class SkyItVideoLiveIE(SkyItPlayerIE):
105 IE_NAME = 'video.sky.it:live'
106 _VALID_URL = r'https?://video\.sky\.it/diretta/(?P<id>[^/?&#]+)'
107 _TEST = {
108 'url': 'https://video.sky.it/diretta/tg24',
109 'info_dict': {
110 'id': '1',
111 'ext': 'mp4',
112 'title': r're:Diretta TG24 \d{4}-\d{2}-\d{2} \d{2}:\d{2}',
113 'description': 'Guarda la diretta streaming di SkyTg24, segui con Sky tutti gli appuntamenti e gli speciali di Tg24.',
114 },
115 'params': {
116 # m3u8 download
117 'skip_download': True,
118 },
119 }
120
121 def _real_extract(self, url):
122 display_id = self._match_id(url)
123 webpage = self._download_webpage(url, display_id)
135dfa2c 124 asset_id = str(self._search_nextjs_data(webpage, display_id)['props']['initialState']['livePage']['content']['asset_id'])
12300fa4
RA
125 livestream = self._download_json(
126 'https://apid.sky.it/vdp/v1/getLivestream',
127 asset_id, query={'id': asset_id})
128 return self._parse_video(livestream, asset_id)
129
130
131class SkyItIE(SkyItPlayerIE):
132 IE_NAME = 'sky.it'
133 _VALID_URL = r'https?://(?:sport|tg24)\.sky\.it(?:/[^/]+)*/\d{4}/\d{2}/\d{2}/(?P<id>[^/?&#]+)'
134 _TESTS = [{
135 'url': 'https://sport.sky.it/calcio/serie-a/2020/11/21/juventus-cagliari-risultato-gol',
136 'info_dict': {
137 'id': '631201',
138 'ext': 'mp4',
139 'title': 'Un rosso alla violenza: in campo per i diritti delle donne',
140 'upload_date': '20201121',
141 'timestamp': 1605995753,
142 },
143 'expected_warnings': ['Unable to download f4m manifest'],
144 }, {
145 'url': 'https://tg24.sky.it/mondo/2020/11/22/australia-squalo-uccide-uomo',
146 'md5': 'fe5c91e59a84a3437eaa0bca6e134ccd',
147 'info_dict': {
148 'id': '631227',
149 'ext': 'mp4',
150 'title': 'Uomo ucciso da uno squalo in Australia',
151 'timestamp': 1606036192,
152 'upload_date': '20201122',
153 },
154 }]
155 _VIDEO_ID_REGEX = r'data-videoid="(\d+)"'
156
157 def _real_extract(self, url):
158 display_id = self._match_id(url)
159 webpage = self._download_webpage(url, display_id)
160 video_id = self._search_regex(
161 self._VIDEO_ID_REGEX, webpage, 'video id')
162 return self._player_url_result(video_id)
163
164
165class SkyItAcademyIE(SkyItIE):
166 IE_NAME = 'skyacademy.it'
167 _VALID_URL = r'https?://(?:www\.)?skyacademy\.it(?:/[^/]+)*/\d{4}/\d{2}/\d{2}/(?P<id>[^/?&#]+)'
168 _TESTS = [{
169 'url': 'https://www.skyacademy.it/eventi-speciali/2019/07/05/a-lezione-di-cinema-con-sky-academy-/',
170 'md5': 'ced5c26638b7863190cbc44dd6f6ba08',
171 'info_dict': {
172 'id': '523458',
173 'ext': 'mp4',
174 'title': 'Sky Academy "The Best CineCamp 2019"',
175 'timestamp': 1562843784,
176 'upload_date': '20190711',
177 }
178 }]
179 _DOMAIN = 'skyacademy'
180 _VIDEO_ID_REGEX = r'id="news-videoId_(\d+)"'
181
182
183class SkyItArteIE(SkyItIE):
184 IE_NAME = 'arte.sky.it'
185 _VALID_URL = r'https?://arte\.sky\.it/video/(?P<id>[^/?&#]+)'
186 _TESTS = [{
187 'url': 'https://arte.sky.it/video/serie-musei-venezia-collezionismo-12-novembre/',
188 'md5': '515aee97b87d7a018b6c80727d3e7e17',
189 'info_dict': {
190 'id': '627926',
191 'ext': 'mp4',
192 'title': "Musei Galleria Franchetti alla Ca' d'Oro Palazzo Grimani",
193 'upload_date': '20201106',
194 'timestamp': 1604664493,
195 }
196 }]
197 _DOMAIN = 'skyarte'
198 _VIDEO_ID_REGEX = r'(?s)<iframe[^>]+src="(?:https:)?//player\.sky\.it/player/external\.html\?[^"]*\bid=(\d+)'
199
200
201class CieloTVItIE(SkyItIE):
202 IE_NAME = 'cielotv.it'
203 _VALID_URL = r'https?://(?:www\.)?cielotv\.it/video/(?P<id>[^.]+)\.html'
204 _TESTS = [{
205 'url': 'https://www.cielotv.it/video/Il-lunedi-e-sempre-un-dramma.html',
206 'md5': 'c4deed77552ba901c2a0d9258320304b',
207 'info_dict': {
208 'id': '499240',
209 'ext': 'mp4',
210 'title': 'Il lunedì è sempre un dramma',
211 'upload_date': '20190329',
212 'timestamp': 1553862178,
213 }
214 }]
215 _DOMAIN = 'cielo'
216 _VIDEO_ID_REGEX = r'videoId\s*=\s*"(\d+)"'
217
218
219class TV8ItIE(SkyItVideoIE):
220 IE_NAME = 'tv8.it'
221 _VALID_URL = r'https?://tv8\.it/showvideo/(?P<id>\d+)'
222 _TESTS = [{
223 'url': 'https://tv8.it/showvideo/630529/ogni-mattina-ucciso-asino-di-andrea-lo-cicero/18-11-2020/',
224 'md5': '9ab906a3f75ea342ed928442f9dabd21',
225 'info_dict': {
226 'id': '630529',
227 'ext': 'mp4',
228 'title': 'Ogni mattina - Ucciso asino di Andrea Lo Cicero',
229 'timestamp': 1605721374,
230 'upload_date': '20201118',
231 }
232 }]
233 _DOMAIN = 'mtv8'