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.

58 lines
2.6 KiB

  1. import re
  2. import json
  3. from .common import InfoExtractor
  4. from ..utils import unescapeHTML
  5. class OoyalaIE(InfoExtractor):
  6. _VALID_URL = r'https?://.+?\.ooyala\.com/.*?embedCode=(?P<id>.+?)(&|$)'
  7. _TEST = {
  8. # From http://it.slashdot.org/story/13/04/25/178216/recovering-data-from-broken-hard-drives-and-ssds-video
  9. u'url': u'http://player.ooyala.com/player.js?embedCode=pxczE2YjpfHfn1f3M-ykG_AmJRRn0PD8',
  10. u'file': u'pxczE2YjpfHfn1f3M-ykG_AmJRRn0PD8.mp4',
  11. u'md5': u'3f5cceb3a7bf461d6c29dc466cf8033c',
  12. u'info_dict': {
  13. u'title': u'Explaining Data Recovery from Hard Drives and SSDs',
  14. u'description': u'How badly damaged does a drive have to be to defeat Russell and his crew? Apparently, smashed to bits.',
  15. },
  16. }
  17. @staticmethod
  18. def _url_for_embed_code(embed_code):
  19. return 'http://player.ooyala.com/player.js?embedCode=%s' % embed_code
  20. def _extract_result(self, info, more_info):
  21. return {'id': info['embedCode'],
  22. 'ext': 'mp4',
  23. 'title': unescapeHTML(info['title']),
  24. 'url': info.get('ipad_url') or info['url'],
  25. 'description': unescapeHTML(more_info['description']),
  26. 'thumbnail': more_info['promo'],
  27. }
  28. def _real_extract(self, url):
  29. mobj = re.match(self._VALID_URL, url)
  30. embedCode = mobj.group('id')
  31. player_url = 'http://player.ooyala.com/player.js?embedCode=%s' % embedCode
  32. player = self._download_webpage(player_url, embedCode)
  33. mobile_url = self._search_regex(r'mobile_player_url="(.+?)&device="',
  34. player, u'mobile player url')
  35. mobile_player = self._download_webpage(mobile_url, embedCode)
  36. videos_info = self._search_regex(
  37. r'var streams=window.oo_testEnv\?\[\]:eval\("\((\[{.*?}\])\)"\);',
  38. mobile_player, u'info').replace('\\"','"')
  39. videos_more_info = self._search_regex(r'eval\("\(({.*?\\"promo\\".*?})\)"', mobile_player, u'more info').replace('\\"','"')
  40. videos_info = json.loads(videos_info)
  41. videos_more_info =json.loads(videos_more_info)
  42. if videos_more_info.get('lineup'):
  43. videos = [self._extract_result(info, more_info) for (info, more_info) in zip(videos_info, videos_more_info['lineup'])]
  44. return {'_type': 'playlist',
  45. 'id': embedCode,
  46. 'title': unescapeHTML(videos_more_info['title']),
  47. 'entries': videos,
  48. }
  49. else:
  50. return self._extract_result(videos_info[0], videos_more_info)