]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/skyit.py
[ie/youtube] Extract upload timestamp if available (#9856)
[yt-dlp.git] / yt_dlp / extractor / skyit.py
1 from .common import InfoExtractor
2 from ..compat import (
3 compat_parse_qs,
4 compat_urllib_parse_urlparse,
5 )
6 from ..utils import (
7 dict_get,
8 int_or_none,
9 parse_duration,
10 unified_timestamp,
11 )
12
13
14 class 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 'skyarte': 'LWk29hfiU39NNdq87ePeRach3nzTSV20o0lTv2001Cd',
29 'theupfront': 'PRSGmDMsg6QMGc04Obpoy7Vsbn7i2Whp',
30 }
31
32 def _player_url_result(self, video_id):
33 return self.url_result(
34 self._PLAYER_TMPL % (video_id, self._DOMAIN),
35 SkyItPlayerIE.ie_key(), video_id)
36
37 def _parse_video(self, video, video_id):
38 title = video['title']
39 is_live = video.get('type') == 'live'
40 hls_url = video.get(('streaming' if is_live else 'hls') + '_url')
41 if not hls_url and video.get('geoblock' if is_live else 'geob'):
42 self.raise_geo_restricted(countries=['IT'])
43
44 formats = self._extract_m3u8_formats(hls_url, video_id, 'mp4')
45
46 return {
47 'id': video_id,
48 'title': title,
49 'formats': formats,
50 'thumbnail': dict_get(video, ('video_still', 'video_still_medium', 'thumb')),
51 'description': video.get('short_desc') or None,
52 'timestamp': unified_timestamp(video.get('create_date')),
53 'duration': int_or_none(video.get('duration_sec')) or parse_duration(video.get('duration')),
54 'is_live': is_live,
55 }
56
57 def _real_extract(self, url):
58 video_id = self._match_id(url)
59 domain = compat_parse_qs(compat_urllib_parse_urlparse(
60 url).query).get('domain', [None])[0]
61 token = dict_get(self._TOKEN_MAP, (domain, 'sky'))
62 video = self._download_json(
63 'https://apid.sky.it/vdp/v1/getVideoData',
64 video_id, query={
65 'caller': 'sky',
66 'id': video_id,
67 'token': token
68 }, headers=self.geo_verification_headers())
69 return self._parse_video(video, video_id)
70
71
72 class SkyItVideoIE(SkyItPlayerIE): # XXX: Do not subclass from concrete IE
73 IE_NAME = 'video.sky.it'
74 _VALID_URL = r'https?://(?:masterchef|video|xfactor)\.sky\.it(?:/[^/]+)*/video/[0-9a-z-]+-(?P<id>\d+)'
75 _TESTS = [{
76 'url': 'https://video.sky.it/news/mondo/video/uomo-ucciso-da-uno-squalo-in-australia-631227',
77 'md5': '5b858a62d9ffe2ab77b397553024184a',
78 'info_dict': {
79 'id': '631227',
80 'ext': 'mp4',
81 'title': 'Uomo ucciso da uno squalo in Australia',
82 'timestamp': 1606036192,
83 'upload_date': '20201122',
84 'duration': 26,
85 'thumbnail': 'https://video.sky.it/captures/thumbs/631227/631227_thumb_880x494.jpg',
86 },
87 'params': {'skip_download': 'm3u8'},
88 }, {
89 'url': 'https://xfactor.sky.it/video/x-factor-2020-replay-audizioni-1-615820',
90 'only_matching': True,
91 }, {
92 'url': 'https://masterchef.sky.it/video/masterchef-9-cosa-e-successo-nella-prima-puntata-562831',
93 'only_matching': True,
94 }]
95
96 def _real_extract(self, url):
97 video_id = self._match_id(url)
98 return self._player_url_result(video_id)
99
100
101 class SkyItVideoLiveIE(SkyItPlayerIE): # XXX: Do not subclass from concrete IE
102 IE_NAME = 'video.sky.it:live'
103 _VALID_URL = r'https?://video\.sky\.it/diretta/(?P<id>[^/?&#]+)'
104 _TEST = {
105 'url': 'https://video.sky.it/diretta/tg24',
106 'info_dict': {
107 'id': '1',
108 'ext': 'mp4',
109 'title': r're:Diretta TG24 \d{4}-\d{2}-\d{2} \d{2}:\d{2}',
110 'description': r're:(?:Clicca play e )?[Gg]uarda la diretta streaming di SkyTg24, segui con Sky tutti gli appuntamenti e gli speciali di Tg24\.',
111 'live_status': 'is_live',
112 },
113 'params': {
114 # m3u8 download
115 'skip_download': True,
116 },
117 }
118
119 def _real_extract(self, url):
120 display_id = self._match_id(url)
121 webpage = self._download_webpage(url, display_id)
122 asset_id = str(self._search_nextjs_data(webpage, display_id)['props']['initialState']['livePage']['content']['asset_id'])
123 livestream = self._download_json(
124 'https://apid.sky.it/vdp/v1/getLivestream',
125 asset_id, query={'id': asset_id})
126 return self._parse_video(livestream, asset_id)
127
128
129 class SkyItIE(SkyItPlayerIE): # XXX: Do not subclass from concrete IE
130 IE_NAME = 'sky.it'
131 _VALID_URL = r'https?://(?:sport|tg24)\.sky\.it(?:/[^/]+)*/\d{4}/\d{2}/\d{2}/(?P<id>[^/?&#]+)'
132 _TESTS = [{
133 'url': 'https://sport.sky.it/calcio/serie-a/2022/11/03/brozovic-inter-news',
134 'info_dict': {
135 'id': '789222',
136 'ext': 'mp4',
137 'title': 'Brozovic con il gruppo: verso convocazione per Juve-Inter',
138 'upload_date': '20221103',
139 'timestamp': 1667484130,
140 'duration': 22,
141 'thumbnail': 'https://videoplatform.sky.it/still/2022/11/03/1667480526353_brozovic_videostill_1.jpg',
142 },
143 'params': {'skip_download': 'm3u8'},
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 'duration': 26,
154 'thumbnail': 'https://video.sky.it/captures/thumbs/631227/631227_thumb_880x494.jpg',
155 },
156 'params': {'skip_download': 'm3u8'},
157 }]
158 _VIDEO_ID_REGEX = r'data-videoid="(\d+)"'
159
160 def _real_extract(self, url):
161 display_id = self._match_id(url)
162 webpage = self._download_webpage(url, display_id)
163 video_id = self._search_regex(
164 self._VIDEO_ID_REGEX, webpage, 'video id')
165 return self._player_url_result(video_id)
166
167
168 class SkyItArteIE(SkyItIE): # XXX: Do not subclass from concrete IE
169 IE_NAME = 'arte.sky.it'
170 _VALID_URL = r'https?://arte\.sky\.it/video/(?P<id>[^/?&#]+)'
171 _TESTS = [{
172 'url': 'https://arte.sky.it/video/oliviero-toscani-torino-galleria-mazzoleni-788962',
173 'md5': '515aee97b87d7a018b6c80727d3e7e17',
174 'info_dict': {
175 'id': '788962',
176 'ext': 'mp4',
177 'title': 'La fotografia di Oliviero Toscani conquista Torino',
178 'upload_date': '20221102',
179 'timestamp': 1667399996,
180 'duration': 12,
181 'thumbnail': 'https://videoplatform.sky.it/still/2022/11/02/1667396388552_oliviero-toscani-torino-galleria-mazzoleni_videostill_1.jpg',
182 },
183 'params': {'skip_download': 'm3u8'},
184 }]
185 _DOMAIN = 'skyarte'
186 _VIDEO_ID_REGEX = r'"embedUrl"\s*:\s*"(?:https:)?//player\.sky\.it/player/external\.html\?[^"]*\bid=(\d+)'
187
188
189 class CieloTVItIE(SkyItIE): # XXX: Do not subclass from concrete IE
190 IE_NAME = 'cielotv.it'
191 _VALID_URL = r'https?://(?:www\.)?cielotv\.it/video/(?P<id>[^.]+)\.html'
192 _TESTS = [{
193 'url': 'https://www.cielotv.it/video/Il-lunedi-e-sempre-un-dramma.html',
194 'md5': 'c4deed77552ba901c2a0d9258320304b',
195 'info_dict': {
196 'id': '499240',
197 'ext': 'mp4',
198 'title': 'Il lunedì è sempre un dramma',
199 'upload_date': '20190329',
200 'timestamp': 1553862178,
201 'duration': 30,
202 'thumbnail': 'https://videoplatform.sky.it/still/2019/03/29/1553858575610_lunedi_dramma_mant_videostill_1.jpg',
203 },
204 'params': {'skip_download': 'm3u8'},
205 }]
206 _DOMAIN = 'cielo'
207 _VIDEO_ID_REGEX = r'videoId\s*=\s*"(\d+)"'
208
209
210 class TV8ItIE(SkyItVideoIE): # XXX: Do not subclass from concrete IE
211 IE_NAME = 'tv8.it'
212 _VALID_URL = r'https?://(?:www\.)?tv8\.it/(?:show)?video/[0-9a-z-]+-(?P<id>\d+)'
213 _TESTS = [{
214 'url': 'https://www.tv8.it/video/ogni-mattina-ucciso-asino-di-andrea-lo-cicero-630529',
215 'md5': '9ab906a3f75ea342ed928442f9dabd21',
216 'info_dict': {
217 'id': '630529',
218 'ext': 'mp4',
219 'title': 'Ogni mattina - Ucciso asino di Andrea Lo Cicero',
220 'timestamp': 1605721374,
221 'upload_date': '20201118',
222 'duration': 114,
223 'thumbnail': 'https://videoplatform.sky.it/still/2020/11/18/1605717753954_ogni-mattina-ucciso-asino-di-andrea-lo-cicero_videostill_1.jpg',
224 },
225 'params': {'skip_download': 'm3u8'},
226 }]
227 _DOMAIN = 'mtv8'