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
3.9 KiB

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