|
@@ -84,34 +84,46 @@ class AlistAPI:
|
|
|
response = requests.post(f"{self.url}/fs/move", data=payload, headers=self.headers)
|
|
|
return response.json()
|
|
|
|
|
|
- def download_directory(self, path, download_path):
|
|
|
- file_list = self.list_directory(path)
|
|
|
+ def download_directory(self, remote_path, local_base_path, current_sub_path=''):
|
|
|
+ file_list = self.list_directory(remote_path)
|
|
|
if not file_list:
|
|
|
return
|
|
|
for file_info in file_list['data']['content']:
|
|
|
+ # 检查是否是目录
|
|
|
if file_info['is_dir']:
|
|
|
- self.download_directory(path + "/" + file_info['name'], download_path)
|
|
|
+ # 构建新的子路径
|
|
|
+ new_sub_path = os.path.join(current_sub_path, file_info['name'])
|
|
|
+ # 递归下载该目录
|
|
|
+ self.download_directory(remote_path + "/" + file_info['name'], local_base_path, new_sub_path)
|
|
|
else:
|
|
|
- file_download_url = self.url + "/d" + path + "/" + file_info['name']
|
|
|
+ file_download_url = self.url + "/d" + remote_path + "/" + file_info['name']
|
|
|
sign = file_info.get('sign')
|
|
|
if sign:
|
|
|
file_download_url += "?sign=" + sign
|
|
|
+ # 构建完整的本地下载路径
|
|
|
+ download_path = os.path.join(local_base_path, current_sub_path.lstrip('/'))
|
|
|
self.aria2_api.add_uris([file_download_url], options={"dir": download_path})
|
|
|
|
|
|
- def debug_directory(self, path, download_path):
|
|
|
- file_list = self.list_directory(path)
|
|
|
+ def debug_directory(self, remote_path, local_base_path, current_sub_path=''):
|
|
|
+ file_list = self.list_directory(remote_path)
|
|
|
if not file_list:
|
|
|
return
|
|
|
for file_info in file_list['data']['content']:
|
|
|
+ # 检查是否是目录
|
|
|
if file_info['is_dir']:
|
|
|
- print(f"Directory: {path}/{file_info['name']}")
|
|
|
- self.debug_directory(path + "/" + file_info['name'], download_path)
|
|
|
+ # 构建新的子路径
|
|
|
+ new_sub_path = os.path.join(current_sub_path, file_info['name'])
|
|
|
+ print(f"Directory: {remote_path}/{file_info['name']} -> Local: {local_base_path}/{new_sub_path}")
|
|
|
+ # 递归遍历子目录
|
|
|
+ self.debug_directory(remote_path + "/" + file_info['name'], local_base_path, new_sub_path)
|
|
|
else:
|
|
|
- file_download_url = self.url + "/d" + path + "/" + file_info['name']
|
|
|
+ file_download_url = self.url + "/d" + remote_path + "/" + file_info['name']
|
|
|
sign = file_info.get('sign')
|
|
|
if sign:
|
|
|
file_download_url += "?sign=" + sign
|
|
|
- print(f"File: {file_download_url}, Save to: {download_path}")
|
|
|
+ # 显示将要下载到的本地路径
|
|
|
+ download_path = os.path.join(local_base_path, current_sub_path.lstrip('/'))
|
|
|
+ print(f"File: {file_download_url} -> Local: {download_path}/{file_info['name']}")
|
|
|
|
|
|
# alist 下载完成复制
|
|
|
def monitor_and_copy(self, download_path, destination_path, check_interval=10):
|