mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-12-22 20:20:09 +09:00
[ooyala] add better fallback values for domain and streams variables
This commit is contained in:
parent
66b4872747
commit
1ed2c4b378
@ -1,12 +1,12 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import base64
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
compat_b64decode,
|
compat_b64decode,
|
||||||
compat_str,
|
compat_str,
|
||||||
compat_urllib_parse_urlencode,
|
|
||||||
)
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
determine_ext,
|
determine_ext,
|
||||||
@ -21,9 +21,9 @@ from ..utils import (
|
|||||||
class OoyalaBaseIE(InfoExtractor):
|
class OoyalaBaseIE(InfoExtractor):
|
||||||
_PLAYER_BASE = 'http://player.ooyala.com/'
|
_PLAYER_BASE = 'http://player.ooyala.com/'
|
||||||
_CONTENT_TREE_BASE = _PLAYER_BASE + 'player_api/v1/content_tree/'
|
_CONTENT_TREE_BASE = _PLAYER_BASE + 'player_api/v1/content_tree/'
|
||||||
_AUTHORIZATION_URL_TEMPLATE = _PLAYER_BASE + 'sas/player_api/v2/authorization/embed_code/%s/%s?'
|
_AUTHORIZATION_URL_TEMPLATE = _PLAYER_BASE + 'sas/player_api/v2/authorization/embed_code/%s/%s'
|
||||||
|
|
||||||
def _extract(self, content_tree_url, video_id, domain='example.org', supportedformats=None, embed_token=None):
|
def _extract(self, content_tree_url, video_id, domain=None, supportedformats=None, embed_token=None):
|
||||||
content_tree = self._download_json(content_tree_url, video_id)['content_tree']
|
content_tree = self._download_json(content_tree_url, video_id)['content_tree']
|
||||||
metadata = content_tree[list(content_tree)[0]]
|
metadata = content_tree[list(content_tree)[0]]
|
||||||
embed_code = metadata['embed_code']
|
embed_code = metadata['embed_code']
|
||||||
@ -31,59 +31,62 @@ class OoyalaBaseIE(InfoExtractor):
|
|||||||
title = metadata['title']
|
title = metadata['title']
|
||||||
|
|
||||||
auth_data = self._download_json(
|
auth_data = self._download_json(
|
||||||
self._AUTHORIZATION_URL_TEMPLATE % (pcode, embed_code)
|
self._AUTHORIZATION_URL_TEMPLATE % (pcode, embed_code),
|
||||||
+ compat_urllib_parse_urlencode({
|
video_id, headers=self.geo_verification_headers(), query={
|
||||||
'domain': domain,
|
'domain': domain or 'player.ooyala.com',
|
||||||
'supportedFormats': supportedformats or 'mp4,rtmp,m3u8,hds,dash,smooth',
|
'supportedFormats': supportedformats or 'mp4,rtmp,m3u8,hds,dash,smooth',
|
||||||
'embedToken': embed_token,
|
'embedToken': embed_token,
|
||||||
}), video_id, headers=self.geo_verification_headers())
|
})['authorization_data'][embed_code]
|
||||||
|
|
||||||
cur_auth_data = auth_data['authorization_data'][embed_code]
|
|
||||||
|
|
||||||
urls = []
|
urls = []
|
||||||
formats = []
|
formats = []
|
||||||
if cur_auth_data['authorized']:
|
streams = auth_data.get('streams') or [{
|
||||||
for stream in cur_auth_data['streams']:
|
'delivery_type': 'hls',
|
||||||
url_data = try_get(stream, lambda x: x['url']['data'], compat_str)
|
'url': {
|
||||||
if not url_data:
|
'data': base64.b64encode(('http://player.ooyala.com/hls/player/all/%s.m3u8' % embed_code).encode()).decode(),
|
||||||
continue
|
}
|
||||||
s_url = compat_b64decode(url_data).decode('utf-8')
|
}]
|
||||||
if not s_url or s_url in urls:
|
for stream in streams:
|
||||||
continue
|
url_data = try_get(stream, lambda x: x['url']['data'], compat_str)
|
||||||
urls.append(s_url)
|
if not url_data:
|
||||||
ext = determine_ext(s_url, None)
|
continue
|
||||||
delivery_type = stream.get('delivery_type')
|
s_url = compat_b64decode(url_data).decode('utf-8')
|
||||||
if delivery_type == 'hls' or ext == 'm3u8':
|
if not s_url or s_url in urls:
|
||||||
formats.extend(self._extract_m3u8_formats(
|
continue
|
||||||
re.sub(r'/ip(?:ad|hone)/', '/all/', s_url), embed_code, 'mp4', 'm3u8_native',
|
urls.append(s_url)
|
||||||
m3u8_id='hls', fatal=False))
|
ext = determine_ext(s_url, None)
|
||||||
elif delivery_type == 'hds' or ext == 'f4m':
|
delivery_type = stream.get('delivery_type')
|
||||||
formats.extend(self._extract_f4m_formats(
|
if delivery_type == 'hls' or ext == 'm3u8':
|
||||||
s_url + '?hdcore=3.7.0', embed_code, f4m_id='hds', fatal=False))
|
formats.extend(self._extract_m3u8_formats(
|
||||||
elif delivery_type == 'dash' or ext == 'mpd':
|
re.sub(r'/ip(?:ad|hone)/', '/all/', s_url), embed_code, 'mp4', 'm3u8_native',
|
||||||
formats.extend(self._extract_mpd_formats(
|
m3u8_id='hls', fatal=False))
|
||||||
s_url, embed_code, mpd_id='dash', fatal=False))
|
elif delivery_type == 'hds' or ext == 'f4m':
|
||||||
elif delivery_type == 'smooth':
|
formats.extend(self._extract_f4m_formats(
|
||||||
self._extract_ism_formats(
|
s_url + '?hdcore=3.7.0', embed_code, f4m_id='hds', fatal=False))
|
||||||
s_url, embed_code, ism_id='mss', fatal=False)
|
elif delivery_type == 'dash' or ext == 'mpd':
|
||||||
elif ext == 'smil':
|
formats.extend(self._extract_mpd_formats(
|
||||||
formats.extend(self._extract_smil_formats(
|
s_url, embed_code, mpd_id='dash', fatal=False))
|
||||||
s_url, embed_code, fatal=False))
|
elif delivery_type == 'smooth':
|
||||||
else:
|
self._extract_ism_formats(
|
||||||
formats.append({
|
s_url, embed_code, ism_id='mss', fatal=False)
|
||||||
'url': s_url,
|
elif ext == 'smil':
|
||||||
'ext': ext or delivery_type,
|
formats.extend(self._extract_smil_formats(
|
||||||
'vcodec': stream.get('video_codec'),
|
s_url, embed_code, fatal=False))
|
||||||
'format_id': delivery_type,
|
else:
|
||||||
'width': int_or_none(stream.get('width')),
|
formats.append({
|
||||||
'height': int_or_none(stream.get('height')),
|
'url': s_url,
|
||||||
'abr': int_or_none(stream.get('audio_bitrate')),
|
'ext': ext or delivery_type,
|
||||||
'vbr': int_or_none(stream.get('video_bitrate')),
|
'vcodec': stream.get('video_codec'),
|
||||||
'fps': float_or_none(stream.get('framerate')),
|
'format_id': delivery_type,
|
||||||
})
|
'width': int_or_none(stream.get('width')),
|
||||||
else:
|
'height': int_or_none(stream.get('height')),
|
||||||
|
'abr': int_or_none(stream.get('audio_bitrate')),
|
||||||
|
'vbr': int_or_none(stream.get('video_bitrate')),
|
||||||
|
'fps': float_or_none(stream.get('framerate')),
|
||||||
|
})
|
||||||
|
if not formats and not auth_data.get('authorized'):
|
||||||
raise ExtractorError('%s said: %s' % (
|
raise ExtractorError('%s said: %s' % (
|
||||||
self.IE_NAME, cur_auth_data['message']), expected=True)
|
self.IE_NAME, auth_data['message']), expected=True)
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
subtitles = {}
|
subtitles = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user