Skip to content

Commit

Permalink
[vzaar] override AES decryption key URL(closes #17521)
Browse files Browse the repository at this point in the history
  • Loading branch information
remitamine committed Dec 3, 2019
1 parent 6797de7 commit c712b16
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions youtube_dl/downloader/hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def real_download(self, filename, info_dict):
s = urlh.read().decode('utf-8', 'ignore')

if not self.can_download(s, info_dict):
if info_dict.get('extra_param_to_segment_url'):
if info_dict.get('extra_param_to_segment_url') or info_dict.get('_decryption_key_url'):
self.report_error('pycrypto not found. Please install it.')
return False
self.report_warning(
Expand Down Expand Up @@ -169,7 +169,7 @@ def is_ad_fragment_end(s):
if decrypt_info['METHOD'] == 'AES-128':
iv = decrypt_info.get('IV') or compat_struct_pack('>8xq', media_sequence)
decrypt_info['KEY'] = decrypt_info.get('KEY') or self.ydl.urlopen(
self._prepare_url(info_dict, decrypt_info['URI'])).read()
self._prepare_url(info_dict, info_dict.get('_decryption_key_url') or decrypt_info['URI'])).read()
frag_content = AES.new(
decrypt_info['KEY'], AES.MODE_CBC, iv).decrypt(frag_content)
self._append_fragment(ctx, frag_content)
Expand Down
15 changes: 9 additions & 6 deletions youtube_dl/extractor/vzaar.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ def _real_extract(self, url):
usp = video_data.get('usp')
if video_data.get('uspEnabled') and isinstance(video_guid, compat_str) and isinstance(usp, dict):
hls_aes = video_data.get('hlsAes')
m3u8_url = ('http://fable.vzaar.com/v5/usp%s/%s/%s.ism/.m3u8?'
% ('aes' if hls_aes else '', video_guid, video_id)) + '&'.join(
'%s=%s' % (k, v) for k, v in usp.items())
formats.extend(self._extract_m3u8_formats(
m3u8_url, video_id, 'mp4', 'm3u8' if hls_aes else 'm3u8_native',
m3u8_id='hls', fatal=False))
qs = '&'.join('%s=%s' % (k, v) for k, v in usp.items())
url_templ = 'http://%%s.vzaar.com/v5/usp%s/%s/%s.ism%%s?' % ('aes' if hls_aes else '', video_guid, video_id)
m3u8_formats = self._extract_m3u8_formats(
url_templ % ('fable', '/.m3u8') + qs, video_id, 'mp4', 'm3u8_native',
m3u8_id='hls', fatal=False)
if hls_aes:
for f in m3u8_formats:
f['_decryption_key_url'] = url_templ % ('goose', '') + qs

This comment has been minimized.

Copy link
@dstftw

dstftw Dec 15, 2019

Collaborator

New options should be passed in downloader_options. Also downloader option should be documented.

This comment has been minimized.

Copy link
@remitamine

remitamine Dec 15, 2019

Author Collaborator

the param is meant as temporary internal variable similar to _seekable used in TurnerBaseIE and the _download_params used by _parse_ism_formats.

This comment has been minimized.

Copy link
@dstftw

dstftw Dec 15, 2019

Collaborator

This should not be internal as it's not the first time key URL needs to be overridden. This is potentially a common need similar to extra_param_to_segment_url.

This comment has been minimized.

Copy link
@remitamine

remitamine Dec 15, 2019

Author Collaborator

I don't think it's a good idea to introduce the option now(with only one example and there might be a need in the future for a templated key url), it the first time I see a need to override the key URL, if this has to exposed it would be better to add it as part of a collection of key-related params, the other cases that I saw before was cases that need special query(sproutvideo), cookies(vdocipher), raw key(deezer), etc...
and I don't see a need to expose this to the user from the beginning.

formats.extend(m3u8_formats)

self._sort_formats(formats)

Expand Down

0 comments on commit c712b16

Please sign in to comment.