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.

169 lines
6.1 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': 1419047100,
  49. 'upload_date': '20141220',
  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. def _real_extract(self, url):
  61. video_id = self._match_id(url)
  62. webpage = self._download_webpage(url, video_id)
  63. data_url = self._search_regex(
  64. r'dataURL\s*:\s*(["\'])(?P<url>/.+/(?:video|audio)[0-9]+-avCustom\.xml)\1',
  65. webpage, 'data url', group='url')
  66. doc = self._download_xml(
  67. compat_urlparse.urljoin(url, data_url), video_id)
  68. title = xpath_text(doc, ['./title', './broadcast/broadcastName'], 'title', fatal=True)
  69. formats = []
  70. processed_urls = []
  71. for asset in doc.findall('./assets/asset'):
  72. for source in (
  73. 'progressiveDownload',
  74. 'dynamicHttpStreamingRedirector',
  75. 'adaptiveHttpStreamingRedirector'):
  76. url_el = asset.find('./%sUrl' % source)
  77. if url_el is None:
  78. continue
  79. video_url = url_el.text
  80. if video_url in processed_urls:
  81. continue
  82. processed_urls.append(video_url)
  83. vbr = int_or_none(xpath_text(asset, './bitrateVideo', 'vbr'), 1000)
  84. abr = int_or_none(xpath_text(asset, './bitrateAudio', 'abr'), 1000)
  85. ext = determine_ext(url_el.text)
  86. if ext == 'm3u8':
  87. url_formats = self._extract_m3u8_formats(
  88. video_url, video_id, 'mp4', entry_protocol='m3u8_native',
  89. preference=0, m3u8_id='HLS', fatal=False)
  90. elif ext == 'f4m':
  91. url_formats = self._extract_f4m_formats(
  92. video_url + '?hdcore=3.7.0&plugin=aasp-3.7.0.39.44', video_id,
  93. preference=0, f4m_id='HDS', fatal=False)
  94. else:
  95. media_type = xpath_text(asset, './mediaType', 'media type', default='MP4')
  96. vbr = int_or_none(xpath_text(asset, './bitrateVideo', 'vbr'), 1000)
  97. abr = int_or_none(xpath_text(asset, './bitrateAudio', 'abr'), 1000)
  98. filesize = int_or_none(xpath_text(asset, './fileSize', 'file size'))
  99. f = {
  100. 'url': video_url,
  101. 'format_id': '%s-%d' % (media_type, vbr or abr),
  102. 'filesize': filesize,
  103. 'abr': abr,
  104. 'preference': 1,
  105. }
  106. if vbr:
  107. width = int_or_none(xpath_text(asset, './frameWidth', 'width'))
  108. height = int_or_none(xpath_text(asset, './frameHeight', 'height'))
  109. f.update({
  110. 'vbr': vbr,
  111. 'width': width,
  112. 'height': height,
  113. })
  114. url_formats = [f]
  115. if not url_formats:
  116. continue
  117. if not vbr:
  118. for f in url_formats:
  119. abr = f.get('tbr') or abr
  120. if 'tbr' in f:
  121. del f['tbr']
  122. f.update({
  123. 'abr': abr,
  124. 'vcodec': 'none',
  125. })
  126. formats.extend(url_formats)
  127. self._sort_formats(formats)
  128. description = xpath_text(doc, './broadcast/broadcastDescription', 'description')
  129. timestamp = parse_iso8601(
  130. xpath_text(
  131. doc, [
  132. './broadcast/broadcastDate',
  133. './broadcast/broadcastStartDate',
  134. './broadcast/broadcastEndDate'],
  135. 'timestamp', default=None))
  136. duration = parse_duration(xpath_text(doc, './duration', 'duration'))
  137. uploader = xpath_text(doc, './rights', 'uploader')
  138. return {
  139. 'id': video_id,
  140. 'title': title,
  141. 'description': description,
  142. 'timestamp': timestamp,
  143. 'duration': duration,
  144. 'uploader': uploader,
  145. 'formats': formats,
  146. }