Skip to content

Commit

Permalink
[downloader/hls] Simplify and carry long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
dstftw committed Jun 20, 2016
1 parent 1f749b6 commit 8369a4f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions youtube_dl/downloader/hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def can_download(manifest):
# 4. https://tools.ietf.org/html/draft-pantos-http-live-streaming-17#section-4.3.3.5
)
check_results = [not re.search(feature, manifest) for feature in UNSUPPORTED_FEATURES]
check_results.append(not (re.search(r'#EXT-X-KEY:METHOD=AES-128', manifest) and not can_decrypt_frag))
check_results.append(can_decrypt_frag or '#EXT-X-KEY:METHOD=AES-128' not in manifest)
return all(check_results)

def real_download(self, filename, info_dict):
Expand Down Expand Up @@ -102,8 +102,9 @@ def real_download(self, filename, info_dict):
frag_content = down.read()
down.close()
if decrypt_info['METHOD'] == 'AES-128':
iv = decrypt_info.get('IV') or compat_struct_pack(">8xq", media_sequence)
frag_content = AES.new(decrypt_info['KEY'], AES.MODE_CBC, iv).decrypt(frag_content)
iv = decrypt_info.get('IV') or compat_struct_pack('>8xq', media_sequence)
frag_content = AES.new(
decrypt_info['KEY'], AES.MODE_CBC, iv).decrypt(frag_content)
ctx['dest_stream'].write(frag_content)
frags_filenames.append(frag_sanitized)
# We only download the first fragment during the test
Expand All @@ -117,7 +118,8 @@ def real_download(self, filename, info_dict):
if 'IV' in decrypt_info:
decrypt_info['IV'] = binascii.unhexlify(decrypt_info['IV'][2:])
if not re.match(r'^https?://', decrypt_info['URI']):
decrypt_info['URI'] = compat_urlparse.urljoin(man_url, decrypt_info['URI'])
decrypt_info['URI'] = compat_urlparse.urljoin(
man_url, decrypt_info['URI'])
decrypt_info['KEY'] = self.ydl.urlopen(decrypt_info['URI']).read()
elif line.startswith('#EXT-X-MEDIA-SEQUENCE'):
media_sequence = int(line[22:])
Expand Down

0 comments on commit 8369a4f

Please sign in to comment.