|
@@ -0,0 +1,47 @@
|
|
|
+import json
|
|
|
+import logging
|
|
|
+import os
|
|
|
+
|
|
|
+from src.api.Aria2API import Aria2API
|
|
|
+from src.api.alist import AlistAPI
|
|
|
+
|
|
|
+
|
|
|
+class RemotePikPakDownloadTask:
|
|
|
+ def __init__(self, config, parent_dir):
|
|
|
+ self.parent_dir = parent_dir
|
|
|
+ self.pik_alist_api = AlistAPI(config['HOME_ALIST_PIK_PAK']['API_URL'],
|
|
|
+ config['HOME_ALIST_PIK_PAK']['USERNAME'],
|
|
|
+ config['HOME_ALIST_PIK_PAK']['PASSWORD'])
|
|
|
+
|
|
|
+ self.aria2_api = Aria2API(config['MAC_MINI_ARIA2']['RPC_URL'],
|
|
|
+ config['MAC_MINI_ARIA2']['RPC_SECRET'])
|
|
|
+
|
|
|
+ self.remote_alist_download_path = config['HOME_ALIST_PIK_PAK']['DOWNLOAD_PATH']
|
|
|
+
|
|
|
+ self.aria2_download_path = config['MAC_MINI_ARIA2']['DESTINATION_PATH']
|
|
|
+
|
|
|
+ def start_download(self):
|
|
|
+ # 获取远程目录结构
|
|
|
+ remote_data = self.pik_alist_api.recursive_collect_contents(
|
|
|
+ self.remote_alist_download_path,
|
|
|
+ self.aria2_download_path
|
|
|
+ )
|
|
|
+ # remote_json_path = os.path.join(self.parent_dir, 'data', 'remote_pikpak.json')
|
|
|
+ # with open(remote_json_path, 'w', encoding='utf-8') as f:
|
|
|
+ # json.dump(remote_data, f, indent=4)
|
|
|
+
|
|
|
+ for home_item in remote_data:
|
|
|
+ if not home_item['is_dir']:
|
|
|
+ cent_data = self.pik_alist_api.get_file_or_directory_info(home_item['path'])
|
|
|
+ if cent_data:
|
|
|
+ self.send_to_aria2(cent_data['data']['raw_url'])
|
|
|
+ logging.info(f"Started to download {cent_data['data']['raw_url']}")
|
|
|
+ else:
|
|
|
+ logging.info("File not found")
|
|
|
+ break
|
|
|
+
|
|
|
+
|
|
|
+ def send_to_aria2(self, file_path):
|
|
|
+ # 将文件添加到 Aria2 下载队列
|
|
|
+ self.aria2_api.add_url(file_path, options={"dir": self.aria2_download_path})
|
|
|
+ logging.info(f"Added to Aria2: {file_path}")
|