2014-04-28 20:32:13 +02:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2015-05-24 17:09:08 +02:00
|
|
|
from ..utils import (
|
|
|
|
int_or_none,
|
|
|
|
unescapeHTML,
|
|
|
|
)
|
2014-04-28 20:32:13 +02:00
|
|
|
|
2014-04-29 14:41:58 +02:00
|
|
|
|
|
|
|
class RTBFIE(InfoExtractor):
|
2015-11-07 22:55:02 +01:00
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
https?://www\.rtbf\.be/
|
|
|
|
(?:
|
|
|
|
video/[^\?]+\?id=|
|
|
|
|
ouftivi/heros/[^&]+&videoId=
|
|
|
|
)
|
|
|
|
(?P<id>\d+)
|
|
|
|
'''
|
|
|
|
_TESTS = [
|
|
|
|
{
|
|
|
|
'url': 'https://www.rtbf.be/video/detail_les-diables-au-coeur-episode-2?id=1921274',
|
|
|
|
'md5': '799f334ddf2c0a582ba80c44655be570',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '1921274',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Les Diables au coeur (épisode 2)',
|
|
|
|
'duration': 3099,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'url': 'http://www.rtbf.be/ouftivi/heros/detail_scooby-doo-mysteres-associes?id=1097&videoId=2057442',
|
|
|
|
'md5': '25aea17e949e1e0c7c41270d60d25f22',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '2057442',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Scooby-Doo, myst\xe8res associ\xe9s',
|
|
|
|
'duration': 1279,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
2014-04-28 20:32:13 +02:00
|
|
|
|
2015-06-10 14:12:43 +02:00
|
|
|
_QUALITIES = [
|
|
|
|
('mobile', 'mobile'),
|
|
|
|
('web', 'SD'),
|
|
|
|
('url', 'MD'),
|
|
|
|
('high', 'HD'),
|
|
|
|
]
|
|
|
|
|
2014-04-28 20:32:13 +02:00
|
|
|
def _real_extract(self, url):
|
2015-05-24 17:09:08 +02:00
|
|
|
video_id = self._match_id(url)
|
2014-04-28 20:32:13 +02:00
|
|
|
|
2015-05-24 17:09:08 +02:00
|
|
|
webpage = self._download_webpage(
|
|
|
|
'http://www.rtbf.be/video/embed?id=%s' % video_id, video_id)
|
2014-04-29 14:41:58 +02:00
|
|
|
|
2015-05-24 17:09:08 +02:00
|
|
|
data = self._parse_json(
|
|
|
|
unescapeHTML(self._search_regex(
|
2015-10-11 22:45:13 +02:00
|
|
|
r'data-media="([^"]+)"', webpage, 'data video')),
|
2015-05-24 17:09:08 +02:00
|
|
|
video_id)
|
2014-04-28 20:32:13 +02:00
|
|
|
|
2015-05-24 17:09:08 +02:00
|
|
|
if data.get('provider').lower() == 'youtube':
|
2015-06-10 14:12:43 +02:00
|
|
|
video_url = data.get('downloadUrl') or data.get('url')
|
2014-04-29 14:41:58 +02:00
|
|
|
return self.url_result(video_url, 'Youtube')
|
2015-06-10 14:12:43 +02:00
|
|
|
formats = []
|
|
|
|
for key, format_id in self._QUALITIES:
|
|
|
|
format_url = data['sources'].get(key)
|
|
|
|
if format_url:
|
|
|
|
formats.append({
|
|
|
|
'format_id': format_id,
|
|
|
|
'url': format_url,
|
|
|
|
})
|
2014-04-28 20:32:13 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
2015-06-10 14:12:43 +02:00
|
|
|
'formats': formats,
|
2014-04-29 14:41:58 +02:00
|
|
|
'title': data['title'],
|
|
|
|
'description': data.get('description') or data.get('subtitle'),
|
2015-05-24 17:09:08 +02:00
|
|
|
'thumbnail': data.get('thumbnail'),
|
2014-04-29 14:41:58 +02:00
|
|
|
'duration': data.get('duration') or data.get('realDuration'),
|
2015-05-24 17:09:08 +02:00
|
|
|
'timestamp': int_or_none(data.get('created')),
|
|
|
|
'view_count': int_or_none(data.get('viewCount')),
|
2014-04-28 20:32:13 +02:00
|
|
|
}
|