From eee81b5b0bd6a288ed174911b98fdee298409b69 Mon Sep 17 00:00:00 2001 From: yuming Date: Wed, 29 Apr 2026 21:59:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E9=98=9F=E5=88=97=E5=BF=AB=E7=85=A7=E4=B8=AD=E5=B7=B2=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E6=95=B0=E4=B8=80=E7=9B=B4=E4=B8=BA0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 切换频道前先等待所有 worker 下载完成,再拍快照, 避免快照时任务还在队列中导致 completed_files 始终为 0。 Co-Authored-By: Claude Sonnet 4.6 --- media_downloader.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/media_downloader.py b/media_downloader.py index e108dc6..9bd874b 100644 --- a/media_downloader.py +++ b/media_downloader.py @@ -705,6 +705,14 @@ async def download_chat_task( update_task_progress(estimated_total=actual_total, is_checking=False) +async def _wait_node_finish(node: TaskNode): + """等待单个频道的所有下载任务完成(含重试中的任务)""" + while True: + if node.need_check and node.finish_task >= node.total_task: + break + await asyncio.sleep(0.5) + + async def download_all_chat(client: pyrogram.Client): """Download All chat""" # Use list() to avoid "dictionary changed size during iteration" error @@ -716,11 +724,11 @@ async def download_all_chat(client: pyrogram.Client): logger.warning(f"Download {key} error: {e}") finally: value.need_check = True - # 所有频道串行跑完后,补一次最后频道的快照;否则末尾那个频道永远只留在 _task_progress - # 里、不会进 _completed_chats,前端会一直显示「🚀 下载中」 - snapshot_current_chat() - # snapshot 只是复制、不会清空 _task_progress,必须 reset 一下,否则前端 h-skip 会把 - # 最后频道的 skipped_files 同时计入 completed_chats 汇总和当前值,造成双计 + # 等当前频道所有下载任务跑完,再拍快照;否则 completed_files 还是 0 + await _wait_node_finish(value.node) + snapshot_current_chat() + reset_task_progress() + # 所有频道都已在循环内快照并重置,此处仅确保最终状态干净 reset_task_progress()