Skip to content

The only downloader you need. 下载器的集大成者。

feat(bittorrent_pack): 添加 Web Tracker 自动初始化功能

XiaoYouChRcd9267283f63
diff --git a/features/bittorrent_pack/pack.py b/features/bittorrent_pack/pack.py
index 97a473a7..4fcaacbd 100644
--- a/features/bittorrent_pack/pack.py
+++ b/features/bittorrent_pack/pack.py
@@ -1,9 +1,12 @@
from urllib.parse import urlparse
+from loguru import logger
+
from app.bases.interfaces import FeaturePack
+from app.services.core_service import coreService
from .cards import BitTorrentResultCard, BitTorrentTaskCard
-from .config import bittorrentConfig
+from .config import bittorrentConfig, getCachedWebTrackers, refreshConfiguredWebTrackers
from .task import BitTorrentTask, parse, resolveLocalTorrentPath
@@ -25,6 +28,15 @@ class BitTorrentPack(FeaturePack):
taskType = BitTorrentTask
config = bittorrentConfig
+ def load(self, mainWindow):
+ if getCachedWebTrackers():
+ return
+
+ coreService.runCoroutine(
+ refreshConfiguredWebTrackers(),
+ self._onDefaultWebTrackersLoaded,
+ )
+
def canHandle(self, url: str) -> bool:
return _isTorrentUrl(url)
@@ -36,3 +48,11 @@ class BitTorrentPack(FeaturePack):
def createResultCard(self, task: BitTorrentTask, parent=None):
return BitTorrentResultCard(task, parent)
+
+ def _onDefaultWebTrackersLoaded(self, result, error: str | None):
+ if error:
+ logger.warning("初始化 Web Tracker 失败: {}", error)
+ return
+
+ logger.info("已自动初始化 {} 条 Web Tracker", len(result or []))
+ bittorrentConfig.webTrackerCard.refreshContent()