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.

172 lines
6.2 KiB

11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
9 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_urlparse
  5. from ..utils import (
  6. determine_ext,
  7. int_or_none,
  8. parse_duration,
  9. parse_iso8601,
  10. xpath_text,
  11. )
  12. class MDRIE(InfoExtractor):
  13. IE_DESC = 'MDR.DE and KiKA'
  14. _VALID_URL = r'https?://(?:www\.)?(?:mdr|kika)\.de/(?:.*)/[a-z]+-?(?P<id>\d+)(?:_.+?)?\.html'
  15. _TESTS = [{
  16. # MDR regularly deletes its videos
  17. 'url': 'http://www.mdr.de/fakt/video189002.html',
  18. 'only_matching': True,
  19. }, {
  20. # audio
  21. 'url': 'http://www.mdr.de/kultur/audio1312272_zc-15948bad_zs-86171fdd.html',
  22. 'md5': '64c4ee50f0a791deb9479cd7bbe9d2fa',
  23. 'info_dict': {
  24. 'id': '1312272',
  25. 'ext': 'mp3',
  26. 'title': 'Feuilleton vom 30. Oktober 2015',
  27. 'duration': 250,
  28. 'uploader': 'MITTELDEUTSCHER RUNDFUNK',
  29. },
  30. }, {
  31. 'url': 'http://www.kika.de/baumhaus/videos/video19636.html',
  32. 'md5': '4930515e36b06c111213e80d1e4aad0e',
  33. 'info_dict': {
  34. 'id': '19636',
  35. 'ext': 'mp4',
  36. 'title': 'Baumhaus vom 30. Oktober 2015',
  37. 'duration': 134,
  38. 'uploader': 'KIKA',
  39. },
  40. }, {
  41. 'url': 'http://www.kika.de/sendungen/einzelsendungen/weihnachtsprogramm/videos/video8182.html',
  42. 'md5': '5fe9c4dd7d71e3b238f04b8fdd588357',
  43. 'info_dict': {
  44. 'id': '8182',
  45. 'ext': 'mp4',
  46. 'title': 'Beutolomäus und der geheime Weihnachtswunsch',
  47. 'description': 'md5:b69d32d7b2c55cbe86945ab309d39bbd',
  48. 'timestamp': 1450950000,
  49. 'upload_date': '20151224',
  50. 'duration': 4628,
  51. 'uploader': 'KIKA',
  52. },
  53. }, {
  54. 'url': 'http://www.kika.de/baumhaus/sendungen/video19636_zc-fea7f8a0_zs-4bf89c60.html',
  55. 'only_matching': True,
  56. }, {
  57. 'url': 'http://www.kika.de/sendungen/einzelsendungen/weihnachtsprogramm/einzelsendung2534.html',
  58. 'only_matching': True,
  59. }, {
  60. 'url': 'http://www.mdr.de/mediathek/mdr-videos/a/video-1334.html',
  61. 'only_matching': True,
  62. }]
  63. def _real_extract(self, url):
  64. video_id = self._match_id(url)
  65. webpage = self._download_webpage(url, video_id)
  66. data_url = self._search_regex(
  67. r'(?:dataURL|playerXml(?:["\'])?)\s*:\s*(["\'])(?P<url>.+/(?:video|audio)-?[0-9]+-avCustom\.xml)\1',
  68. webpage, 'data url', group='url').replace('\/', '/')
  69. doc = self._download_xml(
  70. compat_urlparse.urljoin(url, data_url), video_id)
  71. title = xpath_text(doc, ['./title', './broadcast/broadcastName'], 'title', fatal=True)
  72. formats = []
  73. processed_urls = []
  74. for asset in doc.findall('./assets/asset'):
  75. for source in (
  76. 'progressiveDownload',
  77. 'dynamicHttpStreamingRedirector',
  78. 'adaptiveHttpStreamingRedirector'):
  79. url_el = asset.find('./%sUrl' % source)
  80. if url_el is None:
  81. continue
  82. video_url = url_el.text
  83. if video_url in processed_urls:
  84. continue
  85. processed_urls.append(video_url)
  86. vbr = int_or_none(xpath_text(asset, './bitrateVideo', 'vbr'), 1000)
  87. abr = int_or_none(xpath_text(asset, './bitrateAudio', 'abr'), 1000)
  88. ext = determine_ext(url_el.text)
  89. if ext == 'm3u8':
  90. url_formats = self._extract_m3u8_formats(
  91. video_url, video_id, 'mp4', entry_protocol='m3u8_native',
  92. preference=0, m3u8_id='HLS', fatal=False)
  93. elif ext == 'f4m':
  94. url_formats = self._extract_f4m_formats(
  95. video_url + '?hdcore=3.7.0&plugin=aasp-3.7.0.39.44', video_id,
  96. preference=0, f4m_id='HDS', fatal=False)
  97. else:
  98. media_type = xpath_text(asset, './mediaType', 'media type', default='MP4')
  99. vbr = int_or_none(xpath_text(asset, './bitrateVideo', 'vbr'), 1000)
  100. abr = int_or_none(xpath_text(asset, './bitrateAudio', 'abr'), 1000)
  101. filesize = int_or_none(xpath_text(asset, './fileSize', 'file size'))
  102. f = {
  103. 'url': video_url,
  104. 'format_id': '%s-%d' % (media_type, vbr or abr),
  105. 'filesize': filesize,
  106. 'abr': abr,
  107. 'preference': 1,
  108. }
  109. if vbr:
  110. width = int_or_none(xpath_text(asset, './frameWidth', 'width'))
  111. height = int_or_none(xpath_text(asset, './frameHeight', 'height'))
  112. f.update({
  113. 'vbr': vbr,
  114. 'width': width,
  115. 'height': height,
  116. })
  117. url_formats = [f]
  118. if not url_formats:
  119. continue
  120. if not vbr:
  121. for f in url_formats:
  122. abr = f.get('tbr') or abr
  123. if 'tbr' in f:
  124. del f['tbr']
  125. f.update({
  126. 'abr': abr,
  127. 'vcodec': 'none',
  128. })
  129. formats.extend(url_formats)
  130. self._sort_formats(formats)
  131. description = xpath_text(doc, './broadcast/broadcastDescription', 'description')
  132. timestamp = parse_iso8601(
  133. xpath_text(
  134. doc, [
  135. './broadcast/broadcastDate',
  136. './broadcast/broadcastStartDate',
  137. './broadcast/broadcastEndDate'],
  138. 'timestamp', default=None))
  139. duration = parse_duration(xpath_text(doc, './duration', 'duration'))
  140. uploader = xpath_text(doc, './rights', 'uploader')
  141. return {
  142. 'id': video_id,
  143. 'title': title,
  144. 'description': description,
  145. 'timestamp': timestamp,
  146. 'duration': duration,
  147. 'uploader': uploader,
  148. 'formats': formats,
  149. }