]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/rtbf.py
Prepare for release
[youtubedl] / youtube_dl / extractor / rtbf.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 int_or_none,
7 ExtractorError,
8 )
9
10
11 class RTBFIE(InfoExtractor):
12 _VALID_URL = r'''(?x)
13 https?://(?:www\.)?rtbf\.be/
14 (?:
15 video/[^?]+\?.*\bid=|
16 ouftivi/(?:[^/]+/)*[^?]+\?.*\bvideoId=|
17 auvio/[^/]+\?.*id=
18 )(?P<id>\d+)'''
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)',
26 'description': 'Football - Diables Rouges',
27 'duration': 3099,
28 'upload_date': '20140425',
29 'timestamp': 1398456336,
30 'uploader': 'rtbfsport',
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,
39 }, {
40 'url': 'http://www.rtbf.be/auvio/detail_jeudi-en-prime-siegfried-bracke?id=2102996',
41 'only_matching': True,
42 }]
43 _IMAGE_HOST = 'http://ds1.ds.static.rtbf.be'
44 _PROVIDERS = {
45 'YOUTUBE': 'Youtube',
46 'DAILYMOTION': 'Dailymotion',
47 'VIMEO': 'Vimeo',
48 }
49 _QUALITIES = [
50 ('mobile', 'SD'),
51 ('web', 'MD'),
52 ('high', 'HD'),
53 ]
54
55 def _real_extract(self, url):
56 video_id = self._match_id(url)
57 data = self._download_json(
58 'http://www.rtbf.be/api/media/video?method=getVideoDetail&args[]=%s' % video_id, video_id)
59
60 error = data.get('error')
61 if error:
62 raise ExtractorError('%s said: %s' % (self.IE_NAME, error), expected=True)
63
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])
69
70 formats = []
71 for key, format_id in self._QUALITIES:
72 format_url = data.get(key + 'Url')
73 if format_url:
74 formats.append({
75 'format_id': format_id,
76 'url': format_url,
77 })
78
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
87 return {
88 'id': video_id,
89 'formats': formats,
90 'title': data['title'],
91 'description': data.get('description') or data.get('subtitle'),
92 'thumbnails': thumbnails,
93 'duration': data.get('duration') or data.get('realDuration'),
94 'timestamp': int_or_none(data.get('created')),
95 'view_count': int_or_none(data.get('viewCount')),
96 'uploader': data.get('channel'),
97 'tags': data.get('tags'),
98 }