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.

125 lines
4.6 KiB

  1. # coding: utf-8
  2. import operator
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. unified_strdate,
  7. )
  8. class ZDFIE(InfoExtractor):
  9. _VALID_URL = r'^https?://www\.zdf\.de/ZDFmediathek(?P<hash>#)?/(.*beitrag/(?:video/)?)(?P<video_id>[0-9]+)(?:/[^/?]+)?(?:\?.*)?'
  10. _TEST = {
  11. u"url": u"http://www.zdf.de/ZDFmediathek/beitrag/video/2037704/ZDFspezial---Ende-des-Machtpokers--?bc=sts;stt",
  12. u"file": u"2037704.webm",
  13. u"info_dict": {
  14. u"upload_date": u"20131127",
  15. u"description": u"Union und SPD haben sich auf einen Koalitionsvertrag geeinigt. Aber was bedeutet das für die Bürger? Sehen Sie hierzu das ZDFspezial \"Ende des Machtpokers - Große Koalition für Deutschland\".",
  16. u"uploader": u"spezial",
  17. u"title": u"ZDFspezial - Ende des Machtpokers"
  18. },
  19. u"skip": u"Videos on ZDF.de are depublicised in short order",
  20. }
  21. def _real_extract(self, url):
  22. mobj = re.match(self._VALID_URL, url)
  23. video_id = mobj.group('video_id')
  24. xml_url = u'http://www.zdf.de/ZDFmediathek/xmlservice/web/beitragsDetails?ak=web&id=%s' % video_id
  25. doc = self._download_xml(
  26. xml_url, video_id,
  27. note=u'Downloading video info',
  28. errnote=u'Failed to download video info')
  29. title = doc.find('.//information/title').text
  30. description = doc.find('.//information/detail').text
  31. uploader_node = doc.find('.//details/originChannelTitle')
  32. uploader = None if uploader_node is None else uploader_node.text
  33. duration_str = doc.find('.//details/length').text
  34. duration_m = re.match(r'''(?x)^
  35. (?P<hours>[0-9]{2})
  36. :(?P<minutes>[0-9]{2})
  37. :(?P<seconds>[0-9]{2})
  38. (?:\.(?P<ms>[0-9]+)?)
  39. ''', duration_str)
  40. duration = (
  41. (
  42. (int(duration_m.group('hours')) * 60 * 60) +
  43. (int(duration_m.group('minutes')) * 60) +
  44. int(duration_m.group('seconds'))
  45. )
  46. if duration_m
  47. else None
  48. )
  49. upload_date = unified_strdate(doc.find('.//details/airtime').text)
  50. def xml_to_format(fnode):
  51. video_url = fnode.find('url').text
  52. is_available = u'http://www.metafilegenerator' not in video_url
  53. format_id = fnode.attrib['basetype']
  54. format_m = re.match(r'''(?x)
  55. (?P<vcodec>[^_]+)_(?P<acodec>[^_]+)_(?P<container>[^_]+)_
  56. (?P<proto>[^_]+)_(?P<index>[^_]+)_(?P<indexproto>[^_]+)
  57. ''', format_id)
  58. ext = format_m.group('container')
  59. is_supported = ext != 'f4f'
  60. PROTO_ORDER = ['http', 'rtmp', 'rtsp']
  61. try:
  62. proto_pref = -PROTO_ORDER.index(format_m.group('proto'))
  63. except ValueError:
  64. proto_pref = -999
  65. quality = fnode.find('./quality').text
  66. QUALITY_ORDER = ['veryhigh', '300', 'high', 'med', 'low']
  67. try:
  68. quality_pref = -QUALITY_ORDER.index(quality)
  69. except ValueError:
  70. quality_pref = -999
  71. abr = int(fnode.find('./audioBitrate').text) // 1000
  72. vbr = int(fnode.find('./videoBitrate').text) // 1000
  73. pref = (is_available, is_supported,
  74. proto_pref, quality_pref, vbr, abr)
  75. format_note = u''
  76. if not is_supported:
  77. format_note += u'(unsupported)'
  78. if not format_note:
  79. format_note = None
  80. return {
  81. 'format_id': format_id + u'-' + quality,
  82. 'url': video_url,
  83. 'ext': ext,
  84. 'acodec': format_m.group('acodec'),
  85. 'vcodec': format_m.group('vcodec'),
  86. 'abr': abr,
  87. 'vbr': vbr,
  88. 'width': int(fnode.find('./width').text),
  89. 'height': int(fnode.find('./height').text),
  90. 'filesize': int(fnode.find('./filesize').text),
  91. 'format_note': format_note,
  92. '_pref': pref,
  93. '_available': is_available,
  94. }
  95. format_nodes = doc.findall('.//formitaeten/formitaet')
  96. formats = sorted(filter(lambda f: f['_available'],
  97. map(xml_to_format, format_nodes)),
  98. key=operator.itemgetter('_pref'))
  99. return {
  100. 'id': video_id,
  101. 'title': title,
  102. 'formats': formats,
  103. 'description': description,
  104. 'uploader': uploader,
  105. 'duration': duration,
  106. 'upload_date': upload_date,
  107. }