radiobremen.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import parse_duration
  6. class RadioBremenIE(InfoExtractor):
  7. _VALID_URL = r'http?://(?:www\.)?radiobremen\.de/mediathek/(?:index\.html)?\?id=(?P<id>[0-9]+)'
  8. IE_NAME = 'radiobremen'
  9. _TEST = {
  10. 'url': 'http://www.radiobremen.de/mediathek/index.html?id=114720',
  11. 'info_dict': {
  12. 'id': '114720',
  13. 'ext': 'mp4',
  14. 'duration': 1685,
  15. 'width': 512,
  16. 'title': 'buten un binnen vom 22. Dezember',
  17. 'description': 'Unter anderem mit diesen Themen: 45 Flüchtlinge sind in Worpswede angekommen +++ Freies Internet für alle: Bremer arbeiten an einem flächendeckenden W-Lan-Netzwerk +++ Aktivisten kämpfen für das Unibad +++ So war das Wetter 2014 +++',
  18. },
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. meta_url = "http://www.radiobremen.de/apps/php/mediathek/metadaten.php?id=%s" % video_id
  23. meta_doc = self._download_webpage(meta_url, video_id, 'Downloading metadata')
  24. title = self._html_search_regex("<h1.*>(?P<title>.+)</h1>", meta_doc, "title")
  25. description = self._html_search_regex("<p>(?P<description>.*)</p>", meta_doc, "description")
  26. duration = parse_duration(
  27. self._html_search_regex("L&auml;nge:</td>\s+<td>(?P<duration>[0-9]+:[0-9]+)</td>", meta_doc, "duration"))
  28. page_doc = self._download_webpage(url, video_id, 'Downloading video information')
  29. pattern = "ardformatplayerclassic\(\'playerbereich\',\'(?P<width>[0-9]+)\',\'.*\',\'(?P<video_id>[0-9]+)\',\'(?P<secret>[0-9]+)\',\'(?P<thumbnail>.+)\',\'\'\)"
  30. mobj = re.search(pattern, page_doc)
  31. video_url = (
  32. "http://dl-ondemand.radiobremen.de/mediabase/%s/%s_%s_%s.mp4" %
  33. (video_id, video_id, mobj.group("secret"), mobj.group('width')))
  34. formats = [{
  35. 'url': video_url,
  36. 'ext': 'mp4',
  37. 'width': int(mobj.group("width")),
  38. }]
  39. return {
  40. 'id': video_id,
  41. 'title': title,
  42. 'description': description,
  43. 'duration': duration,
  44. 'formats': formats,
  45. 'thumbnail': mobj.group('thumbnail'),
  46. }