]>
Commit | Line | Data |
---|---|---|
25fadd06 | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
5dd4b346 BF |
4 | import re |
5 | ||
25fadd06 | 6 | from .common import InfoExtractor |
25fadd06 | 7 | from ..utils import ( |
8 | float_or_none, | |
9938a17f | 9 | parse_iso8601, |
896c7a23 | 10 | unescapeHTML, |
25fadd06 | 11 | ) |
12 | ||
13 | ||
14 | class RteIE(InfoExtractor): | |
896c7a23 | 15 | IE_NAME = 'rte' |
16 | IE_DESC = 'Raidió Teilifís Éireann TV' | |
6df7179e | 17 | _VALID_URL = r'https?://(?:www\.)?rte\.ie/player/[^/]{2,3}/show/[^/]+/(?P<id>[0-9]+)' |
25fadd06 | 18 | _TEST = { |
36eb802b | 19 | 'url': 'http://www.rte.ie/player/ie/show/iwitness-862/10478715/', |
25fadd06 | 20 | 'info_dict': { |
36eb802b | 21 | 'id': '10478715', |
896c7a23 | 22 | 'ext': 'flv', |
36eb802b | 23 | 'title': 'Watch iWitness online', |
25fadd06 | 24 | 'thumbnail': 're:^https?://.*\.jpg$', |
36eb802b JMF |
25 | 'description': 'iWitness : The spirit of Ireland, one voice and one minute at a time.', |
26 | 'duration': 60.046, | |
ea1d5bdc PH |
27 | }, |
28 | 'params': { | |
29 | 'skip_download': 'f4m fails with --test atm' | |
25fadd06 | 30 | } |
31 | } | |
3462af03 | 32 | |
25fadd06 | 33 | def _real_extract(self, url): |
34 | video_id = self._match_id(url) | |
25fadd06 | 35 | webpage = self._download_webpage(url, video_id) |
ea1d5bdc | 36 | |
25fadd06 | 37 | title = self._og_search_title(webpage) |
ea1d5bdc PH |
38 | description = self._html_search_meta('description', webpage, 'description') |
39 | duration = float_or_none(self._html_search_meta( | |
40 | 'duration', webpage, 'duration', fatal=False), 1000) | |
41 | ||
e42f4137 S |
42 | thumbnail = None |
43 | thumbnail_meta = self._html_search_meta('thumbnail', webpage) | |
44 | if thumbnail_meta: | |
45 | thumbnail_id = self._search_regex( | |
46 | r'uri:irus:(.+)', thumbnail_meta, | |
47 | 'thumbnail id', fatal=False) | |
48 | if thumbnail_id: | |
49 | thumbnail = 'http://img.rasset.ie/%s.jpg' % thumbnail_id | |
ea1d5bdc | 50 | |
611c1dd9 | 51 | feeds_url = self._html_search_meta('feeds-prefix', webpage, 'feeds url') + video_id |
25fadd06 | 52 | json_string = self._download_json(feeds_url, video_id) |
ea1d5bdc | 53 | |
25fadd06 | 54 | # f4m_url = server + relative_url |
55 | f4m_url = json_string['shows'][0]['media:group'][0]['rte:server'] + json_string['shows'][0]['media:group'][0]['url'] | |
56 | f4m_formats = self._extract_f4m_formats(f4m_url, video_id) | |
19dbaeec | 57 | self._sort_formats(f4m_formats) |
ea1d5bdc | 58 | |
25fadd06 | 59 | return { |
60 | 'id': video_id, | |
61 | 'title': title, | |
62 | 'formats': f4m_formats, | |
63 | 'description': description, | |
64 | 'thumbnail': thumbnail, | |
65 | 'duration': duration, | |
ea1d5bdc | 66 | } |
896c7a23 | 67 | |
68 | ||
896c7a23 | 69 | class RteRadioIE(InfoExtractor): |
70 | IE_NAME = 'rte:radio' | |
71 | IE_DESC = 'Raidió Teilifís Éireann radio' | |
5dd4b346 BF |
72 | # Radioplayer URLs have two distinct specifier formats, |
73 | # the old format #!rii=<channel_id>:<id>:<playable_item_id>:<date>: | |
74 | # the new format #!rii=b<channel_id>_<id>_<playable_item_id>_<date>_ | |
896c7a23 | 75 | # where the IDs are int/empty, the date is DD-MM-YYYY, and the specifier may be truncated. |
76 | # An <id> uniquely defines an individual recording, and is the only part we require. | |
5dd4b346 | 77 | _VALID_URL = r'https?://(?:www\.)?rte\.ie/radio/utils/radioplayer/rteradioweb\.html#!rii=(?:b?[0-9]*)(?:%3A|:|%5F|_)(?P<id>[0-9]+)' |
896c7a23 | 78 | |
5dd4b346 BF |
79 | _TESTS = [{ |
80 | # Old-style player URL; HLS and RTMPE formats | |
896c7a23 | 81 | 'url': 'http://www.rte.ie/radio/utils/radioplayer/rteradioweb.html#!rii=16:10507902:2414:27-12-2015:', |
82 | 'info_dict': { | |
83 | 'id': '10507902', | |
9938a17f | 84 | 'ext': 'mp4', |
896c7a23 | 85 | 'title': 'Gloria', |
86 | 'thumbnail': 're:^https?://.*\.jpg$', | |
9938a17f S |
87 | 'description': 'md5:9ce124a7fb41559ec68f06387cabddf0', |
88 | 'timestamp': 1451203200, | |
89 | 'upload_date': '20151227', | |
896c7a23 | 90 | 'duration': 7230.0, |
91 | }, | |
92 | 'params': { | |
93 | 'skip_download': 'f4m fails with --test atm' | |
94 | } | |
5dd4b346 BF |
95 | }, { |
96 | # New-style player URL; RTMPE formats only | |
97 | 'url': 'http://rte.ie/radio/utils/radioplayer/rteradioweb.html#!rii=b16_3250678_8861_06-04-2012_', | |
98 | 'info_dict': { | |
99 | 'id': '3250678', | |
100 | 'ext': 'flv', | |
101 | 'title': 'The Lyric Concert with Paul Herriott', | |
102 | 'thumbnail': 're:^https?://.*\.jpg$', | |
103 | 'description': '', | |
104 | 'timestamp': 1333742400, | |
105 | 'upload_date': '20120406', | |
106 | 'duration': 7199.016, | |
107 | }, | |
108 | 'params': { | |
109 | 'skip_download': 'f4m fails with --test atm' | |
110 | } | |
111 | }] | |
896c7a23 | 112 | |
113 | def _real_extract(self, url): | |
114 | item_id = self._match_id(url) | |
9938a17f S |
115 | |
116 | json_string = self._download_json( | |
117 | 'http://www.rte.ie/rteavgen/getplaylist/?type=web&format=json&id=' + item_id, | |
118 | item_id) | |
896c7a23 | 119 | |
120 | # NB the string values in the JSON are stored using XML escaping(!) | |
121 | show = json_string['shows'][0] | |
122 | title = unescapeHTML(show['title']) | |
123 | description = unescapeHTML(show.get('description')) | |
124 | thumbnail = show.get('thumbnail') | |
125 | duration = float_or_none(show.get('duration'), 1000) | |
9938a17f | 126 | timestamp = parse_iso8601(show.get('published')) |
896c7a23 | 127 | |
128 | mg = show['media:group'][0] | |
129 | ||
130 | formats = [] | |
131 | ||
5dd4b346 BF |
132 | if mg.get('url'): |
133 | m = re.match(r'(?P<url>rtmpe?://[^/]+)/(?P<app>.+)/(?P<playpath>mp4:.*)', mg['url']) | |
134 | if m: | |
135 | m = m.groupdict() | |
136 | formats.append({ | |
137 | 'url': m['url'] + '/' + m['app'], | |
138 | 'app': m['app'], | |
139 | 'play_path': m['playpath'], | |
140 | 'player_url': url, | |
141 | 'ext': 'flv', | |
142 | 'format_id': 'rtmp', | |
143 | }) | |
896c7a23 | 144 | |
145 | if mg.get('hls_server') and mg.get('hls_url'): | |
9746f431 S |
146 | formats.extend(self._extract_m3u8_formats( |
147 | mg['hls_server'] + mg['hls_url'], item_id, 'mp4', | |
148 | entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)) | |
896c7a23 | 149 | |
150 | if mg.get('hds_server') and mg.get('hds_url'): | |
9746f431 S |
151 | formats.extend(self._extract_f4m_formats( |
152 | mg['hds_server'] + mg['hds_url'], item_id, | |
153 | f4m_id='hds', fatal=False)) | |
154 | ||
155 | self._sort_formats(formats) | |
896c7a23 | 156 | |
157 | return { | |
158 | 'id': item_id, | |
159 | 'title': title, | |
896c7a23 | 160 | 'description': description, |
161 | 'thumbnail': thumbnail, | |
9938a17f | 162 | 'timestamp': timestamp, |
896c7a23 | 163 | 'duration': duration, |
9938a17f | 164 | 'formats': formats, |
896c7a23 | 165 | } |