[oe1] Add support for oe1.orf.at.
[youtube-dl] / youtube_dl / extractor / oe1.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3 import calendar
4 import datetime
5 import json
6 import re
7
8 from .common import InfoExtractor
9
10 # audios on oe1.orf.at are only available for 7 days, so we can't
11 # add tests.
12
13
14 class OE1IE(InfoExtractor):
15     _VALID_URL = r'http://oe1\.orf\.at/programm/(?P<id>\d+)'
16
17     def _real_extract(self, url):
18         mobj = re.match(self._VALID_URL, url)
19         show_id = mobj.group('id')
20         data = json.loads(self._download_webpage(
21             'http://oe1.orf.at/programm/%s/konsole' % show_id,
22             show_id
23         ))
24
25         timestamp = datetime.datetime.strptime('%s %s' % (
26             data['item']['day_label'],
27             data['item']['time']
28         ), '%d.%m.%Y %H:%M')
29         unix_timestamp = calendar.timegm(timestamp.utctimetuple())
30
31         return {
32             'id': show_id,
33             'title': data['item']['title'],
34             'url': data['item']['url_stream'],
35             'ext': 'mp3',
36             'description': data['item']['info'],
37             'timestamp': unix_timestamp
38         }