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