|
@@ -26,6 +26,36 @@ class Aria2FileCopyTask:
|
|
|
if self.thread:
|
|
|
self.thread.join()
|
|
|
|
|
|
+ def copy_new_files(self, src_dir, dest_dir):
|
|
|
+ """复制新文件和目录,如果它们在目标目录中不存在"""
|
|
|
+ if not os.path.exists(dest_dir):
|
|
|
+ os.makedirs(dest_dir)
|
|
|
+ for item in os.listdir(src_dir):
|
|
|
+ src_item = os.path.join(src_dir, item)
|
|
|
+ dest_item = os.path.join(dest_dir, item)
|
|
|
+
|
|
|
+ # 如果是目录
|
|
|
+ if os.path.isdir(src_item):
|
|
|
+ # 检查目标目录是否存在
|
|
|
+ if not os.path.exists(dest_item):
|
|
|
+ # 直接复制整个目录
|
|
|
+ shutil.copytree(src_item, dest_item)
|
|
|
+ logging.info(f"Copied directory from {src_item} to {dest_item}")
|
|
|
+ else:
|
|
|
+ # 如果目标目录已存在,递归处理子目录内容
|
|
|
+ self.copy_new_files(src_item, dest_item)
|
|
|
+ elif not item.endswith('.aria2'): # 检查是否为 .aria2 文件
|
|
|
+ # 如果是文件,且不是 .aria2 文件,则进行复制
|
|
|
+ if not os.path.exists(dest_item):
|
|
|
+ shutil.copy(src_item, dest_item)
|
|
|
+ logging.info(f"Copied file from {src_item} to {dest_item}")
|
|
|
+ # 添加复制完成的提示
|
|
|
+ logging.info(f"Copy complete {dest_item} ")
|
|
|
+ self.nas_sync()
|
|
|
+ logging.info("Completed checking for new files to copy.")
|
|
|
+ else:
|
|
|
+ logging.info(f"File already exists, skipping: {dest_item}")
|
|
|
+
|
|
|
def monitor_aria2_and_move(self):
|
|
|
logging.info("Starting monitoring aria2 is complete and move to " + self.destination_path)
|
|
|
while self.is_running:
|
|
@@ -33,13 +63,15 @@ class Aria2FileCopyTask:
|
|
|
downloads = self.aria2_api.get_downloads()
|
|
|
for download in downloads:
|
|
|
if download.is_complete:
|
|
|
- # 检查下载路径是否存在并且里面是否有文件
|
|
|
- if os.path.exists(self.download_path) and os.listdir(self.download_path):
|
|
|
- # 无论 Aria2 是否有记录,都执行移动操作
|
|
|
- self.move_new_files(self.download_path, self.destination_path)
|
|
|
-
|
|
|
- else:
|
|
|
- logging.info("No new files to move.")
|
|
|
+ # 检查下载的每个文件
|
|
|
+ for file in download.files:
|
|
|
+ if file.selected:
|
|
|
+ filename = os.path.basename(file.path)
|
|
|
+ file_path = os.path.join(self.download_path + '/movie', filename)
|
|
|
+ temp_file = file_path + '.aria2'
|
|
|
+ print(f'temp_file: {temp_file}')
|
|
|
+ if os.path.exists(file_path) and not os.path.exists(temp_file):
|
|
|
+ self.move_new_files(self.download_path, self.destination_path)
|
|
|
|
|
|
time.sleep(10)
|
|
|
|
|
@@ -75,8 +107,8 @@ class Aria2FileCopyTask:
|
|
|
else:
|
|
|
# 如果目标目录已存在,递归处理子目录内容
|
|
|
self.move_new_files(src_item, dest_item)
|
|
|
- else:
|
|
|
- # 如果是文件,处理逻辑与之前相同
|
|
|
+ elif not item.endswith('.aria2'): # 检查是否为 .aria2 文件
|
|
|
+ # 如果是文件,且不是 .aria2 文件,则进行移动
|
|
|
if not os.path.exists(dest_item):
|
|
|
shutil.move(src_item, dest_item)
|
|
|
logging.info(f"Moved file from {src_item} to {dest_item}")
|
|
@@ -86,22 +118,3 @@ class Aria2FileCopyTask:
|
|
|
logging.info("Completed checking for new files to move.")
|
|
|
else:
|
|
|
logging.info(f"File already exists, skipping: {dest_item}")
|
|
|
-
|
|
|
- def copy_new_files(self, src_dir, dest_dir):
|
|
|
- """复制新文件,如果它们在目标目录中不存在"""
|
|
|
- if not os.path.exists(dest_dir):
|
|
|
- os.makedirs(dest_dir)
|
|
|
- for item in os.listdir(src_dir):
|
|
|
- src_item = os.path.join(src_dir, item)
|
|
|
- dest_item = os.path.join(dest_dir, item)
|
|
|
-
|
|
|
- if os.path.isdir(src_item):
|
|
|
- # 如果是目录,则递归复制
|
|
|
- self.copy_new_files(src_item, dest_item)
|
|
|
- else:
|
|
|
- # 如果是文件,则检查目标文件是否存在
|
|
|
- if not os.path.exists(dest_item):
|
|
|
- shutil.copy(src_item, dest_item)
|
|
|
- logging.info(f"Copied new file from {src_item} to {dest_item}")
|
|
|
- else:
|
|
|
- logging.info(f"File already exists, skipping: {dest_item}")
|