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.

54 lines
2.1 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. _TEST = {
  11. u'url': u'http://www.ardmediathek.de/das-erste/tagesschau-in-100-sek?documentId=14077640',
  12. u'file': u'14077640.mp4',
  13. u'md5': u'6ca8824255460c787376353f9e20bbd8',
  14. u'info_dict': {
  15. u"title": u"11.04.2013 09:23 Uhr - Tagesschau in 100 Sekunden"
  16. },
  17. u'skip': u'Requires rtmpdump'
  18. }
  19. def _real_extract(self, url):
  20. # determine video id from url
  21. m = re.match(self._VALID_URL, url)
  22. numid = re.search(r'documentId=([0-9]+)', url)
  23. if numid:
  24. video_id = numid.group(1)
  25. else:
  26. video_id = m.group('video_id')
  27. # determine title and media streams from webpage
  28. html = self._download_webpage(url, video_id)
  29. title = re.search(self._TITLE, html).group('title')
  30. streams = [mo.groupdict() for mo in re.finditer(self._MEDIA_STREAM, html)]
  31. if not streams:
  32. assert '"fsk"' in html
  33. raise ExtractorError(u'This video is only available after 8:00 pm')
  34. # choose default media type and highest quality for now
  35. stream = max([s for s in streams if int(s["media_type"]) == 0],
  36. key=lambda s: int(s["quality"]))
  37. # there's two possibilities: RTMP stream or HTTP download
  38. info = {'id': video_id, 'title': title, 'ext': 'mp4'}
  39. if stream['rtmp_url']:
  40. self.to_screen(u'RTMP download detected')
  41. assert stream['video_url'].startswith('mp4:')
  42. info["url"] = stream["rtmp_url"]
  43. info["play_path"] = stream['video_url']
  44. else:
  45. assert stream["video_url"].endswith('.mp4')
  46. info["url"] = stream["video_url"]
  47. return [info]