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