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