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