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.

78 lines
2.7 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
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. _TESTS = [{
  9. u'url': u'http://www.mdr.de/mediathek/themen/nachrichten/video165624_zc-c5c7de76_zs-3795826d.html',
  10. u'file': u'165624.mp4',
  11. u'md5': u'ae785f36ecbf2f19b42edf1bc9c85815',
  12. u'info_dict': {
  13. u"title": u"MDR aktuell Eins30 09.12.2013, 22:48 Uhr"
  14. },
  15. },
  16. {
  17. u'url': u'http://www.mdr.de/mediathek/radio/mdr1-radio-sachsen/audio718370_zc-67b21197_zs-1b9b2483.html',
  18. u'file': u'718370.mp3',
  19. u'md5': u'a9d21345a234c7b45dee612f290fd8d7',
  20. u'info_dict': {
  21. u"title": u"MDR 1 RADIO SACHSEN 10.12.2013, 05:00 Uhr"
  22. },
  23. }]
  24. def _real_extract(self, url):
  25. m = re.match(self._VALID_URL, url)
  26. video_id = m.group('video_id')
  27. domain = m.group('domain')
  28. # determine title and media streams from webpage
  29. html = self._download_webpage(url, video_id)
  30. title = self._html_search_regex(r'<h2>(.*?)</h2>', html, u'title')
  31. xmlurl = self._search_regex(
  32. r'(/mediathek/(?:.+)/(?:video|audio)[0-9]+-avCustom.xml)', html, u'XML URL')
  33. doc = self._download_xml(domain + xmlurl, video_id)
  34. formats = []
  35. for a in doc.findall('./assets/asset'):
  36. url_el = a.find('.//progressiveDownloadUrl')
  37. if url_el is None:
  38. continue
  39. abr = int(a.find('bitrateAudio').text) // 1000
  40. media_type = a.find('mediaType').text
  41. format = {
  42. 'abr': abr,
  43. 'filesize': int(a.find('fileSize').text),
  44. 'url': url_el.text,
  45. }
  46. vbr_el = a.find('bitrateVideo')
  47. if vbr_el is None:
  48. format.update({
  49. 'vcodec': 'none',
  50. 'format_id': u'%s-%d' % (media_type, abr),
  51. })
  52. else:
  53. vbr = int(vbr_el.text) // 1000
  54. format.update({
  55. 'vbr': vbr,
  56. 'width': int(a.find('frameWidth').text),
  57. 'height': int(a.find('frameHeight').text),
  58. 'format_id': u'%s-%d' % (media_type, vbr),
  59. })
  60. formats.append(format)
  61. formats.sort(key=lambda f: (f.get('vbr'), f['abr']))
  62. if not formats:
  63. raise ExtractorError(u'Could not find any valid formats')
  64. return {
  65. 'id': video_id,
  66. 'title': title,
  67. 'formats': formats,
  68. }