]>
Commit | Line | Data |
---|---|---|
201e3c99 NÉ |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
201e3c99 | 4 | from .common import InfoExtractor |
63f3cab4 S |
5 | from ..utils import ( |
6 | int_or_none, | |
7 | unescapeHTML, | |
8 | ) | |
201e3c99 | 9 | |
65e4ad5b S |
10 | |
11 | class RTBFIE(InfoExtractor): | |
aa8d2d5b | 12 | _VALID_URL = r'https?://(?:www\.)?rtbf\.be/(?:video/[^?]+\?.*\bid=|ouftivi/(?:[^/]+/)*[^?]+\?.*\bvideoId=)(?P<id>\d+)' |
114e6025 S |
13 | _TESTS = [{ |
14 | 'url': 'https://www.rtbf.be/video/detail_les-diables-au-coeur-episode-2?id=1921274', | |
15 | 'md5': '799f334ddf2c0a582ba80c44655be570', | |
16 | 'info_dict': { | |
17 | 'id': '1921274', | |
18 | 'ext': 'mp4', | |
19 | 'title': 'Les Diables au coeur (épisode 2)', | |
20 | 'duration': 3099, | |
21 | } | |
22 | }, { | |
23 | # geo restricted | |
24 | 'url': 'http://www.rtbf.be/ouftivi/heros/detail_scooby-doo-mysteres-associes?id=1097&videoId=2057442', | |
25 | 'only_matching': True, | |
26 | }, { | |
27 | 'url': 'http://www.rtbf.be/ouftivi/niouzz?videoId=2055858', | |
28 | 'only_matching': True, | |
29 | }] | |
201e3c99 | 30 | |
eb8be1fe JMF |
31 | _QUALITIES = [ |
32 | ('mobile', 'mobile'), | |
33 | ('web', 'SD'), | |
34 | ('url', 'MD'), | |
35 | ('high', 'HD'), | |
36 | ] | |
37 | ||
201e3c99 | 38 | def _real_extract(self, url): |
63f3cab4 | 39 | video_id = self._match_id(url) |
201e3c99 | 40 | |
63f3cab4 S |
41 | webpage = self._download_webpage( |
42 | 'http://www.rtbf.be/video/embed?id=%s' % video_id, video_id) | |
65e4ad5b | 43 | |
63f3cab4 S |
44 | data = self._parse_json( |
45 | unescapeHTML(self._search_regex( | |
57d1db8d | 46 | r'data-media="([^"]+)"', webpage, 'data video')), |
63f3cab4 | 47 | video_id) |
201e3c99 | 48 | |
63f3cab4 | 49 | if data.get('provider').lower() == 'youtube': |
eb8be1fe | 50 | video_url = data.get('downloadUrl') or data.get('url') |
65e4ad5b | 51 | return self.url_result(video_url, 'Youtube') |
eb8be1fe JMF |
52 | formats = [] |
53 | for key, format_id in self._QUALITIES: | |
54 | format_url = data['sources'].get(key) | |
55 | if format_url: | |
56 | formats.append({ | |
57 | 'format_id': format_id, | |
58 | 'url': format_url, | |
59 | }) | |
201e3c99 NÉ |
60 | |
61 | return { | |
62 | 'id': video_id, | |
eb8be1fe | 63 | 'formats': formats, |
65e4ad5b S |
64 | 'title': data['title'], |
65 | 'description': data.get('description') or data.get('subtitle'), | |
63f3cab4 | 66 | 'thumbnail': data.get('thumbnail'), |
65e4ad5b | 67 | 'duration': data.get('duration') or data.get('realDuration'), |
63f3cab4 S |
68 | 'timestamp': int_or_none(data.get('created')), |
69 | 'view_count': int_or_none(data.get('viewCount')), | |
201e3c99 | 70 | } |