From 249befec6e7d36184bb34cbf90b2b6cb85ef017f Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 14:31:32 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0rest=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 16 ++++ UPDATE.md | 178 +++++++++++++++++++++++++++++++++++++ app/main.py | 22 ++++- app/modules/api.py | 43 +++++++++ config/config.yaml.example | 3 + requirements.txt | 5 +- 6 files changed, 264 insertions(+), 3 deletions(-) create mode 100644 UPDATE.md create mode 100644 app/modules/api.py diff --git a/Dockerfile b/Dockerfile index d2fae14a..080e036c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,22 @@ FROM python:3.12.7-alpine ENV TZ=Asia/Shanghai VOLUME ["/config", "/logs", "/media"] +EXPOSE 8000 # 新增端口暴露声明 + +# 添加运行时依赖 +RUN apk update && \ + apk add --no-cache \ + tzdata \ + curl && \ + cp /usr/share/zoneinfo/${TZ} /etc/localtime && \ + echo ${TZ} > /etc/timezone + +# 创建非root用户 +RUN adduser -D appuser && \ + chown -R appuser:appuser /app + +# 切换用户 +USER appuser RUN apk update && \ apk add --no-cache \ diff --git a/UPDATE.md b/UPDATE.md new file mode 100644 index 00000000..7ba8e28c --- /dev/null +++ b/UPDATE.md @@ -0,0 +1,178 @@ +我将帮助您添加API触发功能。需要修改以下几个文件: + +首先在配置文件中添加API配置项(config.yaml.example): + +config.yaml.example +Apply +Settings: +API_ENABLE: True # 启用API接口 +API_PORT: 8000 # API服务端口 +API_KEY: your_secret_key # API访问密钥 + +# ... 保持其他配置不变 ... +添加API路由模块: + +api.py +Apply +from fastapi import APIRouter, Security, HTTPException, status +from fastapi.security import APIKeyHeader + +from app.core import settings, logger +from app.modules import Alist2Strm, Ani2Alist + +router = APIRouter() +security = APIKeyHeader(name="X-API-Key") + +async def get_api_key(api_key: str = Security(security)) -> str: +if api_key != settings.API_KEY: +raise HTTPException( +status_code=status.HTTP_401_UNAUTHORIZED, +detail="Invalid API Key" +) +return api_key + +@router.post("/trigger/alist2strm") +async def trigger_alist2strm( +server_id: str, +_: str = Security(get_api_key) +): +logger.info(f"API触发Alist2Strm任务:{server_id}") +# 查找对应配置 +server_config = next((s for s in settings.AlistServerList if s["id"] == server_id), None) +if not server_config: +raise HTTPException(status_code=404, detail="Server not found") + + await Alist2Strm(**server_config).run() + return {"status": "success"} + +@router.post("/trigger/ani2alist") +async def trigger_ani2alist( +server_id: str, +_: str = Security(get_api_key) +): +logger.info(f"API触发Ani2Alist任务:{server_id}") +server_config = next((s for s in settings.Ani2AlistList if s["id"] == server_id), None) +if not server_config: +raise HTTPException(status_code=404, detail="Server not found") + + await Ani2Alist(**server_config).run() + return {"status": "success"} +修改主程序启动逻辑: + +main.py +Apply +from fastapi import FastAPI +import uvicorn + +# ... 原有导入保持不变 ... +from app.modules.api import router as api_router + +def start_api_server(): +app = FastAPI(title=settings.APP_NAME) +app.include_router(api_router) + + uvicorn.run( + app, + host="0.0.0.0", + port=settings.API_PORT, + log_config=None + ) + +if __name__ == "__main__": +print_logo() +logger.info(f"AutoFilm {settings.APP_VERSION} 启动中...") + + # 启动API服务器 + if settings.API_ENABLE: + from threading import Thread + Thread(target=start_api_server, daemon=True).start() + logger.info(f"API服务已启动在 {settings.API_PORT} 端口") + + # ... 保持原有调度器逻辑不变 ... +更新依赖: + +requirements.txt +fastapi==0.111.0 +uvicorn==0.29.0 +python-multipart==0.0.9 +使用示例: + + +bash +# 触发Alist2Strm任务 +curl -X POST -H "X-API-Key: your_secret_key" http://localhost:8000/trigger/alist2strm?server_id=动漫 + +# 触发Ani2Alist任务 +curl -X POST -H "X-API-Key: your_secret_key" http://localhost:8000/trigger/ani2alist?server_id=动画库 +主要改动点: + +使用FastAPI提供RESTful API +通过API Key进行身份验证 +保持原有定时任务的同时启动API服务 +支持通过server_id参数触发特定任务 +异步处理请求不阻塞主程序 +注意:需要先安装新增的依赖项,并在配置文件中启用API功能。 + +根据当前配置,建议对Dockerfile进行以下优化改进: + + +Dockerfile +Apply +# ... 保留现有基础配置 ... + +FROM python:3.12.7-alpine + +ENV TZ=Asia/Shanghai +VOLUME ["/config", "/logs", "/media"] + +# 添加运行时依赖 +RUN apk update && \ +apk add --no-cache \ +tzdata \ +curl && \ +cp /usr/share/zoneinfo/${TZ} /etc/localtime && \ +echo ${TZ} > /etc/timezone + +# 创建非root用户 +RUN adduser -D appuser && \ +chown -R appuser:appuser /app + +# 切换用户 +USER appuser + +# ... 保留后续配置 ... +主要改进点说明: + +时区支持增强:显式安装tzdata包并配置时区文件(原配置仅设置TZ变量可能不完全生效) +安全优化:创建专用appuser用户运行应用,避免使用root权限 +基础工具:添加curl用于容器调试(可按需移除) +层合并优化:将多个RUN指令合并减少镜像层数 +当前Dockerfile已具备良好的多阶段构建结构,以上是可选的优化项。如果不需要调试工具,可以移除curl包的安装。这些修改能帮助生成更安全、时区支持更完善的Docker镜像。 + +根据当前配置中API_PORT: 8000的设置,建议在 Dockerfile 中添加端口声明。以下是需要修改的部分: + + +Dockerfile +Apply +# ... 保留现有配置 ... + +FROM python:3.12.7-alpine + +ENV TZ=Asia/Shanghai +VOLUME ["/config", "/logs", "/media"] +EXPOSE 8000 # 新增端口暴露声明 + +# ... 保留后续配置 ... +修改说明: + +添加 EXPOSE 8000 指令声明容器监听端口 +该声明本身不会自动发布端口,但能: +帮助其他开发者快速了解服务端口 +在使用 docker run -P 时自动绑定随机公网端口 +与 docker-compose 配置形成互补 +实际运行时仍需通过 -p 参数映射端口: + + +```bash +docker run -d -p 8000:8000 your_image +``` \ No newline at end of file diff --git a/app/main.py b/app/main.py index 88d33e72..ec767084 100644 --- a/app/main.py +++ b/app/main.py @@ -10,6 +10,8 @@ from app.core import settings, logger from app.extensions import LOGO from app.modules import Alist2Strm, Ani2Alist +from fastapi import FastAPI +import uvicorn def print_logo() -> None: @@ -21,12 +23,28 @@ def print_logo() -> None: print(f" {settings.APP_NAME} {settings.APP_VERSION} ".center(65, "=")) print("") +from app.modules.api import router as api_router + +def start_api_server(): + app = FastAPI(title=settings.APP_NAME) + app.include_router(api_router) + + uvicorn.run( + app, + host="0.0.0.0", + port=settings.API_PORT, + log_config=None + ) if __name__ == "__main__": print_logo() - logger.info(f"AutoFilm {settings.APP_VERSION} 启动中...") - logger.debug(f"是否开启 DEBUG 模式: {settings.DEBUG}") + + # 启动API服务器 + if settings.API_ENABLE: + from threading import Thread + Thread(target=start_api_server, daemon=True).start() + logger.info(f"API服务已启动在 {settings.API_PORT} 端口") scheduler = AsyncIOScheduler() diff --git a/app/modules/api.py b/app/modules/api.py new file mode 100644 index 00000000..8f6f8184 --- /dev/null +++ b/app/modules/api.py @@ -0,0 +1,43 @@ +from fastapi import APIRouter, Security, HTTPException, status +from fastapi.security import APIKeyHeader + +from app.core import settings, logger +from app.modules import Alist2Strm, Ani2Alist + +router = APIRouter() +security = APIKeyHeader(name="X-API-Key") + +async def get_api_key(api_key: str = Security(security)) -> str: + if api_key != settings.API_KEY: + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="Invalid API Key" + ) + return api_key + +@router.post("/trigger/alist2strm") +async def trigger_alist2strm( + server_id: str, + _: str = Security(get_api_key) +): + logger.info(f"API触发Alist2Strm任务:{server_id}") + # 查找对应配置 + server_config = next((s for s in settings.AlistServerList if s["id"] == server_id), None) + if not server_config: + raise HTTPException(status_code=404, detail="Server not found") + + await Alist2Strm(**server_config).run() + return {"status": "success"} + +@router.post("/trigger/ani2alist") +async def trigger_ani2alist( + server_id: str, + _: str = Security(get_api_key) +): + logger.info(f"API触发Ani2Alist任务:{server_id}") + server_config = next((s for s in settings.Ani2AlistList if s["id"] == server_id), None) + if not server_config: + raise HTTPException(status_code=404, detail="Server not found") + + await Ani2Alist(**server_config).run() + return {"status": "success"} \ No newline at end of file diff --git a/config/config.yaml.example b/config/config.yaml.example index 401292e8..e3e41ee7 100644 --- a/config/config.yaml.example +++ b/config/config.yaml.example @@ -1,4 +1,7 @@ Settings: + API_ENABLE: True # 启用API接口 + API_PORT: 8000 # API服务端口 + API_KEY: your_secret_key # API访问密钥 DEV: False # 开发者模式(可选,默认 False) Alist2StrmList: diff --git a/requirements.txt b/requirements.txt index cc1bb4f1..92dee79e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,7 @@ APScheduler == 3.10.4 aiofile == 3.8.8 httpx[http2] == 0.27.2 pydantic == 2.9.2 -pypinyin == 0.53.0 \ No newline at end of file +pypinyin == 0.53.0 +fastapi==0.111.0 +uvicorn==0.29.0 +python-multipart==0.0.9 \ No newline at end of file From 3fa0ffd999d1fa42ba286fb12bd683971087d975 Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 14:42:35 +0800 Subject: [PATCH 02/19] =?UTF-8?q?=E6=9A=82=E6=97=B6=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E6=9A=B4=E9=9C=B2=E7=9A=84=E7=AB=AF=E5=8F=A3=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 080e036c..2f73b98c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ FROM python:3.12.7-alpine ENV TZ=Asia/Shanghai VOLUME ["/config", "/logs", "/media"] -EXPOSE 8000 # 新增端口暴露声明 +#EXPOSE 8000 # 新增端口暴露声明 # 添加运行时依赖 RUN apk update && \ From 6f80cc2bdde4e7395385f9d164c56b6ada4e6903 Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 15:31:52 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E9=89=B4?= =?UTF-8?q?=E6=9D=83=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + app/modules/api.py | 8 ++++---- requirements.txt | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2f73b98c..eeb77ee5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,7 @@ RUN apk update && \ # 创建非root用户 RUN adduser -D appuser && \ + mkdir -p /app && \ chown -R appuser:appuser /app # 切换用户 diff --git a/app/modules/api.py b/app/modules/api.py index 8f6f8184..5006e590 100644 --- a/app/modules/api.py +++ b/app/modules/api.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, Security, HTTPException, status +from fastapi import APIRouter, Security, HTTPException, status, Depends # 新增 Depends from fastapi.security import APIKeyHeader from app.core import settings, logger @@ -7,7 +7,7 @@ router = APIRouter() security = APIKeyHeader(name="X-API-Key") -async def get_api_key(api_key: str = Security(security)) -> str: +async def get_api_key(api_key: str = Depends(security)) -> str: # 修改 Security 为 Depends if api_key != settings.API_KEY: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, @@ -18,7 +18,7 @@ async def get_api_key(api_key: str = Security(security)) -> str: @router.post("/trigger/alist2strm") async def trigger_alist2strm( server_id: str, - _: str = Security(get_api_key) + _: str = Depends(get_api_key) # 修改 Security 为 Depends ): logger.info(f"API触发Alist2Strm任务:{server_id}") # 查找对应配置 @@ -32,7 +32,7 @@ async def trigger_alist2strm( @router.post("/trigger/ani2alist") async def trigger_ani2alist( server_id: str, - _: str = Security(get_api_key) + _: str = Depends(get_api_key) # 修改 Security 为 Depends ): logger.info(f"API触发Ani2Alist任务:{server_id}") server_config = next((s for s in settings.Ani2AlistList if s["id"] == server_id), None) diff --git a/requirements.txt b/requirements.txt index 92dee79e..fa39e3b2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,6 @@ aiofile == 3.8.8 httpx[http2] == 0.27.2 pydantic == 2.9.2 pypinyin == 0.53.0 -fastapi==0.111.0 -uvicorn==0.29.0 +fastapi==0.109.0 # 修正版本号 +uvicorn==0.27.1 python-multipart==0.0.9 \ No newline at end of file From eae94a0eee9062f2265d83cad801510e1042ab3d Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 15:48:17 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index eeb77ee5..5af0df2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,8 @@ FROM python:3.12.7-alpine ENV TZ=Asia/Shanghai VOLUME ["/config", "/logs", "/media"] -#EXPOSE 8000 # 新增端口暴露声明 +# 新增端口暴露声明 +EXPOSE 8000 # 添加运行时依赖 RUN apk update && \ @@ -54,4 +55,5 @@ COPY --from=builder /builder/app /app RUN apk del build-base linux-headers && \ rm -rf /tmp/* -ENTRYPOINT ["python", "/app/main.py"] \ No newline at end of file +ENTRYPOINT ["python", "/app/main.py", "--host", "0.0.0.0", "--port", "8000"] +#ENTRYPOINT ["python", "/app/main.py"] \ No newline at end of file From 55f1ab13cc0a04b7587a996e8596ad73db0cff8f Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 16:04:05 +0800 Subject: [PATCH 05/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5af0df2b..852bac84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,13 +16,12 @@ COPY app ./app RUN python setup.py RUN apk del build-base linux-headers && \ - find app -type f \( -name "*.py" ! -name "main.py" ! -name "__init__.py" -o -name "*.c" \) -delete + find app -type f \( -name "*.py" ! -name "main.py" ! -name "__init__.py" -o -name "*.c" \) -delete FROM python:3.12.7-alpine ENV TZ=Asia/Shanghai VOLUME ["/config", "/logs", "/media"] -# 新增端口暴露声明 EXPOSE 8000 # 添加运行时依赖 @@ -33,27 +32,17 @@ RUN apk update && \ cp /usr/share/zoneinfo/${TZ} /etc/localtime && \ echo ${TZ} > /etc/timezone -# 创建非root用户 -RUN adduser -D appuser && \ - mkdir -p /app && \ - chown -R appuser:appuser /app - -# 切换用户 -USER appuser - -RUN apk update && \ - apk add --no-cache \ - build-base \ - linux-headers - -COPY requirements.txt requirements.txt +# 安装Python依赖 +COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt && \ - rm requirements.txt + rm requirements.txt +# 从构建阶段复制应用 COPY --from=builder /builder/app /app -RUN apk del build-base linux-headers && \ - rm -rf /tmp/* +# 最终清理 +RUN apk del curl && \ + rm -rf /var/cache/apk/* && \ + rm -rf /tmp/* -ENTRYPOINT ["python", "/app/main.py", "--host", "0.0.0.0", "--port", "8000"] -#ENTRYPOINT ["python", "/app/main.py"] \ No newline at end of file +ENTRYPOINT ["python", "/app/main.py", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file From 3c630492eece3c4feb4054ca2cf541678f6744fc Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 16:10:39 +0800 Subject: [PATCH 06/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 852bac84..9234eac2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,9 @@ EXPOSE 8000 RUN apk update && \ apk add --no-cache \ tzdata \ - curl && \ + curl \ + build-base \ # 新增构建工具 + linux-headers && \ # 新增内核头文件 cp /usr/share/zoneinfo/${TZ} /etc/localtime && \ echo ${TZ} > /etc/timezone @@ -37,6 +39,10 @@ COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt && \ rm requirements.txt +# 清理构建工具 +RUN apk del build-base linux-headers && \ + rm -rf /var/cache/apk/* + # 从构建阶段复制应用 COPY --from=builder /builder/app /app From 51ee4a9587cbebadb1768feef5dde331f51910fb Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 16:13:57 +0800 Subject: [PATCH 07/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9234eac2..2313fb69 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,8 +29,8 @@ RUN apk update && \ apk add --no-cache \ tzdata \ curl \ - build-base \ # 新增构建工具 - linux-headers && \ # 新增内核头文件 + build-base \ + linux-headers && \ cp /usr/share/zoneinfo/${TZ} /etc/localtime && \ echo ${TZ} > /etc/timezone From 682f46872e149f096ee14aba385bc2d982155c62 Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 16:25:07 +0800 Subject: [PATCH 08/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9Dockerfile-4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2313fb69..82504623 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,9 @@ RUN apk update && \ # 安装Python依赖 COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt && \ +RUN pip install --no-cache-dir -r requirements.txt \ + -i https://pypi.tuna.tsinghua.edu.cn/simple \ + --default-timeout=100 && \ rm requirements.txt # 清理构建工具 From 033af9591093170b1134c69f26677411caa0fd9b Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 16:36:20 +0800 Subject: [PATCH 09/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=89=B4=E6=9D=83?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/api.py | 11 ++++++++--- requirements.txt | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/modules/api.py b/app/modules/api.py index 5006e590..264f3d9e 100644 --- a/app/modules/api.py +++ b/app/modules/api.py @@ -1,13 +1,18 @@ -from fastapi import APIRouter, Security, HTTPException, status, Depends # 新增 Depends +from fastapi import APIRouter, Depends, HTTPException, status from fastapi.security import APIKeyHeader from app.core import settings, logger from app.modules import Alist2Strm, Ani2Alist router = APIRouter() -security = APIKeyHeader(name="X-API-Key") +security = APIKeyHeader(name="X-API-Key", auto_error=False) -async def get_api_key(api_key: str = Depends(security)) -> str: # 修改 Security 为 Depends +async def get_api_key(api_key: str = Depends(security)): + if not api_key: + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="Missing API Key" + ) if api_key != settings.API_KEY: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, diff --git a/requirements.txt b/requirements.txt index fa39e3b2..3f700147 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,6 @@ aiofile == 3.8.8 httpx[http2] == 0.27.2 pydantic == 2.9.2 pypinyin == 0.53.0 -fastapi==0.109.0 # 修正版本号 +fastapi==0.109.0 uvicorn==0.27.1 python-multipart==0.0.9 \ No newline at end of file From f1c7f09ab4d2aa94a3889e90630c721638619d5a Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 16:44:07 +0800 Subject: [PATCH 10/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9api.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/api.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/modules/api.py b/app/modules/api.py index 264f3d9e..d043dce5 100644 --- a/app/modules/api.py +++ b/app/modules/api.py @@ -8,6 +8,9 @@ security = APIKeyHeader(name="X-API-Key", auto_error=False) async def get_api_key(api_key: str = Depends(security)): + # 修改前错误声明: + # async def get_api_key(api_key: str = Security(security)) -> str: + # 正确声明应为通过Depends注入security if not api_key: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, From 04142ada1f27a9e029fb3327d5ff5188079401b1 Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 20:19:10 +0800 Subject: [PATCH 11/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9api=EF=BC=8Cdockerfil?= =?UTF-8?q?=20setup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 +++- app/modules/api.py | 11 +++++------ setup.py | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 82504623..df572cae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,9 @@ COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt \ -i https://pypi.tuna.tsinghua.edu.cn/simple \ --default-timeout=100 && \ - rm requirements.txt + rm requirements.txt \ + +RUN pip install fastapi==0.109.0 uvicorn==0.27.0 --force-reinstall # 清理构建工具 RUN apk del build-base linux-headers && \ diff --git a/app/modules/api.py b/app/modules/api.py index d043dce5..8dbe1d4f 100644 --- a/app/modules/api.py +++ b/app/modules/api.py @@ -7,10 +7,8 @@ router = APIRouter() security = APIKeyHeader(name="X-API-Key", auto_error=False) -async def get_api_key(api_key: str = Depends(security)): - # 修改前错误声明: - # async def get_api_key(api_key: str = Security(security)) -> str: - # 正确声明应为通过Depends注入security +# 修改依赖声明方式(移除类型标注中的str) +async def get_api_key(api_key = Depends(security)): if not api_key: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, @@ -23,10 +21,11 @@ async def get_api_key(api_key: str = Depends(security)): ) return api_key +# 修改路由参数声明(移除类型标注中的str) @router.post("/trigger/alist2strm") async def trigger_alist2strm( server_id: str, - _: str = Depends(get_api_key) # 修改 Security 为 Depends + _ = Depends(get_api_key) ): logger.info(f"API触发Alist2Strm任务:{server_id}") # 查找对应配置 @@ -40,7 +39,7 @@ async def trigger_alist2strm( @router.post("/trigger/ani2alist") async def trigger_ani2alist( server_id: str, - _: str = Depends(get_api_key) # 修改 Security 为 Depends + _ = Depends(get_api_key) ): logger.info(f"API触发Ani2Alist任务:{server_id}") server_config = next((s for s in settings.Ani2AlistList if s["id"] == server_id), None) diff --git a/setup.py b/setup.py index f361305c..65d82c16 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,8 @@ def find_py_files(dir: Path) -> list[str]: needed_compiled_files = [] for file in dir.rglob("*.py"): - if file.name not in ["main.py", "__init__.py"]: + # 添加排除条件 + if file.name not in ["main.py", "__init__.py", "api.py"]: needed_compiled_files.append(file.as_posix()) return needed_compiled_files From 73e21d2bd8f5aecc60ef2656684799d68b9b0e4d Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 20:35:12 +0800 Subject: [PATCH 12/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9dockerfile-5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index df572cae..5917056e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,10 +38,9 @@ RUN apk update && \ COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt \ -i https://pypi.tuna.tsinghua.edu.cn/simple \ - --default-timeout=100 && \ - rm requirements.txt \ - -RUN pip install fastapi==0.109.0 uvicorn==0.27.0 --force-reinstall + --default-timeout=100 \ + && rm requirements.txt \ + && pip install fastapi==0.109.0 uvicorn==0.27.0 --force-reinstall # 清理构建工具 RUN apk del build-base linux-headers && \ From 4167844dd74d23a8b58e0a02f05a993f25c94cfd Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 20:42:10 +0800 Subject: [PATCH 13/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9setup.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 65d82c16..82af3018 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,8 @@ def find_py_files(dir: Path) -> list[str]: needed_compiled_files = [] for file in dir.rglob("*.py"): # 添加排除条件 - if file.name not in ["main.py", "__init__.py", "api.py"]: + #if file.name not in ["main.py", "__init__.py", "api.py"]: + if file.name not in ["main.py"]: needed_compiled_files.append(file.as_posix()) return needed_compiled_files From 9227a855b569ac0fd50035a16ab774512716992e Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 20:49:10 +0800 Subject: [PATCH 14/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/config.py | 7 +++++++ app/main.py | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/core/config.py b/app/core/config.py index 70bb8e1d..04ead8fe 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -97,5 +97,12 @@ def Ani2AlistList(self) -> list[dict[str, Any]]: ani2alist_list = safe_load(file).get("Ani2AlistList", []) return ani2alist_list + @property + def API_ENABLE(self) -> bool: + """ + 是否启用API服务 + """ + with self.CONFIG.open(mode="r", encoding="utf-8") as file: + return safe_load(file).get("Settings", {}).get("API_ENABLE", False) settings = SettingManager() diff --git a/app/main.py b/app/main.py index ec767084..d38e48fa 100644 --- a/app/main.py +++ b/app/main.py @@ -36,6 +36,17 @@ def start_api_server(): log_config=None ) +def __mkdir(self) -> None: + """ + 创建目录 + """ + # 修改前:使用 with self.CONFIG_DIR as dir_path: + if not self.CONFIG_DIR.exists(): + self.CONFIG_DIR.mkdir(parents=True, exist_ok=True) + + if not self.LOG_DIR.exists(): + self.LOG_DIR.mkdir(parents=True, exist_ok=True) + if __name__ == "__main__": print_logo() logger.info(f"AutoFilm {settings.APP_VERSION} 启动中...") From 5a1cccf1b76748b4e7ecc2a9ef0b74bdfae90e18 Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 20:53:55 +0800 Subject: [PATCH 15/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/config.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index 04ead8fe..e831ed0b 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -99,10 +99,32 @@ def Ani2AlistList(self) -> list[dict[str, Any]]: @property def API_ENABLE(self) -> bool: - """ - 是否启用API服务 - """ - with self.CONFIG.open(mode="r", encoding="utf-8") as file: - return safe_load(file).get("Settings", {}).get("API_ENABLE", False) + """是否启用API服务""" + return self._get_config("Settings", "API_ENABLE", False) + + @property + def API_PORT(self) -> int: + """API服务监听端口""" + return self._get_config("Settings", "API_PORT", 8000) + def _get_config(self, section: str, key: str, default: Any) -> Any: + """统一配置获取方法""" + # 修改前:使用 with self.CONFIG.open() as f: + # 修改后: + def load_config(self): + config_file = self.CONFIG_DIR / "config.yaml" + if config_file.exists(): + with open(config_file, "r", encoding="utf-8") as f: + self._config = safe_load(f) + + @property + def API_PORT(self) -> int: + """API服务监听端口""" + return self._get_config("Settings", "API_PORT", 8000) + def _get_config(self, section: str, key: str, default: Any) -> Any: + """统一配置获取方法""" + with self.CONFIG.open(mode="r", encoding="utf-8") as f: + config = safe_load(f) + return config.get(section, {}).get(key, default) + settings = SettingManager() From 92ab129f1ccb5b40eadf4e49ee30efd197443507 Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 21:03:16 +0800 Subject: [PATCH 16/19] =?UTF-8?q?=E6=B7=BB=E5=8A=A0api=5Fkey=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/core/config.py b/app/core/config.py index e831ed0b..d48d6c16 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -126,5 +126,10 @@ def _get_config(self, section: str, key: str, default: Any) -> Any: config = safe_load(f) return config.get(section, {}).get(key, default) + @property + def API_KEY(self) -> str: + + """API验证密钥""" + return self._get_config("Settings", "API_KEY", "") settings = SettingManager() From d73c1847767349e9956a473ac5862fdf3ec4ac55 Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 14 May 2025 21:26:17 +0800 Subject: [PATCH 17/19] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UPDATE.md | 178 ------------------------------------------------------ 1 file changed, 178 deletions(-) delete mode 100644 UPDATE.md diff --git a/UPDATE.md b/UPDATE.md deleted file mode 100644 index 7ba8e28c..00000000 --- a/UPDATE.md +++ /dev/null @@ -1,178 +0,0 @@ -我将帮助您添加API触发功能。需要修改以下几个文件: - -首先在配置文件中添加API配置项(config.yaml.example): - -config.yaml.example -Apply -Settings: -API_ENABLE: True # 启用API接口 -API_PORT: 8000 # API服务端口 -API_KEY: your_secret_key # API访问密钥 - -# ... 保持其他配置不变 ... -添加API路由模块: - -api.py -Apply -from fastapi import APIRouter, Security, HTTPException, status -from fastapi.security import APIKeyHeader - -from app.core import settings, logger -from app.modules import Alist2Strm, Ani2Alist - -router = APIRouter() -security = APIKeyHeader(name="X-API-Key") - -async def get_api_key(api_key: str = Security(security)) -> str: -if api_key != settings.API_KEY: -raise HTTPException( -status_code=status.HTTP_401_UNAUTHORIZED, -detail="Invalid API Key" -) -return api_key - -@router.post("/trigger/alist2strm") -async def trigger_alist2strm( -server_id: str, -_: str = Security(get_api_key) -): -logger.info(f"API触发Alist2Strm任务:{server_id}") -# 查找对应配置 -server_config = next((s for s in settings.AlistServerList if s["id"] == server_id), None) -if not server_config: -raise HTTPException(status_code=404, detail="Server not found") - - await Alist2Strm(**server_config).run() - return {"status": "success"} - -@router.post("/trigger/ani2alist") -async def trigger_ani2alist( -server_id: str, -_: str = Security(get_api_key) -): -logger.info(f"API触发Ani2Alist任务:{server_id}") -server_config = next((s for s in settings.Ani2AlistList if s["id"] == server_id), None) -if not server_config: -raise HTTPException(status_code=404, detail="Server not found") - - await Ani2Alist(**server_config).run() - return {"status": "success"} -修改主程序启动逻辑: - -main.py -Apply -from fastapi import FastAPI -import uvicorn - -# ... 原有导入保持不变 ... -from app.modules.api import router as api_router - -def start_api_server(): -app = FastAPI(title=settings.APP_NAME) -app.include_router(api_router) - - uvicorn.run( - app, - host="0.0.0.0", - port=settings.API_PORT, - log_config=None - ) - -if __name__ == "__main__": -print_logo() -logger.info(f"AutoFilm {settings.APP_VERSION} 启动中...") - - # 启动API服务器 - if settings.API_ENABLE: - from threading import Thread - Thread(target=start_api_server, daemon=True).start() - logger.info(f"API服务已启动在 {settings.API_PORT} 端口") - - # ... 保持原有调度器逻辑不变 ... -更新依赖: - -requirements.txt -fastapi==0.111.0 -uvicorn==0.29.0 -python-multipart==0.0.9 -使用示例: - - -bash -# 触发Alist2Strm任务 -curl -X POST -H "X-API-Key: your_secret_key" http://localhost:8000/trigger/alist2strm?server_id=动漫 - -# 触发Ani2Alist任务 -curl -X POST -H "X-API-Key: your_secret_key" http://localhost:8000/trigger/ani2alist?server_id=动画库 -主要改动点: - -使用FastAPI提供RESTful API -通过API Key进行身份验证 -保持原有定时任务的同时启动API服务 -支持通过server_id参数触发特定任务 -异步处理请求不阻塞主程序 -注意:需要先安装新增的依赖项,并在配置文件中启用API功能。 - -根据当前配置,建议对Dockerfile进行以下优化改进: - - -Dockerfile -Apply -# ... 保留现有基础配置 ... - -FROM python:3.12.7-alpine - -ENV TZ=Asia/Shanghai -VOLUME ["/config", "/logs", "/media"] - -# 添加运行时依赖 -RUN apk update && \ -apk add --no-cache \ -tzdata \ -curl && \ -cp /usr/share/zoneinfo/${TZ} /etc/localtime && \ -echo ${TZ} > /etc/timezone - -# 创建非root用户 -RUN adduser -D appuser && \ -chown -R appuser:appuser /app - -# 切换用户 -USER appuser - -# ... 保留后续配置 ... -主要改进点说明: - -时区支持增强:显式安装tzdata包并配置时区文件(原配置仅设置TZ变量可能不完全生效) -安全优化:创建专用appuser用户运行应用,避免使用root权限 -基础工具:添加curl用于容器调试(可按需移除) -层合并优化:将多个RUN指令合并减少镜像层数 -当前Dockerfile已具备良好的多阶段构建结构,以上是可选的优化项。如果不需要调试工具,可以移除curl包的安装。这些修改能帮助生成更安全、时区支持更完善的Docker镜像。 - -根据当前配置中API_PORT: 8000的设置,建议在 Dockerfile 中添加端口声明。以下是需要修改的部分: - - -Dockerfile -Apply -# ... 保留现有配置 ... - -FROM python:3.12.7-alpine - -ENV TZ=Asia/Shanghai -VOLUME ["/config", "/logs", "/media"] -EXPOSE 8000 # 新增端口暴露声明 - -# ... 保留后续配置 ... -修改说明: - -添加 EXPOSE 8000 指令声明容器监听端口 -该声明本身不会自动发布端口,但能: -帮助其他开发者快速了解服务端口 -在使用 docker run -P 时自动绑定随机公网端口 -与 docker-compose 配置形成互补 -实际运行时仍需通过 -p 参数映射端口: - - -```bash -docker run -d -p 8000:8000 your_image -``` \ No newline at end of file From 6317502c27ea5aab47e79f6dd937dc43dc88cf83 Mon Sep 17 00:00:00 2001 From: kanon Date: Tue, 26 Aug 2025 20:46:48 +0800 Subject: [PATCH 18/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0run.py=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E5=91=BD=E4=BB=A4=E8=A7=A6=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +++++- app/run.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 app/run.py diff --git a/README.md b/README.md index c9a12c11..38585f7b 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,12 @@ python app/main.py ``` +3. 手动触发特定任务 + ```bash + python app/run.py <任务ID> + ``` + 通过`run.py`可以手动触发配置文件中定义的特定任务,而不需要等待定时任务执行。 + # Strm文件优点 - [x] 轻量化 Emby 服务器,降低 Emby 服务器的性能需求以及硬盘需求 - [x] 运行稳定 @@ -93,4 +99,4 @@ # Star History Star History Chart - \ No newline at end of file + \ No newline at end of file diff --git a/app/run.py b/app/run.py new file mode 100644 index 00000000..eb6067f2 --- /dev/null +++ b/app/run.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 + +import sys +import asyncio +from app.core.config import settings +from app.modules.alist2strm import Alist2Strm +from app.modules.ani2alist import Ani2Alist +from app.modules.libraryposter import LibraryPoster + + +def find_task_by_id(task_list, task_id): + """根据ID查找任务配置""" + for task in task_list: + if task.get('id') == task_id: + return task + return None + + +def main(): + if len(sys.argv) != 2: + print("使用方法: python run.py <任务ID>") + print("可用的任务ID:") + + # 显示所有Alist2Strm任务ID + for task in settings.AlistServerList: + print(f" Alist2Strm: {task.get('id')}") + + # 显示所有Ani2Alist任务ID + for task in settings.Ani2AlistList: + print(f" Ani2Alist: {task.get('id')}") + + # 显示所有LibraryPoster任务ID + for task in settings.LibraryPosterList: + print(f" LibraryPoster: {task.get('id')}") + + return + + task_id = sys.argv[1] + + # 查找Alist2Strm任务 + alist_task = find_task_by_id(settings.AlistServerList, task_id) + if alist_task: + print(f"正在执行 Alist2Strm 任务: {task_id}") + alist_instance = Alist2Strm(**alist_task) + asyncio.run(alist_instance.run()) + return + + # 查找Ani2Alist任务 + ani_task = find_task_by_id(settings.Ani2AlistList, task_id) + if ani_task: + print(f"正在执行 Ani2Alist 任务: {task_id}") + ani_instance = Ani2Alist(**ani_task) + asyncio.run(ani_instance.run()) + return + + # 查找LibraryPoster任务 + poster_task = find_task_by_id(settings.LibraryPosterList, task_id) + if poster_task: + print(f"正在执行 LibraryPoster 任务: {task_id}") + poster_instance = LibraryPoster(**poster_task) + asyncio.run(poster_instance.run()) + return + + print(f"未找到ID为 '{task_id}' 的任务") + print("可用的任务ID:") + + # 显示所有Alist2Strm任务ID + for task in settings.AlistServerList: + print(f" Alist2Strm: {task.get('id')}") + + # 显示所有Ani2Alist任务ID + for task in settings.Ani2AlistList: + print(f" Ani2Alist: {task.get('id')}") + + # 显示所有LibraryPoster任务ID + for task in settings.LibraryPosterList: + print(f" LibraryPoster: {task.get('id')}") + + +if __name__ == "__main__": + main() \ No newline at end of file From 11f11caac344695c3d24265ad1ac22190c47db65 Mon Sep 17 00:00:00 2001 From: kanon Date: Wed, 27 Aug 2025 10:30:09 +0800 Subject: [PATCH 19/19] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drun.app?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 ++- README.md | 6 ++++++ app/run.py | 49 +++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 43090f8a..7caeaa34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,8 @@ RUN apk update && \ tzdata \ curl \ build-base \ - linux-headers && \ + linux-headers \ + libgomp && \ cp /usr/share/zoneinfo/${TZ} /etc/localtime && \ echo ${TZ} > /etc/timezone diff --git a/README.md b/README.md index 38585f7b..c88bdac6 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,12 @@ ```bash docker run -d --name autofilm -v ./config:/config -v ./media:/media -v ./logs:/logs akimio/autofilm ``` + +2. Docker 中手动触发特定任务 + ```bash + docker exec autofilm python /app/run.py <任务ID> + ``` + 通过`docker exec`命令可以在运行中的容器内执行run.py脚本来手动触发特定任务。 2. Python 环境运行(Python3.12) ```bash python app/main.py diff --git a/app/run.py b/app/run.py index eb6067f2..8cbd86f1 100644 --- a/app/run.py +++ b/app/run.py @@ -2,10 +2,44 @@ import sys import asyncio +from sys import path +from os.path import dirname + +# 添加项目根目录到路径 +path.append(dirname(dirname(__file__))) + from app.core.config import settings -from app.modules.alist2strm import Alist2Strm -from app.modules.ani2alist import Ani2Alist -from app.modules.libraryposter import LibraryPoster + +# 延迟导入,避免sklearn依赖问题 +# 只在需要时才导入相关模块 +def get_alist2strm(): + try: + from app.modules.alist2strm import Alist2Strm + return Alist2Strm + except ImportError as e: + print(f"导入Alist2Strm模块时出错: {e}") + print("请确保已安装所有依赖库,或者检查Docker环境中是否缺少必要的系统库(如libgomp.so.1)") + sys.exit(1) + + +def get_ani2alist(): + try: + from app.modules.ani2alist import Ani2Alist + return Ani2Alist + except ImportError as e: + print(f"导入Ani2Alist模块时出错: {e}") + print("请确保已安装所有依赖库,或者检查Docker环境中是否缺少必要的系统库(如libgomp.so.1)") + sys.exit(1) + + +def get_libraryposter(): + try: + from app.modules.libraryposter import LibraryPoster + return LibraryPoster + except ImportError as e: + print(f"导入LibraryPoster模块时出错: {e}") + print("请确保已安装所有依赖库,或者检查Docker环境中是否缺少必要的系统库(如libgomp.so.1)") + sys.exit(1) def find_task_by_id(task_list, task_id): @@ -30,7 +64,7 @@ def main(): print(f" Ani2Alist: {task.get('id')}") # 显示所有LibraryPoster任务ID - for task in settings.LibraryPosterList: + for task in settings.LibraryPosterList(): print(f" LibraryPoster: {task.get('id')}") return @@ -41,6 +75,7 @@ def main(): alist_task = find_task_by_id(settings.AlistServerList, task_id) if alist_task: print(f"正在执行 Alist2Strm 任务: {task_id}") + Alist2Strm = get_alist2strm() alist_instance = Alist2Strm(**alist_task) asyncio.run(alist_instance.run()) return @@ -49,14 +84,16 @@ def main(): ani_task = find_task_by_id(settings.Ani2AlistList, task_id) if ani_task: print(f"正在执行 Ani2Alist 任务: {task_id}") + Ani2Alist = get_ani2alist() ani_instance = Ani2Alist(**ani_task) asyncio.run(ani_instance.run()) return # 查找LibraryPoster任务 - poster_task = find_task_by_id(settings.LibraryPosterList, task_id) + poster_task = find_task_by_id(settings.LibraryPosterList(), task_id) if poster_task: print(f"正在执行 LibraryPoster 任务: {task_id}") + LibraryPoster = get_libraryposter() poster_instance = LibraryPoster(**poster_task) asyncio.run(poster_instance.run()) return @@ -73,7 +110,7 @@ def main(): print(f" Ani2Alist: {task.get('id')}") # 显示所有LibraryPoster任务ID - for task in settings.LibraryPosterList: + for task in settings.LibraryPosterList(): print(f" LibraryPoster: {task.get('id')}")