]>
Commit | Line | Data |
---|---|---|
201e3c99 NÉ |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
764cd4e6 RA |
4 | import re |
5 | ||
201e3c99 | 6 | from .common import InfoExtractor |
63f3cab4 | 7 | from ..utils import ( |
7c36ea7d | 8 | ExtractorError, |
764cd4e6 RA |
9 | float_or_none, |
10 | int_or_none, | |
11 | strip_or_none, | |
63f3cab4 | 12 | ) |
201e3c99 | 13 | |
65e4ad5b S |
14 | |
15 | class RTBFIE(InfoExtractor): | |
7c36ea7d | 16 | _VALID_URL = r'''(?x) |
17 | https?://(?:www\.)?rtbf\.be/ | |
18 | (?: | |
19 | video/[^?]+\?.*\bid=| | |
20 | ouftivi/(?:[^/]+/)*[^?]+\?.*\bvideoId=| | |
764cd4e6 | 21 | auvio/[^/]+\?.*\b(?P<live>l)?id= |
7c36ea7d | 22 | )(?P<id>\d+)''' |
114e6025 S |
23 | _TESTS = [{ |
24 | 'url': 'https://www.rtbf.be/video/detail_les-diables-au-coeur-episode-2?id=1921274', | |
764cd4e6 | 25 | 'md5': '8c876a1cceeb6cf31b476461ade72384', |
114e6025 S |
26 | 'info_dict': { |
27 | 'id': '1921274', | |
28 | 'ext': 'mp4', | |
29 | 'title': 'Les Diables au coeur (épisode 2)', | |
764cd4e6 RA |
30 | 'description': '(du 25/04/2014)', |
31 | 'duration': 3099.54, | |
7c36ea7d | 32 | 'upload_date': '20140425', |
764cd4e6 | 33 | 'timestamp': 1398456300, |
114e6025 S |
34 | } |
35 | }, { | |
36 | # geo restricted | |
37 | 'url': 'http://www.rtbf.be/ouftivi/heros/detail_scooby-doo-mysteres-associes?id=1097&videoId=2057442', | |
38 | 'only_matching': True, | |
39 | }, { | |
40 | 'url': 'http://www.rtbf.be/ouftivi/niouzz?videoId=2055858', | |
41 | 'only_matching': True, | |
7c36ea7d | 42 | }, { |
43 | 'url': 'http://www.rtbf.be/auvio/detail_jeudi-en-prime-siegfried-bracke?id=2102996', | |
44 | 'only_matching': True, | |
764cd4e6 RA |
45 | }, { |
46 | # Live | |
47 | 'url': 'https://www.rtbf.be/auvio/direct_pure-fm?lid=134775', | |
48 | 'only_matching': True, | |
49 | }, { | |
50 | # Audio | |
51 | 'url': 'https://www.rtbf.be/auvio/detail_cinq-heures-cinema?id=2360811', | |
52 | 'only_matching': True, | |
53 | }, { | |
54 | # With Subtitle | |
55 | 'url': 'https://www.rtbf.be/auvio/detail_les-carnets-du-bourlingueur?id=2361588', | |
56 | 'only_matching': True, | |
114e6025 | 57 | }] |
7c36ea7d | 58 | _IMAGE_HOST = 'http://ds1.ds.static.rtbf.be' |
59 | _PROVIDERS = { | |
60 | 'YOUTUBE': 'Youtube', | |
61 | 'DAILYMOTION': 'Dailymotion', | |
62 | 'VIMEO': 'Vimeo', | |
63 | } | |
eb8be1fe | 64 | _QUALITIES = [ |
7c36ea7d | 65 | ('mobile', 'SD'), |
66 | ('web', 'MD'), | |
eb8be1fe JMF |
67 | ('high', 'HD'), |
68 | ] | |
69 | ||
201e3c99 | 70 | def _real_extract(self, url): |
764cd4e6 RA |
71 | live, media_id = re.match(self._VALID_URL, url).groups() |
72 | embed_page = self._download_webpage( | |
73 | 'https://www.rtbf.be/auvio/embed/' + ('direct' if live else 'media'), | |
74 | media_id, query={'id': media_id}) | |
75 | data = self._parse_json(self._html_search_regex( | |
76 | r'data-media="([^"]+)"', embed_page, 'media data'), media_id) | |
201e3c99 | 77 | |
7c36ea7d | 78 | error = data.get('error') |
79 | if error: | |
80 | raise ExtractorError('%s said: %s' % (self.IE_NAME, error), expected=True) | |
65e4ad5b | 81 | |
7c36ea7d | 82 | provider = data.get('provider') |
83 | if provider in self._PROVIDERS: | |
84 | return self.url_result(data['url'], self._PROVIDERS[provider]) | |
201e3c99 | 85 | |
764cd4e6 RA |
86 | title = data['title'] |
87 | is_live = data.get('isLive') | |
88 | if is_live: | |
89 | title = self._live_title(title) | |
90 | height_re = r'-(\d+)p\.' | |
eb8be1fe | 91 | formats = [] |
764cd4e6 RA |
92 | |
93 | m3u8_url = data.get('urlHlsAes128') or data.get('urlHls') | |
94 | if m3u8_url: | |
95 | formats.extend(self._extract_m3u8_formats( | |
96 | m3u8_url, media_id, 'mp4', m3u8_id='hls', fatal=False)) | |
97 | ||
98 | fix_url = lambda x: x.replace('//rtbf-vod.', '//rtbf.') if '/geo/drm/' in x else x | |
99 | http_url = data.get('url') | |
100 | if formats and http_url and re.search(height_re, http_url): | |
101 | http_url = fix_url(http_url) | |
18806e3b | 102 | for m3u8_f in formats[:]: |
764cd4e6 RA |
103 | height = m3u8_f.get('height') |
104 | if not height: | |
105 | continue | |
106 | f = m3u8_f.copy() | |
107 | del f['protocol'] | |
108 | f.update({ | |
109 | 'format_id': m3u8_f['format_id'].replace('hls-', 'http-'), | |
110 | 'url': re.sub(height_re, '-%dp.' % height, http_url), | |
111 | }) | |
112 | formats.append(f) | |
113 | else: | |
114 | sources = data.get('sources') or {} | |
115 | for key, format_id in self._QUALITIES: | |
116 | format_url = sources.get(key) | |
117 | if not format_url: | |
118 | continue | |
119 | height = int_or_none(self._search_regex( | |
120 | height_re, format_url, 'height', default=None)) | |
eb8be1fe JMF |
121 | formats.append({ |
122 | 'format_id': format_id, | |
764cd4e6 RA |
123 | 'url': fix_url(format_url), |
124 | 'height': height, | |
eb8be1fe | 125 | }) |
201e3c99 | 126 | |
764cd4e6 | 127 | mpd_url = data.get('urlDash') |
1ea24129 | 128 | if mpd_url and (self._downloader.params.get('allow_unplayable_formats') or not data.get('drm')): |
764cd4e6 RA |
129 | formats.extend(self._extract_mpd_formats( |
130 | mpd_url, media_id, mpd_id='dash', fatal=False)) | |
131 | ||
132 | audio_url = data.get('urlAudio') | |
133 | if audio_url: | |
134 | formats.append({ | |
135 | 'format_id': 'audio', | |
136 | 'url': audio_url, | |
137 | 'vcodec': 'none', | |
138 | }) | |
139 | self._sort_formats(formats) | |
140 | ||
141 | subtitles = {} | |
142 | for track in (data.get('tracks') or {}).values(): | |
143 | sub_url = track.get('url') | |
144 | if not sub_url: | |
145 | continue | |
146 | subtitles.setdefault(track.get('lang') or 'fr', []).append({ | |
147 | 'url': sub_url, | |
148 | }) | |
7c36ea7d | 149 | |
201e3c99 | 150 | return { |
764cd4e6 | 151 | 'id': media_id, |
eb8be1fe | 152 | 'formats': formats, |
764cd4e6 RA |
153 | 'title': title, |
154 | 'description': strip_or_none(data.get('description')), | |
155 | 'thumbnail': data.get('thumbnail'), | |
156 | 'duration': float_or_none(data.get('realDuration')), | |
157 | 'timestamp': int_or_none(data.get('liveFrom')), | |
158 | 'series': data.get('programLabel'), | |
159 | 'subtitles': subtitles, | |
160 | 'is_live': is_live, | |
201e3c99 | 161 | } |