From 3f70486c1a8581f515925aa2ca73ef26dac12c8a Mon Sep 17 00:00:00 2001 From: Akimio521 Date: Fri, 25 Oct 2024 21:22:31 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=A0=BC=E5=BC=8F=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=A9=BA=E6=A0=BC=E4=BB=A5=E6=8F=90=E5=8D=87=E5=8F=AF=E8=AF=BB?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.py | 27 ++++++++++++++++----------- app/modules/alist2strm/alist2strm.py | 18 +++++++++--------- app/modules/ani2alist/ani2alist.py | 2 +- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/main.py b/app/main.py index 22e9af9..bb4b7f9 100644 --- a/app/main.py +++ b/app/main.py @@ -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 @@ -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 程序退出!") diff --git a/app/modules/alist2strm/alist2strm.py b/app/modules/alist2strm/alist2strm.py index 5888eee..aade7ac 100644 --- a/app/modules/alist2strm/alist2strm.py +++ b/app/modules/alist2strm/alist2strm.py @@ -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" @@ -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: """ diff --git a/app/modules/ani2alist/ani2alist.py b/app/modules/ani2alist/ani2alist.py index 4c6aa5f..0effc37 100644 --- a/app/modules/ani2alist/ani2alist.py +++ b/app/modules/ani2alist/ani2alist.py @@ -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)