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