2 from __future__ import unicode_literals
9 from .common import InfoExtractor
17 class ORFTVthekIE(InfoExtractor):
18 IE_NAME = 'orf:tvthek'
19 IE_DESC = 'ORF TVthek'
20 _VALID_URL = r'https?://tvthek\.orf\.at/(?:programs/.+?/episodes|topics/.+?|program/[^/]+)/(?P<id>\d+)'
23 'url': 'http://tvthek.orf.at/program/Aufgetischt/2745173/Aufgetischt-Mit-der-Steirischen-Tafelrunde/8891389',
25 'md5': '2942210346ed779588f428a92db88712',
29 'title': 'Aufgetischt: Mit der Steirischen Tafelrunde',
30 'description': 'md5:c1272f0245537812d4e36419c207b67d',
32 'upload_date': '20141208',
35 'skip': 'Blocked outside of Austria',
38 def _real_extract(self, url):
39 playlist_id = self._match_id(url)
40 webpage = self._download_webpage(url, playlist_id)
42 data_json = self._search_regex(
43 r'initializeAdworx\((.+?)\);\n', webpage, 'video info')
44 all_data = json.loads(data_json)
46 def get_segments(all_data):
48 if data['name'] == 'Tracker::EPISODE_DETAIL_PAGE_OVER_PROGRAM':
49 return data['values']['segments']
51 sdata = get_segments(all_data)
53 raise ExtractorError('Unable to extract segments')
55 def quality_to_int(s):
56 m = re.search('([0-9]+)', s)
59 return int(m.group(1))
65 'preference': -10 if fd['delivery'] == 'hls' else None,
66 'format_id': '%s-%s-%s' % (
67 fd['delivery'], fd['quality'], fd['quality_string']),
69 'protocol': fd['protocol'],
70 'quality': quality_to_int(fd['quality']),
71 } for fd in sd['playlist_item_array']['sources']]
73 # Check for geoblocking.
74 # There is a property is_geoprotection, but that's always false
75 geo_str = sd.get('geoprotection_string')
81 if re.match(r'^https?://.*\.mp4$', f['url']))
85 req = HEADRequest(http_url)
86 self._request_webpage(
88 note='Testing for geoblocking',
90 'This video seems to be blocked outside of %s. '
91 'You may want to try the streaming-* formats.')
95 self._sort_formats(formats)
97 upload_date = unified_strdate(sd['created_date'])
101 'title': sd['header'],
103 'description': sd.get('description'),
104 'duration': int(sd['duration_in_seconds']),
105 'upload_date': upload_date,
106 'thumbnail': sd.get('image_full_url'),
116 # Audios on ORF radio are only available for 7 days, so we can't add tests.
119 class ORFOE1IE(InfoExtractor):
121 IE_DESC = 'Radio Österreich 1'
122 _VALID_URL = r'http://oe1\.orf\.at/programm/(?P<id>[0-9]+)'
124 def _real_extract(self, url):
125 show_id = self._match_id(url)
126 data = self._download_json(
127 'http://oe1.orf.at/programm/%s/konsole' % show_id,
131 timestamp = datetime.datetime.strptime('%s %s' % (
132 data['item']['day_label'],
135 unix_timestamp = calendar.timegm(timestamp.utctimetuple())
139 'title': data['item']['title'],
140 'url': data['item']['url_stream'],
142 'description': data['item'].get('info'),
143 'timestamp': unix_timestamp
147 class ORFFM4IE(InfoExtractor):
149 IE_DESC = 'radio FM4'
150 _VALID_URL = r'http://fm4\.orf\.at/7tage/?#(?P<date>[0-9]+)/(?P<show>\w+)'
152 def _real_extract(self, url):
153 mobj = re.match(self._VALID_URL, url)
154 show_date = mobj.group('date')
155 show_id = mobj.group('show')
157 data = self._download_json(
158 'http://audioapi.orf.at/fm4/json/2.0/broadcasts/%s/4%s' % (show_date, show_id),
162 def extract_entry_dict(info, title, subtitle):
164 'id': info['loopStreamId'].replace('.mp3', ''),
165 'url': 'http://loopstream01.apa.at/?channel=fm4&id=%s' % info['loopStreamId'],
167 'description': subtitle,
168 'duration': (info['end'] - info['start']) / 1000,
169 'timestamp': info['start'] / 1000,
173 entries = [extract_entry_dict(t, data['title'], data['subtitle']) for t in data['streams']]
178 'title': data['title'],
179 'description': data['subtitle'],