]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/rtp.py
debian/control: Add recommends on aria2 | wget | curl to use external downloaders.
[youtubedl] / youtube_dl / extractor / rtp.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import json
5
6 from .common import InfoExtractor
7 from ..utils import js_to_json
8
9
10 class RTPIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?rtp\.pt/play/p(?P<program_id>[0-9]+)/(?P<id>[^/?#]+)/?'
12 _TESTS = [{
13 'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas',
14 'info_dict': {
15 'id': 'e174042',
16 'ext': 'mp3',
17 'title': 'Paixões Cruzadas',
18 'description': 'As paixões musicais de António Cartaxo e António Macedo',
19 'thumbnail': 're:^https?://.*\.jpg',
20 },
21 'params': {
22 'skip_download': True, # RTMP download
23 },
24 }, {
25 'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas',
26 'only_matching': True,
27 }]
28
29 def _real_extract(self, url):
30 video_id = self._match_id(url)
31
32 webpage = self._download_webpage(url, video_id)
33 title = self._html_search_meta(
34 'twitter:title', webpage, display_name='title', fatal=True)
35 description = self._html_search_meta('description', webpage)
36 thumbnail = self._og_search_thumbnail(webpage)
37
38 player_config = self._search_regex(
39 r'(?s)RTPPLAY\.player\.newPlayer\(\s*(\{.*?\})\s*\)', webpage, 'player config')
40 config = json.loads(js_to_json(player_config))
41
42 path, ext = config.get('file').rsplit('.', 1)
43 formats = [{
44 'app': config.get('application'),
45 'play_path': '{ext:s}:{path:s}'.format(ext=ext, path=path),
46 'page_url': url,
47 'url': 'rtmp://{streamer:s}/{application:s}'.format(**config),
48 'rtmp_live': config.get('live', False),
49 'ext': ext,
50 'vcodec': config.get('type') == 'audio' and 'none' or None,
51 'player_url': 'http://programas.rtp.pt/play/player.swf?v3',
52 'rtmp_real_time': True,
53 }]
54
55 return {
56 'id': video_id,
57 'title': title,
58 'formats': formats,
59 'description': description,
60 'thumbnail': thumbnail,
61 }