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.

75 lines
2.5 KiB

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