94 lines
3.2 KiB
Python
Raw Normal View History

2014-12-12 20:22:24 +02:00
# coding: utf-8
2019-04-21 22:26:38 +01:00
2014-12-12 20:22:24 +02:00
from __future__ import unicode_literals
2019-04-21 22:26:38 +01:00
import re
2014-12-12 20:22:24 +02:00
from .common import InfoExtractor
2019-03-26 21:54:38 +00:00
from ..utils import js_to_json
2014-12-12 20:22:24 +02:00
2014-12-12 20:22:24 +02:00
class RTPIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?rtp\.pt/play/p(?P<program_id>[0-9]+)/(?P<id>[^/?#]+)/?'
2019-04-21 22:26:38 +01:00
_TESTS = [{
2014-12-12 20:22:24 +02:00
'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas',
'md5': 'e736ce0c665e459ddb818546220b4ef8',
2014-12-12 20:22:24 +02:00
'info_dict': {
2014-12-21 15:28:40 +01:00
'id': 'e174042',
2014-12-12 20:22:24 +02:00
'ext': 'mp3',
'title': 'Paixões Cruzadas',
'description': 'As paixões musicais de António Cartaxo e António Macedo',
'thumbnail': r're:^https?://.*\.jpg',
2014-12-12 20:22:24 +02:00
},
2015-08-21 08:56:05 +06:00
'params': {
# rtmp download
'skip_download': True,
},
}, {
'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas',
'only_matching': True,
}]
2014-12-12 20:22:24 +02: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)
description = self._html_search_meta('description', webpage)
thumbnail = self._og_search_thumbnail(webpage)
player_config = self._search_regex(
2019-03-26 21:54:38 +00:00
r'(?s)RTPPlayer\(({.*?})', webpage, 'player config')
player_config = js_to_json(player_config)
config = self._parse_json(player_config, video_id)
2014-12-12 20:22:24 +02:00
path, ext = config.get('file').rsplit('.', 1)
formats = [{
'format_id': 'rtmp',
'ext': ext,
'preference': -2,
2019-03-26 21:54:38 +00:00
'url': '{file}'.format(**config),
2014-12-12 20:22:24 +02:00
'app': config.get('application'),
'play_path': '{ext:s}:{path:s}'.format(ext=ext, path=path),
'page_url': url,
'player_url': 'http://programas.rtp.pt/play/player.swf?v3',
'rtmp_real_time': True,
2014-12-12 20:22:24 +02:00
}]
self._sort_formats(formats)
2014-12-12 20:22:24 +02:00
return {
'id': video_id,
'title': title,
'formats': formats,
'description': description,
'thumbnail': thumbnail,
}
2019-04-20 20:20:44 +01:00
2019-04-21 22:26:38 +01:00
class RTPPlaylistIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?rtp\.pt/play/p(?P<program_id>[0-9]+)'
def _get_program_id(self, url):
mobj = re.match(self._VALID_URL, url)
program_id = mobj.group('program_id')
return program_id
def _extract_entries(self, url, program_id, page):
entry_url = "https://www.rtp.pt/play/bg_l_ep/?&listProgram=%s&listcategory=&listchannel=&type=radio&page=%s" % (
program_id, page
)
webpage = self._download_webpage(entry_url, program_id)
return [self.url_result('https://www.rtp.pt/play/p%s/%s/' % (program_id, episode), 'RTP')
for episode in re.findall(r'e\d+', webpage)]
2019-04-21 00:22:20 +01:00
def _real_extract(self, url):
2019-04-21 22:26:38 +01:00
page = 1
program_id = self._get_program_id(url)
2019-04-21 22:26:38 +01:00
entry = self._extract_entries(url, program_id, page)
new_entry = self._extract_entries(url, program_id, page + 1)
while new_entry != []:
new_entry = self._extract_entries(url, program_id, page + 1)
entry += new_entry
page += 1
return self.playlist_result(entry, playlist_id=program_id)