From 29303d3818a21ceea285fde52f940c0066027a0b Mon Sep 17 00:00:00 2001 From: thsrite Date: Fri, 24 May 2024 20:18:25 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=AA=92=E4=BD=93=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=88=A0=E9=99=A4v1.6=3D>=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=BE=85=E7=A7=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- plugins/mediasyncdel/__init__.py | 77 +++++++++----------------------- 2 files changed, 22 insertions(+), 58 deletions(-) diff --git a/package.json b/package.json index 21a7f33..1f21309 100644 --- a/package.json +++ b/package.json @@ -130,11 +130,12 @@ "name": "媒体文件同步删除", "description": "同步删除历史记录、源文件和下载任务。", "labels": "文件整理", - "version": "1.5", + "version": "1.6", "icon": "mediasyncdel.png", "author": "thsrite", "level": 1, "history": { + "v1.6": "修复删除辅种", "v1.5": "支持手动删除订阅历史记录(本次更新之后的历史)" } }, diff --git a/plugins/mediasyncdel/__init__.py b/plugins/mediasyncdel/__init__.py index 7ca9ed6..2ff19c1 100644 --- a/plugins/mediasyncdel/__init__.py +++ b/plugins/mediasyncdel/__init__.py @@ -17,9 +17,6 @@ from app.db.models.transferhistory import TransferHistory from app.log import logger from app.modules.emby import Emby from app.modules.jellyfin import Jellyfin -from app.modules.qbittorrent import Qbittorrent -from app.modules.themoviedb.tmdbv3api import Episode -from app.modules.transmission import Transmission from app.plugins import _PluginBase from app.schemas.types import NotificationType, EventType, MediaType, MediaImageType @@ -32,7 +29,7 @@ class MediaSyncDel(_PluginBase): # 插件图标 plugin_icon = "mediasyncdel.png" # 插件版本 - plugin_version = "1.5" + plugin_version = "1.6" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -45,7 +42,6 @@ class MediaSyncDel(_PluginBase): auth_level = 1 # 私有属性 - episode = None _scheduler: Optional[BackgroundScheduler] = None _enabled = False _sync_type: str = "" @@ -58,16 +54,11 @@ class MediaSyncDel(_PluginBase): _transferchain = None _transferhis = None _downloadhis = None - qb = None - tr = None def init_plugin(self, config: dict = None): self._transferchain = TransferChain() self._transferhis = self._transferchain.transferhis self._downloadhis = self._transferchain.downloadhis - self.episode = Episode() - self.qb = Qbittorrent() - self.tr = Transmission() # 停止现有任务 self.stop_service() @@ -1199,12 +1190,8 @@ class MediaSyncDel(_PluginBase): # 删除转种后任务 logger.info(f"删除转种后下载任务:{download} - {download_id}") # 删除转种后下载任务 - if download == "transmission": - self.tr.delete_torrents(delete_file=True, - ids=download_id) - else: - self.qb.delete_torrents(delete_file=True, - ids=download_id) + self.chain.remove_torrents(hashs=torrent_hash, + downloader=download) handle_torrent_hashs.append(download_id) else: # 暂停种子 @@ -1219,10 +1206,7 @@ class MediaSyncDel(_PluginBase): logger.info(f"暂停转种后下载任务:{download} - {download_id}") # 删除转种后下载任务 - if download == "transmission": - self.tr.stop_torrents(ids=download_id) - else: - self.qb.stop_torrents(ids=download_id) + self.chain.stop_torrents(hashs=download_id, downloader=download) handle_torrent_hashs.append(download_id) else: # 未转种de情况 @@ -1237,8 +1221,7 @@ class MediaSyncDel(_PluginBase): handle_torrent_hashs.append(download_id) # 处理辅种 - handle_torrent_hashs = self.__del_seed(download=download, - download_id=download_id, + handle_torrent_hashs = self.__del_seed(download_id=download_id, delete_flag=delete_flag, handle_torrent_hashs=handle_torrent_hashs) # 处理合集 @@ -1284,27 +1267,19 @@ class MediaSyncDel(_PluginBase): # 删除合集种子 if delete_flag: - if str(download_file.downloader) == "transmission": - self.tr.delete_torrents(delete_file=True, - ids=download_file.download_hash) - else: - self.qb.delete_torrents(delete_file=True, - ids=download_file.download_hash) - + self.chain.remove_torrents(hashs=download_file.download_hash, + downloader=download_file.downloader) logger.info(f"删除合集种子 {download_file.downloader} {download_file.download_hash}") else: # 暂停合集种子 - if str(download_file.downloader) == "transmission": - self.tr.stop_torrents(ids=download_file.download_hash) - else: - self.qb.stop_torrents(ids=download_file.download_hash) + self.chain.stop_torrents(hashs=download_file.download_hash, + downloader=download_file.downloader) logger.info(f"暂停合集种子 {download_file.downloader} {download_file.download_hash}") # 已处理种子+1 handle_torrent_hashs.append(download_file.download_hash) # 处理合集辅种 - handle_torrent_hashs = self.__del_seed(download=download_file.downloader, - download_id=download_file.download_hash, + handle_torrent_hashs = self.__del_seed(download_id=download_file.download_hash, delete_flag=delete_flag, handle_torrent_hashs=handle_torrent_hashs) except Exception as e: @@ -1313,7 +1288,7 @@ class MediaSyncDel(_PluginBase): return handle_torrent_hashs - def __del_seed(self, download, download_id, delete_flag, handle_torrent_hashs): + def __del_seed(self, download_id, delete_flag, handle_torrent_hashs): """ 删除辅种 """ @@ -1337,30 +1312,18 @@ class MediaSyncDel(_PluginBase): # 删除辅种历史 for torrent in torrents: handle_torrent_hashs.append(torrent) - if str(download) == "qbittorrent": - # 删除辅种 - if delete_flag: - logger.info(f"删除辅种:{downloader} - {torrent}") - self.qb.delete_torrents(delete_file=True, - ids=torrent) - # 暂停辅种 - else: - self.qb.stop_torrents(ids=torrent) - logger.info(f"辅种:{downloader} - {torrent} 暂停") + # 删除辅种 + if delete_flag: + logger.info(f"删除辅种:{downloader} - {torrent}") + self.chain.remove_torrents(hashs=torrent, + downloader=downloader) + # 暂停辅种 else: - # 删除辅种 - if delete_flag: - logger.info(f"删除辅种:{downloader} - {torrent}") - self.tr.delete_torrents(delete_file=True, - ids=torrent) - # 暂停辅种 - else: - self.tr.stop_torrents(ids=torrent) - logger.info(f"辅种:{downloader} - {torrent} 暂停") + self.chain.stop_torrents(hashs=torrent, download=downloader) + logger.info(f"辅种:{downloader} - {torrent} 暂停") # 处理辅种的辅种 - handle_torrent_hashs = self.__del_seed(download=downloader, - download_id=torrent, + handle_torrent_hashs = self.__del_seed(download_id=torrent, delete_flag=delete_flag, handle_torrent_hashs=handle_torrent_hashs)