]>
Commit | Line | Data |
---|---|---|
0de13634 T |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
e6ff66ef | 4 | import functools |
ca04de46 S |
5 | import re |
6 | ||
38f1eb0a | 7 | from .theplatform import ThePlatformBaseIE |
0de13634 | 8 | from ..utils import ( |
38f1eb0a | 9 | ExtractorError, |
22219f2d | 10 | GeoRestrictedError, |
38f1eb0a | 11 | int_or_none, |
e6ff66ef | 12 | OnDemandPagedList, |
4dfbf869 | 13 | parse_qs, |
e6ff66ef | 14 | try_get, |
15 | urljoin, | |
38f1eb0a | 16 | update_url_query, |
0de13634 T |
17 | ) |
18 | ||
19 | ||
38f1eb0a RA |
20 | class MediasetIE(ThePlatformBaseIE): |
21 | _TP_TLD = 'eu' | |
56f9c77f | 22 | _VALID_URL = r'''(?x) |
ca04de46 S |
23 | (?: |
24 | mediaset:| | |
25 | https?:// | |
38f1eb0a | 26 | (?:(?:www|static3)\.)?mediasetplay\.mediaset\.it/ |
ca04de46 | 27 | (?: |
29f7c58a | 28 | (?:video|on-demand|movie)/(?:[^/]+/)+[^/]+_| |
38f1eb0a | 29 | player/index\.html\?.*?\bprogramGuid= |
ca04de46 | 30 | ) |
bf45295c | 31 | )(?P<id>[0-9A-Z]{16,}) |
56f9c77f | 32 | ''' |
0de13634 T |
33 | _TESTS = [{ |
34 | # full episode | |
02226207 | 35 | 'url': 'https://www.mediasetplay.mediaset.it/video/mrwronglezionidamore/episodio-1_F310575103000102', |
36 | 'md5': 'a7e75c6384871f322adb781d3bd72c26', | |
0de13634 | 37 | 'info_dict': { |
02226207 | 38 | 'id': 'F310575103000102', |
0de13634 | 39 | 'ext': 'mp4', |
02226207 | 40 | 'title': 'Episodio 1', |
22219f2d | 41 | 'description': 'md5:e8017b7d7194e9bfb75299c2b8d81e02', |
56f9c77f | 42 | 'thumbnail': r're:^https?://.*\.jpg$', |
02226207 | 43 | 'duration': 2682.0, |
44 | 'upload_date': '20210530', | |
45 | 'series': 'Mr Wrong - Lezioni d\'amore', | |
46 | 'timestamp': 1622413946, | |
47 | 'uploader': 'Canale 5', | |
48 | 'uploader_id': 'C5', | |
22219f2d | 49 | 'season': 'Season 1', |
50 | 'episode': 'Episode 1', | |
51 | 'season_number': 1, | |
52 | 'episode_number': 1, | |
53 | 'chapters': [{'start_time': 0.0, 'end_time': 439.88}, {'start_time': 439.88, 'end_time': 1685.84}, {'start_time': 1685.84, 'end_time': 2682.0}], | |
56f9c77f | 54 | }, |
9cf648c9 | 55 | }, { |
38f1eb0a | 56 | 'url': 'https://www.mediasetplay.mediaset.it/video/matrix/puntata-del-25-maggio_F309013801000501', |
49ca8db0 | 57 | 'md5': '1276f966ac423d16ba255ce867de073e', |
9cf648c9 | 58 | 'info_dict': { |
38f1eb0a | 59 | 'id': 'F309013801000501', |
9cf648c9 T |
60 | 'ext': 'mp4', |
61 | 'title': 'Puntata del 25 maggio', | |
22219f2d | 62 | 'description': 'md5:ee2e456e3eb1dba5e814596655bb5296', |
9cf648c9 | 63 | 'thumbnail': r're:^https?://.*\.jpg$', |
02226207 | 64 | 'duration': 6565.008, |
65 | 'upload_date': '20200903', | |
9cf648c9 | 66 | 'series': 'Matrix', |
02226207 | 67 | 'timestamp': 1599172492, |
38f1eb0a RA |
68 | 'uploader': 'Canale 5', |
69 | 'uploader_id': 'C5', | |
22219f2d | 70 | 'season': 'Season 5', |
71 | 'episode': 'Episode 5', | |
72 | 'season_number': 5, | |
73 | 'episode_number': 5, | |
74 | 'chapters': [{'start_time': 0.0, 'end_time': 3409.08}, {'start_time': 3409.08, 'end_time': 6565.008}], | |
9cf648c9 | 75 | }, |
ee57a19d | 76 | }, { |
77 | 'url': 'https://www.mediasetplay.mediaset.it/video/cameracafe5/episodio-69-pezzo-di-luna_F303843101017801', | |
78 | 'md5': 'd1650ac9ff944f185556126a736df148', | |
79 | 'info_dict': { | |
80 | 'id': 'F303843101017801', | |
81 | 'ext': 'mp4', | |
82 | 'title': 'Episodio 69 - Pezzo di luna', | |
22219f2d | 83 | 'description': 'md5:7c32c8ec4118b72588b9412f11353f73', |
ee57a19d | 84 | 'thumbnail': r're:^https?://.*\.jpg$', |
85 | 'duration': 263.008, | |
86 | 'upload_date': '20200902', | |
87 | 'series': 'Camera Café 5', | |
88 | 'timestamp': 1599064700, | |
89 | 'uploader': 'Italia 1', | |
90 | 'uploader_id': 'I1', | |
22219f2d | 91 | 'season': 'Season 5', |
92 | 'episode': 'Episode 178', | |
93 | 'season_number': 5, | |
94 | 'episode_number': 178, | |
95 | 'chapters': [{'start_time': 0.0, 'end_time': 261.88}, {'start_time': 261.88, 'end_time': 263.008}], | |
ee57a19d | 96 | }, |
49ca8db0 | 97 | }, { |
98 | 'url': 'https://www.mediasetplay.mediaset.it/video/cameracafe5/episodio-51-tu-chi-sei_F303843107000601', | |
99 | 'md5': '567e9ad375b7a27a0e370650f572a1e3', | |
100 | 'info_dict': { | |
101 | 'id': 'F303843107000601', | |
102 | 'ext': 'mp4', | |
103 | 'title': 'Episodio 51 - Tu chi sei?', | |
22219f2d | 104 | 'description': 'md5:42ef006e56824cc31787a547590923f4', |
49ca8db0 | 105 | 'thumbnail': r're:^https?://.*\.jpg$', |
106 | 'duration': 367.021, | |
107 | 'upload_date': '20200902', | |
108 | 'series': 'Camera Café 5', | |
109 | 'timestamp': 1599069817, | |
110 | 'uploader': 'Italia 1', | |
111 | 'uploader_id': 'I1', | |
22219f2d | 112 | 'season': 'Season 5', |
113 | 'episode': 'Episode 6', | |
114 | 'season_number': 5, | |
115 | 'episode_number': 6, | |
116 | 'chapters': [{'start_time': 0.0, 'end_time': 358.68}, {'start_time': 358.68, 'end_time': 367.021}], | |
117 | }, | |
118 | }, { | |
119 | # movie | |
120 | 'url': 'https://www.mediasetplay.mediaset.it/movie/selvaggi/selvaggi_F006474501000101', | |
121 | 'md5': '720440187a2ae26af8148eb9e6b901ed', | |
122 | 'info_dict': { | |
123 | 'id': 'F006474501000101', | |
124 | 'ext': 'mp4', | |
125 | 'title': 'Selvaggi', | |
126 | 'description': 'md5:cfdedbbfdd12d4d0e5dcf1fa1b75284f', | |
127 | 'thumbnail': r're:^https?://.*\.jpg$', | |
128 | 'duration': 5233.01, | |
129 | 'upload_date': '20210729', | |
130 | 'timestamp': 1627594716, | |
131 | 'uploader': 'Cine34', | |
132 | 'uploader_id': 'B6', | |
133 | 'chapters': [{'start_time': 0.0, 'end_time': 1938.56}, {'start_time': 1938.56, 'end_time': 5233.01}], | |
49ca8db0 | 134 | }, |
0de13634 T |
135 | }, { |
136 | # clip | |
38f1eb0a | 137 | 'url': 'https://www.mediasetplay.mediaset.it/video/gogglebox/un-grande-classico-della-commedia-sexy_FAFU000000661680', |
56f9c77f | 138 | 'only_matching': True, |
0de13634 T |
139 | }, { |
140 | # iframe simple | |
38f1eb0a | 141 | 'url': 'https://static3.mediasetplay.mediaset.it/player/index.html?appKey=5ad3966b1de1c4000d5cec48&programGuid=FAFU000000665924&id=665924', |
56f9c77f | 142 | 'only_matching': True, |
0de13634 T |
143 | }, { |
144 | # iframe twitter (from http://www.wittytv.it/se-prima-mi-fidavo-zero/) | |
38f1eb0a | 145 | 'url': 'https://static3.mediasetplay.mediaset.it/player/index.html?appKey=5ad3966b1de1c4000d5cec48&programGuid=FAFU000000665104&id=665104', |
56f9c77f | 146 | 'only_matching': True, |
ca04de46 | 147 | }, { |
38f1eb0a | 148 | 'url': 'mediaset:FAFU000000665924', |
ca04de46 | 149 | 'only_matching': True, |
bf45295c RA |
150 | }, { |
151 | 'url': 'https://www.mediasetplay.mediaset.it/video/mediasethaacuoreilfuturo/palmieri-alicudi-lisola-dei-tre-bambini-felici--un-decreto-per-alicudi-e-tutte-le-microscuole_FD00000000102295', | |
152 | 'only_matching': True, | |
153 | }, { | |
154 | 'url': 'https://www.mediasetplay.mediaset.it/video/cherryseason/anticipazioni-degli-episodi-del-23-ottobre_F306837101005C02', | |
155 | 'only_matching': True, | |
156 | }, { | |
157 | 'url': 'https://www.mediasetplay.mediaset.it/video/tg5/ambiente-onda-umana-per-salvare-il-pianeta_F309453601079D01', | |
158 | 'only_matching': True, | |
159 | }, { | |
160 | 'url': 'https://www.mediasetplay.mediaset.it/video/grandefratellovip/benedetta-una-doccia-gelata_F309344401044C135', | |
161 | 'only_matching': True, | |
29f7c58a | 162 | }, { |
163 | 'url': 'https://www.mediasetplay.mediaset.it/movie/herculeslaleggendahainizio/hercules-la-leggenda-ha-inizio_F305927501000102', | |
164 | 'only_matching': True, | |
0de13634 T |
165 | }] |
166 | ||
5d29af3d | 167 | @staticmethod |
8fd12a08 S |
168 | def _extract_urls(ie, webpage): |
169 | def _qs(url): | |
4dfbf869 | 170 | return parse_qs(url) |
8fd12a08 S |
171 | |
172 | def _program_guid(qs): | |
173 | return qs.get('programGuid', [None])[0] | |
174 | ||
175 | entries = [] | |
176 | for mobj in re.finditer( | |
177 | r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//(?:www\.)?video\.mediaset\.it/player/playerIFrame(?:Twitter)?\.shtml.*?)\1', | |
178 | webpage): | |
179 | embed_url = mobj.group('url') | |
180 | embed_qs = _qs(embed_url) | |
181 | program_guid = _program_guid(embed_qs) | |
182 | if program_guid: | |
183 | entries.append(embed_url) | |
184 | continue | |
185 | video_id = embed_qs.get('id', [None])[0] | |
186 | if not video_id: | |
187 | continue | |
188 | urlh = ie._request_webpage( | |
189 | embed_url, video_id, note='Following embed URL redirect') | |
7947a1f7 | 190 | embed_url = urlh.geturl() |
8fd12a08 S |
191 | program_guid = _program_guid(_qs(embed_url)) |
192 | if program_guid: | |
193 | entries.append(embed_url) | |
194 | return entries | |
5d29af3d | 195 | |
ef382405 RA |
196 | def _parse_smil_formats(self, smil, smil_url, video_id, namespace=None, f4m_params=None, transform_rtmp_url=None): |
197 | for video in smil.findall(self._xpath_ns('.//video', namespace)): | |
198 | video.attrib['src'] = re.sub(r'(https?://vod05)t(-mediaset-it\.akamaized\.net/.+?.mpd)\?.+', r'\1\2', video.attrib['src']) | |
9b6e72fd | 199 | return super(MediasetIE, self)._parse_smil_formats(smil, smil_url, video_id, namespace, f4m_params, transform_rtmp_url) |
ef382405 | 200 | |
22219f2d | 201 | def _check_drm_formats(self, tp_formats, video_id): |
202 | has_nondrm, drm_manifest = False, '' | |
203 | for f in tp_formats: | |
204 | if '_sampleaes/' in (f.get('manifest_url') or ''): | |
205 | drm_manifest = drm_manifest or f['manifest_url'] | |
206 | f['has_drm'] = True | |
207 | if not f.get('has_drm') and f.get('manifest_url'): | |
208 | has_nondrm = True | |
209 | ||
210 | nodrm_manifest = re.sub(r'_sampleaes/(\w+)_fp_', r'/\1_no_', drm_manifest) | |
211 | if has_nondrm or nodrm_manifest == drm_manifest: | |
212 | return | |
213 | ||
214 | tp_formats.extend(self._extract_m3u8_formats( | |
215 | nodrm_manifest, video_id, m3u8_id='hls', fatal=False) or []) | |
216 | ||
0de13634 | 217 | def _real_extract(self, url): |
38f1eb0a RA |
218 | guid = self._match_id(url) |
219 | tp_path = 'PR1GhC/media/guid/2702976343/' + guid | |
220 | info = self._extract_theplatform_metadata(tp_path, guid) | |
0de13634 | 221 | |
56f9c77f | 222 | formats = [] |
38f1eb0a | 223 | subtitles = {} |
22219f2d | 224 | first_e = geo_e = None |
49ca8db0 | 225 | asset_type = 'geoNo:HD,browser,geoIT|geoNo:HD,geoIT|geoNo:SD,browser,geoIT|geoNo:SD,geoIT|geoNo|HD|SD' |
02226207 | 226 | # TODO: fixup ISM+none manifest URLs |
22219f2d | 227 | for f in ('MPEG4', 'M3U'): |
02226207 | 228 | try: |
229 | tp_formats, tp_subtitles = self._extract_theplatform_smil( | |
230 | update_url_query('http://link.theplatform.%s/s/%s' % (self._TP_TLD, tp_path), { | |
231 | 'mbr': 'true', | |
232 | 'formats': f, | |
233 | 'assetTypes': asset_type, | |
234 | }), guid, 'Downloading %s SMIL data' % (f.split('+')[0])) | |
235 | except ExtractorError as e: | |
22219f2d | 236 | if not geo_e and isinstance(e, GeoRestrictedError): |
237 | geo_e = e | |
02226207 | 238 | if not first_e: |
239 | first_e = e | |
22219f2d | 240 | continue |
241 | self._check_drm_formats(tp_formats, guid) | |
02226207 | 242 | formats.extend(tp_formats) |
243 | subtitles = self._merge_subtitles(subtitles, tp_subtitles) | |
22219f2d | 244 | |
245 | # check for errors and report them | |
246 | if (first_e or geo_e) and not formats: | |
247 | raise geo_e or first_e | |
248 | ||
56f9c77f | 249 | self._sort_formats(formats) |
0de13634 | 250 | |
38f1eb0a | 251 | feed_data = self._download_json( |
02226207 | 252 | 'https://feed.entertainment.tv.theplatform.eu/f/PR1GhC/mediaset-prod-all-programs-v2/guid/-/' + guid, |
253 | guid, fatal=False) | |
38f1eb0a RA |
254 | if feed_data: |
255 | publish_info = feed_data.get('mediasetprogram$publishInfo') or {} | |
02226207 | 256 | thumbnails = feed_data.get('thumbnails') or {} |
257 | thumbnail = None | |
258 | for key, value in thumbnails.items(): | |
259 | if key.startswith('image_keyframe_poster-'): | |
260 | thumbnail = value.get('url') | |
261 | break | |
262 | ||
38f1eb0a | 263 | info.update({ |
22219f2d | 264 | 'description': info.get('description') or feed_data.get('description') or feed_data.get('longDescription'), |
38f1eb0a RA |
265 | 'uploader': publish_info.get('description'), |
266 | 'uploader_id': publish_info.get('channel'), | |
267 | 'view_count': int_or_none(feed_data.get('mediasetprogram$numberOfViews')), | |
02226207 | 268 | 'thumbnail': thumbnail, |
38f1eb0a | 269 | }) |
0de13634 | 270 | |
22219f2d | 271 | if feed_data.get('programType') == 'episode': |
272 | info.update({ | |
273 | 'episode_number': int_or_none( | |
274 | feed_data.get('tvSeasonEpisodeNumber')), | |
275 | 'season_number': int_or_none( | |
276 | feed_data.get('tvSeasonNumber')), | |
277 | 'series': feed_data.get('mediasetprogram$brandTitle'), | |
278 | }) | |
279 | ||
38f1eb0a RA |
280 | info.update({ |
281 | 'id': guid, | |
56f9c77f | 282 | 'formats': formats, |
38f1eb0a RA |
283 | 'subtitles': subtitles, |
284 | }) | |
285 | return info | |
e6ff66ef | 286 | |
287 | ||
288 | class MediasetShowIE(MediasetIE): | |
289 | _VALID_URL = r'''(?x) | |
290 | (?: | |
291 | https?:// | |
292 | (?:(?:www|static3)\.)?mediasetplay\.mediaset\.it/ | |
293 | (?: | |
22219f2d | 294 | (?:fiction|programmi-tv|serie-tv|kids)/(?:.+?/)? |
295 | (?:[a-z-]+)_SE(?P<id>\d{12}) | |
e6ff66ef | 296 | (?:,ST(?P<st>\d{12}))? |
297 | (?:,sb(?P<sb>\d{9}))?$ | |
298 | ) | |
299 | ) | |
300 | ''' | |
301 | _TESTS = [{ | |
22219f2d | 302 | # TV Show webpage (general webpage) |
303 | 'url': 'https://www.mediasetplay.mediaset.it/programmi-tv/leiene/leiene_SE000000000061', | |
e6ff66ef | 304 | 'info_dict': { |
22219f2d | 305 | 'id': '000000000061', |
306 | 'title': 'Le Iene', | |
e6ff66ef | 307 | }, |
22219f2d | 308 | 'playlist_mincount': 7, |
e6ff66ef | 309 | }, { |
22219f2d | 310 | # TV Show webpage (specific season) |
e6ff66ef | 311 | 'url': 'https://www.mediasetplay.mediaset.it/programmi-tv/leiene/leiene_SE000000000061,ST000000002763', |
312 | 'info_dict': { | |
313 | 'id': '000000002763', | |
314 | 'title': 'Le Iene', | |
315 | }, | |
22219f2d | 316 | 'playlist_mincount': 7, |
e6ff66ef | 317 | }, { |
318 | # TV Show specific playlist (with multiple pages) | |
319 | 'url': 'https://www.mediasetplay.mediaset.it/programmi-tv/leiene/iservizi_SE000000000061,ST000000002763,sb100013375', | |
320 | 'info_dict': { | |
321 | 'id': '100013375', | |
322 | 'title': 'I servizi', | |
323 | }, | |
22219f2d | 324 | 'playlist_mincount': 50, |
e6ff66ef | 325 | }] |
326 | ||
327 | _BY_SUBBRAND = 'https://feed.entertainment.tv.theplatform.eu/f/PR1GhC/mediaset-prod-all-programs-v2?byCustomValue={subBrandId}{%s}&sort=:publishInfo_lastPublished|desc,tvSeasonEpisodeNumber|desc&range=%d-%d' | |
328 | _PAGE_SIZE = 25 | |
329 | ||
330 | def _fetch_page(self, sb, page): | |
331 | lower_limit = page * self._PAGE_SIZE + 1 | |
332 | upper_limit = lower_limit + self._PAGE_SIZE - 1 | |
333 | content = self._download_json( | |
334 | self._BY_SUBBRAND % (sb, lower_limit, upper_limit), sb) | |
335 | for entry in content.get('entries') or []: | |
336 | yield self.url_result( | |
337 | 'mediaset:' + entry['guid'], | |
338 | playlist_title=entry['mediasetprogram$subBrandDescription']) | |
339 | ||
340 | def _real_extract(self, url): | |
341 | playlist_id, st, sb = self._match_valid_url(url).group('id', 'st', 'sb') | |
342 | if not sb: | |
22219f2d | 343 | page = self._download_webpage(url, st or playlist_id) |
e6ff66ef | 344 | entries = [self.url_result(urljoin('https://www.mediasetplay.mediaset.it', url)) |
345 | for url in re.findall(r'href="([^<>=]+SE\d{12},ST\d{12},sb\d{9})">[^<]+<', page)] | |
346 | title = (self._html_search_regex(r'(?s)<h1[^>]*>(.+?)</h1>', page, 'title', default=None) | |
347 | or self._og_search_title(page)) | |
348 | return self.playlist_result(entries, st or playlist_id, title) | |
349 | ||
350 | entries = OnDemandPagedList( | |
351 | functools.partial(self._fetch_page, sb), | |
352 | self._PAGE_SIZE) | |
353 | title = try_get(entries, lambda x: x[0]['playlist_title']) | |
354 | ||
355 | return self.playlist_result(entries, sb, title) |