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.

159 lines
5.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import functools
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. int_or_none,
  8. unified_strdate,
  9. OnDemandPagedList,
  10. )
  11. def extract_from_xml_url(ie, video_id, xml_url):
  12. doc = ie._download_xml(
  13. xml_url, video_id,
  14. note='Downloading video info',
  15. errnote='Failed to download video info')
  16. title = doc.find('.//information/title').text
  17. description = doc.find('.//information/detail').text
  18. duration = int(doc.find('.//details/lengthSec').text)
  19. uploader_node = doc.find('.//details/originChannelTitle')
  20. uploader = None if uploader_node is None else uploader_node.text
  21. uploader_id_node = doc.find('.//details/originChannelId')
  22. uploader_id = None if uploader_id_node is None else uploader_id_node.text
  23. upload_date = unified_strdate(doc.find('.//details/airtime').text)
  24. def xml_to_format(fnode):
  25. video_url = fnode.find('url').text
  26. is_available = 'http://www.metafilegenerator' not in video_url
  27. format_id = fnode.attrib['basetype']
  28. format_m = re.match(r'''(?x)
  29. (?P<vcodec>[^_]+)_(?P<acodec>[^_]+)_(?P<container>[^_]+)_
  30. (?P<proto>[^_]+)_(?P<index>[^_]+)_(?P<indexproto>[^_]+)
  31. ''', format_id)
  32. ext = format_m.group('container')
  33. proto = format_m.group('proto').lower()
  34. quality = fnode.find('./quality').text
  35. abr = int(fnode.find('./audioBitrate').text) // 1000
  36. vbr_node = fnode.find('./videoBitrate')
  37. vbr = None if vbr_node is None else int(vbr_node.text) // 1000
  38. width_node = fnode.find('./width')
  39. width = None if width_node is None else int_or_none(width_node.text)
  40. height_node = fnode.find('./height')
  41. height = None if height_node is None else int_or_none(height_node.text)
  42. format_note = ''
  43. if not format_note:
  44. format_note = None
  45. return {
  46. 'format_id': format_id + '-' + quality,
  47. 'url': video_url,
  48. 'ext': ext,
  49. 'acodec': format_m.group('acodec'),
  50. 'vcodec': format_m.group('vcodec'),
  51. 'abr': abr,
  52. 'vbr': vbr,
  53. 'width': width,
  54. 'height': height,
  55. 'filesize': int_or_none(fnode.find('./filesize').text),
  56. 'format_note': format_note,
  57. 'protocol': proto,
  58. '_available': is_available,
  59. }
  60. format_nodes = doc.findall('.//formitaeten/formitaet')
  61. formats = list(filter(
  62. lambda f: f['_available'],
  63. map(xml_to_format, format_nodes)))
  64. ie._sort_formats(formats)
  65. return {
  66. 'id': video_id,
  67. 'title': title,
  68. 'description': description,
  69. 'duration': duration,
  70. 'uploader': uploader,
  71. 'uploader_id': uploader_id,
  72. 'upload_date': upload_date,
  73. 'formats': formats,
  74. }
  75. class ZDFIE(InfoExtractor):
  76. _VALID_URL = r'(?:zdf:|zdf:video:|https?://www\.zdf\.de/ZDFmediathek(?:#)?/(.*beitrag/(?:video/)?))(?P<id>[0-9]+)(?:/[^/?]+)?(?:\?.*)?'
  77. _TEST = {
  78. 'url': 'http://www.zdf.de/ZDFmediathek/beitrag/video/2037704/ZDFspezial---Ende-des-Machtpokers--?bc=sts;stt',
  79. 'info_dict': {
  80. 'id': '2037704',
  81. 'ext': 'webm',
  82. 'title': 'ZDFspezial - Ende des Machtpokers',
  83. '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".',
  84. 'duration': 1022,
  85. 'uploader': 'spezial',
  86. 'uploader_id': '225948',
  87. 'upload_date': '20131127',
  88. },
  89. 'skip': 'Videos on ZDF.de are depublicised in short order',
  90. }
  91. def _real_extract(self, url):
  92. video_id = self._match_id(url)
  93. xml_url = 'http://www.zdf.de/ZDFmediathek/xmlservice/web/beitragsDetails?ak=web&id=%s' % video_id
  94. return extract_from_xml_url(self, video_id, xml_url)
  95. class ZDFChannelIE(InfoExtractor):
  96. _VALID_URL = r'(?:zdf:topic:|https?://www\.zdf\.de/ZDFmediathek(?:#)?/.*kanaluebersicht/)(?P<id>[0-9]+)'
  97. _TEST = {
  98. 'url': 'http://www.zdf.de/ZDFmediathek#/kanaluebersicht/1586442/sendung/Titanic',
  99. 'info_dict': {
  100. 'id': '1586442',
  101. },
  102. 'playlist_count': 3,
  103. }
  104. _PAGE_SIZE = 50
  105. def _fetch_page(self, channel_id, page):
  106. offset = page * self._PAGE_SIZE
  107. xml_url = (
  108. 'http://www.zdf.de/ZDFmediathek/xmlservice/web/aktuellste?ak=web&offset=%d&maxLength=%d&id=%s'
  109. % (offset, self._PAGE_SIZE, channel_id))
  110. doc = self._download_xml(
  111. xml_url, channel_id,
  112. note='Downloading channel info',
  113. errnote='Failed to download channel info')
  114. title = doc.find('.//information/title').text
  115. description = doc.find('.//information/detail').text
  116. for asset in doc.findall('.//teasers/teaser'):
  117. a_type = asset.find('./type').text
  118. a_id = asset.find('./details/assetId').text
  119. if a_type not in ('video', 'topic'):
  120. continue
  121. yield {
  122. '_type': 'url',
  123. 'playlist_title': title,
  124. 'playlist_description': description,
  125. 'url': 'zdf:%s:%s' % (a_type, a_id),
  126. }
  127. def _real_extract(self, url):
  128. channel_id = self._match_id(url)
  129. entries = OnDemandPagedList(
  130. functools.partial(self._fetch_page, channel_id), self._PAGE_SIZE)
  131. return {
  132. '_type': 'playlist',
  133. 'id': channel_id,
  134. 'entries': entries,
  135. }