1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
20 class OoyalaBaseIE(InfoExtractor
):
21 _PLAYER_BASE
= 'http://player.ooyala.com/'
22 _CONTENT_TREE_BASE
= _PLAYER_BASE
+ 'player_api/v1/content_tree/'
23 _AUTHORIZATION_URL_TEMPLATE
= _PLAYER_BASE
+ 'sas/player_api/v2/authorization/embed_code/%s/%s'
25 def _extract(self
, content_tree_url
, video_id
, domain
=None, supportedformats
=None, embed_token
=None):
26 content_tree
= self
._download
_json
(content_tree_url
, video_id
)['content_tree']
27 metadata
= content_tree
[list(content_tree
)[0]]
28 embed_code
= metadata
['embed_code']
29 pcode
= metadata
.get('asset_pcode') or embed_code
30 title
= metadata
['title']
32 auth_data
= self
._download
_json
(
33 self
._AUTHORIZATION
_URL
_TEMPLATE
% (pcode
, embed_code
),
34 video_id
, headers
=self
.geo_verification_headers(), query
={
35 'domain': domain
or 'player.ooyala.com',
36 'supportedFormats': supportedformats
or 'mp4,rtmp,m3u8,hds,dash,smooth',
37 'embedToken': embed_token
,
38 })['authorization_data'][embed_code
]
42 streams
= auth_data
.get('streams') or [{
43 'delivery_type': 'hls',
45 'data': base64
.b64encode(('http://player.ooyala.com/hls/player/all/%s.m3u8' % embed_code
).encode()).decode(),
48 for stream
in streams
:
49 url_data
= try_get(stream
, lambda x
: x
['url']['data'], compat_str
)
52 s_url
= compat_b64decode(url_data
).decode('utf-8')
53 if not s_url
or s_url
in urls
:
56 ext
= determine_ext(s_url
, None)
57 delivery_type
= stream
.get('delivery_type')
58 if delivery_type
== 'hls' or ext
== 'm3u8':
59 formats
.extend(self
._extract
_m
3u8_formats
(
60 re
.sub(r
'/ip(?:ad|hone)/', '/all/', s_url
), embed_code
, 'mp4', 'm3u8_native',
61 m3u8_id
='hls', fatal
=False))
62 elif delivery_type
== 'hds' or ext
== 'f4m':
63 formats
.extend(self
._extract
_f
4m
_formats
(
64 s_url
+ '?hdcore=3.7.0', embed_code
, f4m_id
='hds', fatal
=False))
65 elif delivery_type
== 'dash' or ext
== 'mpd':
66 formats
.extend(self
._extract
_mpd
_formats
(
67 s_url
, embed_code
, mpd_id
='dash', fatal
=False))
68 elif delivery_type
== 'smooth':
69 self
._extract
_ism
_formats
(
70 s_url
, embed_code
, ism_id
='mss', fatal
=False)
72 formats
.extend(self
._extract
_smil
_formats
(
73 s_url
, embed_code
, fatal
=False))
77 'ext': ext
or delivery_type
,
78 'vcodec': stream
.get('video_codec'),
79 'format_id': delivery_type
,
80 'width': int_or_none(stream
.get('width')),
81 'height': int_or_none(stream
.get('height')),
82 'abr': int_or_none(stream
.get('audio_bitrate')),
83 'vbr': int_or_none(stream
.get('video_bitrate')),
84 'fps': float_or_none(stream
.get('framerate')),
86 if not formats
and not auth_data
.get('authorized'):
87 self
.raise_no_formats('%s said: %s' % (
88 self
.IE_NAME
, auth_data
['message']), expected
=True)
89 self
._sort
_formats
(formats
)
92 for lang
, sub
in metadata
.get('closed_captions_vtt', {}).get('captions', {}
).items():
93 sub_url
= sub
.get('url')
103 'description': metadata
.get('description'),
104 'thumbnail': metadata
.get('thumbnail_image') or metadata
.get('promo_image'),
105 'duration': float_or_none(metadata
.get('duration'), 1000),
106 'subtitles': subtitles
,
111 class OoyalaIE(OoyalaBaseIE
):
112 _VALID_URL
= r
'(?:ooyala:|https?://.+?\.ooyala\.com/.*?(?:embedCode|ec)=)(?P<id>.+?)(&|$)'
116 # From http://it.slashdot.org/story/13/04/25/178216/recovering-data-from-broken-hard-drives-and-ssds-video
117 'url': 'http://player.ooyala.com/player.js?embedCode=pxczE2YjpfHfn1f3M-ykG_AmJRRn0PD8',
119 'id': 'pxczE2YjpfHfn1f3M-ykG_AmJRRn0PD8',
121 'title': 'Explaining Data Recovery from Hard Drives and SSDs',
122 'description': 'How badly damaged does a drive have to be to defeat Russell and his crew? Apparently, smashed to bits.',
125 # The video in the original webpage now uses PlayWire
126 'skip': 'Ooyala said: movie expired',
128 # Only available for ipad
129 'url': 'http://player.ooyala.com/player.js?embedCode=x1b3lqZDq9y_7kMyC2Op5qo-p077tXD0',
131 'id': 'x1b3lqZDq9y_7kMyC2Op5qo-p077tXD0',
133 'title': 'Simulation Overview - Levels of Simulation',
138 # Information available only through SAS api
139 # From http://community.plm.automation.siemens.com/t5/News-NX-Manufacturing/Tool-Path-Divide/ba-p/4187
140 'url': 'http://player.ooyala.com/player.js?embedCode=FiOG81ZTrvckcchQxmalf4aQj590qTEx',
141 'md5': 'a84001441b35ea492bc03736e59e7935',
143 'id': 'FiOG81ZTrvckcchQxmalf4aQj590qTEx',
145 'title': 'Divide Tool Path.mp4',
150 # empty stream['url']['data']
151 'url': 'http://player.ooyala.com/player.js?embedCode=w2bnZtYjE6axZ_dw1Cd0hQtXd_ige2Is',
152 'only_matching': True,
157 def _url_for_embed_code(embed_code
):
158 return 'http://player.ooyala.com/player.js?embedCode=%s' % embed_code
161 def _build_url_result(cls
, embed_code
):
162 return cls
.url_result(cls
._url
_for
_embed
_code
(embed_code
),
165 def _real_extract(self
, url
):
166 url
, smuggled_data
= unsmuggle_url(url
, {})
167 embed_code
= self
._match
_id
(url
)
168 domain
= smuggled_data
.get('domain')
169 supportedformats
= smuggled_data
.get('supportedformats')
170 embed_token
= smuggled_data
.get('embed_token')
171 content_tree_url
= self
._CONTENT
_TREE
_BASE
+ 'embed_code/%s/%s' % (embed_code
, embed_code
)
172 return self
._extract
(content_tree_url
, embed_code
, domain
, supportedformats
, embed_token
)
175 class OoyalaExternalIE(OoyalaBaseIE
):
176 _VALID_URL
= r
'''(?x)
179 https?://.+?\.ooyala\.com/.*?\bexternalId=
181 (?P<partner_id>[^:]+)
193 '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',
195 'id': 'FkYWtmazr6Ed8xmvILvKLWjd4QvYZpzG',
197 'title': 'dm_140128_30for30Shorts___JudgingJewellv2',
202 'skip_download': True,
206 def _real_extract(self
, url
):
207 partner_id
, video_id
, pcode
= self
._match
_valid
_url
(url
).groups()
208 content_tree_url
= self
._CONTENT
_TREE
_BASE
+ 'external_id/%s/%s:%s' % (pcode
, partner_id
, video_id
)
209 return self
._extract
(content_tree_url
, video_id
)