]>
Commit | Line | Data |
---|---|---|
e24b5a86 | 1 | from __future__ import unicode_literals |
09825cb5 JMF |
2 | import re |
3 | import json | |
4 | ||
5 | from .common import InfoExtractor | |
6f600ff5 S |
6 | from ..utils import ( |
7 | unescapeHTML, | |
8 | ExtractorError, | |
84bf31aa | 9 | determine_ext, |
6f600ff5 | 10 | ) |
09825cb5 | 11 | |
e24b5a86 | 12 | |
09825cb5 | 13 | class OoyalaIE(InfoExtractor): |
6949d810 | 14 | _VALID_URL = r'(?:ooyala:|https?://.+?\.ooyala\.com/.*?(?:embedCode|ec)=)(?P<id>.+?)(&|$)' |
09825cb5 | 15 | |
6f600ff5 S |
16 | _TESTS = [ |
17 | { | |
18 | # From http://it.slashdot.org/story/13/04/25/178216/recovering-data-from-broken-hard-drives-and-ssds-video | |
19 | 'url': 'http://player.ooyala.com/player.js?embedCode=pxczE2YjpfHfn1f3M-ykG_AmJRRn0PD8', | |
6f600ff5 S |
20 | 'info_dict': { |
21 | 'id': 'pxczE2YjpfHfn1f3M-ykG_AmJRRn0PD8', | |
22 | 'ext': 'mp4', | |
23 | 'title': 'Explaining Data Recovery from Hard Drives and SSDs', | |
24 | 'description': 'How badly damaged does a drive have to be to defeat Russell and his crew? Apparently, smashed to bits.', | |
25 | }, | |
26 | }, { | |
27 | # Only available for ipad | |
28 | 'url': 'http://player.ooyala.com/player.js?embedCode=x1b3lqZDq9y_7kMyC2Op5qo-p077tXD0', | |
6f600ff5 S |
29 | 'info_dict': { |
30 | 'id': 'x1b3lqZDq9y_7kMyC2Op5qo-p077tXD0', | |
31 | 'ext': 'mp4', | |
32 | 'title': 'Simulation Overview - Levels of Simulation', | |
33 | 'description': '', | |
34 | }, | |
09825cb5 | 35 | }, |
6f600ff5 | 36 | ] |
09825cb5 | 37 | |
e8f8e800 JMF |
38 | @staticmethod |
39 | def _url_for_embed_code(embed_code): | |
40 | return 'http://player.ooyala.com/player.js?embedCode=%s' % embed_code | |
41 | ||
c0d0b01f JMF |
42 | @classmethod |
43 | def _build_url_result(cls, embed_code): | |
44 | return cls.url_result(cls._url_for_embed_code(embed_code), | |
9e1a5b84 | 45 | ie=cls.ie_key()) |
c0d0b01f | 46 | |
09825cb5 | 47 | def _extract_result(self, info, more_info): |
84bf31aa YCH |
48 | embedCode = info['embedCode'] |
49 | video_url = info.get('ipad_url') or info['url'] | |
50 | ||
51 | if determine_ext(video_url) == 'm3u8': | |
52 | formats = self._extract_m3u8_formats(video_url, embedCode, ext='mp4') | |
53 | else: | |
54 | formats = [{ | |
55 | 'url': video_url, | |
56 | 'ext': 'mp4', | |
57 | }] | |
58 | ||
e24b5a86 | 59 | return { |
84bf31aa | 60 | 'id': embedCode, |
e24b5a86 | 61 | 'title': unescapeHTML(info['title']), |
84bf31aa | 62 | 'formats': formats, |
e24b5a86 JMF |
63 | 'description': unescapeHTML(more_info['description']), |
64 | 'thumbnail': more_info['promo'], | |
65 | } | |
09825cb5 JMF |
66 | |
67 | def _real_extract(self, url): | |
68 | mobj = re.match(self._VALID_URL, url) | |
69 | embedCode = mobj.group('id') | |
70 | player_url = 'http://player.ooyala.com/player.js?embedCode=%s' % embedCode | |
71 | player = self._download_webpage(player_url, embedCode) | |
72 | mobile_url = self._search_regex(r'mobile_player_url="(.+?)&device="', | |
e24b5a86 | 73 | player, 'mobile player url') |
6f600ff5 S |
74 | # Looks like some videos are only available for particular devices |
75 | # (e.g. http://player.ooyala.com/player.js?embedCode=x1b3lqZDq9y_7kMyC2Op5qo-p077tXD0 | |
76 | # is only available for ipad) | |
77 | # Working around with fetching URLs for all the devices found starting with 'unknown' | |
78 | # until we succeed or eventually fail for each device. | |
79 | devices = re.findall(r'device\s*=\s*"([^"]+)";', player) | |
80 | devices.remove('unknown') | |
81 | devices.insert(0, 'unknown') | |
82 | for device in devices: | |
83 | mobile_player = self._download_webpage( | |
84 | '%s&device=%s' % (mobile_url, device), embedCode, | |
85 | 'Downloading mobile player JS for %s device' % device) | |
86 | videos_info = self._search_regex( | |
87 | r'var streams=window.oo_testEnv\?\[\]:eval\("\((\[{.*?}\])\)"\);', | |
88 | mobile_player, 'info', fatal=False, default=None) | |
89 | if videos_info: | |
90 | break | |
91 | if not videos_info: | |
92 | raise ExtractorError('Unable to extract info') | |
93 | videos_info = videos_info.replace('\\"', '"') | |
94 | videos_more_info = self._search_regex( | |
95 | r'eval\("\(({.*?\\"promo\\".*?})\)"', mobile_player, 'more info').replace('\\"', '"') | |
09825cb5 | 96 | videos_info = json.loads(videos_info) |
6f600ff5 | 97 | videos_more_info = json.loads(videos_more_info) |
09825cb5 JMF |
98 | |
99 | if videos_more_info.get('lineup'): | |
100 | videos = [self._extract_result(info, more_info) for (info, more_info) in zip(videos_info, videos_more_info['lineup'])] | |
e24b5a86 JMF |
101 | return { |
102 | '_type': 'playlist', | |
103 | 'id': embedCode, | |
104 | 'title': unescapeHTML(videos_more_info['title']), | |
105 | 'entries': videos, | |
106 | } | |
09825cb5 JMF |
107 | else: |
108 | return self._extract_result(videos_info[0], videos_more_info) |