]>
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, | |
7c36ea7d | 7 | ExtractorError, |
63f3cab4 | 8 | ) |
201e3c99 | 9 | |
65e4ad5b S |
10 | |
11 | class RTBFIE(InfoExtractor): | |
7c36ea7d | 12 | _VALID_URL = r'''(?x) |
13 | https?://(?:www\.)?rtbf\.be/ | |
14 | (?: | |
15 | video/[^?]+\?.*\bid=| | |
16 | ouftivi/(?:[^/]+/)*[^?]+\?.*\bvideoId=| | |
17 | auvio/[^/]+\?.*id= | |
18 | )(?P<id>\d+)''' | |
114e6025 S |
19 | _TESTS = [{ |
20 | 'url': 'https://www.rtbf.be/video/detail_les-diables-au-coeur-episode-2?id=1921274', | |
21 | 'md5': '799f334ddf2c0a582ba80c44655be570', | |
22 | 'info_dict': { | |
23 | 'id': '1921274', | |
24 | 'ext': 'mp4', | |
25 | 'title': 'Les Diables au coeur (épisode 2)', | |
7c36ea7d | 26 | 'description': 'Football - Diables Rouges', |
114e6025 | 27 | 'duration': 3099, |
7c36ea7d | 28 | 'upload_date': '20140425', |
29 | 'timestamp': 1398456336, | |
30 | 'uploader': 'rtbfsport', | |
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, | |
114e6025 | 42 | }] |
7c36ea7d | 43 | _IMAGE_HOST = 'http://ds1.ds.static.rtbf.be' |
44 | _PROVIDERS = { | |
45 | 'YOUTUBE': 'Youtube', | |
46 | 'DAILYMOTION': 'Dailymotion', | |
47 | 'VIMEO': 'Vimeo', | |
48 | } | |
eb8be1fe | 49 | _QUALITIES = [ |
7c36ea7d | 50 | ('mobile', 'SD'), |
51 | ('web', 'MD'), | |
eb8be1fe JMF |
52 | ('high', 'HD'), |
53 | ] | |
54 | ||
201e3c99 | 55 | def _real_extract(self, url): |
63f3cab4 | 56 | video_id = self._match_id(url) |
7c36ea7d | 57 | data = self._download_json( |
58 | 'http://www.rtbf.be/api/media/video?method=getVideoDetail&args[]=%s' % video_id, video_id) | |
201e3c99 | 59 | |
7c36ea7d | 60 | error = data.get('error') |
61 | if error: | |
62 | raise ExtractorError('%s said: %s' % (self.IE_NAME, error), expected=True) | |
65e4ad5b | 63 | |
7c36ea7d | 64 | data = data['data'] |
65 | ||
66 | provider = data.get('provider') | |
67 | if provider in self._PROVIDERS: | |
68 | return self.url_result(data['url'], self._PROVIDERS[provider]) | |
201e3c99 | 69 | |
eb8be1fe JMF |
70 | formats = [] |
71 | for key, format_id in self._QUALITIES: | |
7c36ea7d | 72 | format_url = data.get(key + 'Url') |
eb8be1fe JMF |
73 | if format_url: |
74 | formats.append({ | |
75 | 'format_id': format_id, | |
76 | 'url': format_url, | |
77 | }) | |
201e3c99 | 78 | |
7c36ea7d | 79 | thumbnails = [] |
80 | for thumbnail_id, thumbnail_url in data.get('thumbnail', {}).items(): | |
81 | if thumbnail_id != 'default': | |
82 | thumbnails.append({ | |
83 | 'url': self._IMAGE_HOST + thumbnail_url, | |
84 | 'id': thumbnail_id, | |
85 | }) | |
86 | ||
201e3c99 NÉ |
87 | return { |
88 | 'id': video_id, | |
eb8be1fe | 89 | 'formats': formats, |
65e4ad5b S |
90 | 'title': data['title'], |
91 | 'description': data.get('description') or data.get('subtitle'), | |
7c36ea7d | 92 | 'thumbnails': thumbnails, |
65e4ad5b | 93 | 'duration': data.get('duration') or data.get('realDuration'), |
63f3cab4 S |
94 | 'timestamp': int_or_none(data.get('created')), |
95 | 'view_count': int_or_none(data.get('viewCount')), | |
7c36ea7d | 96 | 'uploader': data.get('channel'), |
97 | 'tags': data.get('tags'), | |
201e3c99 | 98 | } |