]>
Commit | Line | Data |
---|---|---|
abea9145 | 1 | # coding: utf-8 |
b0adbe98 S |
2 | from __future__ import unicode_literals |
3 | ||
b8d8cced S |
4 | import re |
5 | ||
afbdd3ac | 6 | from .common import InfoExtractor |
b8d8cced | 7 | from ..compat import ( |
b8d8cced | 8 | compat_str, |
b9d68c19 | 9 | compat_urlparse, |
b8d8cced | 10 | ) |
b0adbe98 | 11 | from ..utils import ( |
51342717 | 12 | determine_ext, |
b9d68c19 | 13 | ExtractorError, |
f1388739 YCH |
14 | find_xpath_attr, |
15 | fix_xml_ampersands, | |
b8d8cced | 16 | GeoRestrictedError, |
b9d68c19 | 17 | HEADRequest, |
f1388739 | 18 | int_or_none, |
b0adbe98 | 19 | parse_duration, |
a0566bbf | 20 | remove_start, |
b8d8cced | 21 | strip_or_none, |
a0566bbf | 22 | try_get, |
b0adbe98 | 23 | unified_strdate, |
b8d8cced | 24 | unified_timestamp, |
f1388739 | 25 | update_url_query, |
b8d8cced | 26 | urljoin, |
06d5556d | 27 | xpath_text, |
b0adbe98 S |
28 | ) |
29 | ||
30 | ||
034a8849 | 31 | class RaiBaseIE(InfoExtractor): |
b8d8cced S |
32 | _UUID_RE = r'[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}' |
33 | _GEO_COUNTRIES = ['IT'] | |
34 | _GEO_BYPASS = False | |
35 | ||
36 | def _extract_relinker_info(self, relinker_url, video_id): | |
0c7b4f49 RA |
37 | if not re.match(r'https?://', relinker_url): |
38 | return {'formats': [{'url': relinker_url}]} | |
39 | ||
034a8849 | 40 | formats = [] |
b8d8cced S |
41 | geoprotection = None |
42 | is_live = None | |
43 | duration = None | |
034a8849 YCH |
44 | |
45 | for platform in ('mon', 'flash', 'native'): | |
034a8849 YCH |
46 | relinker = self._download_xml( |
47 | relinker_url, video_id, | |
48 | note='Downloading XML metadata for platform %s' % platform, | |
49 | transform_source=fix_xml_ampersands, | |
38cce791 YCH |
50 | query={'output': 45, 'pl': platform}, |
51 | headers=self.geo_verification_headers()) | |
034a8849 | 52 | |
b8d8cced S |
53 | if not geoprotection: |
54 | geoprotection = xpath_text( | |
55 | relinker, './geoprotection', default=None) == 'Y' | |
56 | ||
57 | if not is_live: | |
58 | is_live = xpath_text( | |
59 | relinker, './is_live', default=None) == 'Y' | |
60 | if not duration: | |
61 | duration = parse_duration(xpath_text( | |
62 | relinker, './duration', default=None)) | |
63 | ||
64 | url_elem = find_xpath_attr(relinker, './url', 'type', 'content') | |
65 | if url_elem is None: | |
66 | continue | |
67 | ||
68 | media_url = url_elem.text | |
69 | ||
70 | # This does not imply geo restriction (e.g. | |
71 | # http://www.raisport.rai.it/dl/raiSport/media/rassegna-stampa-04a9f4bd-b563-40cf-82a6-aad3529cb4a9.html) | |
a0566bbf | 72 | if '/video_no_available.mp4' in media_url: |
b8d8cced | 73 | continue |
034a8849 YCH |
74 | |
75 | ext = determine_ext(media_url) | |
76 | if (ext == 'm3u8' and platform != 'mon') or (ext == 'f4m' and platform != 'flash'): | |
77 | continue | |
78 | ||
c17eb5b4 | 79 | if ext == 'm3u8' or 'format=m3u8' in media_url or platform == 'mon': |
034a8849 YCH |
80 | formats.extend(self._extract_m3u8_formats( |
81 | media_url, video_id, 'mp4', 'm3u8_native', | |
82 | m3u8_id='hls', fatal=False)) | |
c17eb5b4 | 83 | elif ext == 'f4m' or platform == 'flash': |
034a8849 YCH |
84 | manifest_url = update_url_query( |
85 | media_url.replace('manifest#live_hds.f4m', 'manifest.f4m'), | |
86 | {'hdcore': '3.7.0', 'plugin': 'aasp-3.7.0.39.44'}) | |
87 | formats.extend(self._extract_f4m_formats( | |
88 | manifest_url, video_id, f4m_id='hds', fatal=False)) | |
89 | else: | |
90 | bitrate = int_or_none(xpath_text(relinker, 'bitrate')) | |
91 | formats.append({ | |
92 | 'url': media_url, | |
93 | 'tbr': bitrate if bitrate > 0 else None, | |
94 | 'format_id': 'http-%d' % bitrate if bitrate > 0 else 'http', | |
95 | }) | |
96 | ||
b8d8cced | 97 | if not formats and geoprotection is True: |
b7da73eb | 98 | self.raise_geo_restricted(countries=self._GEO_COUNTRIES, metadata_available=True) |
b8d8cced | 99 | |
b9d68c19 | 100 | formats.extend(self._create_http_urls(relinker_url, formats)) |
101 | ||
b8d8cced S |
102 | return dict((k, v) for k, v in { |
103 | 'is_live': is_live, | |
104 | 'duration': duration, | |
105 | 'formats': formats, | |
106 | }.items() if v is not None) | |
034a8849 | 107 | |
b9d68c19 | 108 | def _create_http_urls(self, relinker_url, fmts): |
109 | _RELINKER_REG = r'https?://(?P<host>[^/]+?)/(?:i/)?(?P<extra>[^/]+?)/(?P<path>.+?)/(?P<id>\d+)(?:_(?P<quality>[\d\,]+))?(?:\.mp4|/playlist\.m3u8).+?' | |
110 | _MP4_TMPL = '%s&overrideUserAgentRule=mp4-%s' | |
111 | _QUALITY = { | |
112 | # tbr: w, h | |
113 | '250': [352, 198], | |
114 | '400': [512, 288], | |
115 | '700': [512, 288], | |
116 | '800': [700, 394], | |
117 | '1200': [736, 414], | |
118 | '1800': [1024, 576], | |
119 | '2400': [1280, 720], | |
120 | '3200': [1440, 810], | |
121 | '3600': [1440, 810], | |
122 | '5000': [1920, 1080], | |
123 | '10000': [1920, 1080], | |
124 | } | |
125 | ||
126 | def test_url(url): | |
127 | resp = self._request_webpage( | |
128 | HEADRequest(url), None, headers={'User-Agent': 'Rai'}, | |
129 | fatal=False, errnote=False, note=False) | |
130 | ||
131 | if resp is False: | |
132 | return False | |
133 | ||
134 | if resp.code == 200: | |
135 | return False if resp.url == url else resp.url | |
136 | return None | |
137 | ||
138 | def get_format_info(tbr): | |
139 | import math | |
140 | br = int_or_none(tbr) | |
141 | if len(fmts) == 1 and not br: | |
142 | br = fmts[0].get('tbr') | |
143 | if br > 300: | |
144 | tbr = compat_str(math.floor(br / 100) * 100) | |
145 | else: | |
146 | tbr = '250' | |
147 | ||
148 | # try extracting info from available m3u8 formats | |
149 | format_copy = None | |
150 | for f in fmts: | |
151 | if f.get('tbr'): | |
152 | br_limit = math.floor(br / 100) | |
153 | if br_limit - 1 <= math.floor(f['tbr'] / 100) <= br_limit + 1: | |
154 | format_copy = f.copy() | |
155 | return { | |
156 | 'width': format_copy.get('width'), | |
157 | 'height': format_copy.get('height'), | |
158 | 'tbr': format_copy.get('tbr'), | |
159 | 'vcodec': format_copy.get('vcodec'), | |
160 | 'acodec': format_copy.get('acodec'), | |
161 | 'fps': format_copy.get('fps'), | |
162 | 'format_id': 'https-%s' % tbr, | |
163 | } if format_copy else { | |
164 | 'width': _QUALITY[tbr][0], | |
165 | 'height': _QUALITY[tbr][1], | |
166 | 'format_id': 'https-%s' % tbr, | |
167 | 'tbr': int(tbr), | |
168 | } | |
169 | ||
170 | loc = test_url(_MP4_TMPL % (relinker_url, '*')) | |
171 | if not isinstance(loc, compat_str): | |
172 | return [] | |
173 | ||
174 | mobj = re.match( | |
175 | _RELINKER_REG, | |
176 | test_url(relinker_url) or '') | |
177 | if not mobj: | |
178 | return [] | |
179 | ||
180 | available_qualities = mobj.group('quality').split(',') if mobj.group('quality') else ['*'] | |
181 | available_qualities = [i for i in available_qualities if i] | |
182 | ||
183 | formats = [] | |
184 | for q in available_qualities: | |
185 | fmt = { | |
186 | 'url': _MP4_TMPL % (relinker_url, q), | |
187 | 'protocol': 'https', | |
188 | 'ext': 'mp4', | |
189 | } | |
190 | fmt.update(get_format_info(q)) | |
191 | formats.append(fmt) | |
192 | return formats | |
193 | ||
1b3feca0 | 194 | @staticmethod |
00dd0cd5 | 195 | def _extract_subtitles(url, video_data): |
196 | STL_EXT = 'stl' | |
197 | SRT_EXT = 'srt' | |
1b3feca0 | 198 | subtitles = {} |
00dd0cd5 | 199 | subtitles_array = video_data.get('subtitlesArray') or [] |
200 | for k in ('subtitles', 'subtitlesUrl'): | |
201 | subtitles_array.append({'url': video_data.get(k)}) | |
202 | for subtitle in subtitles_array: | |
203 | sub_url = subtitle.get('url') | |
204 | if sub_url and isinstance(sub_url, compat_str): | |
205 | sub_lang = subtitle.get('language') or 'it' | |
206 | sub_url = urljoin(url, sub_url) | |
207 | sub_ext = determine_ext(sub_url, SRT_EXT) | |
208 | subtitles.setdefault(sub_lang, []).append({ | |
209 | 'ext': sub_ext, | |
210 | 'url': sub_url, | |
1b3feca0 | 211 | }) |
00dd0cd5 | 212 | if STL_EXT == sub_ext: |
213 | subtitles[sub_lang].append({ | |
214 | 'ext': SRT_EXT, | |
215 | 'url': sub_url[:-len(STL_EXT)] + SRT_EXT, | |
216 | }) | |
1b3feca0 S |
217 | return subtitles |
218 | ||
2b28b892 | 219 | |
51342717 | 220 | class RaiPlayIE(RaiBaseIE): |
a0566bbf | 221 | _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplay\.it/.+?-(?P<id>%s))\.(?:html|json)' % RaiBaseIE._UUID_RE |
51342717 | 222 | _TESTS = [{ |
51342717 T |
223 | 'url': 'http://www.raiplay.it/video/2014/04/Report-del-07042014-cb27157f-9dd0-4aee-b788-b1f67643a391.html', |
224 | 'md5': '8970abf8caf8aef4696e7b1f2adfc696', | |
225 | 'info_dict': { | |
226 | 'id': 'cb27157f-9dd0-4aee-b788-b1f67643a391', | |
227 | 'ext': 'mp4', | |
b8d8cced | 228 | 'title': 'Report del 07/04/2014', |
8bdd16b4 | 229 | 'alt_title': 'St 2013/14 - Espresso nel caffè - 07/04/2014', |
abea9145 | 230 | 'description': 'md5:d730c168a58f4bb35600fc2f881ec04e', |
51342717 | 231 | 'thumbnail': r're:^https?://.*\.jpg$', |
abea9145 | 232 | 'uploader': 'Rai Gulp', |
b8d8cced | 233 | 'duration': 6160, |
8bdd16b4 | 234 | 'series': 'Report', |
235 | 'season': '2013/14', | |
00dd0cd5 | 236 | 'subtitles': { |
237 | 'it': 'count:2', | |
238 | }, | |
b8d8cced S |
239 | }, |
240 | 'params': { | |
241 | 'skip_download': True, | |
242 | }, | |
b9d68c19 | 243 | }, { |
244 | # 1080p direct mp4 url | |
245 | 'url': 'https://www.raiplay.it/video/2021/03/Leonardo-S1E1-b5703b02-82ee-475a-85b6-c9e4a8adf642.html', | |
246 | 'md5': '2e501e8651d72f05ffe8f5d286ad560b', | |
247 | 'info_dict': { | |
248 | 'id': 'b5703b02-82ee-475a-85b6-c9e4a8adf642', | |
249 | 'ext': 'mp4', | |
250 | 'title': 'Leonardo - S1E1', | |
251 | 'alt_title': 'St 1 Ep 1 - Episodio 1', | |
252 | 'description': 'md5:f5360cd267d2de146e4e3879a5a47d31', | |
253 | 'thumbnail': r're:^https?://.*\.jpg$', | |
254 | 'uploader': 'Rai 1', | |
255 | 'duration': 3229, | |
256 | 'series': 'Leonardo', | |
257 | 'season': 'Season 1', | |
258 | }, | |
b8d8cced S |
259 | }, { |
260 | 'url': 'http://www.raiplay.it/video/2016/11/gazebotraindesi-efebe701-969c-4593-92f3-285f0d1ce750.html?', | |
261 | 'only_matching': True, | |
00dd0cd5 | 262 | }, { |
263 | # subtitles at 'subtitlesArray' key (see #27698) | |
264 | 'url': 'https://www.raiplay.it/video/2020/12/Report---04-01-2021-2e90f1de-8eee-4de4-ac0e-78d21db5b600.html', | |
265 | 'only_matching': True, | |
0852947f | 266 | }, { |
267 | # DRM protected | |
268 | 'url': 'https://www.raiplay.it/video/2020/09/Lo-straordinario-mondo-di-Zoey-S1E1-Lo-straordinario-potere-di-Zoey-ed493918-1d32-44b7-8454-862e473d00ff.html', | |
269 | 'only_matching': True, | |
51342717 | 270 | }] |
2b28b892 | 271 | |
51342717 | 272 | def _real_extract(self, url): |
a0566bbf | 273 | base, video_id = re.match(self._VALID_URL, url).groups() |
2b28b892 | 274 | |
b8d8cced | 275 | media = self._download_json( |
a0566bbf | 276 | base + '.json', video_id, 'Downloading video JSON') |
2b28b892 | 277 | |
8eec0120 | 278 | if not self._downloader.params.get('allow_unplayable_formats'): |
0852947f | 279 | if try_get( |
280 | media, | |
281 | (lambda x: x['rights_management']['rights']['drm'], | |
282 | lambda x: x['program_info']['rights_management']['rights']['drm']), | |
283 | dict): | |
284 | raise ExtractorError('This video is DRM protected.', expected=True) | |
285 | ||
b8d8cced | 286 | title = media['name'] |
b8d8cced S |
287 | video = media['video'] |
288 | ||
abea9145 | 289 | relinker_info = self._extract_relinker_info(video['content_url'], video_id) |
b8d8cced | 290 | self._sort_formats(relinker_info['formats']) |
2b28b892 | 291 | |
51342717 | 292 | thumbnails = [] |
8bdd16b4 | 293 | for _, value in media.get('images', {}).items(): |
294 | if value: | |
295 | thumbnails.append({ | |
296 | 'url': urljoin(url, value), | |
297 | }) | |
034a8849 | 298 | |
8bdd16b4 | 299 | date_published = media.get('date_published') |
300 | time_published = media.get('time_published') | |
301 | if date_published and time_published: | |
302 | date_published += ' ' + time_published | |
b0adbe98 | 303 | |
00dd0cd5 | 304 | subtitles = self._extract_subtitles(url, video) |
1b3feca0 | 305 | |
8bdd16b4 | 306 | program_info = media.get('program_info') or {} |
307 | season = media.get('season') | |
308 | ||
b8d8cced | 309 | info = { |
a0566bbf | 310 | 'id': remove_start(media.get('id'), 'ContentItem-') or video_id, |
311 | 'display_id': video_id, | |
9c48b5a1 S |
312 | 'title': self._live_title(title) if relinker_info.get( |
313 | 'is_live') else title, | |
8bdd16b4 | 314 | 'alt_title': strip_or_none(media.get('subtitle')), |
b8d8cced | 315 | 'description': media.get('description'), |
9c48b5a1 | 316 | 'uploader': strip_or_none(media.get('channel')), |
8bdd16b4 | 317 | 'creator': strip_or_none(media.get('editor') or None), |
b8d8cced | 318 | 'duration': parse_duration(video.get('duration')), |
8bdd16b4 | 319 | 'timestamp': unified_timestamp(date_published), |
51342717 | 320 | 'thumbnails': thumbnails, |
8bdd16b4 | 321 | 'series': program_info.get('name'), |
322 | 'season_number': int_or_none(season), | |
323 | 'season': season if (season and not season.isdigit()) else None, | |
324 | 'episode': media.get('episode_title'), | |
325 | 'episode_number': int_or_none(media.get('episode')), | |
1b3feca0 | 326 | 'subtitles': subtitles, |
51342717 | 327 | } |
b0adbe98 | 328 | |
b8d8cced | 329 | info.update(relinker_info) |
b8d8cced S |
330 | return info |
331 | ||
06d5556d | 332 | |
a0566bbf | 333 | class RaiPlayLiveIE(RaiPlayIE): |
334 | _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplay\.it/dirette/(?P<id>[^/?#&]+))' | |
335 | _TESTS = [{ | |
9c48b5a1 S |
336 | 'url': 'http://www.raiplay.it/dirette/rainews24', |
337 | 'info_dict': { | |
338 | 'id': 'd784ad40-e0ae-4a69-aa76-37519d238a9c', | |
339 | 'display_id': 'rainews24', | |
340 | 'ext': 'mp4', | |
341 | 'title': 're:^Diretta di Rai News 24 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', | |
a0566bbf | 342 | 'description': 'md5:4d00bcf6dc98b27c6ec480de329d1497', |
9c48b5a1 S |
343 | 'uploader': 'Rai News 24', |
344 | 'creator': 'Rai News 24', | |
345 | 'is_live': True, | |
346 | }, | |
347 | 'params': { | |
348 | 'skip_download': True, | |
349 | }, | |
a0566bbf | 350 | }] |
449c6657 | 351 | |
352 | ||
1115271a | 353 | class RaiPlayPlaylistIE(InfoExtractor): |
a0566bbf | 354 | _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplay\.it/programmi/(?P<id>[^/?#&]+))' |
1115271a S |
355 | _TESTS = [{ |
356 | 'url': 'http://www.raiplay.it/programmi/nondirloalmiocapo/', | |
357 | 'info_dict': { | |
358 | 'id': 'nondirloalmiocapo', | |
359 | 'title': 'Non dirlo al mio capo', | |
a0566bbf | 360 | 'description': 'md5:98ab6b98f7f44c2843fd7d6f045f153b', |
1115271a S |
361 | }, |
362 | 'playlist_mincount': 12, | |
363 | }] | |
364 | ||
365 | def _real_extract(self, url): | |
a0566bbf | 366 | base, playlist_id = re.match(self._VALID_URL, url).groups() |
1115271a | 367 | |
a0566bbf | 368 | program = self._download_json( |
369 | base + '.json', playlist_id, 'Downloading program JSON') | |
1115271a S |
370 | |
371 | entries = [] | |
a0566bbf | 372 | for b in (program.get('blocks') or []): |
373 | for s in (b.get('sets') or []): | |
374 | s_id = s.get('id') | |
375 | if not s_id: | |
376 | continue | |
377 | medias = self._download_json( | |
378 | '%s/%s.json' % (base, s_id), s_id, | |
379 | 'Downloading content set JSON', fatal=False) | |
380 | if not medias: | |
381 | continue | |
382 | for m in (medias.get('items') or []): | |
383 | path_id = m.get('path_id') | |
384 | if not path_id: | |
385 | continue | |
386 | video_url = urljoin(url, path_id) | |
387 | entries.append(self.url_result( | |
388 | video_url, ie=RaiPlayIE.ie_key(), | |
389 | video_id=RaiPlayIE._match_id(video_url))) | |
390 | ||
391 | return self.playlist_result( | |
392 | entries, playlist_id, program.get('name'), | |
393 | try_get(program, lambda x: x['program_info']['description'])) | |
1115271a S |
394 | |
395 | ||
034a8849 | 396 | class RaiIE(RaiBaseIE): |
2b2da3ba | 397 | _VALID_URL = r'https?://[^/]+\.(?:rai\.(?:it|tv)|rainews\.it)/.+?-(?P<id>%s)(?:-.+?)?\.html' % RaiBaseIE._UUID_RE |
51342717 | 398 | _TESTS = [{ |
b8d8cced S |
399 | # var uniquename = "ContentItem-..." |
400 | # data-id="ContentItem-..." | |
51342717 T |
401 | 'url': 'http://www.raisport.rai.it/dl/raiSport/media/rassegna-stampa-04a9f4bd-b563-40cf-82a6-aad3529cb4a9.html', |
402 | 'info_dict': { | |
403 | 'id': '04a9f4bd-b563-40cf-82a6-aad3529cb4a9', | |
404 | 'ext': 'mp4', | |
405 | 'title': 'TG PRIMO TEMPO', | |
b8d8cced | 406 | 'thumbnail': r're:^https?://.*\.jpg$', |
51342717 | 407 | 'duration': 1758, |
b8d8cced | 408 | 'upload_date': '20140612', |
8bdd16b4 | 409 | }, |
410 | 'skip': 'This content is available only in Italy', | |
51342717 | 411 | }, { |
b8d8cced | 412 | # with ContentItem in many metas |
51342717 T |
413 | 'url': 'http://www.rainews.it/dl/rainews/media/Weekend-al-cinema-da-Hollywood-arriva-il-thriller-di-Tate-Taylor-La-ragazza-del-treno-1632c009-c843-4836-bb65-80c33084a64b.html', |
414 | 'info_dict': { | |
415 | 'id': '1632c009-c843-4836-bb65-80c33084a64b', | |
416 | 'ext': 'mp4', | |
b8d8cced S |
417 | 'title': 'Weekend al cinema, da Hollywood arriva il thriller di Tate Taylor "La ragazza del treno"', |
418 | 'description': 'I film in uscita questa settimana.', | |
51342717 | 419 | 'thumbnail': r're:^https?://.*\.png$', |
b8d8cced S |
420 | 'duration': 833, |
421 | 'upload_date': '20161103', | |
51342717 T |
422 | } |
423 | }, { | |
b8d8cced | 424 | # with ContentItem in og:url |
51342717 | 425 | 'url': 'http://www.rai.it/dl/RaiTV/programmi/media/ContentItem-efb17665-691c-45d5-a60c-5301333cbb0c.html', |
b9d68c19 | 426 | 'md5': '06345bd97c932f19ffb129973d07a020', |
51342717 T |
427 | 'info_dict': { |
428 | 'id': 'efb17665-691c-45d5-a60c-5301333cbb0c', | |
429 | 'ext': 'mp4', | |
430 | 'title': 'TG1 ore 20:00 del 03/11/2016', | |
b8d8cced | 431 | 'description': 'TG1 edizione integrale ore 20:00 del giorno 03/11/2016', |
51342717 | 432 | 'thumbnail': r're:^https?://.*\.jpg$', |
b8d8cced | 433 | 'duration': 2214, |
51342717 | 434 | 'upload_date': '20161103', |
51342717 | 435 | } |
51342717 | 436 | }, { |
b8d8cced S |
437 | # initEdizione('ContentItem-...' |
438 | 'url': 'http://www.tg1.rai.it/dl/tg1/2010/edizioni/ContentSet-9b6e0cba-4bef-4aef-8cf0-9f7f665b7dfb-tg1.html?item=undefined', | |
439 | 'info_dict': { | |
440 | 'id': 'c2187016-8484-4e3a-8ac8-35e475b07303', | |
441 | 'ext': 'mp4', | |
442 | 'title': r're:TG1 ore \d{2}:\d{2} del \d{2}/\d{2}/\d{4}', | |
443 | 'duration': 2274, | |
444 | 'upload_date': '20170401', | |
445 | }, | |
446 | 'skip': 'Changes daily', | |
51342717 | 447 | }, { |
b8d8cced | 448 | # HLS live stream with ContentItem in og:url |
51342717 | 449 | 'url': 'http://www.rainews.it/dl/rainews/live/ContentItem-3156f2f2-dc70-4953-8e2f-70d7489d4ce9.html', |
51342717 T |
450 | 'info_dict': { |
451 | 'id': '3156f2f2-dc70-4953-8e2f-70d7489d4ce9', | |
452 | 'ext': 'mp4', | |
453 | 'title': 'La diretta di Rainews24', | |
15e4b6b7 | 454 | }, |
b8d8cced S |
455 | 'params': { |
456 | 'skip_download': True, | |
457 | }, | |
0c7b4f49 RA |
458 | }, { |
459 | # Direct MMS URL | |
460 | 'url': 'http://www.rai.it/dl/RaiTV/programmi/media/ContentItem-b63a4089-ac28-48cf-bca5-9f5b5bc46df5.html', | |
461 | 'only_matching': True, | |
2b2da3ba S |
462 | }, { |
463 | 'url': 'https://www.rainews.it/tgr/marche/notiziari/video/2019/02/ContentItem-6ba945a2-889c-4a80-bdeb-8489c70a8db9.html', | |
464 | 'only_matching': True, | |
51342717 | 465 | }] |
06d5556d | 466 | |
51342717 T |
467 | def _extract_from_content_id(self, content_id, url): |
468 | media = self._download_json( | |
469 | 'http://www.rai.tv/dl/RaiTV/programmi/media/ContentItem-%s.html?json' % content_id, | |
470 | content_id, 'Downloading video JSON') | |
471 | ||
b8d8cced S |
472 | title = media['name'].strip() |
473 | ||
474 | media_type = media['type'] | |
475 | if 'Audio' in media_type: | |
476 | relinker_info = { | |
085d9dd9 | 477 | 'formats': [{ |
b8d8cced S |
478 | 'format_id': media.get('formatoAudio'), |
479 | 'url': media['audioUrl'], | |
480 | 'ext': media.get('formatoAudio'), | |
085d9dd9 | 481 | }] |
b8d8cced S |
482 | } |
483 | elif 'Video' in media_type: | |
484 | relinker_info = self._extract_relinker_info(media['mediaUri'], content_id) | |
485 | else: | |
486 | raise ExtractorError('not a media file') | |
487 | ||
488 | self._sort_formats(relinker_info['formats']) | |
489 | ||
51342717 T |
490 | thumbnails = [] |
491 | for image_type in ('image', 'image_medium', 'image_300'): | |
492 | thumbnail_url = media.get(image_type) | |
493 | if thumbnail_url: | |
494 | thumbnails.append({ | |
495 | 'url': compat_urlparse.urljoin(url, thumbnail_url), | |
496 | }) | |
497 | ||
00dd0cd5 | 498 | subtitles = self._extract_subtitles(url, media) |
51342717 | 499 | |
b8d8cced | 500 | info = { |
51342717 | 501 | 'id': content_id, |
b8d8cced S |
502 | 'title': title, |
503 | 'description': strip_or_none(media.get('desc')), | |
51342717 T |
504 | 'thumbnails': thumbnails, |
505 | 'uploader': media.get('author'), | |
506 | 'upload_date': unified_strdate(media.get('date')), | |
507 | 'duration': parse_duration(media.get('length')), | |
51342717 T |
508 | 'subtitles': subtitles, |
509 | } | |
b8d8cced S |
510 | |
511 | info.update(relinker_info) | |
512 | ||
513 | return info | |
514 | ||
515 | def _real_extract(self, url): | |
516 | video_id = self._match_id(url) | |
517 | ||
518 | webpage = self._download_webpage(url, video_id) | |
519 | ||
520 | content_item_id = None | |
521 | ||
522 | content_item_url = self._html_search_meta( | |
523 | ('og:url', 'og:video', 'og:video:secure_url', 'twitter:url', | |
524 | 'twitter:player', 'jsonlink'), webpage, default=None) | |
525 | if content_item_url: | |
526 | content_item_id = self._search_regex( | |
527 | r'ContentItem-(%s)' % self._UUID_RE, content_item_url, | |
528 | 'content item id', default=None) | |
529 | ||
530 | if not content_item_id: | |
531 | content_item_id = self._search_regex( | |
532 | r'''(?x) | |
533 | (?: | |
534 | (?:initEdizione|drawMediaRaiTV)\(| | |
00dd0cd5 | 535 | <(?:[^>]+\bdata-id|var\s+uniquename)=| |
536 | <iframe[^>]+\bsrc= | |
b8d8cced S |
537 | ) |
538 | (["\']) | |
539 | (?:(?!\1).)*\bContentItem-(?P<id>%s) | |
540 | ''' % self._UUID_RE, | |
541 | webpage, 'content item id', default=None, group='id') | |
542 | ||
543 | content_item_ids = set() | |
361f293a S |
544 | if content_item_id: |
545 | content_item_ids.add(content_item_id) | |
b8d8cced S |
546 | if video_id not in content_item_ids: |
547 | content_item_ids.add(video_id) | |
548 | ||
549 | for content_item_id in content_item_ids: | |
550 | try: | |
551 | return self._extract_from_content_id(content_item_id, url) | |
552 | except GeoRestrictedError: | |
553 | raise | |
554 | except ExtractorError: | |
555 | pass | |
556 | ||
a0566bbf | 557 | relinker_url = self._proto_relative_url(self._search_regex( |
b8d8cced S |
558 | r'''(?x) |
559 | (?: | |
560 | var\s+videoURL| | |
561 | mediaInfo\.mediaUri | |
562 | )\s*=\s* | |
563 | ([\'"]) | |
564 | (?P<url> | |
565 | (?:https?:)? | |
566 | //mediapolis(?:vod)?\.rai\.it/relinker/relinkerServlet\.htm\? | |
567 | (?:(?!\1).)*\bcont=(?:(?!\1).)+)\1 | |
568 | ''', | |
a0566bbf | 569 | webpage, 'relinker URL', group='url')) |
b8d8cced S |
570 | |
571 | relinker_info = self._extract_relinker_info( | |
572 | urljoin(url, relinker_url), video_id) | |
573 | self._sort_formats(relinker_info['formats']) | |
574 | ||
575 | title = self._search_regex( | |
576 | r'var\s+videoTitolo\s*=\s*([\'"])(?P<title>[^\'"]+)\1', | |
577 | webpage, 'title', group='title', | |
578 | default=None) or self._og_search_title(webpage) | |
579 | ||
580 | info = { | |
581 | 'id': video_id, | |
582 | 'title': title, | |
583 | } | |
584 | ||
585 | info.update(relinker_info) | |
586 | ||
587 | return info |