[sproutvideo] Fix extractor
This commit is contained in:
parent
662087e491
commit
36071a8d06
@ -43,9 +43,6 @@ def get_suitable_downloader(info_dict, params={}):
|
|||||||
if ed.can_download(info_dict):
|
if ed.can_download(info_dict):
|
||||||
return ed
|
return ed
|
||||||
|
|
||||||
if info_dict.get('force_hlsdl') is True:
|
|
||||||
return HlsFD
|
|
||||||
|
|
||||||
if protocol.startswith('m3u8') and info_dict.get('is_live'):
|
if protocol.startswith('m3u8') and info_dict.get('is_live'):
|
||||||
return FFmpegFD
|
return FFmpegFD
|
||||||
|
|
||||||
|
@ -121,8 +121,6 @@ class FragmentFD(FileDownloader):
|
|||||||
del ctx['fragment_filename_sanitized']
|
del ctx['fragment_filename_sanitized']
|
||||||
|
|
||||||
def _prepare_frag_download(self, ctx):
|
def _prepare_frag_download(self, ctx):
|
||||||
if 'hls' not in ctx:
|
|
||||||
ctx['hls'] = False
|
|
||||||
if 'live' not in ctx:
|
if 'live' not in ctx:
|
||||||
ctx['live'] = False
|
ctx['live'] = False
|
||||||
if not ctx['live']:
|
if not ctx['live']:
|
||||||
@ -145,7 +143,6 @@ class FragmentFD(FileDownloader):
|
|||||||
'retries': self.params.get('retries', 0),
|
'retries': self.params.get('retries', 0),
|
||||||
'nopart': self.params.get('nopart', False),
|
'nopart': self.params.get('nopart', False),
|
||||||
'test': self.params.get('test', False),
|
'test': self.params.get('test', False),
|
||||||
'hls': ctx['hls'],
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
tmpfilename = self.temp_name(ctx['filename'])
|
tmpfilename = self.temp_name(ctx['filename'])
|
||||||
|
@ -105,7 +105,6 @@ class HlsFD(FragmentFD):
|
|||||||
'filename': filename,
|
'filename': filename,
|
||||||
'total_frags': media_frags,
|
'total_frags': media_frags,
|
||||||
'ad_frags': ad_frags,
|
'ad_frags': ad_frags,
|
||||||
'hls': '#EXT-X-KEY:METHOD=AES-128' in s,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self._prepare_and_start_frag_download(ctx)
|
self._prepare_and_start_frag_download(ctx)
|
||||||
@ -176,8 +175,10 @@ class HlsFD(FragmentFD):
|
|||||||
iv = decrypt_info.get('IV') or compat_struct_pack('>8xq', media_sequence)
|
iv = decrypt_info.get('IV') or compat_struct_pack('>8xq', media_sequence)
|
||||||
decrypt_info['KEY'] = decrypt_info.get('KEY') or self.ydl.urlopen(
|
decrypt_info['KEY'] = decrypt_info.get('KEY') or self.ydl.urlopen(
|
||||||
self._prepare_url(info_dict, info_dict.get('_decryption_key_url') or decrypt_info['URI'])).read()
|
self._prepare_url(info_dict, info_dict.get('_decryption_key_url') or decrypt_info['URI'])).read()
|
||||||
frag_content = AES.new(
|
# We don't decrypt fragments during the test
|
||||||
decrypt_info['KEY'], AES.MODE_CBC, iv).decrypt(frag_content)
|
if not test:
|
||||||
|
frag_content = AES.new(
|
||||||
|
decrypt_info['KEY'], AES.MODE_CBC, iv).decrypt(frag_content)
|
||||||
self._append_fragment(ctx, frag_content)
|
self._append_fragment(ctx, frag_content)
|
||||||
# We only download the first fragment during the test
|
# We only download the first fragment during the test
|
||||||
if test:
|
if test:
|
||||||
|
@ -45,8 +45,7 @@ class HttpFD(FileDownloader):
|
|||||||
headers.update(add_headers)
|
headers.update(add_headers)
|
||||||
|
|
||||||
is_test = self.params.get('test', False)
|
is_test = self.params.get('test', False)
|
||||||
is_hls = self.params.get('hls', False)
|
chunk_size = self._TEST_FILE_SIZE if is_test else (
|
||||||
chunk_size = self._TEST_FILE_SIZE if is_test and not is_hls else (
|
|
||||||
info_dict.get('downloader_options', {}).get('http_chunk_size')
|
info_dict.get('downloader_options', {}).get('http_chunk_size')
|
||||||
or self.params.get('http_chunk_size') or 0)
|
or self.params.get('http_chunk_size') or 0)
|
||||||
|
|
||||||
@ -195,8 +194,7 @@ class HttpFD(FileDownloader):
|
|||||||
# However, for a test we still would like to download just a piece of a file.
|
# However, for a test we still would like to download just a piece of a file.
|
||||||
# To achieve this we limit data_len to _TEST_FILE_SIZE and manually control
|
# To achieve this we limit data_len to _TEST_FILE_SIZE and manually control
|
||||||
# block size when downloading a file.
|
# block size when downloading a file.
|
||||||
# If we are using HLS we cannot cut the fragment because it will break the decryption.
|
if is_test and (data_len is None or int(data_len) > self._TEST_FILE_SIZE):
|
||||||
if is_test and not is_hls and (data_len is None or int(data_len) > self._TEST_FILE_SIZE):
|
|
||||||
data_len = self._TEST_FILE_SIZE
|
data_len = self._TEST_FILE_SIZE
|
||||||
|
|
||||||
if data_len is not None:
|
if data_len is not None:
|
||||||
|
@ -12,10 +12,11 @@ from ..compat import (
|
|||||||
|
|
||||||
|
|
||||||
class SproutVideoIE(InfoExtractor):
|
class SproutVideoIE(InfoExtractor):
|
||||||
_VALID_URL = r'(?:https?:|)//videos.sproutvideo.com/embed/(?P<id>[a-f0-9]+)/[a-f0-9]+\??.*'
|
_NOSCHEMA_URL = r'//videos.sproutvideo.com/embed/(?P<id>[a-f0-9]+)/[a-f0-9]+'
|
||||||
|
_VALID_URL = r'https?:%s' % _NOSCHEMA_URL
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'https://videos.sproutvideo.com/embed/4c9dddb01910e3c9c4/0fc24387c4f24ee3',
|
'url': 'https://videos.sproutvideo.com/embed/4c9dddb01910e3c9c4/0fc24387c4f24ee3',
|
||||||
'md5': '1343ce1a6cb39d67889bfa07c7b02b0e',
|
'md5': 'fbc675bb97437e797d11d14d99563f50',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '4c9dddb01910e3c9c4',
|
'id': '4c9dddb01910e3c9c4',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
@ -26,9 +27,14 @@ class SproutVideoIE(InfoExtractor):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _extract_url(webpage):
|
def _extract_url(webpage):
|
||||||
sproutvideo = re.search(
|
sproutvideo = re.search(
|
||||||
r'(?:<iframe\s+class=[\'\"]sproutvideo-player.*src|href)=[\'\"](?P<url>%s)[\'\"]' % SproutVideoIE._VALID_URL, webpage)
|
r'(?:<iframe\s+class=[\'\"]sproutvideo-player.*src|href)=[\'\"](?P<url>(?:https?:|)%s[^\'\"]+)[\'\"]' % SproutVideoIE._NOSCHEMA_URL, webpage)
|
||||||
if sproutvideo:
|
if sproutvideo:
|
||||||
return sproutvideo.group('url')
|
video_url = sproutvideo.group('url')
|
||||||
|
# Fix the video URL if the iframe doesn't have a defined schema
|
||||||
|
if video_url[:2] == '//':
|
||||||
|
video_url = 'https:' + video_url
|
||||||
|
return video_url
|
||||||
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
@ -42,30 +48,31 @@ class SproutVideoIE(InfoExtractor):
|
|||||||
# signature->m for manifests
|
# signature->m for manifests
|
||||||
# signature->k for keys
|
# signature->k for keys
|
||||||
# signature->t for segments
|
# signature->t for segments
|
||||||
m_sig = self._policy_to_qs(parsed_data, 'm')
|
m_sign = self._policy_to_qs(parsed_data, 'm')
|
||||||
k_sig = self._policy_to_qs(parsed_data, 'k')
|
k_sign = self._policy_to_qs(parsed_data, 'k')
|
||||||
t_sig = self._policy_to_qs(parsed_data, 't')
|
t_sign = self._policy_to_qs(parsed_data, 't')
|
||||||
|
|
||||||
url = "https://{0}.videos.sproutvideo.com/{1}/{2}/video/index.m3u8?{3}"
|
resource_url = 'https://{0}.videos.sproutvideo.com/{1}/{2}/video/index.m3u8?{3}'
|
||||||
url = url.format(parsed_data['base'],
|
resource_url = resource_url.format(parsed_data['base'],
|
||||||
parsed_data['s3_user_hash'],
|
parsed_data['s3_user_hash'],
|
||||||
parsed_data['s3_video_hash'],
|
parsed_data['s3_video_hash'],
|
||||||
m_sig)
|
m_sign)
|
||||||
|
|
||||||
formats = self._extract_m3u8_formats(url, video_id, 'mp4', 'm3u8_native',
|
formats = self._extract_m3u8_formats(resource_url, video_id, 'mp4', entry_protocol='m3u8_native',
|
||||||
m3u8_id='hls', fatal=False)
|
m3u8_id='hls', fatal=False)
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
for i in range(len(formats)):
|
for entry in formats:
|
||||||
formats[i]['url'] = "{}?{}".format(formats[i]['url'], m_sig)
|
entry.update({
|
||||||
|
'url': '{0}?{1}'.format(entry['url'], m_sign),
|
||||||
|
'extra_param_to_segment_url': t_sign,
|
||||||
|
'extra_param_to_key_url': k_sign,
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': parsed_data['title'],
|
'title': parsed_data['title'],
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'force_hlsdl': True, # currently FFmpeg is not supported
|
|
||||||
'extra_param_to_segment_url': t_sig,
|
|
||||||
'extra_param_to_key_url': k_sig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def _format_qsdata(self, qs_data):
|
def _format_qsdata(self, qs_data):
|
||||||
@ -75,6 +82,6 @@ class SproutVideoIE(InfoExtractor):
|
|||||||
return parsed_dict
|
return parsed_dict
|
||||||
|
|
||||||
def _policy_to_qs(self, policy, key):
|
def _policy_to_qs(self, policy, key):
|
||||||
sig = self._format_qsdata(policy['signatures'][key])
|
sign = self._format_qsdata(policy['signatures'][key])
|
||||||
sig['sessionID'] = policy['sessionID']
|
sign['sessionID'] = policy['sessionID']
|
||||||
return compat_urllib_parse_urlencode(sig, doseq=True)
|
return compat_urllib_parse_urlencode(sign, doseq=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user