123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import json
- import time
- from api.alist import AlistAPI
- from api.aria2 import Aria2API
- if __name__ == '__main__':
- API_URL = 'http://203.184.131.60:5244/api'
- API_USERNAME = 'admin'
- API_PASSWORD = 'nokidc123@#'
- bash_path = '/pikpak/aaaaa'
- local_download_path = "/aaa"
- arai2_download_path = "/Volumes/data/xxx"
- remote_alist_api = AlistAPI(API_URL,
- API_USERNAME,
- API_PASSWORD)
- aria2_api = Aria2API("http://127.0.0.1:6800", "")
- cur_dir = input('输入目录 4.15')
- remote_alist_api.login(API_USERNAME, API_PASSWORD)
- remote_download_path = bash_path + "/" + cur_dir
- print(f"当前目录 {remote_download_path}")
- # remote_data = remote_alist_api.list_directory(remote_download_path)
- remote_data = remote_alist_api.recursive_collect_contents(
- remote_download_path,
- local_download_path
- )
- # js = json.dumps(remote_data, sort_keys=True, indent=4, separators=(',', ':'))
- # print(js)
- download_url = []
- for home_item in remote_data:
- if not home_item['is_dir']:
- name = home_item['name']
- # parent_folder_name = home_item['parent_folder_name'] # /movie or /tv
- download_path = arai2_download_path
- cent_data = remote_alist_api.get_file_or_directory_info(home_item['path'])
- if cent_data['code'] != 200:
- break
- dow_time = {
- 'raw_url': cent_data['data']['raw_url'],
- 'download_path': download_path,
- 'name': name,
- }
- download_url.append(dow_time)
- aria2_downloads = []
- for download_item in download_url:
- if download_item['raw_url'] is not None:
- tmp_download = aria2_api.add_url(download_item['raw_url'], options={"dir": download_item['download_path']})
- if tmp_download is not None:
- # 检查下载是否完成
- while not tmp_download.is_complete:
- tmp_download.update() # 更新下载状态
- print("下载中...")
- time.sleep(10) # 等待10秒再次检查
- if tmp_download.is_complete:
- print(f"{download_item['name']} ---- 下载完成")
|