Skip to content

Commit

Permalink
fix 下载器整理
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Jan 9, 2025
1 parent 13955da commit f32405b
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions app/chain/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,6 @@ def __handle_transfer(self, task: TransferTask,
处理整理任务
"""
try:
# 维护整理任务视图
if not task.background:
self.__put_to_jobview(task)
# 识别
if not task.mediainfo:
mediainfo = None
Expand Down Expand Up @@ -992,9 +989,11 @@ def __is_allow_filesize(_size: int, _min_filesize: int) -> bool:
processed_num = 0
# 失败数量
fail_num = 0

logger.info(f"正在计划整理 {total_num} 个文件...")

# 启动进度
if not background:
# 启动进度
self.progress.start(ProgressKey.FileTransfer)
__process_msg = f"开始整理,共 {total_num} 个文件 ..."
logger.info(__process_msg)
Expand All @@ -1003,6 +1002,7 @@ def __is_allow_filesize(_size: int, _min_filesize: int) -> bool:
key=ProgressKey.FileTransfer)

# 整理所有文件
transfer_tasks: List[TransferTask] = []
for file_item, bluray_dir in file_items:
if global_vars.is_system_stopped:
break
Expand All @@ -1013,6 +1013,7 @@ def __is_allow_filesize(_size: int, _min_filesize: int) -> bool:
or file_item.path.find('/.') != -1 \
or file_item.path.find('/@eaDir') != -1:
logger.debug(f"{file_item.path} 是回收站或隐藏的文件")
fail_num += 1
continue

# 整理屏蔽词不处理
Expand Down Expand Up @@ -1040,14 +1041,6 @@ def __is_allow_filesize(_size: int, _min_filesize: int) -> bool:
fail_num += 1
continue

# 更新进度
if not background:
__process_msg = f"正在整理 ({processed_num + 1}/{total_num}{file_item.name} ..."
logger.info(__process_msg)
self.progress.update(value=processed_num / total_num * 100,
text=__process_msg,
key=ProgressKey.FileTransfer)

if not meta:
# 文件元数据
file_meta = MetaInfoPath(file_path)
Expand Down Expand Up @@ -1112,21 +1105,36 @@ def __is_allow_filesize(_size: int, _min_filesize: int) -> bool:
if background:
self.put_to_queue(task=transfer_task)
logger.info(f"{file_path.name} 已添加到整理队列")
processed_num += 1
else:
# 加入列表
self.__put_to_jobview(transfer_task)
transfer_tasks.append(transfer_task)

# 实时整理
if not background:
for transfer_task in transfer_tasks:
if global_vars.is_system_stopped:
break
# 更新进度
__process_msg = f"正在整理 ({processed_num + fail_num + 1}/{total_num}{transfer_task.fileitem.name} ..."
logger.info(__process_msg)
self.progress.update(value=(processed_num + fail_num) / total_num * 100,
text=__process_msg,
key=ProgressKey.FileTransfer)
state, err_msg = self.__handle_transfer(
task=transfer_task,
callback=self.__default_callback
)
if not state:
all_success = False
logger.warn(f"{file_path.name} {err_msg}")
err_msgs.append(f"{file_path.name} {err_msg}")
logger.warn(f"{transfer_task.fileitem.name} {err_msg}")
err_msgs.append(f"{transfer_task.fileitem.name} {err_msg}")
fail_num += 1
# 完成计数
processed_num += 1
else:
processed_num += 1

# 整理结束
if not background:
# 整理结束
__end_msg = f"整理队列处理完成,共整理 {total_num} 个文件,失败 {fail_num} 个"
logger.info(__end_msg)
self.progress.update(value=100,
Expand Down

0 comments on commit f32405b

Please sign in to comment.