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.

184 lines
6.7 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. 'skip': '404 not found',
  31. }, {
  32. 'url': 'http://www.kika.de/baumhaus/videos/video19636.html',
  33. 'md5': '4930515e36b06c111213e80d1e4aad0e',
  34. 'info_dict': {
  35. 'id': '19636',
  36. 'ext': 'mp4',
  37. 'title': 'Baumhaus vom 30. Oktober 2015',
  38. 'duration': 134,
  39. 'uploader': 'KIKA',
  40. },
  41. 'skip': '404 not found',
  42. }, {
  43. 'url': 'http://www.kika.de/sendungen/einzelsendungen/weihnachtsprogramm/videos/video8182.html',
  44. 'md5': '5fe9c4dd7d71e3b238f04b8fdd588357',
  45. 'info_dict': {
  46. 'id': '8182',
  47. 'ext': 'mp4',
  48. 'title': 'Beutolomäus und der geheime Weihnachtswunsch',
  49. 'description': 'md5:b69d32d7b2c55cbe86945ab309d39bbd',
  50. 'timestamp': 1482541200,
  51. 'upload_date': '20161224',
  52. 'duration': 4628,
  53. 'uploader': 'KIKA',
  54. },
  55. }, {
  56. # audio with alternative playerURL pattern
  57. 'url': 'http://www.mdr.de/kultur/videos-und-audios/audio-radio/operation-mindfuck-robert-wilson100.html',
  58. 'info_dict': {
  59. 'id': '100',
  60. 'ext': 'mp4',
  61. 'title': 'Feature: Operation Mindfuck - Robert Anton Wilson',
  62. 'duration': 3239,
  63. 'uploader': 'MITTELDEUTSCHER RUNDFUNK',
  64. },
  65. }, {
  66. 'url': 'http://www.kika.de/baumhaus/sendungen/video19636_zc-fea7f8a0_zs-4bf89c60.html',
  67. 'only_matching': True,
  68. }, {
  69. 'url': 'http://www.kika.de/sendungen/einzelsendungen/weihnachtsprogramm/einzelsendung2534.html',
  70. 'only_matching': True,
  71. }, {
  72. 'url': 'http://www.mdr.de/mediathek/mdr-videos/a/video-1334.html',
  73. 'only_matching': True,
  74. }]
  75. def _real_extract(self, url):
  76. video_id = self._match_id(url)
  77. webpage = self._download_webpage(url, video_id)
  78. data_url = self._search_regex(
  79. r'(?:dataURL|playerXml(?:["\'])?)\s*:\s*(["\'])(?P<url>.+?-avCustom\.xml)\1',
  80. webpage, 'data url', group='url').replace(r'\/', '/')
  81. doc = self._download_xml(
  82. compat_urlparse.urljoin(url, data_url), video_id)
  83. title = xpath_text(doc, ['./title', './broadcast/broadcastName'], 'title', fatal=True)
  84. formats = []
  85. processed_urls = []
  86. for asset in doc.findall('./assets/asset'):
  87. for source in (
  88. 'progressiveDownload',
  89. 'dynamicHttpStreamingRedirector',
  90. 'adaptiveHttpStreamingRedirector'):
  91. url_el = asset.find('./%sUrl' % source)
  92. if url_el is None:
  93. continue
  94. video_url = url_el.text
  95. if video_url in processed_urls:
  96. continue
  97. processed_urls.append(video_url)
  98. vbr = int_or_none(xpath_text(asset, './bitrateVideo', 'vbr'), 1000)
  99. abr = int_or_none(xpath_text(asset, './bitrateAudio', 'abr'), 1000)
  100. ext = determine_ext(url_el.text)
  101. if ext == 'm3u8':
  102. url_formats = self._extract_m3u8_formats(
  103. video_url, video_id, 'mp4', entry_protocol='m3u8_native',
  104. preference=0, m3u8_id='HLS', fatal=False)
  105. elif ext == 'f4m':
  106. url_formats = self._extract_f4m_formats(
  107. video_url + '?hdcore=3.7.0&plugin=aasp-3.7.0.39.44', video_id,
  108. preference=0, f4m_id='HDS', fatal=False)
  109. else:
  110. media_type = xpath_text(asset, './mediaType', 'media type', default='MP4')
  111. vbr = int_or_none(xpath_text(asset, './bitrateVideo', 'vbr'), 1000)
  112. abr = int_or_none(xpath_text(asset, './bitrateAudio', 'abr'), 1000)
  113. filesize = int_or_none(xpath_text(asset, './fileSize', 'file size'))
  114. f = {
  115. 'url': video_url,
  116. 'format_id': '%s-%d' % (media_type, vbr or abr),
  117. 'filesize': filesize,
  118. 'abr': abr,
  119. 'preference': 1,
  120. }
  121. if vbr:
  122. width = int_or_none(xpath_text(asset, './frameWidth', 'width'))
  123. height = int_or_none(xpath_text(asset, './frameHeight', 'height'))
  124. f.update({
  125. 'vbr': vbr,
  126. 'width': width,
  127. 'height': height,
  128. })
  129. url_formats = [f]
  130. if not url_formats:
  131. continue
  132. if not vbr:
  133. for f in url_formats:
  134. abr = f.get('tbr') or abr
  135. if 'tbr' in f:
  136. del f['tbr']
  137. f.update({
  138. 'abr': abr,
  139. 'vcodec': 'none',
  140. })
  141. formats.extend(url_formats)
  142. self._sort_formats(formats)
  143. description = xpath_text(doc, './broadcast/broadcastDescription', 'description')
  144. timestamp = parse_iso8601(
  145. xpath_text(
  146. doc, [
  147. './broadcast/broadcastDate',
  148. './broadcast/broadcastStartDate',
  149. './broadcast/broadcastEndDate'],
  150. 'timestamp', default=None))
  151. duration = parse_duration(xpath_text(doc, './duration', 'duration'))
  152. uploader = xpath_text(doc, './rights', 'uploader')
  153. return {
  154. 'id': video_id,
  155. 'title': title,
  156. 'description': description,
  157. 'timestamp': timestamp,
  158. 'duration': duration,
  159. 'uploader': uploader,
  160. 'formats': formats,
  161. }