]>
Commit | Line | Data |
---|---|---|
f70daac1 PH |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
8 | int_or_none, | |
9 | parse_duration, | |
10 | parse_iso8601, | |
11 | unescapeHTML, | |
6344fa04 | 12 | compat_str, |
f70daac1 PH |
13 | ) |
14 | ||
15 | ||
16 | class RTSIE(InfoExtractor): | |
17 | IE_DESC = 'RTS.ch' | |
6344fa04 S |
18 | _VALID_URL = r'^https?://(?:www\.)?rts\.ch/(?:[^/]+/){2,}(?P<id>[0-9]+)-.*?\.html' |
19 | ||
20 | _TESTS = [ | |
21 | { | |
22 | 'url': 'http://www.rts.ch/archives/tv/divers/3449373-les-enfants-terribles.html', | |
23 | 'md5': '753b877968ad8afaeddccc374d4256a5', | |
24 | 'info_dict': { | |
25 | 'id': '3449373', | |
26 | 'ext': 'mp4', | |
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, | |
33 | 'thumbnail': 're:^https?://.*\.image' | |
34 | }, | |
35 | }, | |
36 | { | |
37 | 'url': 'http://www.rts.ch/emissions/passe-moi-les-jumelles/5624067-entre-ciel-et-mer.html', | |
38 | 'md5': 'c197f0b2421995c63a64cc73d800f42e', | |
39 | 'info_dict': { | |
40 | 'id': '5738317', | |
41 | 'ext': 'mp4', | |
42 | 'duration': 55, | |
43 | 'title': 'Bande de lancement de Passe-moi les jumelles', | |
44 | 'description': '', | |
45 | 'uploader': 'Passe-moi les jumelles', | |
46 | 'upload_date': '20140404', | |
47 | 'timestamp': 1396635300, | |
48 | 'thumbnail': 're:^https?://.*\.image' | |
49 | }, | |
50 | }, | |
51 | { | |
52 | 'url': 'http://www.rts.ch/video/sport/hockey/5745975-1-2-kloten-fribourg-5-2-second-but-pour-gotteron-par-kwiatowski.html', | |
53 | 'md5': 'b4326fecd3eb64a458ba73c73e91299d', | |
54 | 'info_dict': { | |
55 | 'id': '5745975', | |
56 | 'ext': 'mp4', | |
57 | 'duration': 48, | |
58 | 'title': '1/2, Kloten - Fribourg (5-2): second but pour Gottéron par Kwiatowski', | |
59 | 'description': 'Hockey - Playoff', | |
60 | 'uploader': 'Hockey', | |
61 | 'upload_date': '20140403', | |
62 | 'timestamp': 1396556882, | |
63 | 'thumbnail': 're:^https?://.*\.image' | |
64 | }, | |
65 | 'skip': 'Blocked outside Switzerland', | |
f70daac1 | 66 | }, |
6344fa04 S |
67 | { |
68 | 'url': 'http://www.rts.ch/video/info/journal-continu/5745356-londres-cachee-par-un-epais-smog.html', | |
69 | 'md5': '9bb06503773c07ce83d3cbd793cebb91', | |
70 | 'info_dict': { | |
71 | 'id': '5745356', | |
72 | 'ext': 'mp4', | |
73 | 'duration': 33, | |
74 | 'title': 'Londres cachée par un épais smog', | |
75 | 'description': 'Un important voile de smog recouvre Londres depuis mercredi, provoqué par la pollution et du sable du Sahara.', | |
76 | 'uploader': 'Le Journal en continu', | |
77 | 'upload_date': '20140403', | |
78 | 'timestamp': 1396537322, | |
79 | 'thumbnail': 're:^https?://.*\.image' | |
80 | }, | |
81 | }, | |
82 | { | |
83 | 'url': 'http://www.rts.ch/audio/couleur3/programmes/la-belle-video-de-stephane-laurenceau/5706148-urban-hippie-de-damien-krisl-03-04-2014.html', | |
84 | 'md5': 'dd8ef6a22dff163d063e2a52bc8adcae', | |
85 | 'info_dict': { | |
86 | 'id': '5706148', | |
87 | 'ext': 'mp3', | |
88 | 'duration': 123, | |
89 | 'title': '"Urban Hippie", de Damien Krisl', | |
90 | 'description': 'Des Hippies super glam.', | |
91 | 'upload_date': '20140403', | |
92 | 'timestamp': 1396551600, | |
93 | }, | |
94 | }, | |
95 | ] | |
f70daac1 PH |
96 | |
97 | def _real_extract(self, url): | |
98 | m = re.match(self._VALID_URL, url) | |
99 | video_id = m.group('id') | |
100 | ||
6344fa04 S |
101 | def download_json(video_id): |
102 | return self._download_json( | |
103 | 'http://www.rts.ch/a/%s.html?f=json/article' % video_id, video_id) | |
104 | ||
105 | all_info = download_json(video_id) | |
106 | ||
107 | # video_id extracted out of URL is not always a real id | |
108 | if 'video' not in all_info and 'audio' not in all_info: | |
109 | page = self._download_webpage(url, video_id) | |
110 | video_id = self._html_search_regex(r'<(?:video|audio) data-id="(\d+)"', page, 'video id') | |
111 | all_info = download_json(video_id) | |
112 | ||
113 | info = all_info['video']['JSONinfo'] if 'video' in all_info else all_info['audio'] | |
f70daac1 PH |
114 | |
115 | upload_timestamp = parse_iso8601(info.get('broadcast_date')) | |
6344fa04 S |
116 | duration = info.get('duration') or info.get('cutout') or info.get('cutduration') |
117 | if isinstance(duration, compat_str): | |
118 | duration = parse_duration(duration) | |
119 | view_count = info.get('plays') | |
f70daac1 | 120 | thumbnail = unescapeHTML(info.get('preview_image_url')) |
6344fa04 S |
121 | |
122 | def extract_bitrate(url): | |
123 | return int_or_none(self._search_regex( | |
124 | r'-([0-9]+)k\.', url, 'bitrate', default=None)) | |
125 | ||
f70daac1 PH |
126 | formats = [{ |
127 | 'format_id': fid, | |
128 | 'url': furl, | |
6344fa04 | 129 | 'tbr': extract_bitrate(furl), |
f70daac1 | 130 | } for fid, furl in info['streams'].items()] |
6344fa04 S |
131 | |
132 | if 'media' in info: | |
133 | formats.extend([{ | |
134 | 'format_id': '%s-%sk' % (media['ext'], media['rate']), | |
135 | 'url': 'http://download-video.rts.ch/%s' % media['url'], | |
136 | 'tbr': media['rate'] or extract_bitrate(media['url']), | |
137 | } for media in info['media'] if media.get('rate')]) | |
138 | ||
f70daac1 PH |
139 | self._sort_formats(formats) |
140 | ||
141 | return { | |
142 | 'id': video_id, | |
143 | 'formats': formats, | |
144 | 'title': info['title'], | |
145 | 'description': info.get('intro'), | |
146 | 'duration': duration, | |
6344fa04 | 147 | 'view_count': view_count, |
f70daac1 PH |
148 | 'uploader': info.get('programName'), |
149 | 'timestamp': upload_timestamp, | |
f605128d | 150 | 'thumbnail': thumbnail, |
f70daac1 | 151 | } |