oe1.py 1.0 KB

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