The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
feat(pack): 统一通过 FeaturePack.parse 进行二次解析分发
XiaoYouChRf24db80c8df7
diff --git a/app/models/pack.py b/app/models/pack.pyindex f1fb5ca0..2f96c556 100644--- a/app/models/pack.py+++ b/app/models/pack.py@@ -47,7 +47,10 @@ class UriScheme:class TaskParser:priority: int = 100pack: FeaturePack- delegate: Callable[[TaskOptions], Awaitable[Task]]++ def __init__(self, pack: FeaturePack | None = None) -> None:+ if pack is not None:+ self.pack = packdef match(self, options: TaskOptions) -> bool:raise NotImplementedError@@ -276,9 +279,11 @@ class FeaturePack:capturedLinks: str | None = Noneparsers: list[type[TaskParser]] = []- parse: Callable[[TaskOptions], Awaitable[Task]] | None = None- addTask: Callable[[Task], None] | None = None- submit: Callable[..., str] | None = None++ # 由 Feature Service 注入+ parse: Callable[[TaskOptions], Awaitable[Task]]+ addTask: Callable[[Task], None]+ submit: Callable[..., str]def __init__(self, services: PackServices):self._services = servicesdiff --git a/app/services/feature_service.py b/app/services/feature_service.pyindex 08f99e86..ad20e595 100644--- a/app/services/feature_service.py+++ b/app/services/feature_service.py@@ -75,7 +75,7 @@ class FeatureService:self._packs.append(pack)self._packByPackId[pack.packId] = pack- pack.parse = self.parse+ pack.parse = self._parsepack.addTask = self._taskService.addpack.submit = self._coroutineRunner.submit@@ -83,10 +83,7 @@ class FeatureService:self._pagePackMap[PageClass] = packfor ParserClass in pack.parsers:- parser = ParserClass()- parser.pack = pack- parser.delegate = self._parse- self._parsers.append(parser)+ self._parsers.append(ParserClass(pack))self._parsers.sort(key=lambda p: p.priority)if pack.config:diff --git a/features/ffmpeg_pack/pack.py b/features/ffmpeg_pack/pack.pyindex 958c8ffa..38efd10b 100644--- a/features/ffmpeg_pack/pack.py+++ b/features/ffmpeg_pack/pack.py@@ -26,8 +26,8 @@ class MergeParser(TaskParser):if not ffmpegRuntime.path() or not ffmpegRuntime.ffprobePath():raise RuntimeError("未找到可用的 ffmpeg 和 ffprobe,请先在设置中安装或配置 FFmpeg")- videoTask = await self.delegate(options.video)- audioTask = await self.delegate(options.audio)+ videoTask = await self.pack.parse(options.video)+ audioTask = await self.pack.parse(options.audio)videoStep: HttpTaskStep = videoTask.steps[0] # type: ignore[assignment]audioStep: HttpTaskStep = audioTask.steps[0] # type: ignore[assignment]diff --git a/features/github_pack/pack.py b/features/github_pack/pack.pyindex 37d4f2b5..07fc603a 100644--- a/features/github_pack/pack.py+++ b/features/github_pack/pack.py@@ -124,7 +124,7 @@ class GitHubParser(TaskParser):logger.info("GitHub 选用 {}", winner)headers = options.headers if winner == originalUrl else toProxyHeaders(options.headers)- task = await self.delegate(replace(options, url=winner, headers=headers, file=file))+ task = await self.pack.parse(replace(options, url=winner, headers=headers, file=file))if task.packId != "m3u8":task.url = originalUrlif task.steps and type(task.steps[0]) is HttpTaskStep and fallbackUrls:diff --git a/features/http_pack/pack.py b/features/http_pack/pack.pyindex 4e38eaf3..1c5b2a4d 100644--- a/features/http_pack/pack.py+++ b/features/http_pack/pack.py@@ -231,7 +231,7 @@ class HttpParser(TaskParser):if isinstance(options, ResourceTaskOptions) and options.name and options.size > 0:file = RemoteFile(name=options.name, fileSize=options.size, canUseRangeRequests=options.canUseRangeRequests)return buildTask(replace(options, file=file))- return await self.delegate(replace(options, file=await probe(options)))+ return await self.pack.parse(replace(options, file=await probe(options)))def buildOptionCards(task: Task, parent: QWidget | None = None) -> list[OptionCard]:diff --git a/features/wrapped_link_pack/pack.py b/features/wrapped_link_pack/pack.pyindex eb2322fe..62801cbf 100644--- a/features/wrapped_link_pack/pack.py+++ b/features/wrapped_link_pack/pack.py@@ -48,7 +48,7 @@ class WrappedLinkParser(TaskParser):return urlparse(options.url.strip()).scheme.lower() in SCHEMESasync def parse(self, options: TaskOptions) -> Task:- return await self.delegate(replace(options, url=toInnerUrl(options.url)))+ return await self.pack.parse(replace(options, url=toInnerUrl(options.url)))class WrappedLinkPack(FeaturePack):