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.

45 lines
1.8 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. )
  6. class ARDIE(InfoExtractor):
  7. _VALID_URL = r'^(?:https?://)?(?:(?:www\.)?ardmediathek\.de|mediathek\.daserste\.de)/(?:.*/)(?P<video_id>[^/\?]+)(?:\?.*)?'
  8. _TITLE = r'<h1(?: class="boxTopHeadline")?>(?P<title>.*)</h1>'
  9. _MEDIA_STREAM = r'mediaCollection\.addMediaStream\((?P<media_type>\d+), (?P<quality>\d+), "(?P<rtmp_url>[^"]*)", "(?P<video_url>[^"]*)", "[^"]*"\)'
  10. def _real_extract(self, url):
  11. # determine video id from url
  12. m = re.match(self._VALID_URL, url)
  13. numid = re.search(r'documentId=([0-9]+)', url)
  14. if numid:
  15. video_id = numid.group(1)
  16. else:
  17. video_id = m.group('video_id')
  18. # determine title and media streams from webpage
  19. html = self._download_webpage(url, video_id)
  20. title = re.search(self._TITLE, html).group('title')
  21. streams = [m.groupdict() for m in re.finditer(self._MEDIA_STREAM, html)]
  22. if not streams:
  23. assert '"fsk"' in html
  24. raise ExtractorError(u'This video is only available after 8:00 pm')
  25. # choose default media type and highest quality for now
  26. stream = max([s for s in streams if int(s["media_type"]) == 0],
  27. key=lambda s: int(s["quality"]))
  28. # there's two possibilities: RTMP stream or HTTP download
  29. info = {'id': video_id, 'title': title, 'ext': 'mp4'}
  30. if stream['rtmp_url']:
  31. self.to_screen(u'RTMP download detected')
  32. assert stream['video_url'].startswith('mp4:')
  33. info["url"] = stream["rtmp_url"]
  34. info["play_path"] = stream['video_url']
  35. else:
  36. assert stream["video_url"].endswith('.mp4')
  37. info["url"] = stream["video_url"]
  38. return [info]