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.

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