From 7aaa6727e679420685d665759d8eec15241cfae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AE=E5=8F=AE=E5=BD=93?= <604054726@qq.com> Date: Sun, 18 Feb 2024 00:13:18 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=AA=92=E4=BD=93=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E7=9A=84=E9=97=AE=E9=A2=98/=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E8=AE=BE=E7=BD=AE=E6=97=B6=E8=A2=AB=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=8D=A1=E4=BD=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/downloadsitetag/__init__.py | 43 ++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/plugins/downloadsitetag/__init__.py b/plugins/downloadsitetag/__init__.py index b0d88cb..4aa089a 100644 --- a/plugins/downloadsitetag/__init__.py +++ b/plugins/downloadsitetag/__init__.py @@ -1,3 +1,5 @@ +import datetime +import pytz from typing import List, Tuple, Dict, Any from app.core.context import Context @@ -10,6 +12,7 @@ from app.modules.qbittorrent import Qbittorrent from app.modules.transmission import Transmission from app.db.downloadhistory_oper import DownloadHistoryOper from app.modules.themoviedb.tmdbapi import TmdbHelper +from apscheduler.schedulers.background import BackgroundScheduler class DownloadSiteTag(_PluginBase): # 插件名称 @@ -38,6 +41,7 @@ class DownloadSiteTag(_PluginBase): downloader_tr = None downloadhistory_oper = None tmdb_helper = None + _scheduler = None _enabled = False _onlyonce = False _enabled_media_tag = False @@ -63,13 +67,26 @@ class DownloadSiteTag(_PluginBase): self._category_tv = config.get("category_tv") or "电视" self._category_anime = config.get("category_anime") or "动漫" + # 停止现有任务 + self.stop_service() + if self._onlyonce: + # 创建定时任务控制器 + self._scheduler = BackgroundScheduler(timezone=settings.TZ) # 执行一次, 关闭onlyonce self._onlyonce = False config.update({"onlyonce": self._onlyonce}) self.update_config(config) - # 补全下载历史的标签与分类 - self._complemented_history() + # 添加 补全下载历史的标签与分类 任务 + self._scheduler.add_job(func= self._complemented_history, trigger='date', + run_date=datetime.datetime.now( + tz=pytz.timezone(settings.TZ)) + datetime.timedelta(seconds=3) + ) + + if self._scheduler and self._scheduler.get_jobs(): + # 启动服务 + self._scheduler.print_jobs() + self._scheduler.start() def get_state(self) -> bool: return self._enabled @@ -85,6 +102,7 @@ class DownloadSiteTag(_PluginBase): """ 补全下载历史的标签与分类 """ + logger.info(f"{self.LOG_TAG}开始执行: 补全下载历史的标签与分类 ...") for DOWNLOADER in ["qbittorrent", "transmission"]: logger.info(f"{self.LOG_TAG}开始扫描下载器 {DOWNLOADER} ...") # 获取下载器中的种子 @@ -122,10 +140,10 @@ class DownloadSiteTag(_PluginBase): if self._enabled_media_tag and history.title: _tags.append(history.title) # 分类, 如果勾选开关的话