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