diff --git a/app/modules/rtorrent/__init__.py b/app/modules/rtorrent/__init__.py index 89d9823b..61af67a9 100644 --- a/app/modules/rtorrent/__init__.py +++ b/app/modules/rtorrent/__init__.py @@ -196,7 +196,7 @@ class RtorrentModule(_ModuleBase, _DownloaderBase[Rtorrent]): # 不需要的文件ID file_ids = [] # 需要的集清单 - sucess_epidised = [] + sucess_epidised = set() try: for torrent_file in torrent_files: file_id = torrent_file.get("id") @@ -206,10 +206,11 @@ class RtorrentModule(_ModuleBase, _DownloaderBase[Rtorrent]): or not set(meta_info.episode_list).issubset(episodes): file_ids.append(file_id) else: - sucess_epidised = list(set(sucess_epidised).union(set(meta_info.episode_list))) + sucess_epidised.update(meta_info.episode_list) finally: torrent_files.clear() del torrent_files + sucess_epidised = list(sucess_epidised) if sucess_epidised and file_ids: # 设置不需要的文件优先级为0(不下载) server.set_files(torrent_hash=torrent_hash, file_ids=file_ids, priority=0) @@ -321,7 +322,7 @@ class RtorrentModule(_ModuleBase, _DownloaderBase[Rtorrent]): return None return ret_torrents # noqa - def transfer_completed(self, hashs: str, downloader: Optional[str] = None) -> None: + def transfer_completed(self, hashs: Union[str, list], downloader: Optional[str] = None) -> None: """ 转移完成后的处理 :param hashs: 种子Hash @@ -338,15 +339,7 @@ class RtorrentModule(_ModuleBase, _DownloaderBase[Rtorrent]): else: tags = ['已整理'] # 直接设置完整标签(覆盖) - if isinstance(hashs, str): - hashs_list = [hashs] - else: - hashs_list = hashs - for tid in hashs_list: - try: - server._proxy.d.custom1.set(tid, ",".join(tags)) - except Exception: - pass + server.set_torrents_tag(ids=hashs, tags=tags, overwrite=True) return None def remove_torrents(self, hashs: Union[str, list], delete_file: Optional[bool] = True, diff --git a/app/modules/rtorrent/rtorrent.py b/app/modules/rtorrent/rtorrent.py index 87b17d09..9767e1f4 100644 --- a/app/modules/rtorrent/rtorrent.py +++ b/app/modules/rtorrent/rtorrent.py @@ -402,9 +402,12 @@ class Rtorrent: logger.error(f"设置种子文件状态出错:{str(err)}") return False - def set_torrents_tag(self, ids: Union[str, list], tags: List[str]) -> bool: + def set_torrents_tag(self, ids: Union[str, list], tags: List[str], overwrite: bool = False) -> bool: """ 设置种子标签(使用d.custom1) + :param ids: 种子Hash + :param tags: 标签列表 + :param overwrite: 是否覆盖现有标签,默认为合并 """ if not self._proxy: return False @@ -414,12 +417,16 @@ class Rtorrent: if isinstance(ids, str): ids = [ids] for tid in ids: - # 获取现有标签 - existing = self._proxy.d.custom1(tid) - existing_tags = [t.strip() for t in existing.split(",") if t.strip()] if existing else [] - # 合并标签 - merged = list(set(existing_tags + tags)) - self._proxy.d.custom1.set(tid, ",".join(merged)) + if overwrite: + # 直接覆盖标签 + self._proxy.d.custom1.set(tid, ",".join(tags)) + else: + # 获取现有标签 + existing = self._proxy.d.custom1(tid) + existing_tags = [t.strip() for t in existing.split(",") if t.strip()] if existing else [] + # 合并标签 + merged = list(set(existing_tags + tags)) + self._proxy.d.custom1.set(tid, ",".join(merged)) return True except Exception as err: logger.error(f"设置种子Tag出错:{str(err)}")