-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
126 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .config import settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python3 | ||
# encoding: utf-8 | ||
|
||
|
||
import logging | ||
from pathlib import Path | ||
from yaml import safe_load | ||
|
||
from version import APP_VERSION | ||
|
||
|
||
class SettingManager: | ||
""" | ||
系统配置 | ||
""" | ||
|
||
# APP 名称 | ||
APP_NAME: str = "Autofilm" | ||
# APP 版本 | ||
APP_VERSION: int = APP_VERSION | ||
# 时区 | ||
TZ: str = "Asia/Shanghai" | ||
|
||
def __init__(self) -> None: | ||
""" | ||
初始化 SettingManager 对象 | ||
""" | ||
self.__mkdir() | ||
self.__init_logging() | ||
|
||
def __mkdir(self) -> None: | ||
""" | ||
创建目录 | ||
""" | ||
with self.CONFIG_DIR as dir_path: | ||
if not dir_path.exists(): | ||
dir_path.mkdir(parents=True, exist_ok=True) | ||
|
||
def __init_logging(self): | ||
""" | ||
初始化 loggging 日志模块内容 | ||
""" | ||
with self.CONFIG.open(mode="r", encoding="utf-8") as file: | ||
log_level = safe_load(file).get("Settings").get("log_level") or "INFO" | ||
|
||
formatter = "[%(levelname)s]%(asctime)s - %(message)s" | ||
logging.basicConfig(format=formatter, level=getattr(logging, log_level)) | ||
|
||
@property | ||
def BASE_DIR(self) -> Path: | ||
return Path(__file__).parents[2] | ||
|
||
@property | ||
def CONFIG_DIR(self) -> Path: | ||
return self.BASE_DIR / "config" | ||
|
||
@property | ||
def CONFIG(self) -> Path: | ||
return self.CONFIG_DIR / "config.yaml" | ||
|
||
@property | ||
def AlistServerList(self) -> list[dict[str, any]]: | ||
with self.CONFIG.open(mode="r", encoding="utf-8") as file: | ||
alist_server_list = safe_load(file).get("Alist2StrmList", []) | ||
return alist_server_list | ||
|
||
|
||
settings = SettingManager() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
# -*- coding:utf-8 -*- | ||
import argparse | ||
#!/usr/bin/env python3 | ||
# encoding: utf-8 | ||
|
||
import logging | ||
import asyncio | ||
from sys import path | ||
from os.path import dirname | ||
|
||
from apscheduler.schedulers.asyncio import AsyncIOScheduler | ||
from apscheduler.triggers.cron import CronTrigger | ||
|
||
import autofilm | ||
from version import APP_VERSION | ||
path.append(dirname(__file__)) | ||
from core import settings | ||
from modules import Alist2Strm | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Autofilm参数配置") | ||
parser.add_argument( | ||
"--config_path", type=str, help="配置文件路径", default="../config/config.yaml" | ||
) | ||
parser.add_argument( | ||
"--log_level", | ||
type=str, | ||
help="日志级别", | ||
default="INFO", | ||
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], | ||
) | ||
args = parser.parse_args() | ||
logging.info(f"当前的APP版本是:{settings.APP_VERSION}") | ||
|
||
formatter = "[%(asctime)s][%(levelname)s]%(funcName)s:%(message)s" | ||
logging.basicConfig(format=formatter, level=getattr(logging, args.log_level)) | ||
scheduler = AsyncIOScheduler() | ||
|
||
for server in settings.AlistServerList: | ||
cron = server.get("cron") | ||
if cron: | ||
scheduler.add_job(Alist2Strm(**server).run,trigger=CronTrigger.from_crontab(cron)) | ||
logging.info(f"{server["id"]}已被添加至后台任务") | ||
else: | ||
logging.warning(f"{server["id"]}未设置Cron") | ||
|
||
logging.info(f"当前的APP版本是:{APP_VERSION}") | ||
logging.info(f"配置文件路径:{args.config_path}") | ||
scheduler.start() | ||
|
||
my_autofilm = autofilm.AutoFilm(config_path=args.config_path) | ||
my_autofilm.run_Alist2Strm() | ||
try: | ||
asyncio.get_event_loop().run_forever() | ||
except (KeyboardInterrupt, SystemExit): | ||
print("AutoFilm程序退出!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
Settings: | ||
output_dir: /media # 输出路径 | ||
subtitle: True # 是否下载字幕 | ||
img: False # 是否下载图片 | ||
nfo: True # 是否下载视频信息文件 | ||
library_mode: False # 媒体库模式 | ||
log_level: DEBUG # 日志输出等级(可选,默认 INFO) | ||
|
||
AlistServerList: | ||
- id: 动漫A # 任意字符,用于标识Alist服务器 | ||
url: https://alist.example.com # Alist服务器URL | ||
username: alist # Alist账号 | ||
password: adminadmin # Alist密码 | ||
base_path: /ani/A/ # Alist服务器上文件夹路径 | ||
token: # AList未启用签名时,设置为空字符串 | ||
async_mode: False # 设置 subtitle,img,nfo 等二进制文件是否启用异步下载 | ||
overwrite: False # 本地路径存在同名文件时是否重新生成/下载该文件 | ||
|
||
- id: 电影A | ||
url: https://alist.example1.com | ||
- cron: 0 20 * * * # 后台定时任务 Crontable 表达式 | ||
url: https://alist.akimio.top # Alist 服务器地址 | ||
username: admin # Alist 账号 | ||
password: adminadmin # Alist 密码 | ||
token: # AList 未启用签名时,设置为空字符串 | ||
source_dir: /ani/A # Alist 服务器上文件夹路径 | ||
target_dir: D:\media\ # 输出路径 | ||
flatten_mode: False # 平铺模式,开启后 subtitle、image、nfo 强制关闭(可选,默认 False) | ||
subtitle: False # 是否下载字幕文件(可选,默认 False) | ||
image: False # 是否下载图片文件(可选,默认 False) | ||
nfo: False # 是否下载 .nfo 文件(可选,默认 False) | ||
overwrite: False # 覆盖模式,本地路径存在同名文件时是否重新生成/下载该文件(可选,默认 False) | ||
max_workers: 5 # 下载文件最大并发数(可选,默认 5) | ||
- cron: 0 0 7 * * | ||
url: http://alist.example2.com:5244 | ||
username: alist | ||
password: alist | ||
base_path: /movie/A/ | ||
token: | ||
async_mode: True | ||
overwrite: False | ||
|
||
- id: OneDrive | ||
url: https://alist.example2.com | ||
username: alist | ||
password: adminadmin | ||
base_path: /网盘/OneDrive/ | ||
password: alist | ||
token: alist-a1b2c3d4-12... | ||
async_mode: False | ||
overwrite: True | ||
source_dir: /ani/A | ||
target_dir: ~/media/my_video | ||
flatten_mode: False | ||
subtitle: False | ||
image: False | ||
nfo: False | ||
overwrite: False | ||
max_workers: 5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
aiofile == 3.8.8 | ||
PyYAML == 6.0.1 | ||
python-alist == 0.0.13.0.2 | ||
python-alist == 0.0.13.0.2 | ||
APScheduler == 3.10.4 |