|
@@ -10,28 +10,32 @@ class Aria2Monitor:
|
|
|
self.aria2_api = API(self.aria2_client)
|
|
|
|
|
|
def monitor_and_move_shutil(self, destination_folder, check_interval=10):
|
|
|
- """
|
|
|
- Monitor active downloads and move completed downloads with multiple files to a destination folder.
|
|
|
- """
|
|
|
while True:
|
|
|
downloads = self.aria2_api.get_downloads()
|
|
|
for download in downloads:
|
|
|
if download.is_complete:
|
|
|
+ all_files_moved = True
|
|
|
for file in download.files:
|
|
|
if file.selected:
|
|
|
file_path = file.path
|
|
|
file_name = os.path.basename(file_path)
|
|
|
-
|
|
|
- # 构建目标路径
|
|
|
target_path = os.path.join(destination_folder, file_name)
|
|
|
-
|
|
|
- # 移动文件
|
|
|
- if os.path.exists(file_path):
|
|
|
- shutil.move(file_path, target_path)
|
|
|
- print(f"Moved: {file_path} -> {target_path}")
|
|
|
-
|
|
|
- # 从 Aria2 中移除已完成的下载记录
|
|
|
- download.remove()
|
|
|
+ print(f"Prepare to move: {file_path} -> {target_path}")
|
|
|
+
|
|
|
+ try:
|
|
|
+ if os.path.exists(file_path):
|
|
|
+ shutil.move(file_path, target_path)
|
|
|
+ print(f"Successfully moved: {file_path} -> {target_path}")
|
|
|
+ else:
|
|
|
+ print(f"File not found: {file_path}")
|
|
|
+ all_files_moved = False
|
|
|
+ except Exception as e:
|
|
|
+ print(f"Error moving file: {e}")
|
|
|
+ all_files_moved = False
|
|
|
+
|
|
|
+ # 仅在所有文件都成功移动后删除记录
|
|
|
+ if all_files_moved:
|
|
|
+ download.remove()
|
|
|
|
|
|
time.sleep(check_interval)
|
|
|
|