2014-12-12 19:22:24 +01:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2019-05-28 05:58:12 +02:00
|
|
|
from ..utils import (
|
|
|
|
determine_ext,
|
|
|
|
js_to_json,
|
|
|
|
)
|
2014-12-12 19:22:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
class RTPIE(InfoExtractor):
|
2014-12-14 00:13:07 +01:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?rtp\.pt/play/p(?P<program_id>[0-9]+)/(?P<id>[^/?#]+)/?'
|
|
|
|
_TESTS = [{
|
2014-12-12 19:22:24 +01:00
|
|
|
'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas',
|
2015-02-06 21:59:17 +01:00
|
|
|
'md5': 'e736ce0c665e459ddb818546220b4ef8',
|
2014-12-12 19:22:24 +01:00
|
|
|
'info_dict': {
|
2014-12-21 15:28:40 +01:00
|
|
|
'id': 'e174042',
|
2014-12-12 19:22:24 +01:00
|
|
|
'ext': 'mp3',
|
|
|
|
'title': 'Paixões Cruzadas',
|
|
|
|
'description': 'As paixões musicais de António Cartaxo e António Macedo',
|
2017-01-02 13:08:07 +01:00
|
|
|
'thumbnail': r're:^https?://.*\.jpg',
|
2014-12-12 19:22:24 +01:00
|
|
|
},
|
2014-12-14 00:13:07 +01:00
|
|
|
}, {
|
|
|
|
'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas',
|
|
|
|
'only_matching': True,
|
|
|
|
}]
|
2014-12-12 19:22:24 +01:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
title = self._html_search_meta(
|
|
|
|
'twitter:title', webpage, display_name='title', fatal=True)
|
2015-02-06 21:59:17 +01:00
|
|
|
|
2019-05-28 05:58:12 +02:00
|
|
|
config = self._parse_json(self._search_regex(
|
|
|
|
r'(?s)RTPPlayer\(({.+?})\);', webpage,
|
|
|
|
'player config'), video_id, js_to_json)
|
|
|
|
file_url = config['file']
|
|
|
|
ext = determine_ext(file_url)
|
|
|
|
if ext == 'm3u8':
|
|
|
|
file_key = config.get('fileKey')
|
|
|
|
formats = self._extract_m3u8_formats(
|
|
|
|
file_url, video_id, 'mp4', 'm3u8_native',
|
|
|
|
m3u8_id='hls', fatal=file_key)
|
|
|
|
if file_key:
|
|
|
|
formats.append({
|
|
|
|
'url': 'https://cdn-ondemand.rtp.pt' + file_key,
|
|
|
|
'preference': 1,
|
|
|
|
})
|
|
|
|
self._sort_formats(formats)
|
|
|
|
else:
|
|
|
|
formats = [{
|
|
|
|
'url': file_url,
|
|
|
|
'ext': ext,
|
|
|
|
}]
|
|
|
|
if config.get('mediaType') == 'audio':
|
|
|
|
for f in formats:
|
|
|
|
f['vcodec'] = 'none'
|
2015-02-06 21:59:17 +01:00
|
|
|
|
2014-12-12 19:22:24 +01:00
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': title,
|
|
|
|
'formats': formats,
|
2019-05-28 05:58:12 +02:00
|
|
|
'description': self._html_search_meta(['description', 'twitter:description'], webpage),
|
|
|
|
'thumbnail': config.get('poster') or self._og_search_thumbnail(webpage),
|
2014-12-12 19:22:24 +01:00
|
|
|
}
|