]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/rtbf.py
[downloader/common] Always skip "already downloaded" check when outputting to stdout
[yt-dlp.git] / youtube_dl / extractor / rtbf.py
CommitLineData
201e3c99
1# coding: utf-8
2from __future__ import unicode_literals
3
201e3c99 4from .common import InfoExtractor
63f3cab4
S
5from ..utils import (
6 int_or_none,
7 unescapeHTML,
8)
201e3c99 9
65e4ad5b
S
10
11class RTBFIE(InfoExtractor):
12 _VALID_URL = r'https?://www.rtbf.be/video/[^\?]+\?id=(?P<id>\d+)'
201e3c99
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
eb8be1fe
JMF
24 _QUALITIES = [
25 ('mobile', 'mobile'),
26 ('web', 'SD'),
27 ('url', 'MD'),
28 ('high', 'HD'),
29 ]
30
201e3c99 31 def _real_extract(self, url):
63f3cab4 32 video_id = self._match_id(url)
201e3c99 33
63f3cab4
S
34 webpage = self._download_webpage(
35 'http://www.rtbf.be/video/embed?id=%s' % video_id, video_id)
65e4ad5b 36
63f3cab4
S
37 data = self._parse_json(
38 unescapeHTML(self._search_regex(
39 r'data-video="([^"]+)"', webpage, 'data video')),
40 video_id)
201e3c99 41
63f3cab4 42 if data.get('provider').lower() == 'youtube':
eb8be1fe 43 video_url = data.get('downloadUrl') or data.get('url')
65e4ad5b 44 return self.url_result(video_url, 'Youtube')
eb8be1fe
JMF
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 })
201e3c99
53
54 return {
55 'id': video_id,
eb8be1fe 56 'formats': formats,
65e4ad5b
S
57 'title': data['title'],
58 'description': data.get('description') or data.get('subtitle'),
63f3cab4 59 'thumbnail': data.get('thumbnail'),
65e4ad5b 60 'duration': data.get('duration') or data.get('realDuration'),
63f3cab4
S
61 'timestamp': int_or_none(data.get('created')),
62 'view_count': int_or_none(data.get('viewCount')),
201e3c99 63 }