Add playlist format extraction.
This commit is contained in:
parent
30d2664c59
commit
93748c89e1
@ -32,7 +32,6 @@ from ..utils import (
|
|||||||
update_url_query,
|
update_url_query,
|
||||||
clean_html,
|
clean_html,
|
||||||
mimetype2ext,
|
mimetype2ext,
|
||||||
url_or_none,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -614,70 +613,68 @@ class BrightcoveNewIE(AdobePassIE):
|
|||||||
title = json_data['name'].strip()
|
title = json_data['name'].strip()
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
# playlistId data starts from `videos`, videoId from `sources`
|
for source in json_data.get('sources', []):
|
||||||
for vid in json_data.get('videos', [json_data]):
|
container = source.get('container')
|
||||||
for source in vid.get('sources', []):
|
ext = mimetype2ext(source.get('type'))
|
||||||
container = source.get('container')
|
src = source.get('src')
|
||||||
ext = mimetype2ext(source.get('type'))
|
# https://support.brightcove.com/playback-api-video-fields-reference#key_systems_object
|
||||||
src = source.get('src')
|
if ext == 'ism' or container == 'WVM' or source.get('key_systems'):
|
||||||
# https://support.brightcove.com/playback-api-video-fields-reference#key_systems_object
|
continue
|
||||||
if ext == 'ism' or container == 'WVM' or source.get('key_systems'):
|
elif ext == 'm3u8' or container == 'M2TS':
|
||||||
|
if not src:
|
||||||
continue
|
continue
|
||||||
elif ext == 'm3u8' or container == 'M2TS':
|
formats.extend(self._extract_m3u8_formats(
|
||||||
if not src:
|
src, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
|
||||||
continue
|
elif ext == 'mpd':
|
||||||
formats.extend(self._extract_m3u8_formats(
|
if not src:
|
||||||
src, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
|
continue
|
||||||
elif ext == 'mpd':
|
formats.extend(self._extract_mpd_formats(src, video_id, 'dash', fatal=False))
|
||||||
if not src:
|
else:
|
||||||
continue
|
streaming_src = source.get('streaming_src')
|
||||||
formats.extend(self._extract_mpd_formats(src, video_id, 'dash', fatal=False))
|
stream_name, app_name = source.get('stream_name'), source.get('app_name')
|
||||||
|
if not src and not streaming_src and (not stream_name or not app_name):
|
||||||
|
continue
|
||||||
|
tbr = float_or_none(source.get('avg_bitrate'), 1000)
|
||||||
|
height = int_or_none(source.get('height'))
|
||||||
|
width = int_or_none(source.get('width'))
|
||||||
|
f = {
|
||||||
|
'tbr': tbr,
|
||||||
|
'filesize': int_or_none(source.get('size')),
|
||||||
|
'container': container,
|
||||||
|
'ext': ext or container.lower(),
|
||||||
|
}
|
||||||
|
if width == 0 and height == 0:
|
||||||
|
f.update({
|
||||||
|
'vcodec': 'none',
|
||||||
|
})
|
||||||
else:
|
else:
|
||||||
streaming_src = source.get('streaming_src')
|
f.update({
|
||||||
stream_name, app_name = source.get('stream_name'), source.get('app_name')
|
'width': width,
|
||||||
if not src and not streaming_src and (not stream_name or not app_name):
|
'height': height,
|
||||||
continue
|
'vcodec': source.get('codec'),
|
||||||
tbr = float_or_none(source.get('avg_bitrate'), 1000)
|
})
|
||||||
height = int_or_none(source.get('height'))
|
|
||||||
width = int_or_none(source.get('width'))
|
|
||||||
f = {
|
|
||||||
'tbr': tbr,
|
|
||||||
'filesize': int_or_none(source.get('size')),
|
|
||||||
'container': container,
|
|
||||||
'ext': ext or container.lower(),
|
|
||||||
}
|
|
||||||
if width == 0 and height == 0:
|
|
||||||
f.update({
|
|
||||||
'vcodec': 'none',
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
f.update({
|
|
||||||
'width': width,
|
|
||||||
'height': height,
|
|
||||||
'vcodec': source.get('codec'),
|
|
||||||
})
|
|
||||||
|
|
||||||
def build_format_id(kind):
|
def build_format_id(kind):
|
||||||
format_id = kind
|
format_id = kind
|
||||||
if tbr:
|
if tbr:
|
||||||
format_id += '-%dk' % int(tbr)
|
format_id += '-%dk' % int(tbr)
|
||||||
if height:
|
if height:
|
||||||
format_id += '-%dp' % height
|
format_id += '-%dp' % height
|
||||||
return format_id
|
return format_id
|
||||||
|
|
||||||
if src or streaming_src:
|
if src or streaming_src:
|
||||||
f.update({
|
f.update({
|
||||||
'url': src or streaming_src,
|
'url': src or streaming_src,
|
||||||
'format_id': build_format_id('http' if src else 'http-streaming'),
|
'format_id': build_format_id('http' if src else 'http-streaming'),
|
||||||
'source_preference': 0 if src else -1,
|
'source_preference': 0 if src else -1,
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
f.update({
|
f.update({
|
||||||
'url': app_name,
|
'url': app_name,
|
||||||
'play_path': stream_name,
|
'play_path': stream_name,
|
||||||
'format_id': build_format_id('rtmp'),
|
'format_id': build_format_id('rtmp'),
|
||||||
})
|
})
|
||||||
formats.append(f)
|
formats.append(f)
|
||||||
if not formats:
|
if not formats:
|
||||||
# for sonyliv.com DRM protected videos
|
# for sonyliv.com DRM protected videos
|
||||||
s3_source_url = json_data.get('custom_fields', {}).get('s3sourceurl')
|
s3_source_url = json_data.get('custom_fields', {}).get('s3sourceurl')
|
||||||
@ -724,6 +721,17 @@ class BrightcoveNewIE(AdobePassIE):
|
|||||||
'is_live': is_live,
|
'is_live': is_live,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _extract_playlist(self, json_data, headers):
|
||||||
|
playlist_id = json_data.get('id')
|
||||||
|
playlist_title = json_data.get('name')
|
||||||
|
playlist_description = json_data.get('description')
|
||||||
|
playlist_vids = json_data.get('videos', [])
|
||||||
|
|
||||||
|
return self.playlist_result(
|
||||||
|
[self._parse_brightcove_metadata(vid, vid.get('id'), headers) for vid in playlist_vids],
|
||||||
|
playlist_id, playlist_title, playlist_description,
|
||||||
|
)
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
url, smuggled_data = unsmuggle_url(url, {})
|
url, smuggled_data = unsmuggle_url(url, {})
|
||||||
self._initialize_geo_bypass({
|
self._initialize_geo_bypass({
|
||||||
@ -787,5 +795,8 @@ class BrightcoveNewIE(AdobePassIE):
|
|||||||
'tveToken': tve_token,
|
'tveToken': tve_token,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if content_type == 'playlist':
|
||||||
|
return self._extract_playlist(json_data, headers)
|
||||||
|
|
||||||
return self._parse_brightcove_metadata(
|
return self._parse_brightcove_metadata(
|
||||||
json_data, video_id, headers=headers)
|
json_data, video_id, headers=headers)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user