The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
Close #359
XiaoYouChRa3d7418e9285
diff --git a/app/services/core_service.py b/app/services/core_service.pyindex 89e86d00..6aff6d8b 100644--- a/app/services/core_service.py+++ b/app/services/core_service.py@@ -126,10 +126,6 @@ class CoreService(QThread):callbackId: 回调函数标识符"""try:- url = payload.get('url', '')- if not url:- raise ValueError("URL 不能为空")-result = await featureService.parse(payload)if callbackId and callbackId in self._pendingCallbacks:diff --git a/app/services/feature_service.py b/app/services/feature_service.pyindex 4ac2858e..a1a0a7cf 100644--- a/app/services/feature_service.py+++ b/app/services/feature_service.py@@ -3,6 +3,7 @@ import sysimport tomllibfrom pathlib import Pathfrom typing import TYPE_CHECKING, Dict, Any+from urllib.parse import urlparsefrom loguru import logger@@ -232,7 +233,7 @@ class FeatureService:logger.opt(exception=e).error("加载 FeaturePack 失败 {}", packInfo["name"])return False- def getPackForUrl(self, url: str) -> tuple[str, FeaturePack] | tuple[None, None]:+ def _matchPackForUrl(self, url: str) -> tuple[str, FeaturePack] | tuple[None, None]:for packName, packInstance in self.sortedPacksCache:try:if packInstance.canHandle(url):@@ -241,8 +242,30 @@ class FeatureService:logger.opt(exception=e).error("FeaturePack.canHandle 失败 {}", packName)return None, None+ def getPackForUrl(+ self,+ url: str,+ ) -> tuple[str, str | None, FeaturePack | None]:+ url = str(url).strip()+ if not url:+ return "", None, None++ packName, packInstance = self._matchPackForUrl(url)+ if packInstance is not None:+ return url, packName, packInstance++ if urlparse(url).scheme:+ return url, None, None++ implicitUrl = f"http://{url}"+ packName, packInstance = self._matchPackForUrl(implicitUrl)+ if packInstance is None:+ return url, None, None++ return implicitUrl, packName, packInstance+def canHandle(self, url: str) -> bool:- _, packInstance = self.getPackForUrl(url)+ _, _, packInstance = self.getPackForUrl(url)return packInstance is not Nonedef getPackForTask(self, task: Task) -> tuple[str, FeaturePack] | tuple[None, None]:@@ -267,10 +290,14 @@ class FeatureService:if not url:raise ValueError("URL 不能为空")- packName, packInstance = self.getPackForUrl(url)+ resolvedUrl, packName, packInstance = self.getPackForUrl(url)if packInstance is None:raise ValueError(f"未找到可处理该链接的 FeaturePack: {url}")+ if payload.get("url") != resolvedUrl:+ payload = payload.copy()+ payload["url"] = resolvedUrl+task = await packInstance.parse(payload)setattr(task, "_featurePackName", packName)return task