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.

68 lines
2.8 KiB

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