From 9ad68d80a9375aed30d099f3b62e4267e5797611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AE=E5=8F=AE=E5=BD=93?= <604054726@qq.com> Date: Wed, 21 Feb 2024 09:27:11 +0800 Subject: [PATCH 1/3] fix interval_cron --- package.json | 2 +- plugins/downloadsitetag/__init__.py | 46 ++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 96c50f7..0c025d2 100644 --- a/package.json +++ b/package.json @@ -338,7 +338,7 @@ "DownloadSiteTag": { "name": "下载任务分类与标签", "description": "自动给下载任务分类与打站点标签、剧集名称标签", - "version": "1.6", + "version": "1.7", "icon": "Youtube-dl_B.png", "author": "叮叮当", "level": 1 diff --git a/plugins/downloadsitetag/__init__.py b/plugins/downloadsitetag/__init__.py index 02d4c4f..f9d2fb1 100644 --- a/plugins/downloadsitetag/__init__.py +++ b/plugins/downloadsitetag/__init__.py @@ -26,7 +26,7 @@ class DownloadSiteTag(_PluginBase): # 插件图标 plugin_icon = "Youtube-dl_B.png" # 插件版本 - plugin_version = "1.6" + plugin_version = "1.7" # 插件作者 plugin_author = "叮叮当" # 作者主页 @@ -45,6 +45,7 @@ class DownloadSiteTag(_PluginBase): downloader_tr = None downloadhistory_oper = None tmdb_helper = None + sites_helper = None _scheduler = None _enabled = False _onlyonce = False @@ -64,6 +65,7 @@ class DownloadSiteTag(_PluginBase): self.downloader_tr = Transmission() self.downloadhistory_oper = DownloadHistoryOper() self.tmdb_helper = TmdbHelper() + self.sites_helper = SitesHelper() # 读取配置 if config: self._enabled = config.get("enabled") @@ -78,10 +80,10 @@ class DownloadSiteTag(_PluginBase): self._category_movie = config.get("category_movie") or "电影" self._category_tv = config.get("category_tv") or "电视" self._category_anime = config.get("category_anime") or "动漫" - if self.plugin_version == "1.6" and not ("interval_time" in config): + if not ("interval_cron" in config): # 新版本v1.6更新插件配置默认配置 config["interval"] = self._interval - config["interval_time"] = self._interval_cron + config["interval_cron"] = self._interval_cron config["interval_time"] = self._interval_time config["interval_unit"] = self._interval_unit self.update_config(config) @@ -180,6 +182,9 @@ class DownloadSiteTag(_PluginBase): _hash = self._get_hash(torrent=torrent, dl_type=DOWNLOADER) if not _hash: continue + # 获取种子当前标签 + torrent_tags = self._get_label(torrent=torrent, dl_type=DOWNLOADER) + torrent_cat = self._get_category(torrent=torrent, dl_type=DOWNLOADER) # 提取种子hash对应的下载历史 history: DownloadHistory = self.downloadhistory_oper.get_by_hash(_hash) if not history: @@ -198,21 +203,25 @@ class DownloadSiteTag(_PluginBase): # 加入历史记录 if _key: dispose_history[_key] = history + # 获取已知索引列表 + indexers_list = [v.get("name") for k, v in (self.sites_helper._indexers or {}).items()] + # JackettIndexers索引器支持多个站点, 如果不存在历史记录, 则通过tracker会再次附加其他站点名称 + indexers_list.append("JackettIndexers") + # 如果标签已经存在任意站点, 则不再添加站点标签 + if set(indexers_list).intersection(set(torrent_tags)): + history.torrent_site = None # 如果站点名称为空, 尝试通过trackers识别 - if not history.torrent_site: + elif not history.torrent_site: trackers = self._get_trackers(torrent=torrent, dl_type=DOWNLOADER) for tracker in trackers: domain = StringUtils.get_url_domain(tracker) - site_info = SitesHelper().get_indexer(domain) + site_info = self.sites_helper.get_indexer(domain) if site_info: history.torrent_site = site_info.get("name") break # 如果通过tracker还是无法获取站点名称, 且tmdbid, type, title都是空的, 那么跳过当前种子 if not history.torrent_site and not history.tmdbid and not history.type and not history.title: continue - # 获取种子当前标签 - torrent_tags = self._get_label(torrent=torrent, dl_type=DOWNLOADER) - torrent_cat = self._get_category(torrent=torrent, dl_type=DOWNLOADER) # 按设置生成需要写入的标签与分类 _tags = [] _cat = None @@ -698,6 +707,27 @@ class DownloadSiteTag(_PluginBase): ] } ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + }, + 'content': [ + { + 'component': 'VAlert', + 'props': { + 'type': 'info', + 'variant': 'tonal', + 'text': '定时任务:支持两种定时方式,主要针对辅种刷流等种子补全站点信息。如没有对应的需求建议切换为禁用。' + } + } + ] + } + ] } ] } From 63c327096eca417558dcb047957f8fa59f10b462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AE=E5=8F=AE=E5=BD=93?= <604054726@qq.com> Date: Wed, 21 Feb 2024 13:57:46 +0800 Subject: [PATCH 2/3] fix self._event.set() --- plugins/downloadsitetag/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/downloadsitetag/__init__.py b/plugins/downloadsitetag/__init__.py index f9d2fb1..2e76ff5 100644 --- a/plugins/downloadsitetag/__init__.py +++ b/plugins/downloadsitetag/__init__.py @@ -1,5 +1,6 @@ import datetime import pytz +import threading from typing import List, Tuple, Dict, Any from app.core.context import Context @@ -39,7 +40,9 @@ class DownloadSiteTag(_PluginBase): auth_level = 1 # 日志前缀 LOG_TAG = "[DownloadSiteTag] " - + + # 退出事件 + _event = threading.Event() # 私有属性 downloader_qb = None downloader_tr = None @@ -176,6 +179,9 @@ class DownloadSiteTag(_PluginBase): logger.info(f"{self.LOG_TAG}下载器 {DOWNLOADER} 分析种子信息中 ...") for torrent in torrents: try: + if self._event.is_set(): + logger.info(f"{self.LOG_TAG}停止服务{'(定时任务)' if interval else ''}: 补全下载历史的标签与分类") + return # 获取已处理种子的key (size, name) _key = self._torrent_key(torrent=torrent, dl_type=DOWNLOADER) # 获取种子hash From 3c5fed32958fd75704ce282fde020fb579998100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AE=E5=8F=AE=E5=BD=93?= <604054726@qq.com> Date: Wed, 21 Feb 2024 16:54:05 +0800 Subject: [PATCH 3/3] fix --- plugins/downloadsitetag/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/downloadsitetag/__init__.py b/plugins/downloadsitetag/__init__.py index 2e76ff5..9b42caa 100644 --- a/plugins/downloadsitetag/__init__.py +++ b/plugins/downloadsitetag/__init__.py @@ -162,6 +162,11 @@ class DownloadSiteTag(_PluginBase): logger.info(f"{self.LOG_TAG}开始执行{'(定时任务)' if interval else ''}: 补全下载历史的标签与分类 ...") # 记录处理的种子, 供辅种(无下载历史)使用 dispose_history = {} + # 所有站点索引 + indexers = [indexer.get("name") for indexer in self.sites_helper.get_indexers()] + # JackettIndexers索引器支持多个站点, 如果不存在历史记录, 则通过tracker会再次附加其他站点名称 + indexers.append("JackettIndexers") + indexers = set(indexers) for DOWNLOADER in ["qbittorrent", "transmission"]: logger.info(f"{self.LOG_TAG}开始扫描下载器 {DOWNLOADER} ...") # 获取下载器中的种子 @@ -209,12 +214,8 @@ class DownloadSiteTag(_PluginBase): # 加入历史记录 if _key: dispose_history[_key] = history - # 获取已知索引列表 - indexers_list = [v.get("name") for k, v in (self.sites_helper._indexers or {}).items()] - # JackettIndexers索引器支持多个站点, 如果不存在历史记录, 则通过tracker会再次附加其他站点名称 - indexers_list.append("JackettIndexers") # 如果标签已经存在任意站点, 则不再添加站点标签 - if set(indexers_list).intersection(set(torrent_tags)): + if indexers.intersection(set(torrent_tags)): history.torrent_site = None # 如果站点名称为空, 尝试通过trackers识别 elif not history.torrent_site: