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
7.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor
  6. from ..compat import compat_urlparse
  7. from ..utils import (
  8. ExtractorError,
  9. unsmuggle_url,
  10. mimetype2ext,
  11. float_or_none,
  12. )
  13. class MediasiteIE(InfoExtractor):
  14. _VALID_URL = r'''(?xi)
  15. https?://[a-z0-9\-\.:\[\]]+/Mediasite/Play/
  16. (?P<id>[0-9a-f]{32,34})
  17. (?P<QueryString>\?[^#]+|)
  18. '''
  19. _TESTS = [
  20. {
  21. 'url': 'https://hitsmediaweb.h-its.org/mediasite/Play/2db6c271681e4f199af3c60d1f82869b1d',
  22. 'info_dict': {
  23. 'id': '2db6c271681e4f199af3c60d1f82869b1d',
  24. 'ext': 'mp4',
  25. 'title': 'Lecture: Tuesday, September 20, 2016 - Sir Andrew Wiles',
  26. 'description': 'Sir Andrew Wiles: “Equations in arithmetic”\\n\\nI will describe some of the interactions between modern number theory and the problem of solving equations in rational numbers or integers\\u0027.',
  27. 'timestamp': 1474268400.0,
  28. 'upload_date': '20160919',
  29. },
  30. },
  31. {
  32. 'url': 'http://mediasite.uib.no/Mediasite/Play/90bb363295d945d6b548c867d01181361d?catalog=a452b7df-9ae1-46b7-a3ba-aceeb285f3eb',
  33. 'info_dict': {
  34. 'id': '90bb363295d945d6b548c867d01181361d',
  35. 'ext': 'mp4',
  36. 'upload_date': '20150429',
  37. 'title': '5) IT-forum 2015-Dag 1 - Dungbeetle - How and why Rain created a tiny bug tracker for Unity',
  38. 'timestamp': 1430311380.0,
  39. },
  40. },
  41. {
  42. 'url': 'https://collegerama.tudelft.nl/Mediasite/Play/585a43626e544bdd97aeb71a0ec907a01d',
  43. 'md5': '481fda1c11f67588c0d9d8fbdced4e39',
  44. 'info_dict': {
  45. 'id': '585a43626e544bdd97aeb71a0ec907a01d',
  46. 'ext': 'mp4',
  47. 'title': 'Een nieuwe wereld: waarden, bewustzijn en techniek van de mensheid 2.0.',
  48. 'description': '',
  49. 'thumbnail': r're:^https?://.*\.jpg(?:\?.*)?$',
  50. 'duration': 7713.088,
  51. 'timestamp': 1413309600,
  52. 'upload_date': '20141014',
  53. },
  54. },
  55. {
  56. 'url': 'https://collegerama.tudelft.nl/Mediasite/Play/86a9ea9f53e149079fbdb4202b521ed21d?catalog=fd32fd35-6c99-466c-89d4-cd3c431bc8a4',
  57. 'md5': 'ef1fdded95bdf19b12c5999949419c92',
  58. 'info_dict': {
  59. 'id': '86a9ea9f53e149079fbdb4202b521ed21d',
  60. 'ext': 'wmv',
  61. 'title': '64ste Vakantiecursus: Afvalwater',
  62. 'description': 'md5:7fd774865cc69d972f542b157c328305',
  63. 'thumbnail': r're:^https?://.*\.jpg(?:\?.*?)?$',
  64. 'duration': 10853,
  65. 'timestamp': 1326446400,
  66. 'upload_date': '20120113',
  67. },
  68. },
  69. {
  70. 'url': 'http://digitalops.sandia.gov/Mediasite/Play/24aace4429fc450fb5b38cdbf424a66e1d',
  71. 'md5': '9422edc9b9a60151727e4b6d8bef393d',
  72. 'info_dict': {
  73. 'id': '24aace4429fc450fb5b38cdbf424a66e1d',
  74. 'ext': 'mp4',
  75. 'title': 'Xyce Software Training - Section 1',
  76. 'description': r're:(?s)SAND Number: SAND 2013-7800.{200,}',
  77. 'upload_date': '20120409',
  78. 'timestamp': 1333983600,
  79. 'duration': 7794,
  80. }
  81. }
  82. ]
  83. # look in Mediasite.Core.js (Mediasite.ContentStreamType[*])
  84. _STREAM_TYPES = {
  85. 0: 'video1', # the main video
  86. 2: 'slide',
  87. 3: 'presentation',
  88. 4: 'video2', # screencast?
  89. 5: 'video3',
  90. }
  91. def _real_extract(self, url):
  92. url, data = unsmuggle_url(url, {})
  93. mobj = re.match(self._VALID_URL, url)
  94. ResourceId = mobj.group('id')
  95. QueryString = mobj.group('QueryString')
  96. webpage = self._download_webpage(url, ResourceId) # XXX: add UrlReferrer?
  97. # XXX: might have also extracted UrlReferrer and QueryString from the html
  98. ServicePath = compat_urlparse.urljoin(url, self._html_search_regex(
  99. r'<div id="ServicePath">(.+?)</div>', webpage, ResourceId,
  100. default='/Mediasite/PlayerService/PlayerService.svc/json'))
  101. PlayerOptions = self._download_json(
  102. '%s/GetPlayerOptions' % (ServicePath), ResourceId,
  103. headers={
  104. 'Content-type': 'application/json; charset=utf-8',
  105. 'X-Requested-With': 'XMLHttpRequest',
  106. },
  107. data=json.dumps({
  108. 'getPlayerOptionsRequest': {
  109. 'ResourceId': ResourceId,
  110. 'QueryString': QueryString,
  111. 'UrlReferrer': data.get('UrlReferrer', ''),
  112. 'UseScreenReader': False,
  113. }
  114. }).encode('utf-8'))
  115. Presentation = PlayerOptions['d']['Presentation']
  116. if Presentation is None:
  117. raise ExtractorError('Mediasite says: %s' %
  118. (PlayerOptions['d']['PlayerPresentationStatusMessage'],),
  119. expected=True)
  120. thumbnails = []
  121. formats = []
  122. for snum, Stream in enumerate(Presentation['Streams']):
  123. stream_type = self._STREAM_TYPES.get(
  124. Stream['StreamType'], 'type%u' % Stream['StreamType'])
  125. stream_formats = []
  126. for unum, VideoUrl in enumerate(Stream['VideoUrls']):
  127. url = VideoUrl['Location']
  128. # XXX: if Stream.get('CanChangeScheme', False), switch scheme to HTTP/HTTPS
  129. if VideoUrl['MediaType'] == 'SS':
  130. stream_formats.extend(self._extract_ism_formats(
  131. url, ResourceId, ism_id='%s-%u.%u' % (stream_type, snum, unum)))
  132. continue
  133. stream_formats.append({
  134. 'format_id': '%s-%u.%u' % (stream_type, snum, unum),
  135. 'url': url,
  136. 'ext': mimetype2ext(VideoUrl['MimeType']),
  137. })
  138. # TODO: if Stream['HasSlideContent']:
  139. # synthesise an MJPEG video stream '%s-%u.slides' % (stream_type, snum)
  140. # from Stream['Slides']
  141. # this will require writing a custom downloader...
  142. # disprefer 'secondary' streams
  143. if Stream['StreamType'] != 0:
  144. for fmt in stream_formats:
  145. fmt['preference'] = -1
  146. ThumbnailUrl = Stream.get('ThumbnailUrl')
  147. if ThumbnailUrl:
  148. thumbnails.append({
  149. 'id': '%s-%u' % (stream_type, snum),
  150. 'url': compat_urlparse.urljoin(url, ThumbnailUrl),
  151. 'preference': -1 if Stream['StreamType'] != 0 else 0,
  152. })
  153. formats.extend(stream_formats)
  154. self._sort_formats(formats)
  155. # XXX: Presentation['Presenters']
  156. # XXX: Presentation['Transcript']
  157. return {
  158. 'id': ResourceId,
  159. 'title': Presentation['Title'],
  160. 'description': Presentation.get('Description'),
  161. 'duration': float_or_none(Presentation.get('Duration'), 1000),
  162. 'timestamp': float_or_none(Presentation.get('UnixTime'), 1000),
  163. 'formats': formats,
  164. 'thumbnails': thumbnails,
  165. }