From 476dfef7d9b63b1d4c90a4e51ebef1d6cd2dfae4 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 12 Jul 2026 16:47:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20qBittorrent=20=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E4=BB=BB=E5=8A=A1=E4=B8=B4=E6=97=B6=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E6=AE=8B=E7=95=99=20(#6093)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/qbittorrent/__init__.py | 1 + tests/test_qbittorrent_compat.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/modules/qbittorrent/__init__.py b/app/modules/qbittorrent/__init__.py index 6da0da0c6..b1441376f 100644 --- a/app/modules/qbittorrent/__init__.py +++ b/app/modules/qbittorrent/__init__.py @@ -218,6 +218,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]): if settings.TORRENT_TAG and settings.TORRENT_TAG not in torrent_tags: logger.info(f"给种子 {torrent_hash} 打上标签:{settings.TORRENT_TAG}") server.set_torrents_tag(ids=torrent_hash, tags=[settings.TORRENT_TAG]) + server.delete_torrents_tag(torrent_hash, tag) return downloader or self.get_default_config_name(), torrent_hash, torrent_layout, f"下载任务已存在" finally: torrents.clear() diff --git a/tests/test_qbittorrent_compat.py b/tests/test_qbittorrent_compat.py index 88c7112d1..eb13980fd 100644 --- a/tests/test_qbittorrent_compat.py +++ b/tests/test_qbittorrent_compat.py @@ -541,6 +541,30 @@ def test_download_falls_back_to_tag_lookup_when_added_ids_missing(): fake_server.get_torrent_id_by_tag.assert_called_once_with(tags="tmp-tag-01") +def test_download_removes_temporary_tag_from_existing_torrent(): + """重复添加任务时应从已存在的种子中删除本次临时标签。""" + fake_server = MagicMock() + fake_server.add_torrent.return_value = (False, []) + fake_server.get_content_layout.return_value = "Original" + fake_server.get_torrents.return_value = ([{ + "name": "test", + "total_size": len(b"torrent-content"), + "hash": "existing123", + "tags": "tmp-tag-01,moviepilot-tag", + }], None) + + module = _build_module(fake_server) + result = module.download( + content=b"torrent-content", + download_dir=Path("/downloads"), + cookie="", + downloader="qb", + ) + + assert result == ("qb", "existing123", "Original", "下载任务已存在") + fake_server.delete_torrents_tag.assert_called_once_with("existing123", "tmp-tag-01") + + def test_get_files_retries_until_qbittorrent_files_available(): """qBittorrent 添加任务后文件列表短暂未就绪时应重试。""" torrent_files = [{"id": 12, "name": "Show.S01E12.mkv"}]