fm4.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import calendar
  4. import datetime
  5. import re
  6. from .common import InfoExtractor
  7. # audios on fm4.orf.at are only available for 7 days, so we can't
  8. # add tests.
  9. class FM4IE(InfoExtractor):
  10. IE_DESC = 'fm4.orf.at'
  11. _VALID_URL = r'http://fm4\.orf\.at/7tage#(?P<date>[0-9]+)/(?P<show>[\w]+)'
  12. def _extract_entry_dict(self, info, title, subtitle):
  13. result = {
  14. 'id': info['loopStreamId'].replace('.mp3', ''),
  15. 'url': 'http://loopstream01.apa.at/?channel=fm4&id=%s' % info['loopStreamId'],
  16. 'title': title,
  17. 'description': subtitle,
  18. 'duration': (info['end'] - info['start']) / 1000,
  19. 'timestamp': info['start'] / 1000,
  20. 'ext': 'mp3'
  21. }
  22. return result
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. show_date = mobj.group('date')
  26. show_id = mobj.group('show')
  27. data = self._download_json(
  28. 'http://audioapi.orf.at/fm4/json/2.0/broadcasts/%s/4%s' % (show_date, show_id),
  29. show_id
  30. )
  31. entries = [ self._extract_entry_dict(t, data['title'], data['subtitle']) for t in data['streams']]
  32. return {
  33. '_type': 'playlist',
  34. 'id': show_id,
  35. 'title': data['title'],
  36. 'description': data['subtitle'],
  37. 'entries': entries
  38. }