]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ooyala.py
1f7b4d2e7e9fa79ef9f81f71f190f943c35dd3a5
[youtubedl] / youtube_dl / extractor / 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 @staticmethod
22 def _url_for_embed_code(embed_code):
23 return 'http://player.ooyala.com/player.js?embedCode=%s' % embed_code
24
25 def _extract_result(self, info, more_info):
26 return {'id': info['embedCode'],
27 'ext': 'mp4',
28 'title': unescapeHTML(info['title']),
29 'url': info.get('ipad_url') or info['url'],
30 'description': unescapeHTML(more_info['description']),
31 'thumbnail': more_info['promo'],
32 }
33
34 def _real_extract(self, url):
35 mobj = re.match(self._VALID_URL, url)
36 embedCode = mobj.group('id')
37 player_url = 'http://player.ooyala.com/player.js?embedCode=%s' % embedCode
38 player = self._download_webpage(player_url, embedCode)
39 mobile_url = self._search_regex(r'mobile_player_url="(.+?)&device="',
40 player, u'mobile player url')
41 mobile_player = self._download_webpage(mobile_url, embedCode)
42 videos_info = self._search_regex(
43 r'var streams=window.oo_testEnv\?\[\]:eval\("\((\[{.*?}\])\)"\);',
44 mobile_player, u'info').replace('\\"','"')
45 videos_more_info = self._search_regex(r'eval\("\(({.*?\\"promo\\".*?})\)"', mobile_player, u'more info').replace('\\"','"')
46 videos_info = json.loads(videos_info)
47 videos_more_info =json.loads(videos_more_info)
48
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 {'_type': 'playlist',
52 'id': embedCode,
53 'title': unescapeHTML(videos_more_info['title']),
54 'entries': videos,
55 }
56 else:
57 return self._extract_result(videos_info[0], videos_more_info)
58