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.

100 lines
4.2 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. unescapeHTML,
  7. ExtractorError,
  8. )
  9. class OoyalaIE(InfoExtractor):
  10. _VALID_URL = r'(?:ooyala:|https?://.+?\.ooyala\.com/.*?(?:embedCode|ec)=)(?P<id>.+?)(&|$)'
  11. _TESTS = [
  12. {
  13. # From http://it.slashdot.org/story/13/04/25/178216/recovering-data-from-broken-hard-drives-and-ssds-video
  14. 'url': 'http://player.ooyala.com/player.js?embedCode=pxczE2YjpfHfn1f3M-ykG_AmJRRn0PD8',
  15. 'md5': '3f5cceb3a7bf461d6c29dc466cf8033c',
  16. 'info_dict': {
  17. 'id': 'pxczE2YjpfHfn1f3M-ykG_AmJRRn0PD8',
  18. 'ext': 'mp4',
  19. 'title': 'Explaining Data Recovery from Hard Drives and SSDs',
  20. 'description': 'How badly damaged does a drive have to be to defeat Russell and his crew? Apparently, smashed to bits.',
  21. },
  22. }, {
  23. # Only available for ipad
  24. 'url': 'http://player.ooyala.com/player.js?embedCode=x1b3lqZDq9y_7kMyC2Op5qo-p077tXD0',
  25. 'md5': '4b9754921fddb68106e48c142e2a01e6',
  26. 'info_dict': {
  27. 'id': 'x1b3lqZDq9y_7kMyC2Op5qo-p077tXD0',
  28. 'ext': 'mp4',
  29. 'title': 'Simulation Overview - Levels of Simulation',
  30. 'description': '',
  31. },
  32. },
  33. ]
  34. @staticmethod
  35. def _url_for_embed_code(embed_code):
  36. return 'http://player.ooyala.com/player.js?embedCode=%s' % embed_code
  37. @classmethod
  38. def _build_url_result(cls, embed_code):
  39. return cls.url_result(cls._url_for_embed_code(embed_code),
  40. ie=cls.ie_key())
  41. def _extract_result(self, info, more_info):
  42. return {
  43. 'id': info['embedCode'],
  44. 'ext': 'mp4',
  45. 'title': unescapeHTML(info['title']),
  46. 'url': info.get('ipad_url') or info['url'],
  47. 'description': unescapeHTML(more_info['description']),
  48. 'thumbnail': more_info['promo'],
  49. }
  50. def _real_extract(self, url):
  51. mobj = re.match(self._VALID_URL, url)
  52. embedCode = mobj.group('id')
  53. player_url = 'http://player.ooyala.com/player.js?embedCode=%s' % embedCode
  54. player = self._download_webpage(player_url, embedCode)
  55. mobile_url = self._search_regex(r'mobile_player_url="(.+?)&device="',
  56. player, 'mobile player url')
  57. # Looks like some videos are only available for particular devices
  58. # (e.g. http://player.ooyala.com/player.js?embedCode=x1b3lqZDq9y_7kMyC2Op5qo-p077tXD0
  59. # is only available for ipad)
  60. # Working around with fetching URLs for all the devices found starting with 'unknown'
  61. # until we succeed or eventually fail for each device.
  62. devices = re.findall(r'device\s*=\s*"([^"]+)";', player)
  63. devices.remove('unknown')
  64. devices.insert(0, 'unknown')
  65. for device in devices:
  66. mobile_player = self._download_webpage(
  67. '%s&device=%s' % (mobile_url, device), embedCode,
  68. 'Downloading mobile player JS for %s device' % device)
  69. videos_info = self._search_regex(
  70. r'var streams=window.oo_testEnv\?\[\]:eval\("\((\[{.*?}\])\)"\);',
  71. mobile_player, 'info', fatal=False, default=None)
  72. if videos_info:
  73. break
  74. if not videos_info:
  75. raise ExtractorError('Unable to extract info')
  76. videos_info = videos_info.replace('\\"', '"')
  77. videos_more_info = self._search_regex(
  78. r'eval\("\(({.*?\\"promo\\".*?})\)"', mobile_player, 'more info').replace('\\"', '"')
  79. videos_info = json.loads(videos_info)
  80. videos_more_info = json.loads(videos_more_info)
  81. if videos_more_info.get('lineup'):
  82. videos = [self._extract_result(info, more_info) for (info, more_info) in zip(videos_info, videos_more_info['lineup'])]
  83. return {
  84. '_type': 'playlist',
  85. 'id': embedCode,
  86. 'title': unescapeHTML(videos_more_info['title']),
  87. 'entries': videos,
  88. }
  89. else:
  90. return self._extract_result(videos_info[0], videos_more_info)