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.

111 lines
4.0 KiB

  1. # coding: utf-8
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  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. proto = format_m.group('proto').lower()
  60. quality = fnode.find('./quality').text
  61. abr = int(fnode.find('./audioBitrate').text) // 1000
  62. vbr = int(fnode.find('./videoBitrate').text) // 1000
  63. format_note = u''
  64. if not format_note:
  65. format_note = None
  66. return {
  67. 'format_id': format_id + u'-' + quality,
  68. 'url': video_url,
  69. 'ext': ext,
  70. 'acodec': format_m.group('acodec'),
  71. 'vcodec': format_m.group('vcodec'),
  72. 'abr': abr,
  73. 'vbr': vbr,
  74. 'width': int_or_none(fnode.find('./width').text),
  75. 'height': int_or_none(fnode.find('./height').text),
  76. 'filesize': int_or_none(fnode.find('./filesize').text),
  77. 'format_note': format_note,
  78. 'protocol': proto,
  79. '_available': is_available,
  80. }
  81. format_nodes = doc.findall('.//formitaeten/formitaet')
  82. formats = list(filter(
  83. lambda f: f['_available'],
  84. map(xml_to_format, format_nodes)))
  85. self._sort_formats(formats)
  86. return {
  87. 'id': video_id,
  88. 'title': title,
  89. 'formats': formats,
  90. 'description': description,
  91. 'uploader': uploader,
  92. 'duration': duration,
  93. 'upload_date': upload_date,
  94. }