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.

108 lines
4.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. unified_strdate,
  8. )
  9. class ZDFIE(InfoExtractor):
  10. _VALID_URL = r'^https?://www\.zdf\.de/ZDFmediathek(?P<hash>#)?/(.*beitrag/(?:video/)?)(?P<video_id>[0-9]+)(?:/[^/?]+)?(?:\?.*)?'
  11. _TEST = {
  12. 'url': 'http://www.zdf.de/ZDFmediathek/beitrag/video/2037704/ZDFspezial---Ende-des-Machtpokers--?bc=sts;stt',
  13. 'info_dict': {
  14. 'id': '2037704',
  15. 'ext': 'webm',
  16. 'title': 'ZDFspezial - Ende des Machtpokers',
  17. 'description': '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".',
  18. 'duration': 1022,
  19. 'uploader': 'spezial',
  20. 'uploader_id': '225948',
  21. 'upload_date': '20131127',
  22. },
  23. 'skip': 'Videos on ZDF.de are depublicised in short order',
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('video_id')
  28. xml_url = 'http://www.zdf.de/ZDFmediathek/xmlservice/web/beitragsDetails?ak=web&id=%s' % video_id
  29. doc = self._download_xml(
  30. xml_url, video_id,
  31. note='Downloading video info',
  32. errnote='Failed to download video info')
  33. title = doc.find('.//information/title').text
  34. description = doc.find('.//information/detail').text
  35. duration = int(doc.find('.//details/lengthSec').text)
  36. uploader_node = doc.find('.//details/originChannelTitle')
  37. uploader = None if uploader_node is None else uploader_node.text
  38. uploader_id_node = doc.find('.//details/originChannelId')
  39. uploader_id = None if uploader_id_node is None else uploader_id_node.text
  40. upload_date = unified_strdate(doc.find('.//details/airtime').text)
  41. def xml_to_format(fnode):
  42. video_url = fnode.find('url').text
  43. is_available = 'http://www.metafilegenerator' not in video_url
  44. format_id = fnode.attrib['basetype']
  45. format_m = re.match(r'''(?x)
  46. (?P<vcodec>[^_]+)_(?P<acodec>[^_]+)_(?P<container>[^_]+)_
  47. (?P<proto>[^_]+)_(?P<index>[^_]+)_(?P<indexproto>[^_]+)
  48. ''', format_id)
  49. ext = format_m.group('container')
  50. proto = format_m.group('proto').lower()
  51. quality = fnode.find('./quality').text
  52. abr = int(fnode.find('./audioBitrate').text) // 1000
  53. vbr_node = fnode.find('./videoBitrate')
  54. vbr = None if vbr_node is None else int(vbr_node.text) // 1000
  55. width_node = fnode.find('./width')
  56. width = None if width_node is None else int_or_none(width_node.text)
  57. height_node = fnode.find('./height')
  58. height = None if height_node is None else int_or_none(height_node.text)
  59. format_note = ''
  60. if not format_note:
  61. format_note = None
  62. return {
  63. 'format_id': format_id + '-' + quality,
  64. 'url': video_url,
  65. 'ext': ext,
  66. 'acodec': format_m.group('acodec'),
  67. 'vcodec': format_m.group('vcodec'),
  68. 'abr': abr,
  69. 'vbr': vbr,
  70. 'width': width,
  71. 'height': height,
  72. 'filesize': int_or_none(fnode.find('./filesize').text),
  73. 'format_note': format_note,
  74. 'protocol': proto,
  75. '_available': is_available,
  76. }
  77. format_nodes = doc.findall('.//formitaeten/formitaet')
  78. formats = list(filter(
  79. lambda f: f['_available'],
  80. map(xml_to_format, format_nodes)))
  81. self._sort_formats(formats)
  82. return {
  83. 'id': video_id,
  84. 'title': title,
  85. 'description': description,
  86. 'duration': duration,
  87. 'uploader': uploader,
  88. 'uploader_id': uploader_id,
  89. 'upload_date': upload_date,
  90. 'formats': formats,
  91. }