zdf.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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<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. video_id = self._match_id(url)
  27. xml_url = 'http://www.zdf.de/ZDFmediathek/xmlservice/web/beitragsDetails?ak=web&id=%s' % video_id
  28. doc = self._download_xml(
  29. xml_url, video_id,
  30. note='Downloading video info',
  31. errnote='Failed to download video info')
  32. title = doc.find('.//information/title').text
  33. description = doc.find('.//information/detail').text
  34. duration = int(doc.find('.//details/lengthSec').text)
  35. uploader_node = doc.find('.//details/originChannelTitle')
  36. uploader = None if uploader_node is None else uploader_node.text
  37. uploader_id_node = doc.find('.//details/originChannelId')
  38. uploader_id = None if uploader_id_node is None else uploader_id_node.text
  39. upload_date = unified_strdate(doc.find('.//details/airtime').text)
  40. def xml_to_format(fnode):
  41. video_url = fnode.find('url').text
  42. is_available = 'http://www.metafilegenerator' not in video_url
  43. format_id = fnode.attrib['basetype']
  44. format_m = re.match(r'''(?x)
  45. (?P<vcodec>[^_]+)_(?P<acodec>[^_]+)_(?P<container>[^_]+)_
  46. (?P<proto>[^_]+)_(?P<index>[^_]+)_(?P<indexproto>[^_]+)
  47. ''', format_id)
  48. ext = format_m.group('container')
  49. proto = format_m.group('proto').lower()
  50. quality = fnode.find('./quality').text
  51. abr = int(fnode.find('./audioBitrate').text) // 1000
  52. vbr_node = fnode.find('./videoBitrate')
  53. vbr = None if vbr_node is None else int(vbr_node.text) // 1000
  54. width_node = fnode.find('./width')
  55. width = None if width_node is None else int_or_none(width_node.text)
  56. height_node = fnode.find('./height')
  57. height = None if height_node is None else int_or_none(height_node.text)
  58. format_note = ''
  59. if not format_note:
  60. format_note = None
  61. return {
  62. 'format_id': format_id + '-' + quality,
  63. 'url': video_url,
  64. 'ext': ext,
  65. 'acodec': format_m.group('acodec'),
  66. 'vcodec': format_m.group('vcodec'),
  67. 'abr': abr,
  68. 'vbr': vbr,
  69. 'width': width,
  70. 'height': height,
  71. 'filesize': int_or_none(fnode.find('./filesize').text),
  72. 'format_note': format_note,
  73. 'protocol': proto,
  74. '_available': is_available,
  75. }
  76. format_nodes = doc.findall('.//formitaeten/formitaet')
  77. formats = list(filter(
  78. lambda f: f['_available'],
  79. map(xml_to_format, format_nodes)))
  80. self._sort_formats(formats)
  81. return {
  82. 'id': video_id,
  83. 'title': title,
  84. 'description': description,
  85. 'duration': duration,
  86. 'uploader': uploader,
  87. 'uploader_id': uploader_id,
  88. 'upload_date': upload_date,
  89. 'formats': formats,
  90. }