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.

116 lines
4.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_parse_qs
  6. from ..utils import (
  7. xpath_text,
  8. xpath_element,
  9. int_or_none,
  10. parse_iso8601,
  11. ExtractorError,
  12. )
  13. class RICEIE(InfoExtractor):
  14. _VALID_URL = r'https?://mediahub\.rice\.edu/app/[Pp]ortal/video\.aspx\?(?P<query>.+)'
  15. _TEST = {
  16. 'url': 'https://mediahub.rice.edu/app/Portal/video.aspx?PortalID=25ffd62c-3d01-4b29-8c70-7c94270efb3e&DestinationID=66bc9434-03bd-4725-b47e-c659d8d809db&ContentID=YEWIvbhb40aqdjMD1ALSqw',
  17. 'md5': '9b83b4a2eead4912dc3b7fac7c449b6a',
  18. 'info_dict': {
  19. 'id': 'YEWIvbhb40aqdjMD1ALSqw',
  20. 'ext': 'mp4',
  21. 'title': 'Active Learning in Archeology',
  22. 'upload_date': '20140616',
  23. 'timestamp': 1402926346,
  24. }
  25. }
  26. _NS = 'http://schemas.datacontract.org/2004/07/ensembleVideo.Data.Service.Contracts.Models.Player.Config'
  27. def _real_extract(self, url):
  28. qs = compat_parse_qs(re.match(self._VALID_URL, url).group('query'))
  29. if not qs.get('PortalID') or not qs.get('DestinationID') or not qs.get('ContentID'):
  30. raise ExtractorError('Invalid URL', expected=True)
  31. portal_id = qs['PortalID'][0]
  32. playlist_id = qs['DestinationID'][0]
  33. content_id = qs['ContentID'][0]
  34. content_data = self._download_xml('https://mediahub.rice.edu/api/portal/GetContentTitle', content_id, query={
  35. 'portalId': portal_id,
  36. 'playlistId': playlist_id,
  37. 'contentId': content_id
  38. })
  39. metadata = xpath_element(content_data, './/metaData', fatal=True)
  40. title = xpath_text(metadata, 'primaryTitle', fatal=True)
  41. encodings = xpath_element(content_data, './/encodings', fatal=True)
  42. player_data = self._download_xml('https://mediahub.rice.edu/api/player/GetPlayerConfig', content_id, query={
  43. 'temporaryLinkId': xpath_text(encodings, 'temporaryLinkId', fatal=True),
  44. 'contentId': content_id,
  45. })
  46. common_fmt = {}
  47. dimensions = xpath_text(encodings, 'dimensions')
  48. if dimensions:
  49. wh = dimensions.split('x')
  50. if len(wh) == 2:
  51. common_fmt.update({
  52. 'width': int_or_none(wh[0]),
  53. 'height': int_or_none(wh[1]),
  54. })
  55. formats = []
  56. rtsp_path = xpath_text(player_data, self._xpath_ns('RtspPath', self._NS))
  57. if rtsp_path:
  58. fmt = {
  59. 'url': rtsp_path,
  60. 'format_id': 'rtsp',
  61. }
  62. fmt.update(common_fmt)
  63. formats.append(fmt)
  64. for source in player_data.findall(self._xpath_ns('.//Source', self._NS)):
  65. video_url = xpath_text(source, self._xpath_ns('File', self._NS))
  66. if not video_url:
  67. continue
  68. if '.m3u8' in video_url:
  69. formats.extend(self._extract_m3u8_formats(video_url, content_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  70. else:
  71. fmt = {
  72. 'url': video_url,
  73. 'format_id': video_url.split(':')[0],
  74. }
  75. fmt.update(common_fmt)
  76. rtmp = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>.+))/(?P<playpath>mp4:.+)$', video_url)
  77. if rtmp:
  78. fmt.update({
  79. 'url': rtmp.group('url'),
  80. 'play_path': rtmp.group('playpath'),
  81. 'app': rtmp.group('app'),
  82. 'ext': 'flv',
  83. })
  84. formats.append(fmt)
  85. self._sort_formats(formats)
  86. thumbnails = []
  87. for content_asset in content_data.findall('.//contentAssets'):
  88. asset_type = xpath_text(content_asset, 'type')
  89. if asset_type == 'image':
  90. image_url = xpath_text(content_asset, 'httpPath')
  91. if not image_url:
  92. continue
  93. thumbnails.append({
  94. 'id': xpath_text(content_asset, 'ID'),
  95. 'url': image_url,
  96. })
  97. return {
  98. 'id': content_id,
  99. 'title': title,
  100. 'description': xpath_text(metadata, 'abstract'),
  101. 'duration': int_or_none(xpath_text(metadata, 'duration')),
  102. 'timestamp': parse_iso8601(xpath_text(metadata, 'dateUpdated')),
  103. 'thumbnails': thumbnails,
  104. 'formats': formats,
  105. }