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