This commit is contained in:
jxxghp
2023-06-15 15:11:03 +08:00
parent aeb30b94a6
commit 1d835d68b8
3 changed files with 83 additions and 27 deletions

View File

@ -82,7 +82,7 @@ class SubtitleModule(_ModuleBase):
ret = request.get_res(sublink)
if ret and ret.status_code == 200:
# 创建目录
if not download_dir.exists():
if download_dir.is_dir() and not download_dir.exists():
download_dir.mkdir(parents=True, exist_ok=True)
# 保存ZIP
file_name = TorrentHelper.get_url_filename(ret, sublink)
@ -100,7 +100,10 @@ class SubtitleModule(_ModuleBase):
shutil.unpack_archive(zip_file, zip_path, format='zip')
# 遍历转移文件
for sub_file in SystemUtils.list_files_with_extensions(zip_path, settings.RMT_SUBEXT):
target_sub_file = download_dir / sub_file.name
if download_dir.is_dir():
target_sub_file = download_dir / sub_file.name
else:
target_sub_file = download_dir.with_name(sub_file.name)
if target_sub_file.exists():
logger.info(f"字幕文件已存在:{target_sub_file}")
continue
@ -116,7 +119,10 @@ class SubtitleModule(_ModuleBase):
sub_file = settings.TEMP_PATH / file_name
# 保存
sub_file.write_bytes(ret.content)
target_sub_file = download_dir / sub_file.name
if download_dir.is_dir():
target_sub_file = download_dir / sub_file.name
else:
target_sub_file = download_dir.with_name(sub_file.name)
logger.info(f"转移字幕 {sub_file}{target_sub_file}")
SystemUtils.copy(sub_file, target_sub_file)
else: