|
@@ -84,6 +84,20 @@ 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)
|
|
|
+ # 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)
|
|
|
+ # else:
|
|
|
+ # file_download_url = self.url + "/d" + path + "/" + file_info['name']
|
|
|
+ # sign = file_info.get('sign')
|
|
|
+ # if sign:
|
|
|
+ # file_download_url += "?sign=" + sign
|
|
|
+ # self.aria2_api.add_uris([file_download_url], options={"dir": download_path})
|
|
|
+
|
|
|
def download_directory(self, remote_path, local_base_path, current_sub_path=''):
|
|
|
file_list = self.list_directory(remote_path)
|
|
|
if not file_list:
|
|
@@ -96,13 +110,14 @@ class AlistAPI:
|
|
|
# 递归下载该目录
|
|
|
self.download_directory(remote_path + "/" + file_info['name'], local_base_path, new_sub_path)
|
|
|
else:
|
|
|
- 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})
|
|
|
+ # 获取文件的详细信息
|
|
|
+ file_detail = self.get_file_or_directory_info(remote_path + "/" + file_info['name'])
|
|
|
+ if file_detail and file_detail['code'] == 200:
|
|
|
+ raw_url = file_detail['data']['raw_url']
|
|
|
+ # 将真实 URL 添加到 Aria2 下载队列
|
|
|
+ self.aria2_api.add_uris([raw_url], options={"dir": current_sub_path})
|
|
|
+ else:
|
|
|
+ print(f"Failed to get detailed information for {file_info['name']}")
|
|
|
|
|
|
def debug_directory(self, remote_path, local_base_path, current_sub_path=''):
|
|
|
file_list = self.list_directory(remote_path)
|
|
@@ -117,13 +132,28 @@ class AlistAPI:
|
|
|
# 递归遍历子目录
|
|
|
self.debug_directory(remote_path + "/" + file_info['name'], local_base_path, new_sub_path)
|
|
|
else:
|
|
|
- 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('/'))
|
|
|
- print(f"File: {file_download_url} -> Local: {download_path}/{file_info['name']}")
|
|
|
+ # 获取文件的详细信息
|
|
|
+ file_detail = self.get_file_or_directory_info(remote_path + "/" + file_info['name'])
|
|
|
+ if file_detail and file_detail['code'] == 200:
|
|
|
+ raw_url = file_detail['data']['raw_url']
|
|
|
+ print(f"File: {file_info['name']} -> Download URL: {raw_url}")
|
|
|
+ else:
|
|
|
+ print(f"Failed to get detailed information for {file_info['name']}")
|
|
|
+
|
|
|
+ # def debug_directory(self, path, download_path):
|
|
|
+ # file_list = self.list_directory(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)
|
|
|
+ # else:
|
|
|
+ # file_download_url = self.url + "/d" + 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}")
|
|
|
|
|
|
# alist 下载完成复制
|
|
|
def monitor_and_copy(self, download_path, destination_path, check_interval=10):
|