#72 Fix issue with unicode filenames in aria2c (Closes #71)

Authored-by: shirtjs <2660574+shirtjs@users.noreply.github.com> (shirt-dev)
This commit is contained in:
shirt-dev 2021-02-10 15:57:18 -05:00 committed by GitHub
parent fb198a8a9c
commit 539d158c50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,6 @@
import subprocess import subprocess
import sys import sys
import time import time
import shutil
try: try:
from Crypto.Cipher import AES from Crypto.Cipher import AES
@ -32,6 +31,7 @@
is_outdated_version, is_outdated_version,
process_communicate_or_kill, process_communicate_or_kill,
sanitized_Request, sanitized_Request,
sanitize_open,
) )
@ -126,23 +126,27 @@ def _call_downloader(self, tmpfilename, info_dict):
for [i, url] in enumerate(info_dict['url_list']): for [i, url] in enumerate(info_dict['url_list']):
tmpsegmentname = '%s_%s.frag' % (tmpfilename, i) tmpsegmentname = '%s_%s.frag' % (tmpfilename, i)
file_list.append(tmpsegmentname) file_list.append(tmpsegmentname)
with open(tmpfilename, 'wb') as dest: dest, _ = sanitize_open(tmpfilename, 'wb')
for i in file_list: for i in file_list:
if 'decrypt_info' in info_dict: src, _ = sanitize_open(i, 'rb')
decrypt_info = info_dict['decrypt_info'] if 'decrypt_info' in info_dict:
with open(i, 'rb') as src: decrypt_info = info_dict['decrypt_info']
if decrypt_info['METHOD'] == 'AES-128': if decrypt_info['METHOD'] == 'AES-128':
iv = decrypt_info.get('IV') iv = decrypt_info.get('IV')
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()
encrypted_data = src.read() encrypted_data = src.read()
decrypted_data = AES.new( decrypted_data = AES.new(
decrypt_info['KEY'], AES.MODE_CBC, iv).decrypt(encrypted_data) decrypt_info['KEY'], AES.MODE_CBC, iv).decrypt(encrypted_data)
dest.write(decrypted_data) dest.write(decrypted_data)
else:
shutil.copyfileobj(open(i, 'rb'), dest)
else: else:
shutil.copyfileobj(open(i, 'rb'), dest) fragment_data = src.read()
dest.write(fragment_data)
else:
fragment_data = src.read()
dest.write(fragment_data)
src.close()
dest.close()
if not self.params.get('keep_fragments', False): if not self.params.get('keep_fragments', False):
for file_path in file_list: for file_path in file_list:
try: try:
@ -263,8 +267,9 @@ def _make_cmd(self, tmpfilename, info_dict):
for [i, url] in enumerate(info_dict['url_list']): for [i, url] in enumerate(info_dict['url_list']):
tmpsegmentname = '%s_%s.frag' % (os.path.basename(tmpfilename), i) tmpsegmentname = '%s_%s.frag' % (os.path.basename(tmpfilename), i)
url_list.append('%s\n\tout=%s' % (url, tmpsegmentname)) url_list.append('%s\n\tout=%s' % (url, tmpsegmentname))
with open(url_list_file, 'w') as f: stream, _ = sanitize_open(url_list_file, 'wb')
f.write('\n'.join(url_list)) stream.write('\n'.join(url_list).encode('utf-8'))
stream.close()
cmd += ['-i', url_list_file] cmd += ['-i', url_list_file]
else: else: