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.

64 lines
2.1 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. )
  6. class MDRIE(InfoExtractor):
  7. _VALID_URL = r'^(?P<domain>(?:https?://)?(?:www\.)?mdr\.de)/mediathek/(?:.*)/(?P<type>video|audio)(?P<video_id>[^/_]+)_.*'
  8. # No tests, MDR regularily deletes its videos
  9. def _real_extract(self, url):
  10. m = re.match(self._VALID_URL, url)
  11. video_id = m.group('video_id')
  12. domain = m.group('domain')
  13. # determine title and media streams from webpage
  14. html = self._download_webpage(url, video_id)
  15. title = self._html_search_regex(r'<h2>(.*?)</h2>', html, u'title')
  16. xmlurl = self._search_regex(
  17. r'(/mediathek/(?:.+)/(?:video|audio)[0-9]+-avCustom.xml)', html, u'XML URL')
  18. doc = self._download_xml(domain + xmlurl, video_id)
  19. formats = []
  20. for a in doc.findall('./assets/asset'):
  21. url_el = a.find('.//progressiveDownloadUrl')
  22. if url_el is None:
  23. continue
  24. abr = int(a.find('bitrateAudio').text) // 1000
  25. media_type = a.find('mediaType').text
  26. format = {
  27. 'abr': abr,
  28. 'filesize': int(a.find('fileSize').text),
  29. 'url': url_el.text,
  30. }
  31. vbr_el = a.find('bitrateVideo')
  32. if vbr_el is None:
  33. format.update({
  34. 'vcodec': 'none',
  35. 'format_id': u'%s-%d' % (media_type, abr),
  36. })
  37. else:
  38. vbr = int(vbr_el.text) // 1000
  39. format.update({
  40. 'vbr': vbr,
  41. 'width': int(a.find('frameWidth').text),
  42. 'height': int(a.find('frameHeight').text),
  43. 'format_id': u'%s-%d' % (media_type, vbr),
  44. })
  45. formats.append(format)
  46. if not formats:
  47. raise ExtractorError(u'Could not find any valid formats')
  48. self._sort_formats(formats)
  49. return {
  50. 'id': video_id,
  51. 'title': title,
  52. 'formats': formats,
  53. }