Add playlist support to BrightcoveNewIE.

This commit is contained in:
Kyle 2019-06-08 09:11:22 +09:00
parent 695720ebe8
commit 30d2664c59

View File

@ -32,6 +32,7 @@ from ..utils import (
update_url_query, update_url_query,
clean_html, clean_html,
mimetype2ext, mimetype2ext,
url_or_none,
) )
@ -483,7 +484,7 @@ class BrightcoveLegacyIE(InfoExtractor):
class BrightcoveNewIE(AdobePassIE): class BrightcoveNewIE(AdobePassIE):
IE_NAME = 'brightcove:new' IE_NAME = 'brightcove:new'
_VALID_URL = r'https?://players\.brightcove\.net/(?P<account_id>\d+)/(?P<player_id>[^/]+)_(?P<embed>[^/]+)/index\.html\?.*videoId=(?P<video_id>\d+|ref:[^&]+)' _VALID_URL = r'https?://players\.brightcove\.net/(?P<account_id>\d+)/(?P<player_id>[^/]+)_(?P<embed>[^/]+)/index\.html\?.*(?P<content_type>video|playlist)Id=(?P<video_id>\d+|ref:[^&]+)'
_TESTS = [{ _TESTS = [{
'url': 'http://players.brightcove.net/929656772001/e41d32dc-ec74-459e-a845-6c69f7b724ea_default/index.html?videoId=4463358922001', 'url': 'http://players.brightcove.net/929656772001/e41d32dc-ec74-459e-a845-6c69f7b724ea_default/index.html?videoId=4463358922001',
'md5': 'c8100925723840d4b0d243f7025703be', 'md5': 'c8100925723840d4b0d243f7025703be',
@ -516,6 +517,19 @@ class BrightcoveNewIE(AdobePassIE):
# m3u8 download # m3u8 download
'skip_download': True, 'skip_download': True,
} }
}, {
# playlist streams
'url': 'http://players.brightcove.net/5690807595001/HyZNerRl7_default/index.html?playlistId=5743160747001',
'info_dict': {
'id': '5743160747001',
'ext': 'mp4',
'title': 'prod ntv',
'uploader_id': '5690807595001',
},
'params': {
# m3u8 download
'skip_download': True,
}
}, { }, {
# ref: prefixed video id # ref: prefixed video id
'url': 'http://players.brightcove.net/3910869709001/21519b5c-4b3b-4363-accb-bdc8f358f823_default/index.html?videoId=ref:7069442', 'url': 'http://players.brightcove.net/3910869709001/21519b5c-4b3b-4363-accb-bdc8f358f823_default/index.html?videoId=ref:7069442',
@ -600,68 +614,70 @@ class BrightcoveNewIE(AdobePassIE):
title = json_data['name'].strip() title = json_data['name'].strip()
formats = [] formats = []
for source in json_data.get('sources', []): # playlistId data starts from `videos`, videoId from `sources`
container = source.get('container') for vid in json_data.get('videos', [json_data]):
ext = mimetype2ext(source.get('type')) for source in vid.get('sources', []):
src = source.get('src') container = source.get('container')
# https://support.brightcove.com/playback-api-video-fields-reference#key_systems_object ext = mimetype2ext(source.get('type'))
if ext == 'ism' or container == 'WVM' or source.get('key_systems'): src = source.get('src')
continue # https://support.brightcove.com/playback-api-video-fields-reference#key_systems_object
elif ext == 'm3u8' or container == 'M2TS': if ext == 'ism' or container == 'WVM' or source.get('key_systems'):
if not src:
continue continue
formats.extend(self._extract_m3u8_formats( elif ext == 'm3u8' or container == 'M2TS':
src, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)) if not src:
elif ext == 'mpd': continue
if not src: formats.extend(self._extract_m3u8_formats(
continue src, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
formats.extend(self._extract_mpd_formats(src, video_id, 'dash', fatal=False)) elif ext == 'mpd':
else: if not src:
streaming_src = source.get('streaming_src') continue
stream_name, app_name = source.get('stream_name'), source.get('app_name') formats.extend(self._extract_mpd_formats(src, video_id, 'dash', fatal=False))
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:
f.update({ streaming_src = source.get('streaming_src')
'width': width, stream_name, app_name = source.get('stream_name'), source.get('app_name')
'height': height, if not src and not streaming_src and (not stream_name or not app_name):
'vcodec': source.get('codec'), 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:
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')
@ -715,7 +731,7 @@ class BrightcoveNewIE(AdobePassIE):
'ip_blocks': smuggled_data.get('geo_ip_blocks'), 'ip_blocks': smuggled_data.get('geo_ip_blocks'),
}) })
account_id, player_id, embed, video_id = re.match(self._VALID_URL, url).groups() account_id, player_id, embed, content_type, video_id = re.match(self._VALID_URL, url).groups()
webpage = self._download_webpage( webpage = self._download_webpage(
'http://players.brightcove.net/%s/%s_%s/index.min.js' 'http://players.brightcove.net/%s/%s_%s/index.min.js'
@ -736,7 +752,7 @@ class BrightcoveNewIE(AdobePassIE):
r'policyKey\s*:\s*(["\'])(?P<pk>.+?)\1', r'policyKey\s*:\s*(["\'])(?P<pk>.+?)\1',
webpage, 'policy key', group='pk') webpage, 'policy key', group='pk')
api_url = 'https://edge.api.brightcove.com/playback/v1/accounts/%s/videos/%s' % (account_id, video_id) api_url = 'https://edge.api.brightcove.com/playback/v1/accounts/%s/%ss/%s' % (account_id, content_type, video_id)
headers = { headers = {
'Accept': 'application/json;pk=%s' % policy_key, 'Accept': 'application/json;pk=%s' % policy_key,
} }