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