logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

mdr.py (7070B)


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