You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.6 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. unescapeHTML,
  6. )
  7. class ZDFIE(InfoExtractor):
  8. _VALID_URL = r'^http://www\.zdf\.de\/ZDFmediathek\/(.*beitrag\/video\/)(?P<video_id>[^/\?]+)(?:\?.*)?'
  9. _TITLE = r'<h1(?: class="beitragHeadline")?>(?P<title>.*)</h1>'
  10. _MEDIA_STREAM = r'<a href="(?P<video_url>.+(?P<media_type>.streaming).+/zdf/(?P<quality>[^\/]+)/[^"]*)".+class="play".+>'
  11. _MMS_STREAM = r'href="(?P<video_url>mms://[^"]*)"'
  12. _RTSP_STREAM = r'(?P<video_url>rtsp://[^"]*.mp4)'
  13. def _real_extract(self, url):
  14. mobj = re.match(self._VALID_URL, url)
  15. if mobj is None:
  16. raise ExtractorError(u'Invalid URL: %s' % url)
  17. video_id = mobj.group('video_id')
  18. html = self._download_webpage(url, video_id)
  19. streams = [m.groupdict() for m in re.finditer(self._MEDIA_STREAM, html)]
  20. if streams is None:
  21. raise ExtractorError(u'No media url found.')
  22. # s['media_type'] == 'wstreaming' -> use 'Windows Media Player' and mms url
  23. # s['media_type'] == 'hstreaming' -> use 'Quicktime' and rtsp url
  24. # choose first/default media type and highest quality for now
  25. for s in streams: #find 300 - dsl1000mbit
  26. if s['quality'] == '300' and s['media_type'] == 'wstreaming':
  27. stream_=s
  28. break
  29. for s in streams: #find veryhigh - dsl2000mbit
  30. if s['quality'] == 'veryhigh' and s['media_type'] == 'wstreaming': # 'hstreaming' - rtsp is not working
  31. stream_=s
  32. break
  33. if stream_ is None:
  34. raise ExtractorError(u'No stream found.')
  35. media_link = self._download_webpage(stream_['video_url'], video_id,'Get stream URL')
  36. self.report_extraction(video_id)
  37. mobj = re.search(self._TITLE, html)
  38. if mobj is None:
  39. raise ExtractorError(u'Cannot extract title')
  40. title = unescapeHTML(mobj.group('title'))
  41. mobj = re.search(self._MMS_STREAM, media_link)
  42. if mobj is None:
  43. mobj = re.search(self._RTSP_STREAM, media_link)
  44. if mobj is None:
  45. raise ExtractorError(u'Cannot extract mms:// or rtsp:// URL')
  46. mms_url = mobj.group('video_url')
  47. mobj = re.search('(.*)[.](?P<ext>[^.]+)', mms_url)
  48. if mobj is None:
  49. raise ExtractorError(u'Cannot extract extention')
  50. ext = mobj.group('ext')
  51. return [{'id': video_id,
  52. 'url': mms_url,
  53. 'title': title,
  54. 'ext': ext
  55. }]