]>
Commit | Line | Data |
---|---|---|
c3f3b29b NJ |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
ad5747ba | 4 | import re |
c3f3b29b NJ |
5 | |
6 | from .common import InfoExtractor | |
c3f3b29b NJ |
7 | |
8 | ||
9 | class RTPIE(InfoExtractor): | |
bad5c1a3 PH |
10 | _VALID_URL = r'https?://(?:www\.)?rtp\.pt/play/p(?P<program_id>[0-9]+)/(?P<id>[^/?#]+)/?' |
11 | _TESTS = [{ | |
c3f3b29b | 12 | 'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas', |
ad5747ba | 13 | 'md5': 'e736ce0c665e459ddb818546220b4ef8', |
c3f3b29b | 14 | 'info_dict': { |
a86cbf58 | 15 | 'id': 'e174042', |
c3f3b29b NJ |
16 | 'ext': 'mp3', |
17 | 'title': 'Paixões Cruzadas', | |
18 | 'description': 'As paixões musicais de António Cartaxo e António Macedo', | |
ec85ded8 | 19 | 'thumbnail': r're:^https?://.*\.jpg', |
c3f3b29b | 20 | }, |
5d003e29 S |
21 | 'params': { |
22 | # rtmp download | |
23 | 'skip_download': True, | |
24 | }, | |
bad5c1a3 PH |
25 | }, { |
26 | 'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas', | |
27 | 'only_matching': True, | |
28 | }] | |
c3f3b29b NJ |
29 | |
30 | def _real_extract(self, url): | |
31 | video_id = self._match_id(url) | |
32 | ||
33 | webpage = self._download_webpage(url, video_id) | |
34 | title = self._html_search_meta( | |
35 | 'twitter:title', webpage, display_name='title', fatal=True) | |
36 | description = self._html_search_meta('description', webpage) | |
37 | thumbnail = self._og_search_thumbnail(webpage) | |
38 | ||
39 | player_config = self._search_regex( | |
40 | r'(?s)RTPPLAY\.player\.newPlayer\(\s*(\{.*?\})\s*\)', webpage, 'player config') | |
ad5747ba | 41 | config = self._parse_json(player_config, video_id) |
c3f3b29b NJ |
42 | |
43 | path, ext = config.get('file').rsplit('.', 1) | |
44 | formats = [{ | |
ad5747ba NJ |
45 | 'format_id': 'rtmp', |
46 | 'ext': ext, | |
47 | 'vcodec': config.get('type') == 'audio' and 'none' or None, | |
48 | 'preference': -2, | |
49 | 'url': 'rtmp://{streamer:s}/{application:s}'.format(**config), | |
c3f3b29b NJ |
50 | 'app': config.get('application'), |
51 | 'play_path': '{ext:s}:{path:s}'.format(ext=ext, path=path), | |
52 | 'page_url': url, | |
c3f3b29b | 53 | 'rtmp_live': config.get('live', False), |
c3f3b29b | 54 | 'player_url': 'http://programas.rtp.pt/play/player.swf?v3', |
1a2548d9 | 55 | 'rtmp_real_time': True, |
c3f3b29b NJ |
56 | }] |
57 | ||
ad5747ba NJ |
58 | # Construct regular HTTP download URLs |
59 | replacements = { | |
60 | 'audio': { | |
61 | 'format_id': 'mp3', | |
62 | 'pattern': r'^nas2\.share/wavrss/', | |
63 | 'repl': 'http://rsspod.rtp.pt/podcasts/', | |
64 | 'vcodec': 'none', | |
65 | }, | |
66 | 'video': { | |
67 | 'format_id': 'mp4_h264', | |
68 | 'pattern': r'^nas2\.share/h264/', | |
69 | 'repl': 'http://rsspod.rtp.pt/videocasts/', | |
70 | 'vcodec': 'h264', | |
71 | }, | |
72 | } | |
73 | r = replacements[config['type']] | |
74 | if re.match(r['pattern'], config['file']) is not None: | |
75 | formats.append({ | |
76 | 'format_id': r['format_id'], | |
77 | 'url': re.sub(r['pattern'], r['repl'], config['file']), | |
78 | 'vcodec': r['vcodec'], | |
79 | }) | |
80 | ||
81 | self._sort_formats(formats) | |
82 | ||
c3f3b29b NJ |
83 | return { |
84 | 'id': video_id, | |
85 | 'title': title, | |
86 | 'formats': formats, | |
87 | 'description': description, | |
88 | 'thumbnail': thumbnail, | |
89 | } |