]>
Commit | Line | Data |
---|---|---|
89284910 | 1 | # coding: utf-8 |
5d73273f | 2 | from __future__ import unicode_literals |
89284910 | 3 | |
54543467 | 4 | import json |
5d73273f | 5 | import re |
eb368012 S |
6 | import calendar |
7 | import datetime | |
54543467 JMF |
8 | |
9 | from .common import InfoExtractor | |
10 | from ..utils import ( | |
5d73273f PH |
11 | HEADRequest, |
12 | unified_strdate, | |
2acc1f8f | 13 | ExtractorError, |
14137b57 S |
14 | strip_jsonp, |
15 | int_or_none, | |
16 | float_or_none, | |
17 | determine_ext, | |
18 | remove_end, | |
54543467 JMF |
19 | ) |
20 | ||
5d73273f | 21 | |
eb368012 S |
22 | class ORFTVthekIE(InfoExtractor): |
23 | IE_NAME = 'orf:tvthek' | |
24 | IE_DESC = 'ORF TVthek' | |
13d27a42 | 25 | _VALID_URL = r'https?://tvthek\.orf\.at/(?:programs/.+?/episodes|topics?/.+?|program/[^/]+)/(?P<id>\d+)' |
5d73273f | 26 | |
13d27a42 | 27 | _TESTS = [{ |
a6620ac2 PH |
28 | 'url': 'http://tvthek.orf.at/program/Aufgetischt/2745173/Aufgetischt-Mit-der-Steirischen-Tafelrunde/8891389', |
29 | 'playlist': [{ | |
30 | 'md5': '2942210346ed779588f428a92db88712', | |
31 | 'info_dict': { | |
32 | 'id': '8896777', | |
33 | 'ext': 'mp4', | |
34 | 'title': 'Aufgetischt: Mit der Steirischen Tafelrunde', | |
35 | 'description': 'md5:c1272f0245537812d4e36419c207b67d', | |
36 | 'duration': 2668, | |
37 | 'upload_date': '20141208', | |
38 | }, | |
39 | }], | |
13d27a42 PH |
40 | 'skip': 'Blocked outside of Austria / Germany', |
41 | }, { | |
42 | 'url': 'http://tvthek.orf.at/topic/Im-Wandel-der-Zeit/8002126/Best-of-Ingrid-Thurnher/7982256', | |
43 | 'playlist': [{ | |
44 | 'md5': '68f543909aea49d621dfc7703a11cfaf', | |
45 | 'info_dict': { | |
46 | 'id': '7982259', | |
47 | 'ext': 'mp4', | |
48 | 'title': 'Best of Ingrid Thurnher', | |
49 | 'upload_date': '20140527', | |
50 | 'description': 'Viele Jahre war Ingrid Thurnher das "Gesicht" der ZIB 2. Vor ihrem Wechsel zur ZIB 2 im jahr 1995 moderierte sie unter anderem "Land und Leute", "Österreich-Bild" und "Niederösterreich heute".', | |
51 | } | |
52 | }], | |
53 | '_skip': 'Blocked outside of Austria / Germany', | |
54 | }] | |
54543467 | 55 | |
54543467 | 56 | def _real_extract(self, url): |
a6620ac2 | 57 | playlist_id = self._match_id(url) |
54543467 JMF |
58 | webpage = self._download_webpage(url, playlist_id) |
59 | ||
5d73273f PH |
60 | data_json = self._search_regex( |
61 | r'initializeAdworx\((.+?)\);\n', webpage, 'video info') | |
62 | all_data = json.loads(data_json) | |
2acc1f8f S |
63 | |
64 | def get_segments(all_data): | |
65 | for data in all_data: | |
13d27a42 PH |
66 | if data['name'] in ( |
67 | 'Tracker::EPISODE_DETAIL_PAGE_OVER_PROGRAM', | |
68 | 'Tracker::EPISODE_DETAIL_PAGE_OVER_TOPIC'): | |
2acc1f8f S |
69 | return data['values']['segments'] |
70 | ||
71 | sdata = get_segments(all_data) | |
72 | if not sdata: | |
73 | raise ExtractorError('Unable to extract segments') | |
5d73273f PH |
74 | |
75 | def quality_to_int(s): | |
76 | m = re.search('([0-9]+)', s) | |
77 | if m is None: | |
78 | return -1 | |
79 | return int(m.group(1)) | |
80 | ||
81 | entries = [] | |
82 | for sd in sdata: | |
83 | video_id = sd['id'] | |
84 | formats = [{ | |
85 | 'preference': -10 if fd['delivery'] == 'hls' else None, | |
86 | 'format_id': '%s-%s-%s' % ( | |
87 | fd['delivery'], fd['quality'], fd['quality_string']), | |
88 | 'url': fd['src'], | |
89 | 'protocol': fd['protocol'], | |
90 | 'quality': quality_to_int(fd['quality']), | |
91 | } for fd in sd['playlist_item_array']['sources']] | |
92 | ||
93 | # Check for geoblocking. | |
94 | # There is a property is_geoprotection, but that's always false | |
95 | geo_str = sd.get('geoprotection_string') | |
96 | if geo_str: | |
97 | try: | |
98 | http_url = next( | |
99 | f['url'] | |
100 | for f in formats | |
101 | if re.match(r'^https?://.*\.mp4$', f['url'])) | |
102 | except StopIteration: | |
103 | pass | |
104 | else: | |
105 | req = HEADRequest(http_url) | |
4f81667d | 106 | self._request_webpage( |
5d73273f PH |
107 | req, video_id, |
108 | note='Testing for geoblocking', | |
109 | errnote=(( | |
110 | 'This video seems to be blocked outside of %s. ' | |
111 | 'You may want to try the streaming-* formats.') | |
112 | % geo_str), | |
113 | fatal=False) | |
114 | ||
e277f2a6 | 115 | self._check_formats(formats, video_id) |
5d73273f PH |
116 | self._sort_formats(formats) |
117 | ||
118 | upload_date = unified_strdate(sd['created_date']) | |
119 | entries.append({ | |
54543467 | 120 | '_type': 'video', |
5d73273f PH |
121 | 'id': video_id, |
122 | 'title': sd['header'], | |
123 | 'formats': formats, | |
124 | 'description': sd.get('description'), | |
125 | 'duration': int(sd['duration_in_seconds']), | |
126 | 'upload_date': upload_date, | |
127 | 'thumbnail': sd.get('image_full_url'), | |
128 | }) | |
129 | ||
130 | return { | |
131 | '_type': 'playlist', | |
132 | 'entries': entries, | |
133 | 'id': playlist_id, | |
134 | } | |
eb368012 S |
135 | |
136 | ||
eb368012 S |
137 | class ORFOE1IE(InfoExtractor): |
138 | IE_NAME = 'orf:oe1' | |
139 | IE_DESC = 'Radio Österreich 1' | |
5886b38d | 140 | _VALID_URL = r'https?://oe1\.orf\.at/(?:programm/|konsole.*?#\?track_id=)(?P<id>[0-9]+)' |
27ca82eb PH |
141 | |
142 | # Audios on ORF radio are only available for 7 days, so we can't add tests. | |
143 | _TEST = { | |
144 | 'url': 'http://oe1.orf.at/konsole?show=on_demand#?track_id=394211', | |
145 | 'only_matching': True, | |
146 | } | |
eb368012 S |
147 | |
148 | def _real_extract(self, url): | |
a6620ac2 | 149 | show_id = self._match_id(url) |
eb368012 S |
150 | data = self._download_json( |
151 | 'http://oe1.orf.at/programm/%s/konsole' % show_id, | |
152 | show_id | |
153 | ) | |
154 | ||
155 | timestamp = datetime.datetime.strptime('%s %s' % ( | |
156 | data['item']['day_label'], | |
157 | data['item']['time'] | |
158 | ), '%d.%m.%Y %H:%M') | |
159 | unix_timestamp = calendar.timegm(timestamp.utctimetuple()) | |
160 | ||
161 | return { | |
162 | 'id': show_id, | |
163 | 'title': data['item']['title'], | |
164 | 'url': data['item']['url_stream'], | |
165 | 'ext': 'mp3', | |
166 | 'description': data['item'].get('info'), | |
167 | 'timestamp': unix_timestamp | |
168 | } | |
169 | ||
170 | ||
171 | class ORFFM4IE(InfoExtractor): | |
b9f030cc | 172 | IE_NAME = 'orf:fm4' |
eb368012 | 173 | IE_DESC = 'radio FM4' |
5886b38d | 174 | _VALID_URL = r'https?://fm4\.orf\.at/(?:7tage/?#|player/)(?P<date>[0-9]+)/(?P<show>\w+)' |
eb368012 | 175 | |
98698606 S |
176 | _TEST = { |
177 | 'url': 'http://fm4.orf.at/player/20160110/IS/', | |
178 | 'md5': '01e736e8f1cef7e13246e880a59ad298', | |
179 | 'info_dict': { | |
180 | 'id': '2016-01-10_2100_tl_54_7DaysSun13_11244', | |
181 | 'ext': 'mp3', | |
182 | 'title': 'Im Sumpf', | |
183 | 'description': 'md5:384c543f866c4e422a55f66a62d669cd', | |
184 | 'duration': 7173, | |
185 | 'timestamp': 1452456073, | |
186 | 'upload_date': '20160110', | |
187 | }, | |
f5535ed0 | 188 | 'skip': 'Live streams on FM4 got deleted soon', |
98698606 S |
189 | } |
190 | ||
eb368012 S |
191 | def _real_extract(self, url): |
192 | mobj = re.match(self._VALID_URL, url) | |
193 | show_date = mobj.group('date') | |
194 | show_id = mobj.group('show') | |
195 | ||
196 | data = self._download_json( | |
197 | 'http://audioapi.orf.at/fm4/json/2.0/broadcasts/%s/4%s' % (show_date, show_id), | |
198 | show_id | |
199 | ) | |
200 | ||
201 | def extract_entry_dict(info, title, subtitle): | |
202 | return { | |
203 | 'id': info['loopStreamId'].replace('.mp3', ''), | |
204 | 'url': 'http://loopstream01.apa.at/?channel=fm4&id=%s' % info['loopStreamId'], | |
205 | 'title': title, | |
206 | 'description': subtitle, | |
207 | 'duration': (info['end'] - info['start']) / 1000, | |
208 | 'timestamp': info['start'] / 1000, | |
209 | 'ext': 'mp3' | |
210 | } | |
211 | ||
212 | entries = [extract_entry_dict(t, data['title'], data['subtitle']) for t in data['streams']] | |
213 | ||
214 | return { | |
215 | '_type': 'playlist', | |
216 | 'id': show_id, | |
217 | 'title': data['title'], | |
218 | 'description': data['subtitle'], | |
219 | 'entries': entries | |
5f6a1245 | 220 | } |
14137b57 S |
221 | |
222 | ||
223 | class ORFIPTVIE(InfoExtractor): | |
224 | IE_NAME = 'orf:iptv' | |
225 | IE_DESC = 'iptv.ORF.at' | |
5886b38d | 226 | _VALID_URL = r'https?://iptv\.orf\.at/(?:#/)?stories/(?P<id>\d+)' |
14137b57 S |
227 | |
228 | _TEST = { | |
529d26c3 S |
229 | 'url': 'http://iptv.orf.at/stories/2275236/', |
230 | 'md5': 'c8b22af4718a4b4af58342529453e3e5', | |
14137b57 | 231 | 'info_dict': { |
529d26c3 | 232 | 'id': '350612', |
14137b57 | 233 | 'ext': 'flv', |
529d26c3 S |
234 | 'title': 'Weitere Evakuierungen um Vulkan Calbuco', |
235 | 'description': 'md5:d689c959bdbcf04efeddedbf2299d633', | |
236 | 'duration': 68.197, | |
14137b57 | 237 | 'thumbnail': 're:^https?://.*\.jpg$', |
529d26c3 | 238 | 'upload_date': '20150425', |
14137b57 S |
239 | }, |
240 | } | |
241 | ||
242 | def _real_extract(self, url): | |
243 | story_id = self._match_id(url) | |
244 | ||
245 | webpage = self._download_webpage( | |
246 | 'http://iptv.orf.at/stories/%s' % story_id, story_id) | |
247 | ||
248 | video_id = self._search_regex( | |
249 | r'data-video(?:id)?="(\d+)"', webpage, 'video id') | |
250 | ||
251 | data = self._download_json( | |
252 | 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id, | |
253 | video_id)[0] | |
254 | ||
255 | duration = float_or_none(data['duration'], 1000) | |
256 | ||
257 | video = data['sources']['default'] | |
258 | load_balancer_url = video['loadBalancerUrl'] | |
259 | abr = int_or_none(video.get('audioBitrate')) | |
260 | vbr = int_or_none(video.get('bitrate')) | |
261 | fps = int_or_none(video.get('videoFps')) | |
262 | width = int_or_none(video.get('videoWidth')) | |
263 | height = int_or_none(video.get('videoHeight')) | |
264 | thumbnail = video.get('preview') | |
265 | ||
266 | rendition = self._download_json( | |
267 | load_balancer_url, video_id, transform_source=strip_jsonp) | |
268 | ||
269 | f = { | |
270 | 'abr': abr, | |
271 | 'vbr': vbr, | |
272 | 'fps': fps, | |
273 | 'width': width, | |
274 | 'height': height, | |
275 | } | |
276 | ||
277 | formats = [] | |
278 | for format_id, format_url in rendition['redirect'].items(): | |
279 | if format_id == 'rtmp': | |
280 | ff = f.copy() | |
281 | ff.update({ | |
282 | 'url': format_url, | |
283 | 'format_id': format_id, | |
284 | }) | |
285 | formats.append(ff) | |
286 | elif determine_ext(format_url) == 'f4m': | |
287 | formats.extend(self._extract_f4m_formats( | |
288 | format_url, video_id, f4m_id=format_id)) | |
289 | elif determine_ext(format_url) == 'm3u8': | |
290 | formats.extend(self._extract_m3u8_formats( | |
291 | format_url, video_id, 'mp4', m3u8_id=format_id)) | |
292 | else: | |
293 | continue | |
294 | self._sort_formats(formats) | |
295 | ||
296 | title = remove_end(self._og_search_title(webpage), ' - iptv.ORF.at') | |
297 | description = self._og_search_description(webpage) | |
298 | upload_date = unified_strdate(self._html_search_meta( | |
299 | 'dc.date', webpage, 'upload date')) | |
300 | ||
301 | return { | |
302 | 'id': video_id, | |
303 | 'title': title, | |
304 | 'description': description, | |
305 | 'duration': duration, | |
306 | 'thumbnail': thumbnail, | |
307 | 'upload_date': upload_date, | |
308 | 'formats': formats, | |
309 | } |