pikpak.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import json
  2. import time
  3. from api.alist import AlistAPI
  4. from api.aria2 import Aria2API
  5. if __name__ == '__main__':
  6. API_URL = 'http://203.184.131.60:5244/api'
  7. API_USERNAME = 'admin'
  8. API_PASSWORD = 'nokidc123@#'
  9. bash_path = '/pikpak/aaaaa'
  10. local_download_path = "/aaa"
  11. arai2_download_path = "/Volumes/data/xxx"
  12. remote_alist_api = AlistAPI(API_URL,
  13. API_USERNAME,
  14. API_PASSWORD)
  15. aria2_api = Aria2API("http://127.0.0.1:6800", "")
  16. cur_dir = input('输入目录 4.15')
  17. remote_alist_api.login(API_USERNAME, API_PASSWORD)
  18. remote_download_path = bash_path + "/" + cur_dir
  19. print(f"当前目录 {remote_download_path}")
  20. # remote_data = remote_alist_api.list_directory(remote_download_path)
  21. remote_data = remote_alist_api.recursive_collect_contents(
  22. remote_download_path,
  23. local_download_path
  24. )
  25. # js = json.dumps(remote_data, sort_keys=True, indent=4, separators=(',', ':'))
  26. # print(js)
  27. download_url = []
  28. for home_item in remote_data:
  29. if not home_item['is_dir']:
  30. name = home_item['name']
  31. # parent_folder_name = home_item['parent_folder_name'] # /movie or /tv
  32. download_path = arai2_download_path
  33. cent_data = remote_alist_api.get_file_or_directory_info(home_item['path'])
  34. if cent_data['code'] != 200:
  35. break
  36. dow_time = {
  37. 'raw_url': cent_data['data']['raw_url'],
  38. 'download_path': download_path,
  39. 'name': name,
  40. }
  41. download_url.append(dow_time)
  42. aria2_downloads = []
  43. for download_item in download_url:
  44. if download_item['raw_url'] is not None:
  45. tmp_download = aria2_api.add_url(download_item['raw_url'], options={"dir": download_item['download_path']})
  46. if tmp_download is not None:
  47. # 检查下载是否完成
  48. while not tmp_download.is_complete:
  49. tmp_download.update() # 更新下载状态
  50. print("下载中...")
  51. time.sleep(10) # 等待10秒再次检查
  52. if tmp_download.is_complete:
  53. print(f"{download_item['name']} ---- 下载完成")