]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/rtbf.py
Initiate new 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 unescapeHTML,
8 )
9
10
11 class RTBFIE(InfoExtractor):
12 _VALID_URL = r'https?://www.rtbf.be/video/[^\?]+\?id=(?P<id>\d+)'
13 _TEST = {
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
24 _QUALITIES = [
25 ('mobile', 'mobile'),
26 ('web', 'SD'),
27 ('url', 'MD'),
28 ('high', 'HD'),
29 ]
30
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33
34 webpage = self._download_webpage(
35 'http://www.rtbf.be/video/embed?id=%s' % video_id, video_id)
36
37 data = self._parse_json(
38 unescapeHTML(self._search_regex(
39 r'data-video="([^"]+)"', webpage, 'data video')),
40 video_id)
41
42 if data.get('provider').lower() == 'youtube':
43 video_url = data.get('downloadUrl') or data.get('url')
44 return self.url_result(video_url, 'Youtube')
45 formats = []
46 for key, format_id in self._QUALITIES:
47 format_url = data['sources'].get(key)
48 if format_url:
49 formats.append({
50 'format_id': format_id,
51 'url': format_url,
52 })
53
54 return {
55 'id': video_id,
56 'formats': formats,
57 'title': data['title'],
58 'description': data.get('description') or data.get('subtitle'),
59 'thumbnail': data.get('thumbnail'),
60 'duration': data.get('duration') or data.get('realDuration'),
61 'timestamp': int_or_none(data.get('created')),
62 'view_count': int_or_none(data.get('viewCount')),
63 }