Skip to content

Commit

Permalink
style: 优化日志输出格式,增加空格以提升可读性
Browse files Browse the repository at this point in the history
  • Loading branch information
Akimio521 committed Oct 25, 2024
1 parent 6c24eb5 commit 3f70486
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
27 changes: 16 additions & 11 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from asyncio import get_event_loop
from sys import path
from os.path import dirname

path.append(dirname(dirname(__file__)))

from apscheduler.schedulers.asyncio import AsyncIOScheduler
Expand All @@ -16,37 +17,41 @@

if __name__ == "__main__":
print(LOGO + str(settings.APP_VERSION).center(65, "="))
logger.info(f"AutoFilm {settings.APP_VERSION}启动中...")
logger.info(f"AutoFilm {settings.APP_VERSION} 启动中...")

scheduler = AsyncIOScheduler()

if settings.AlistServerList:
logger.info("检测到Alist2Strm模块配置,正在添加至后台任务")
for server in settings.AlistServerList:
cron = server.get("cron")
if cron:
scheduler.add_job(Alist2Strm(**server).run,trigger=CronTrigger.from_crontab(cron))
logger.info(f'{server["id"]}已被添加至后台任务')
scheduler.add_job(
Alist2Strm(**server).run, trigger=CronTrigger.from_crontab(cron)
)
logger.info(f'{server["id"]} 已被添加至后台任务')
else:
logger.warning(f'{server["id"]}未设置Cron')
logger.warning(f'{server["id"]} 未设置Cron')
else:
logger.warning("未检测到Alist2Strm模块配置")
logger.warning("未检测到 Alist2Strm 模块配置")

if settings.Ani2AlistList:
logger.info("检测到Ani2Alist模块配置,正在添加至后台任务")
for server in settings.Ani2AlistList:
cron = server.get("cron")
if cron:
scheduler.add_job(Ani2Alist(**server).run,trigger=CronTrigger.from_crontab(cron))
logger.info(f'{server["id"]}已被添加至后台任务')
scheduler.add_job(
Ani2Alist(**server).run, trigger=CronTrigger.from_crontab(cron)
)
logger.info(f'{server["id"]} 已被添加至后台任务')
else:
logger.warning(f'{server["id"]}未设置Cron')
logger.warning(f'{server["id"]} 未设置Cron')
else:
logger.warning("未检测到Ani2Alist模块配置")
logger.warning("未检测到 Ani2Alist 模块配置")

scheduler.start()

try:
get_event_loop().run_forever()
except (KeyboardInterrupt, SystemExit):
logger.info("AutoFilm程序退出!")
logger.info("AutoFilm 程序退出!")
18 changes: 9 additions & 9 deletions app/modules/alist2strm/alist2strm.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ def filter(path: AlistPath) -> bool:
return False

if not path.suffix.lower() in self.process_file_exts:
logger.debug(f"文件{path.name}不在处理列表中")
logger.debug(f"文件 {path.name} 不在处理列表中")
return False

local_path = self.__get_local_path(path)
self.processed_local_paths.add(local_path)

if not self.overwrite and local_path.exists():
logger.debug(f"文件{local_path.name}已存在,跳过处理{path.path}")
logger.debug(f"文件 {local_path.name} 已存在,跳过处理 {path.path}")
return False

return True

if not self.mode in ["AlistURL", "RawURL", "AlistPath"]:
logger.warning(
f"Alist2Strm的模式{self.mode}不存在,已设置为默认模式AlistURL"
f"Alist2Strm的模式 {self.mode} 不存在,已设置为默认模式AlistURL"
)
self.mode = "AlistURL"

Expand Down Expand Up @@ -162,31 +162,31 @@ async def __file_processer(self, path: AlistPath) -> None:
elif self.mode == "AlistPath":
content = path.path
else:
raise ValueError(f"AlistStrm未知的模式{self.mode}")
raise ValueError(f"AlistStrm未知的模式 {self.mode}")

try:
_parent = local_path.parent
if not _parent.exists():
await to_thread(_parent.mkdir, parents=True, exist_ok=True)

logger.debug(f"开始处理{local_path}")
logger.debug(f"开始处理 {local_path}")
if local_path.suffix == ".strm":
async with async_open(local_path, mode="w", encoding="utf-8") as file:
await file.write(content)
logger.info(f"{local_path.name}创建成功")
logger.info(f"{local_path.name} 创建成功")
else:
async with self.__max_downloaders:
async with async_open(local_path, mode="wb") as file:
async with self.session.get(path.download_url) as resp:
if resp.status != 200:
raise RuntimeError(
f"下载{path.download_url}失败,状态码:{resp.status}"
f"下载 {path.download_url} 失败,状态码:{resp.status}"
)
async for chunk in resp.content.iter_chunked(1024):
await file.write(chunk)
logger.info(f"{local_path.name}下载成功")
logger.info(f"{local_path.name} 下载成功")
except Exception as e:
raise RuntimeError(f"{local_path}处理失败,详细信息:{e}")
raise RuntimeError(f"{local_path} 处理失败,详细信息:{e}")

def __get_local_path(self, path: AlistPath) -> Path:
"""
Expand Down
2 changes: 1 addition & 1 deletion app/modules/ani2alist/ani2alist.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def merge_dicts(target_dict: dict, source_dict: dict) -> dict:
)
if not storage:
logger.debug(
f"在Alist服务器上未找到存储器{self.__target_dir},开始创建存储器"
f"在Alist服务器上未找到存储器 {self.__target_dir},开始创建存储器"
)
storage = AlistStorage(driver="UrlTree", mount_path=self.__target_dir)
await client.async_api_admin_storage_create(storage)
Expand Down

0 comments on commit 3f70486

Please sign in to comment.