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 / Germany',
37 'url': 'http://tvthek.orf.at/topic/Im-Wandel-der-Zeit/8002126/Best-of-Ingrid-Thurnher/7982256',
39 'md5': '68f543909aea49d621dfc7703a11cfaf',
43 'title': 'Best of Ingrid Thurnher',
44 'upload_date': '20140527',
45 '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".',
48 '_skip': 'Blocked outside of Austria / Germany',
51 def _real_extract(self, url):
52 playlist_id = self._match_id(url)
53 webpage = self._download_webpage(url, playlist_id)
55 data_json = self._search_regex(
56 r'initializeAdworx\((.+?)\);\n', webpage, 'video info')
57 all_data = json.loads(data_json)
59 def get_segments(all_data):
62 'Tracker::EPISODE_DETAIL_PAGE_OVER_PROGRAM',
63 'Tracker::EPISODE_DETAIL_PAGE_OVER_TOPIC'):
64 return data['values']['segments']
66 sdata = get_segments(all_data)
68 raise ExtractorError('Unable to extract segments')
70 def quality_to_int(s):
71 m = re.search('([0-9]+)', s)
74 return int(m.group(1))
80 'preference': -10 if fd['delivery'] == 'hls' else None,
81 'format_id': '%s-%s-%s' % (
82 fd['delivery'], fd['quality'], fd['quality_string']),
84 'protocol': fd['protocol'],
85 'quality': quality_to_int(fd['quality']),
86 } for fd in sd['playlist_item_array']['sources']]
88 # Check for geoblocking.
89 # There is a property is_geoprotection, but that's always false
90 geo_str = sd.get('geoprotection_string')
96 if re.match(r'^https?://.*\.mp4$', f['url']))
100 req = HEADRequest(http_url)
101 self._request_webpage(
103 note='Testing for geoblocking',
105 'This video seems to be blocked outside of %s. '
106 'You may want to try the streaming-* formats.')
110 self._sort_formats(formats)
112 upload_date = unified_strdate(sd['created_date'])
116 'title': sd['header'],
118 'description': sd.get('description'),
119 'duration': int(sd['duration_in_seconds']),
120 'upload_date': upload_date,
121 'thumbnail': sd.get('image_full_url'),
131 # Audios on ORF radio are only available for 7 days, so we can't add tests.
134 class ORFOE1IE(InfoExtractor):
136 IE_DESC = 'Radio Österreich 1'
137 _VALID_URL = r'http://oe1\.orf\.at/programm/(?P<id>[0-9]+)'
139 def _real_extract(self, url):
140 show_id = self._match_id(url)
141 data = self._download_json(
142 'http://oe1.orf.at/programm/%s/konsole' % show_id,
146 timestamp = datetime.datetime.strptime('%s %s' % (
147 data['item']['day_label'],
150 unix_timestamp = calendar.timegm(timestamp.utctimetuple())
154 'title': data['item']['title'],
155 'url': data['item']['url_stream'],
157 'description': data['item'].get('info'),
158 'timestamp': unix_timestamp
162 class ORFFM4IE(InfoExtractor):
164 IE_DESC = 'radio FM4'
165 _VALID_URL = r'http://fm4\.orf\.at/7tage/?#(?P<date>[0-9]+)/(?P<show>\w+)'
167 def _real_extract(self, url):
168 mobj = re.match(self._VALID_URL, url)
169 show_date = mobj.group('date')
170 show_id = mobj.group('show')
172 data = self._download_json(
173 'http://audioapi.orf.at/fm4/json/2.0/broadcasts/%s/4%s' % (show_date, show_id),
177 def extract_entry_dict(info, title, subtitle):
179 'id': info['loopStreamId'].replace('.mp3', ''),
180 'url': 'http://loopstream01.apa.at/?channel=fm4&id=%s' % info['loopStreamId'],
182 'description': subtitle,
183 'duration': (info['end'] - info['start']) / 1000,
184 'timestamp': info['start'] / 1000,
188 entries = [extract_entry_dict(t, data['title'], data['subtitle']) for t in data['streams']]
193 'title': data['title'],
194 'description': data['subtitle'],