]>
Commit | Line | Data |
---|---|---|
0de13634 T |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
ca04de46 S |
4 | import re |
5 | ||
38f1eb0a | 6 | from .theplatform import ThePlatformBaseIE |
8fd12a08 S |
7 | from ..compat import ( |
8 | compat_parse_qs, | |
8fd12a08 S |
9 | compat_urllib_parse_urlparse, |
10 | ) | |
0de13634 | 11 | from ..utils import ( |
38f1eb0a RA |
12 | ExtractorError, |
13 | int_or_none, | |
14 | update_url_query, | |
0de13634 T |
15 | ) |
16 | ||
17 | ||
38f1eb0a RA |
18 | class MediasetIE(ThePlatformBaseIE): |
19 | _TP_TLD = 'eu' | |
56f9c77f | 20 | _VALID_URL = r'''(?x) |
ca04de46 S |
21 | (?: |
22 | mediaset:| | |
23 | https?:// | |
38f1eb0a | 24 | (?:(?:www|static3)\.)?mediasetplay\.mediaset\.it/ |
ca04de46 | 25 | (?: |
29f7c58a | 26 | (?:video|on-demand|movie)/(?:[^/]+/)+[^/]+_| |
38f1eb0a | 27 | player/index\.html\?.*?\bprogramGuid= |
ca04de46 | 28 | ) |
bf45295c | 29 | )(?P<id>[0-9A-Z]{16,}) |
56f9c77f | 30 | ''' |
0de13634 T |
31 | _TESTS = [{ |
32 | # full episode | |
38f1eb0a | 33 | 'url': 'https://www.mediasetplay.mediaset.it/video/hellogoodbye/quarta-puntata_FAFU000000661824', |
0de13634 T |
34 | 'md5': '9b75534d42c44ecef7bf1ffeacb7f85d', |
35 | 'info_dict': { | |
38f1eb0a | 36 | 'id': 'FAFU000000661824', |
0de13634 T |
37 | 'ext': 'mp4', |
38 | 'title': 'Quarta puntata', | |
38f1eb0a | 39 | 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e', |
56f9c77f | 40 | 'thumbnail': r're:^https?://.*\.jpg$', |
38f1eb0a | 41 | 'duration': 1414.26, |
d105a7ed | 42 | 'upload_date': '20161107', |
56f9c77f | 43 | 'series': 'Hello Goodbye', |
38f1eb0a RA |
44 | 'timestamp': 1478532900, |
45 | 'uploader': 'Rete 4', | |
46 | 'uploader_id': 'R4', | |
56f9c77f | 47 | }, |
9cf648c9 | 48 | }, { |
38f1eb0a RA |
49 | 'url': 'https://www.mediasetplay.mediaset.it/video/matrix/puntata-del-25-maggio_F309013801000501', |
50 | 'md5': '288532f0ad18307705b01e581304cd7b', | |
9cf648c9 | 51 | 'info_dict': { |
38f1eb0a | 52 | 'id': 'F309013801000501', |
9cf648c9 T |
53 | 'ext': 'mp4', |
54 | 'title': 'Puntata del 25 maggio', | |
38f1eb0a | 55 | 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e', |
9cf648c9 | 56 | 'thumbnail': r're:^https?://.*\.jpg$', |
38f1eb0a RA |
57 | 'duration': 6565.007, |
58 | 'upload_date': '20180526', | |
9cf648c9 | 59 | 'series': 'Matrix', |
38f1eb0a RA |
60 | 'timestamp': 1527326245, |
61 | 'uploader': 'Canale 5', | |
62 | 'uploader_id': 'C5', | |
9cf648c9 | 63 | }, |
0de13634 T |
64 | }, { |
65 | # clip | |
38f1eb0a | 66 | 'url': 'https://www.mediasetplay.mediaset.it/video/gogglebox/un-grande-classico-della-commedia-sexy_FAFU000000661680', |
56f9c77f | 67 | 'only_matching': True, |
0de13634 T |
68 | }, { |
69 | # iframe simple | |
38f1eb0a | 70 | 'url': 'https://static3.mediasetplay.mediaset.it/player/index.html?appKey=5ad3966b1de1c4000d5cec48&programGuid=FAFU000000665924&id=665924', |
56f9c77f | 71 | 'only_matching': True, |
0de13634 T |
72 | }, { |
73 | # iframe twitter (from http://www.wittytv.it/se-prima-mi-fidavo-zero/) | |
38f1eb0a | 74 | 'url': 'https://static3.mediasetplay.mediaset.it/player/index.html?appKey=5ad3966b1de1c4000d5cec48&programGuid=FAFU000000665104&id=665104', |
56f9c77f | 75 | 'only_matching': True, |
ca04de46 | 76 | }, { |
38f1eb0a | 77 | 'url': 'mediaset:FAFU000000665924', |
ca04de46 | 78 | 'only_matching': True, |
bf45295c RA |
79 | }, { |
80 | 'url': 'https://www.mediasetplay.mediaset.it/video/mediasethaacuoreilfuturo/palmieri-alicudi-lisola-dei-tre-bambini-felici--un-decreto-per-alicudi-e-tutte-le-microscuole_FD00000000102295', | |
81 | 'only_matching': True, | |
82 | }, { | |
83 | 'url': 'https://www.mediasetplay.mediaset.it/video/cherryseason/anticipazioni-degli-episodi-del-23-ottobre_F306837101005C02', | |
84 | 'only_matching': True, | |
85 | }, { | |
86 | 'url': 'https://www.mediasetplay.mediaset.it/video/tg5/ambiente-onda-umana-per-salvare-il-pianeta_F309453601079D01', | |
87 | 'only_matching': True, | |
88 | }, { | |
89 | 'url': 'https://www.mediasetplay.mediaset.it/video/grandefratellovip/benedetta-una-doccia-gelata_F309344401044C135', | |
90 | 'only_matching': True, | |
29f7c58a | 91 | }, { |
92 | 'url': 'https://www.mediasetplay.mediaset.it/movie/herculeslaleggendahainizio/hercules-la-leggenda-ha-inizio_F305927501000102', | |
93 | 'only_matching': True, | |
0de13634 T |
94 | }] |
95 | ||
5d29af3d | 96 | @staticmethod |
8fd12a08 S |
97 | def _extract_urls(ie, webpage): |
98 | def _qs(url): | |
99 | return compat_parse_qs(compat_urllib_parse_urlparse(url).query) | |
100 | ||
101 | def _program_guid(qs): | |
102 | return qs.get('programGuid', [None])[0] | |
103 | ||
104 | entries = [] | |
105 | for mobj in re.finditer( | |
106 | r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//(?:www\.)?video\.mediaset\.it/player/playerIFrame(?:Twitter)?\.shtml.*?)\1', | |
107 | webpage): | |
108 | embed_url = mobj.group('url') | |
109 | embed_qs = _qs(embed_url) | |
110 | program_guid = _program_guid(embed_qs) | |
111 | if program_guid: | |
112 | entries.append(embed_url) | |
113 | continue | |
114 | video_id = embed_qs.get('id', [None])[0] | |
115 | if not video_id: | |
116 | continue | |
117 | urlh = ie._request_webpage( | |
118 | embed_url, video_id, note='Following embed URL redirect') | |
7947a1f7 | 119 | embed_url = urlh.geturl() |
8fd12a08 S |
120 | program_guid = _program_guid(_qs(embed_url)) |
121 | if program_guid: | |
122 | entries.append(embed_url) | |
123 | return entries | |
5d29af3d | 124 | |
ef382405 RA |
125 | def _parse_smil_formats(self, smil, smil_url, video_id, namespace=None, f4m_params=None, transform_rtmp_url=None): |
126 | for video in smil.findall(self._xpath_ns('.//video', namespace)): | |
127 | video.attrib['src'] = re.sub(r'(https?://vod05)t(-mediaset-it\.akamaized\.net/.+?.mpd)\?.+', r'\1\2', video.attrib['src']) | |
9b6e72fd | 128 | return super(MediasetIE, self)._parse_smil_formats(smil, smil_url, video_id, namespace, f4m_params, transform_rtmp_url) |
ef382405 | 129 | |
0de13634 | 130 | def _real_extract(self, url): |
38f1eb0a RA |
131 | guid = self._match_id(url) |
132 | tp_path = 'PR1GhC/media/guid/2702976343/' + guid | |
133 | info = self._extract_theplatform_metadata(tp_path, guid) | |
0de13634 | 134 | |
56f9c77f | 135 | formats = [] |
38f1eb0a RA |
136 | subtitles = {} |
137 | first_e = None | |
138 | for asset_type in ('SD', 'HD'): | |
ef382405 RA |
139 | # TODO: fixup ISM+none manifest URLs |
140 | for f in ('MPEG4', 'MPEG-DASH+none', 'M3U+none'): | |
38f1eb0a RA |
141 | try: |
142 | tp_formats, tp_subtitles = self._extract_theplatform_smil( | |
143 | update_url_query('http://link.theplatform.%s/s/%s' % (self._TP_TLD, tp_path), { | |
144 | 'mbr': 'true', | |
145 | 'formats': f, | |
146 | 'assetTypes': asset_type, | |
ef382405 | 147 | }), guid, 'Downloading %s %s SMIL data' % (f.split('+')[0], asset_type)) |
38f1eb0a RA |
148 | except ExtractorError as e: |
149 | if not first_e: | |
150 | first_e = e | |
151 | break | |
152 | for tp_f in tp_formats: | |
153 | tp_f['quality'] = 1 if asset_type == 'HD' else 0 | |
154 | formats.extend(tp_formats) | |
155 | subtitles = self._merge_subtitles(subtitles, tp_subtitles) | |
156 | if first_e and not formats: | |
157 | raise first_e | |
56f9c77f | 158 | self._sort_formats(formats) |
0de13634 | 159 | |
38f1eb0a RA |
160 | fields = [] |
161 | for templ, repls in (('tvSeason%sNumber', ('', 'Episode')), ('mediasetprogram$%s', ('brandTitle', 'numberOfViews', 'publishInfo'))): | |
162 | fields.extend(templ % repl for repl in repls) | |
163 | feed_data = self._download_json( | |
164 | 'https://feed.entertainment.tv.theplatform.eu/f/PR1GhC/mediaset-prod-all-programs/guid/-/' + guid, | |
165 | guid, fatal=False, query={'fields': ','.join(fields)}) | |
166 | if feed_data: | |
167 | publish_info = feed_data.get('mediasetprogram$publishInfo') or {} | |
168 | info.update({ | |
169 | 'episode_number': int_or_none(feed_data.get('tvSeasonEpisodeNumber')), | |
170 | 'season_number': int_or_none(feed_data.get('tvSeasonNumber')), | |
171 | 'series': feed_data.get('mediasetprogram$brandTitle'), | |
172 | 'uploader': publish_info.get('description'), | |
173 | 'uploader_id': publish_info.get('channel'), | |
174 | 'view_count': int_or_none(feed_data.get('mediasetprogram$numberOfViews')), | |
175 | }) | |
0de13634 | 176 | |
38f1eb0a RA |
177 | info.update({ |
178 | 'id': guid, | |
56f9c77f | 179 | 'formats': formats, |
38f1eb0a RA |
180 | 'subtitles': subtitles, |
181 | }) | |
182 | return info |