alroyso 10 місяців тому
батько
коміт
2a3d6a289a
1 змінених файлів з 2 додано та 108 видалено
  1. 2 108
      main.py

+ 2 - 108
main.py

@@ -1,114 +1,8 @@
-# This is a sample Python script.
-import configparser
-import json
 import logging
-import os
-import time
 
-from api.alist import AlistAPI
-from api.aria2 import Aria2API
-from api.nas_tools import NasToolsClient
-
-
-def is_downloaded(fileName, downloaded_files_path=""):
-    if not os.path.exists(downloaded_files_path):
-        return False
-    with open(downloaded_files_path, 'r', encoding='utf-8') as file:
-        downloaded_files = file.readlines()
-    downloaded_files = [line.strip() for line in downloaded_files]
-    return fileName in downloaded_files
-
-
-def record_download(filename, downloaded_files_path=""):
-    with open(downloaded_files_path, 'a', encoding='utf-8') as file:
-        file.write(filename + "\n")
+from app import app
 
 
 if __name__ == '__main__':
     logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
-    # 获取当前脚本的绝对路径
-    current_directory = os.path.dirname(os.path.abspath(__file__))
-    # 构建 config.ini 文件的路径
-    config_path = os.path.join(current_directory, 'config', 'config.ini')
-
-    # 读取配置文件
-    config = configparser.ConfigParser()
-    config.read(config_path)
-    download_data_json = os.path.join(current_directory, 'data', 'download.txt')
-    # 获取当前脚本所在目录的上级目录
-    # parent_directory = os.path.dirname(current_directory)
-    base_url = config['NSTOOLS']['URL']
-    api_key = config['NSTOOLS']['API_KEY']
-    nas_tools_api = NasToolsClient(base_url, api_key)
-
-    alist_username = config['REMOTE_ALIST']['USERNAME']
-    alist_password = config['REMOTE_ALIST']['PASSWORD']
-    remote_alist_download_path = config['REMOTE_ALIST']['DOWNLOAD_PATH']
-    remote_alist_api = AlistAPI(config['REMOTE_ALIST']['API_URL'],
-                                config['REMOTE_ALIST']['USERNAME'],
-                                config['REMOTE_ALIST']['PASSWORD'])
-
-    home_alist_download_path = config['HOME_ALIST']['DOWNLOAD_PATH']
-    home_scy_alist_copy_path = config['HOME_ALIST']['SCY_COPY_PATH']
-    home_des_alist_copy_path = config['HOME_ALIST']['DES_COPY_PATH']
-    docker_download_path = config['ARIA2']['DOCKER_DOWNLOAD_PATH']
-
-    aria2_api = Aria2API(config['ARIA2']['RPC_URL'], config['ARIA2']['RPC_SECRET'])
-    destination_path = config['ARIA2']['DES_COPY_PATH']
-
-    download_url = []
-    filename = None
-    # while is_running:
-    row_download_path = None
-
-    remote_alist_api.login(alist_username, alist_password)
-    # 获取远程目录结构
-    remote_json_path = remote_alist_api.save_directory_contents(
-        remote_alist_download_path,
-        home_alist_download_path,
-        home_scy_alist_copy_path,
-        home_des_alist_copy_path,
-        current_directory)
-    for home_item in remote_json_path:
-        if not home_item['is_dir']:
-            if not is_downloaded(home_item['name'], download_data_json):
-                name = home_item['name']
-                parent_folder_name = home_item['parent_folder_name']  # /movie or /tv
-                download_path = docker_download_path + "/" + parent_folder_name
-                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)
-                record_download(name, download_data_json)
-                #
-    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']} ---- 下载完成")
-
-    # 初始化日志和配置
-    URL = "http://192.168.88.249:3000"
-    API_KEY = "vBgKbiM1N7at0TtacAcbVCFf82pydcxC"
-    nas_tools_api = NasToolsClient(URL, API_KEY)
-    nas_tools_api.login('admin', 'password')
-    # self.nas_tools_api.run_service('sync')
-    sjson = nas_tools_api.sync_list()
-    print(sjson)
-    directory_ids = [sjson['data']['result']['13']['id'], sjson['data']['result']['14']['id']]
-    for directory_id in directory_ids:
-        nas_tools_api.sync(directory_id)
-
+    app.run(debug=True, port=5000)