Update cleaninvalidseed to v1.8

This commit is contained in:
xuzhi
2024-05-28 14:25:12 +00:00
parent d699146406
commit 57cc748942
2 changed files with 76 additions and 21 deletions

View File

@@ -702,11 +702,12 @@
"name": "清理QB无效做种",
"description": "清理已经被站点删除的种子及对应源文件仅支持QB",
"labels": "Qbittorrent",
"version": "1.7",
"version": "1.8",
"icon": "clean_a.png",
"author": "DzAvril",
"level": 1,
"history": {
"v1.8": "增加远程命令切换全量通知修复bug",
"v1.7": "修复因消息内容包含'_'导致telegram API调用失败的问题",
"v1.6": "修复当种子有多个标签时,通过标签过滤不删除种子会失效的问题",
"v1.5": "1. 增加通过分类、标签过滤不删除种子功能2. 全量通知提供更多信息",

View File

@@ -28,7 +28,7 @@ class CleanInvalidSeed(_PluginBase):
# 插件图标
plugin_icon = "clean_a.png"
# 插件版本
plugin_version = "1.7"
plugin_version = "1.8"
# 插件作者
plugin_author = "DzAvril"
# 作者主页
@@ -94,22 +94,7 @@ class CleanInvalidSeed(_PluginBase):
)
# 关闭一次性开关
self._onlyonce = False
self.update_config(
{
"onlyonce": False,
"cron": self._cron,
"enabled": self._enabled,
"notify": self._notify,
"delete_invalid_torrents": self._delete_invalid_torrents,
"delete_invalid_files": self._delete_invalid_files,
"detect_invalid_files": self._detect_invalid_files,
"notify_all": self._notify_all,
"download_dirs": self._download_dirs,
"exclude_keywords": self._exclude_keywords,
"exclude_categories": self._exclude_categories,
"exclude_labels": self._exclude_labels,
}
)
self._update_config()
# 启动任务
if self._scheduler.get_jobs():
@@ -119,6 +104,24 @@ class CleanInvalidSeed(_PluginBase):
def get_state(self) -> bool:
return self._enabled
def _update_config(self):
self.update_config(
{
"onlyonce": False,
"cron": self._cron,
"enabled": self._enabled,
"notify": self._notify,
"delete_invalid_torrents": self._delete_invalid_torrents,
"delete_invalid_files": self._delete_invalid_files,
"detect_invalid_files": self._detect_invalid_files,
"notify_all": self._notify_all,
"download_dirs": self._download_dirs,
"exclude_keywords": self._exclude_keywords,
"exclude_categories": self._exclude_categories,
"exclude_labels": self._exclude_labels,
}
)
@staticmethod
def get_command() -> List[Dict[str, Any]]:
"""
@@ -154,6 +157,13 @@ class CleanInvalidSeed(_PluginBase):
"category": "QB",
"data": {"action": "delete_invalid_files"},
},
{
"cmd": "/toggle_notify_all",
"event": EventType.PluginAction,
"desc": "QB清理插件切换全量通知",
"category": "QB",
"data": {"action": "toggle_notify_all"},
},
]
@eventmanager.register(EventType.PluginAction)
@@ -189,6 +199,22 @@ class CleanInvalidSeed(_PluginBase):
logger.info("收到远程命令,开始清理无效源文件")
self._delete_invalid_files = True
self.detect_invalid_files()
elif event_data.get("action") == "toggle_notify_all":
self._notify_all = not self._notify_all
self._update_config()
if self._notify_all:
self.post_message(
channel=event.event_data.get("channel"),
title="已开启全量通知",
userid=event.event_data.get("user"),
)
else:
self.post_message(
channel=event.event_data.get("channel"),
title="已关闭全量通知",
userid=event.event_data.get("user"),
)
return
else:
logger.error("收到未知远程命令")
return
@@ -256,8 +282,8 @@ class CleanInvalidSeed(_PluginBase):
# tracker未工作但暂时不能判定为失效做种需人工判断
tracker_not_working_torrents = []
working_tracker_set = set()
exclude_categories = self._exclude_categories.split("\n")
exclude_labels = self._exclude_labels.split("\n")
exclude_categories = self._exclude_categories.split("\n") if self._exclude_categories else []
exclude_labels = self._exclude_labels.split("\n") if self._exclude_labels else []
# 第一轮筛选出所有未工作的种子
for torrent in all_torrents:
trackers = torrent.trackers
@@ -442,7 +468,15 @@ class CleanInvalidSeed(_PluginBase):
source_paths = []
total_size = 0
deleted_file_cnt = 0
exclude_key_words = self._exclude_keywords.split("\n")
exclude_key_words = self._exclude_keywords.split("\n") if self._exclude_keywords else []
if not self._download_dirs:
logger.error("未配置下载目录,无法检测未做种无效源文件")
self.post_message(
mtype=NotificationType.SiteMessage,
title=f"【检测无效源文件】",
text="未配置下载目录,无法检测未做种无效源文件",
)
return
for path in self._download_dirs.split("\n"):
mp_path, qb_path = path.split(":")
source_path_map[mp_path] = qb_path
@@ -760,3 +794,23 @@ class CleanInvalidSeed(_PluginBase):
self._scheduler = None
except Exception as e:
logger.error("退出插件失败:%s" % str(e))
if __name__ == "__main__":
clean = CleanInvalidSeed()
config = {
"enabled": True,
"notify": True,
"download_dirs": "/sata16t/春天:/保种/春天\n/sata16t/观众:/保种/观众\n/sata16t/UB:/保种/UB\n/sata16t/听听歌:/保种/听听歌\n/ssd/Download/shualiu:/Downloads/shualiu",
"delete_invalid_torrents": False,
"delete_invalid_files": False,
"detect_invalid_files": True,
"notify_all": False,
"onlyonce": False,
"cron": "0 0 * * *",
"exclude_keywords": "ABF-075\nIPZZ-002-C_GG5\nIPZZ-061\n.!qB",
"exclude_categories": "电影",
"exclude_labels": "春天",
}
clean.init_plugin(config)
clean.clean_invalid_seed()