]>
Commit | Line | Data |
---|---|---|
f70daac1 PH |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
7db2897d | 6 | from .srgssr import SRGSSRIE |
1cc79574 PH |
7 | from ..compat import ( |
8 | compat_str, | |
f13b88c6 | 9 | compat_urllib_parse_urlparse, |
1cc79574 | 10 | ) |
f70daac1 PH |
11 | from ..utils import ( |
12 | int_or_none, | |
13 | parse_duration, | |
14 | parse_iso8601, | |
15 | unescapeHTML, | |
f13b88c6 | 16 | xpath_text, |
f70daac1 PH |
17 | ) |
18 | ||
19 | ||
7db2897d | 20 | class RTSIE(SRGSSRIE): |
f70daac1 | 21 | IE_DESC = 'RTS.ch' |
7db2897d | 22 | _VALID_URL = r'rts:(?P<rts_id>\d+)|https?://(?:www\.)?rts\.ch/(?:[^/]+/){2,}(?P<id>[0-9]+)-(?P<display_id>.+?)\.html' |
6344fa04 S |
23 | |
24 | _TESTS = [ | |
25 | { | |
26 | 'url': 'http://www.rts.ch/archives/tv/divers/3449373-les-enfants-terribles.html', | |
7db2897d | 27 | 'md5': 'f254c4b26fb1d3c183793d52bc40d3e7', |
6344fa04 S |
28 | 'info_dict': { |
29 | 'id': '3449373', | |
b1399a14 | 30 | 'display_id': 'les-enfants-terribles', |
422f7c11 | 31 | 'ext': 'mp4', |
6344fa04 S |
32 | 'duration': 1488, |
33 | 'title': 'Les Enfants Terribles', | |
34 | 'description': 'France Pommier et sa soeur Luce Feral, les deux filles de ce groupe de 5.', | |
35 | 'uploader': 'Divers', | |
36 | 'upload_date': '19680921', | |
37 | 'timestamp': -40280400, | |
b1399a14 S |
38 | 'thumbnail': 're:^https?://.*\.image', |
39 | 'view_count': int, | |
6344fa04 | 40 | }, |
422f7c11 | 41 | 'params': { |
42 | # m3u8 download | |
43 | 'skip_download': True, | |
44 | } | |
6344fa04 S |
45 | }, |
46 | { | |
47 | 'url': 'http://www.rts.ch/emissions/passe-moi-les-jumelles/5624067-entre-ciel-et-mer.html', | |
7db2897d | 48 | 'md5': 'f1077ac5af686c76528dc8d7c5df29ba', |
6344fa04 | 49 | 'info_dict': { |
7db2897d | 50 | 'id': '5742494', |
51 | 'display_id': '5742494', | |
422f7c11 | 52 | 'ext': 'mp4', |
09baa7da S |
53 | 'duration': 3720, |
54 | 'title': 'Les yeux dans les cieux - Mon homard au Canada', | |
55 | 'description': 'md5:d22ee46f5cc5bac0912e5a0c6d44a9f7', | |
6344fa04 S |
56 | 'uploader': 'Passe-moi les jumelles', |
57 | 'upload_date': '20140404', | |
58 | 'timestamp': 1396635300, | |
b1399a14 S |
59 | 'thumbnail': 're:^https?://.*\.image', |
60 | 'view_count': int, | |
6344fa04 | 61 | }, |
422f7c11 | 62 | 'params': { |
63 | # m3u8 download | |
64 | 'skip_download': True, | |
65 | } | |
6344fa04 S |
66 | }, |
67 | { | |
68 | 'url': 'http://www.rts.ch/video/sport/hockey/5745975-1-2-kloten-fribourg-5-2-second-but-pour-gotteron-par-kwiatowski.html', | |
69 | 'md5': 'b4326fecd3eb64a458ba73c73e91299d', | |
70 | 'info_dict': { | |
71 | 'id': '5745975', | |
b1399a14 | 72 | 'display_id': '1-2-kloten-fribourg-5-2-second-but-pour-gotteron-par-kwiatowski', |
6344fa04 S |
73 | 'ext': 'mp4', |
74 | 'duration': 48, | |
75 | 'title': '1/2, Kloten - Fribourg (5-2): second but pour Gottéron par Kwiatowski', | |
76 | 'description': 'Hockey - Playoff', | |
77 | 'uploader': 'Hockey', | |
78 | 'upload_date': '20140403', | |
79 | 'timestamp': 1396556882, | |
b1399a14 S |
80 | 'thumbnail': 're:^https?://.*\.image', |
81 | 'view_count': int, | |
6344fa04 S |
82 | }, |
83 | 'skip': 'Blocked outside Switzerland', | |
f70daac1 | 84 | }, |
6344fa04 S |
85 | { |
86 | 'url': 'http://www.rts.ch/video/info/journal-continu/5745356-londres-cachee-par-un-epais-smog.html', | |
7db2897d | 87 | 'md5': '9f713382f15322181bb366cc8c3a4ff0', |
6344fa04 S |
88 | 'info_dict': { |
89 | 'id': '5745356', | |
b1399a14 | 90 | 'display_id': 'londres-cachee-par-un-epais-smog', |
422f7c11 | 91 | 'ext': 'mp4', |
6344fa04 S |
92 | 'duration': 33, |
93 | 'title': 'Londres cachée par un épais smog', | |
94 | 'description': 'Un important voile de smog recouvre Londres depuis mercredi, provoqué par la pollution et du sable du Sahara.', | |
95 | 'uploader': 'Le Journal en continu', | |
96 | 'upload_date': '20140403', | |
97 | 'timestamp': 1396537322, | |
b1399a14 S |
98 | 'thumbnail': 're:^https?://.*\.image', |
99 | 'view_count': int, | |
6344fa04 | 100 | }, |
422f7c11 | 101 | 'params': { |
102 | # m3u8 download | |
103 | 'skip_download': True, | |
104 | } | |
6344fa04 S |
105 | }, |
106 | { | |
107 | 'url': 'http://www.rts.ch/audio/couleur3/programmes/la-belle-video-de-stephane-laurenceau/5706148-urban-hippie-de-damien-krisl-03-04-2014.html', | |
108 | 'md5': 'dd8ef6a22dff163d063e2a52bc8adcae', | |
109 | 'info_dict': { | |
110 | 'id': '5706148', | |
b1399a14 | 111 | 'display_id': 'urban-hippie-de-damien-krisl-03-04-2014', |
6344fa04 S |
112 | 'ext': 'mp3', |
113 | 'duration': 123, | |
114 | 'title': '"Urban Hippie", de Damien Krisl', | |
115 | 'description': 'Des Hippies super glam.', | |
116 | 'upload_date': '20140403', | |
117 | 'timestamp': 1396551600, | |
118 | }, | |
119 | }, | |
ba911137 S |
120 | { |
121 | # article with videos on rhs | |
122 | 'url': 'http://www.rts.ch/sport/hockey/6693917-hockey-davos-decroche-son-31e-titre-de-champion-de-suisse.html', | |
123 | 'info_dict': { | |
124 | 'id': '6693917', | |
125 | 'title': 'Hockey: Davos décroche son 31e titre de champion de Suisse', | |
126 | }, | |
127 | 'playlist_mincount': 5, | |
b1399a14 | 128 | } |
6344fa04 | 129 | ] |
f70daac1 PH |
130 | |
131 | def _real_extract(self, url): | |
132 | m = re.match(self._VALID_URL, url) | |
7db2897d | 133 | media_id = m.group('rts_id') or m.group('id') |
134 | display_id = m.group('display_id') or media_id | |
f70daac1 | 135 | |
f8514f61 | 136 | def download_json(internal_id): |
6344fa04 | 137 | return self._download_json( |
f8514f61 | 138 | 'http://www.rts.ch/a/%s.html?f=json/article' % internal_id, |
b1399a14 | 139 | display_id) |
6344fa04 | 140 | |
7db2897d | 141 | all_info = download_json(media_id) |
6344fa04 | 142 | |
7db2897d | 143 | # media_id extracted out of URL is not always a real id |
6344fa04 | 144 | if 'video' not in all_info and 'audio' not in all_info: |
b1399a14 | 145 | page = self._download_webpage(url, display_id) |
ba911137 S |
146 | |
147 | # article with videos on rhs | |
148 | videos = re.findall( | |
7db2897d | 149 | r'<article[^>]+class="content-item"[^>]*>\s*<a[^>]+data-video-urn="urn:([^"]+)"', |
ba911137 | 150 | page) |
7db2897d | 151 | if not videos: |
152 | videos = re.findall( | |
153 | r'(?s)<iframe[^>]+class="srg-player"[^>]+src="[^"]+urn:([^"]+)"', | |
154 | page) | |
ba911137 | 155 | if videos: |
7db2897d | 156 | entries = [self.url_result('srgssr:%s' % video_urn, 'SRGSSR') for video_urn in videos] |
157 | return self.playlist_result(entries, media_id, self._og_search_title(page)) | |
ba911137 | 158 | |
f8514f61 PH |
159 | internal_id = self._html_search_regex( |
160 | r'<(?:video|audio) data-id="([0-9]+)"', page, | |
161 | 'internal video id') | |
162 | all_info = download_json(internal_id) | |
6344fa04 | 163 | |
7db2897d | 164 | media_type = 'video' if 'video' in all_info else 'audio' |
165 | ||
166 | # check for errors | |
167 | self.get_media_data('rts', media_type, media_id) | |
168 | ||
6344fa04 | 169 | info = all_info['video']['JSONinfo'] if 'video' in all_info else all_info['audio'] |
f70daac1 PH |
170 | |
171 | upload_timestamp = parse_iso8601(info.get('broadcast_date')) | |
6344fa04 S |
172 | duration = info.get('duration') or info.get('cutout') or info.get('cutduration') |
173 | if isinstance(duration, compat_str): | |
174 | duration = parse_duration(duration) | |
175 | view_count = info.get('plays') | |
f70daac1 | 176 | thumbnail = unescapeHTML(info.get('preview_image_url')) |
6344fa04 S |
177 | |
178 | def extract_bitrate(url): | |
179 | return int_or_none(self._search_regex( | |
180 | r'-([0-9]+)k\.', url, 'bitrate', default=None)) | |
181 | ||
f13b88c6 S |
182 | formats = [] |
183 | for format_id, format_url in info['streams'].items(): | |
7db2897d | 184 | if format_id == 'hds_sd' and 'hds' in info['streams']: |
185 | continue | |
186 | if format_id == 'hls_sd' and 'hls' in info['streams']: | |
187 | continue | |
f13b88c6 S |
188 | if format_url.endswith('.f4m'): |
189 | token = self._download_xml( | |
190 | 'http://tp.srgssr.ch/token/akahd.xml?stream=%s/*' % compat_urllib_parse_urlparse(format_url).path, | |
7db2897d | 191 | media_id, 'Downloading %s token' % format_id) |
f13b88c6 S |
192 | auth_params = xpath_text(token, './/authparams', 'auth params') |
193 | if not auth_params: | |
194 | continue | |
422f7c11 | 195 | formats.extend(self._extract_f4m_formats( |
f13b88c6 | 196 | '%s?%s&hdcore=3.4.0&plugin=aasp-3.4.0.132.66' % (format_url, auth_params), |
422f7c11 | 197 | media_id, f4m_id=format_id, fatal=False)) |
f13b88c6 | 198 | elif format_url.endswith('.m3u8'): |
422f7c11 | 199 | formats.extend(self._extract_m3u8_formats( |
f2017cb0 | 200 | format_url, media_id, 'mp4', 'm3u8_native', m3u8_id=format_id, fatal=False)) |
f13b88c6 S |
201 | else: |
202 | formats.append({ | |
203 | 'format_id': format_id, | |
204 | 'url': format_url, | |
205 | 'tbr': extract_bitrate(format_url), | |
206 | }) | |
6344fa04 S |
207 | |
208 | if 'media' in info: | |
209 | formats.extend([{ | |
210 | 'format_id': '%s-%sk' % (media['ext'], media['rate']), | |
211 | 'url': 'http://download-video.rts.ch/%s' % media['url'], | |
212 | 'tbr': media['rate'] or extract_bitrate(media['url']), | |
213 | } for media in info['media'] if media.get('rate')]) | |
214 | ||
7db2897d | 215 | self._check_formats(formats, media_id) |
f70daac1 PH |
216 | self._sort_formats(formats) |
217 | ||
218 | return { | |
7db2897d | 219 | 'id': media_id, |
b1399a14 | 220 | 'display_id': display_id, |
f70daac1 PH |
221 | 'formats': formats, |
222 | 'title': info['title'], | |
223 | 'description': info.get('intro'), | |
224 | 'duration': duration, | |
6344fa04 | 225 | 'view_count': view_count, |
f70daac1 PH |
226 | 'uploader': info.get('programName'), |
227 | 'timestamp': upload_timestamp, | |
f605128d | 228 | 'thumbnail': thumbnail, |
f70daac1 | 229 | } |