1 from __future__ import unicode_literals
6 from .common import InfoExtractor
15 class OoyalaBaseIE(InfoExtractor):
17 def _extract_result(self, info, more_info):
18 embedCode = info['embedCode']
19 video_url = info.get('ipad_url') or info['url']
21 if determine_ext(video_url) == 'm3u8':
22 formats = self._extract_m3u8_formats(video_url, embedCode, ext='mp4')
31 'title': unescapeHTML(info['title']),
33 'description': unescapeHTML(more_info['description']),
34 'thumbnail': more_info['promo'],
37 def _extract(self, player_url, video_id):
38 player = self._download_webpage(player_url, video_id)
39 mobile_url = self._search_regex(r'mobile_player_url="(.+?)&device="',
40 player, 'mobile player url')
41 # Looks like some videos are only available for particular devices
42 # (e.g. http://player.ooyala.com/player.js?embedCode=x1b3lqZDq9y_7kMyC2Op5qo-p077tXD0
43 # is only available for ipad)
44 # Working around with fetching URLs for all the devices found starting with 'unknown'
45 # until we succeed or eventually fail for each device.
46 devices = re.findall(r'device\s*=\s*"([^"]+)";', player)
47 devices.remove('unknown')
48 devices.insert(0, 'unknown')
49 for device in devices:
50 mobile_player = self._download_webpage(
51 '%s&device=%s' % (mobile_url, device), video_id,
52 'Downloading mobile player JS for %s device' % device)
53 videos_info = self._search_regex(
54 r'var streams=window.oo_testEnv\?\[\]:eval\("\((\[{.*?}\])\)"\);',
55 mobile_player, 'info', fatal=False, default=None)
61 auth_data = self._download_json(
62 'http://player.ooyala.com/sas/player_api/v1/authorization/embed_code/%s/%s?domain=www.example.org&supportedFormats=mp4,webm' % (video_id, video_id),
65 cur_auth_data = auth_data['authorization_data'][video_id]
67 for stream in cur_auth_data['streams']:
69 'url': base64.b64decode(stream['url']['data'].encode('ascii')).decode('utf-8'),
70 'ext': stream.get('delivery_type'),
71 'format': stream.get('video_codec'),
72 'format_id': stream.get('profile'),
73 'width': int_or_none(stream.get('width')),
74 'height': int_or_none(stream.get('height')),
75 'abr': int_or_none(stream.get('audio_bitrate')),
76 'vbr': int_or_none(stream.get('video_bitrate')),
82 'title': 'Ooyala video',
85 if not cur_auth_data['authorized']:
86 raise ExtractorError(cur_auth_data['message'], expected=True)
89 raise ExtractorError('Unable to extract info')
90 videos_info = videos_info.replace('\\"', '"')
91 videos_more_info = self._search_regex(
92 r'eval\("\(({.*?\\"promo\\".*?})\)"', mobile_player, 'more info').replace('\\"', '"')
93 videos_info = json.loads(videos_info)
94 videos_more_info = json.loads(videos_more_info)
96 if videos_more_info.get('lineup'):
97 videos = [self._extract_result(info, more_info) for (info, more_info) in zip(videos_info, videos_more_info['lineup'])]
101 'title': unescapeHTML(videos_more_info['title']),
105 return self._extract_result(videos_info[0], videos_more_info)
108 class OoyalaIE(OoyalaBaseIE):
109 _VALID_URL = r'(?:ooyala:|https?://.+?\.ooyala\.com/.*?(?:embedCode|ec)=)(?P<id>.+?)(&|$)'
113 # From http://it.slashdot.org/story/13/04/25/178216/recovering-data-from-broken-hard-drives-and-ssds-video
114 'url': 'http://player.ooyala.com/player.js?embedCode=pxczE2YjpfHfn1f3M-ykG_AmJRRn0PD8',
116 'id': 'pxczE2YjpfHfn1f3M-ykG_AmJRRn0PD8',
118 'title': 'Explaining Data Recovery from Hard Drives and SSDs',
119 'description': 'How badly damaged does a drive have to be to defeat Russell and his crew? Apparently, smashed to bits.',
122 # Only available for ipad
123 'url': 'http://player.ooyala.com/player.js?embedCode=x1b3lqZDq9y_7kMyC2Op5qo-p077tXD0',
125 'id': 'x1b3lqZDq9y_7kMyC2Op5qo-p077tXD0',
127 'title': 'Simulation Overview - Levels of Simulation',
132 # Information available only through SAS api
133 # From http://community.plm.automation.siemens.com/t5/News-NX-Manufacturing/Tool-Path-Divide/ba-p/4187
134 'url': 'http://player.ooyala.com/player.js?embedCode=FiOG81ZTrvckcchQxmalf4aQj590qTEx',
135 'md5': 'a84001441b35ea492bc03736e59e7935',
137 'id': 'FiOG81ZTrvckcchQxmalf4aQj590qTEx',
139 'title': 'Ooyala video',
145 def _url_for_embed_code(embed_code):
146 return 'http://player.ooyala.com/player.js?embedCode=%s' % embed_code
149 def _build_url_result(cls, embed_code):
150 return cls.url_result(cls._url_for_embed_code(embed_code),
153 def _real_extract(self, url):
154 embed_code = self._match_id(url)
155 player_url = 'http://player.ooyala.com/player.js?embedCode=%s' % embed_code
156 return self._extract(player_url, embed_code)
159 class OoyalaExternalIE(OoyalaBaseIE):
160 _VALID_URL = r'''(?x)
163 https?://.+?\.ooyala\.com/.*?\bexternalId=
165 (?P<partner_id>[^:]+)
177 'url': 'https://player.ooyala.com/player.js?externalId=espn:10365079&pcode=1kNG061cgaoolOncv54OAO1ceO-I&adSetCode=91cDU6NuXTGKz3OdjOxFdAgJVtQcKJnI&callback=handleEvents&hasModuleParams=1&height=968&playerBrandingId=7af3bd04449c444c964f347f11873075&targetReplaceId=videoPlayer&width=1656&wmode=opaque&allowScriptAccess=always',
179 'id': 'FkYWtmazr6Ed8xmvILvKLWjd4QvYZpzG',
181 'title': 'dm_140128_30for30Shorts___JudgingJewellv2',
186 'skip_download': True,
190 def _real_extract(self, url):
191 mobj = re.match(self._VALID_URL, url)
192 partner_id = mobj.group('partner_id')
193 video_id = mobj.group('id')
194 pcode = mobj.group('pcode')
195 player_url = 'http://player.ooyala.com/player.js?externalId=%s:%s&pcode=%s' % (partner_id, video_id, pcode)
196 return self._extract(player_url, video_id)