2 from __future__ import unicode_literals
6 from .srgssr import SRGSSRIE
7 from ..compat import compat_str
17 class RTSIE(SRGSSRIE):
19 _VALID_URL = r'rts:(?P<rts_id>\d+)|https?://(?:.+?\.)?rts\.ch/(?:[^/]+/){2,}(?P<id>[0-9]+)-(?P<display_id>.+?)\.html'
23 'url': 'http://www.rts.ch/archives/tv/divers/3449373-les-enfants-terribles.html',
24 'md5': 'ff7f8450a90cf58dacb64e29707b4a8e',
27 'display_id': 'les-enfants-terribles',
30 'title': 'Les Enfants Terribles',
31 'description': 'France Pommier et sa soeur Luce Feral, les deux filles de ce groupe de 5.',
33 'upload_date': '19680921',
34 'timestamp': -40280400,
35 'thumbnail': r're:^https?://.*\.image',
40 'url': 'http://www.rts.ch/emissions/passe-moi-les-jumelles/5624067-entre-ciel-et-mer.html',
43 'title': 'Passe-moi les jumelles',
45 'playlist_mincount': 4,
48 'url': 'http://www.rts.ch/video/sport/hockey/5745975-1-2-kloten-fribourg-5-2-second-but-pour-gotteron-par-kwiatowski.html',
51 'display_id': '1-2-kloten-fribourg-5-2-second-but-pour-gotteron-par-kwiatowski',
54 'title': '1/2, Kloten - Fribourg (5-2): second but pour Gottéron par Kwiatowski',
55 'description': 'Hockey - Playoff',
57 'upload_date': '20140403',
58 'timestamp': 1396556882,
59 'thumbnail': r're:^https?://.*\.image',
64 'skip_download': True,
66 'skip': 'Blocked outside Switzerland',
69 'url': 'http://www.rts.ch/video/info/journal-continu/5745356-londres-cachee-par-un-epais-smog.html',
70 'md5': '1bae984fe7b1f78e94abc74e802ed99f',
73 'display_id': 'londres-cachee-par-un-epais-smog',
76 'title': 'Londres cachée par un épais smog',
77 'description': 'Un important voile de smog recouvre Londres depuis mercredi, provoqué par la pollution et du sable du Sahara.',
78 'uploader': 'L\'actu en vidéo',
79 'upload_date': '20140403',
80 'timestamp': 1396537322,
81 'thumbnail': r're:^https?://.*\.image',
86 'url': 'http://www.rts.ch/audio/couleur3/programmes/la-belle-video-de-stephane-laurenceau/5706148-urban-hippie-de-damien-krisl-03-04-2014.html',
87 'md5': 'dd8ef6a22dff163d063e2a52bc8adcae',
90 'display_id': 'urban-hippie-de-damien-krisl-03-04-2014',
93 'title': '"Urban Hippie", de Damien Krisl',
94 'description': 'Des Hippies super glam.',
95 'upload_date': '20140403',
96 'timestamp': 1396551600,
100 # article with videos on rhs
101 'url': 'http://www.rts.ch/sport/hockey/6693917-hockey-davos-decroche-son-31e-titre-de-champion-de-suisse.html',
104 'title': 'Hockey: Davos décroche son 31e titre de champion de Suisse',
106 'playlist_mincount': 5,
109 'url': 'http://pages.rts.ch/emissions/passe-moi-les-jumelles/5624065-entre-ciel-et-mer.html',
110 'only_matching': True,
114 def _real_extract(self, url):
115 m = re.match(self._VALID_URL, url)
116 media_id = m.group('rts_id') or m.group('id')
117 display_id = m.group('display_id') or media_id
119 def download_json(internal_id):
120 return self._download_json(
121 'http://www.rts.ch/a/%s.html?f=json/article' % internal_id,
124 all_info = download_json(media_id)
126 # media_id extracted out of URL is not always a real id
127 if 'video' not in all_info and 'audio' not in all_info:
130 for item in all_info.get('items', []):
131 item_url = item.get('url')
134 entries.append(self.url_result(item_url, 'RTS'))
137 page, urlh = self._download_webpage_handle(url, display_id)
138 if re.match(self._VALID_URL, urlh.geturl()).group('id') != media_id:
139 return self.url_result(urlh.geturl(), 'RTS')
141 # article with videos on rhs
143 r'<article[^>]+class="content-item"[^>]*>\s*<a[^>]+data-video-urn="urn:([^"]+)"',
147 r'(?s)<iframe[^>]+class="srg-player"[^>]+src="[^"]+urn:([^"]+)"',
150 entries = [self.url_result('srgssr:%s' % video_urn, 'SRGSSR') for video_urn in videos]
153 return self.playlist_result(entries, media_id, all_info.get('title'))
155 internal_id = self._html_search_regex(
156 r'<(?:video|audio) data-id="([0-9]+)"', page,
158 all_info = download_json(internal_id)
160 media_type = 'video' if 'video' in all_info else 'audio'
163 self.get_media_data('rts', media_type, media_id)
165 info = all_info['video']['JSONinfo'] if 'video' in all_info else all_info['audio']
167 title = info['title']
169 def extract_bitrate(url):
170 return int_or_none(self._search_regex(
171 r'-([0-9]+)k\.', url, 'bitrate', default=None))
174 streams = info.get('streams', {})
175 for format_id, format_url in streams.items():
176 if format_id == 'hds_sd' and 'hds' in streams:
178 if format_id == 'hls_sd' and 'hls' in streams:
180 ext = determine_ext(format_url)
181 if ext in ('m3u8', 'f4m'):
182 format_url = self._get_tokenized_src(format_url, media_id, format_id)
184 formats.extend(self._extract_f4m_formats(
185 format_url + ('?' if '?' not in format_url else '&') + 'hdcore=3.4.0',
186 media_id, f4m_id=format_id, fatal=False))
188 formats.extend(self._extract_m3u8_formats(
189 format_url, media_id, 'mp4', 'm3u8_native', m3u8_id=format_id, fatal=False))
192 'format_id': format_id,
194 'tbr': extract_bitrate(format_url),
197 for media in info.get('media', []):
198 media_url = media.get('url')
199 if not media_url or re.match(r'https?://', media_url):
201 rate = media.get('rate')
202 ext = media.get('ext') or determine_ext(media_url, 'mp4')
205 format_id += '-%dk' % rate
207 'format_id': format_id,
208 'url': 'http://download-video.rts.ch/' + media_url,
209 'tbr': rate or extract_bitrate(media_url),
212 self._check_formats(formats, media_id)
213 self._sort_formats(formats)
215 duration = info.get('duration') or info.get('cutout') or info.get('cutduration')
216 if isinstance(duration, compat_str):
217 duration = parse_duration(duration)
221 'display_id': display_id,
224 'description': info.get('intro'),
225 'duration': duration,
226 'view_count': int_or_none(info.get('plays')),
227 'uploader': info.get('programName'),
228 'timestamp': parse_iso8601(info.get('broadcast_date')),
229 'thumbnail': unescapeHTML(info.get('preview_image_url')),