The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
refactor(runtime): 深化 BinaryRuntime 接口,安装流程去 parse
XiaoYouChR37b3b75bab38
diff --git a/app/client.py b/app/client.pyindex 64d2cf4f..ae80e2f2 100644--- a/app/client.py+++ b/app/client.py@@ -165,16 +165,22 @@ async def fetchFile() -> None:client = buildClient()try:- async with client.stream("GET", url) as response:+ outputPath.parent.mkdir(parents=True, exist_ok=True)+ response = await client.get(url)+ try:response.raise_for_status()- total = int(response.headers.get("content-length", 0))+ total = int(response.headers.get("content-length", b"0"))received = 0with open(outputPath, "wb") as f:- async for chunk in response.aiter_bytes():+ async for chunk in response.stream():+ if not chunk:+ continuef.write(chunk)received += len(chunk)if onProgress and total:onProgress(received / total * 100)+ finally:+ response.close()finally:client.close()diff --git a/app/install.py b/app/install.pyindex 5b729d36..ec45ed27 100644--- a/app/install.py+++ b/app/install.py@@ -9,16 +9,11 @@ import zipfilefrom dataclasses import dataclass, fieldfrom pathlib import Path, PurePosixPathfrom time import perf_counter-from typing import TYPE_CHECKINGfrom urllib.parse import urlparsefrom app.models.task import Task, TaskError, TaskStep, TaskStatusfrom app.platform.filesystem import deletePath, toPosixPath-if TYPE_CHECKING:- from collections.abc import Awaitable, Callable- from app.models.task import TaskOptions-CHUNK_SIZE = 1 << 20ARCHIVE_SUFFIXES = (".zip", ".tar.gz")@@ -227,51 +222,54 @@ class BinaryInstallStep(TaskStep):self.setStatus(TaskStatus.COMPLETED)-async def createInstallTask(- delegate: Callable[[TaskOptions], Awaitable[Task]],+@dataclass(kw_only=True)+class FetchStep(TaskStep):+ canPause = False+ url: str+ outputFile: str = ""++ async def run(self, reportSpeed, waitForSpeedLimit) -> None:+ from app.client import fetchFile++ def onProgress(p):+ self.progress = p+ reportSpeed()++ await fetchFile(self.url, Path(self.outputFile), onProgress=onProgress)+ self.setStatus(TaskStatus.COMPLETED)+++def createInstallTask(url: str,outputFolder: Path,name: str = "",executableNames: tuple[str, ...] = (),sha256Url: str = "",) -> InstallTask:- from app.models.task import TaskOptions-assetName = PurePosixPath(urlparse(url).path).name- download = await delegate(TaskOptions(url=url, outputFolder=outputFolder))- downloadStep = download.steps[0]-archive = isArchive(assetName)if archive:targetPath = toPosixPath(outputFolder / assetName)else:binaryName = executableNames[0] if executableNames else assetNametargetPath = toPosixPath(outputFolder / binaryName)- downloadStep.outputFile = targetPathtask = InstallTask(name=name or assetName,url=url,packId="install",- fileSize=download.fileSize,+ fileSize=0,outputFolder=outputFolder,installFolder=str(outputFolder),)stepIndex = 1- downloadStep.stepIndex = stepIndex- task.addStep(downloadStep)+ task.addStep(FetchStep(stepIndex=stepIndex, url=url, outputFile=targetPath))stepIndex += 1if sha256Url:- checksumDownload = await delegate(- TaskOptions(url=sha256Url, outputFolder=outputFolder)- )- checksumStep = checksumDownload.steps[0]sha256Path = toPosixPath(outputFolder / PurePosixPath(urlparse(sha256Url).path).name)- checksumStep.outputFile = sha256Path- checksumStep.stepIndex = stepIndex- task.addStep(checksumStep)+ task.addStep(FetchStep(stepIndex=stepIndex, url=sha256Url, outputFile=sha256Path))stepIndex += 1task.addStep(ChecksumStep(stepIndex=stepIndex, targetFile=targetPath, sha256File=sha256Path,@@ -284,7 +282,6 @@ async def createInstallTask(stepIndex=stepIndex,archivePath=targetPath,outputFolder=extractFolder,- archiveSize=download.fileSize,))stepIndex += 1task.addStep(InstallStep(diff --git a/app/services/runtime_status.py b/app/services/runtime_status.pyindex b4b89e20..8e5ea7cb 100644--- a/app/services/runtime_status.py+++ b/app/services/runtime_status.py@@ -17,10 +17,12 @@ class RuntimeStatus:name: strpath: str = ""version: str = ""+ detail: str = ""latestVersion: str = ""error: str = ""isBusy: bool = FalseisInstalling: bool = False+ progress: float = 0class RuntimeStatusService(QObject):@@ -80,12 +82,36 @@ class RuntimeStatusService(QObject):runtimeId=runtimeId,)+ def cancelInstall(self, runtime: BinaryRuntime) -> None:+ runtimeId = runtime.runtimeId+ if runtimeId not in self._installingIds:+ return+ workId = self._workIds.pop(runtimeId, None)+ if workId:+ self._coroutineRunner.cancel(workId)+ self._installingIds.discard(runtimeId)+ self._runtimes.pop(runtimeId, None)+ status = RuntimeStatus(runtimeId, runtime.name, path=runtime.path())+ self._statuses[runtimeId] = status+ self.statusChanged.emit(status)+async def _runInstall(self, runtime: BinaryRuntime) -> None:from app.models.task import TaskStatus- task = await runtime.installTask()+ task = await runtime.createInstallTask()task.setStatus(TaskStatus.RUNNING)- await task.run(lambda *a: None, lambda: asyncio.sleep(0))++ def reportProgress(*_args):+ step = next((s for s in task.steps if s.progress > 0), None)+ if step:+ runtimeId = runtime.runtimeId+ current = self._statuses.get(runtimeId)+ if current and current.isInstalling and current.progress != step.progress:+ status = replace(current, progress=step.progress)+ self._statuses[runtimeId] = status+ self.statusChanged.emit(status)++ await task.run(reportProgress, lambda: asyncio.sleep(0))def _onInstallFinished(self, _, runtimeId: str) -> None:self._installingIds.discard(runtimeId)@@ -95,6 +121,8 @@ class RuntimeStatusService(QObject):self.invalidate(runtime)def _onInstallFailed(self, error: str, runtimeId: str) -> None:+ if runtimeId not in self._installingIds:+ returnself._installingIds.discard(runtimeId)self._workIds.pop(runtimeId, None)self._runtimes.pop(runtimeId, None)@@ -127,9 +155,12 @@ class RuntimeStatusService(QObject):logger.opt(exception=e).error("runtime probe submit failed: {}", runtimeId)self._onProbeFailed(repr(e), runtimeId, name, path)- def _onProbeFinished(self, version: str, runtimeId: str, name: str, path: str) -> None:+ def _onProbeFinished(self, versionInfo, runtimeId: str, name: str, path: str) -> None:self._workIds.pop(runtimeId, None)- status = RuntimeStatus(runtimeId, name, path=path, version=version)+ status = RuntimeStatus(+ runtimeId, name, path=path,+ version=versionInfo.version, detail=versionInfo.detail,+ )self._statuses[runtimeId] = statusself.statusChanged.emit(status)diff --git a/app/view/components/setting_cards.py b/app/view/components/setting_cards.pyindex c3bc1214..1d5560db 100644--- a/app/view/components/setting_cards.py+++ b/app/view/components/setting_cards.py@@ -804,6 +804,7 @@ class RuntimeCard(SettingCard):super().__init__(FluentIcon.INFO, runtime.name, self.tr("正在检测运行时..."), parent)self.installButton = PrimaryPushButton(self.tr("一键安装"), self)+ self.cancelButton = ToolButton(FluentIcon.CLOSE, self)self.refreshButton = ToolButton(FluentIcon.SYNC, self)self.deleteButton = ToolButton(FluentIcon.DELETE, self)@@ -815,6 +816,9 @@ class RuntimeCard(SettingCard):def _initWidget(self) -> None:if not self._runtime.canInstall:self.installButton.hide()+ self.cancelButton.hide()+ self.cancelButton.setToolTip(self.tr("取消安装"))+ self.cancelButton.installEventFilter(ToolTipFilter(self.cancelButton))self.deleteButton.hide()self.deleteButton.setToolTip(self.tr("卸载"))self.deleteButton.installEventFilter(ToolTipFilter(self.deleteButton))@@ -824,6 +828,8 @@ class RuntimeCard(SettingCard):def _initLayout(self) -> None:self.hBoxLayout.addWidget(self.installButton, 0, Qt.AlignmentFlag.AlignRight)self.hBoxLayout.addSpacing(8)+ self.hBoxLayout.addWidget(self.cancelButton, 0, Qt.AlignmentFlag.AlignRight)+ self.hBoxLayout.addSpacing(8)self.hBoxLayout.addWidget(self.refreshButton, 0, Qt.AlignmentFlag.AlignRight)self.hBoxLayout.addSpacing(8)self.hBoxLayout.addWidget(self.deleteButton, 0, Qt.AlignmentFlag.AlignRight)@@ -832,6 +838,7 @@ class RuntimeCard(SettingCard):def _bind(self) -> None:self._runtimeStatusService.statusChanged.connect(self._onRuntimeStatusChanged)self.installButton.clicked.connect(self._onInstallClicked)+ self.cancelButton.clicked.connect(self._onCancelClicked)self.deleteButton.clicked.connect(self._onDeleteClicked)self.refreshButton.clicked.connect(self._onRefreshClicked)@@ -839,34 +846,46 @@ class RuntimeCard(SettingCard):self._runtimeStatusService.refreshStatus(self._runtime)def updateStatus(self, status) -> None:+ from app.update import isNewer+self.refreshButton.setEnabled(not status.isBusy and not status.isInstalling)isInstalled = bool(status.path)isManaged = self._runtime.isAppManaged()isUpdateAvailable = (isInstalled and isManagedand status.latestVersion- and (not status.version or self._runtime.isNewer(status.version, status.latestVersion))+ and (not status.version or isNewer(status.version, status.latestVersion)))if status.isInstalling:- self.setContent(self.tr("正在安装..."))+ if status.progress > 0:+ self.setContent(self.tr("正在安装... {0}%").format(f"{status.progress:.0f}"))+ else:+ self.setContent(self.tr("正在安装..."))self.installButton.hide()+ self.cancelButton.setVisible(self._runtime.canInstall)self.deleteButton.hide()returnif status.isBusy:self.setContent(self.tr("正在检测运行时..."))self.installButton.hide()+ self.cancelButton.hide()self.deleteButton.hide()return+ self.cancelButton.hide()+if status.error:self.setContent(self.tr("检测运行时失败"))elif isInstalled:- if status.version and status.latestVersion:- line1 = self.tr("版本: {0}(最新: {1})").format(status.version, status.latestVersion)- elif status.version:- line1 = self.tr("版本: {0}").format(status.version)+ versionDisplay = status.version+ if status.detail:+ versionDisplay = f"{versionDisplay} | {status.detail}" if versionDisplay else status.detail+ if versionDisplay and status.latestVersion:+ line1 = self.tr("版本: {0}(最新: {1})").format(versionDisplay, status.latestVersion)+ elif versionDisplay:+ line1 = self.tr("版本: {0}").format(versionDisplay)elif status.latestVersion:line1 = self.tr("最新版本: {0}").format(status.latestVersion)else:@@ -900,6 +919,9 @@ class RuntimeCard(SettingCard):def _onInstallClicked(self) -> None:self._runtimeStatusService.install(self._runtime)+ def _onCancelClicked(self) -> None:+ self._runtimeStatusService.cancelInstall(self._runtime)+def _onDeleteClicked(self) -> None:from qfluentwidgets import MessageBoxdiff --git a/features/ed2k_pack/config.py b/features/ed2k_pack/config.pyindex 1fe719d5..822402fc 100644--- a/features/ed2k_pack/config.py+++ b/features/ed2k_pack/config.py@@ -6,7 +6,7 @@ from pathlib import Pathfrom app.config.paths import APP_DATA_DIRfrom app.models.pack import BinaryRuntime, PackConfig-from app.platform.filesystem import findExecutable, toPosixPath+from app.platform.filesystem import toPosixPathfrom PySide6.QtCore import QT_TRANSLATE_NOOP as Nfrom qfluentwidgets import ConfigItem, BoolValidator, FluentIcon, RangeConfigItem, RangeValidator@@ -80,52 +80,33 @@ class ED2kRuntime(BinaryRuntime):title = N("BinaryRuntime", "eD2k / eMule")description = N("BinaryRuntime", "支持电驴协议,适合下载经典资源")icon = FluentIcon.BOOK_SHELF- isRecommended = False- def path(self) -> str:- return findExecutable(Path(ed2kConfig.installFolder.value), "goed2kd")-- def isAppManaged(self) -> bool:- p = self.path()- return bool(p) and Path(p).is_relative_to(Path(ed2kConfig.installFolder.value))+ def installFolder(self) -> Path:+ return Path(ed2kConfig.installFolder.value)async def fetchLatestVersion(self) -> str:from app.update import fetchGitHubLatestTagreturn await fetchGitHubLatestTag("XiaoYouChR/Python-eD2k")- def delete(self) -> None:- import shutil- folder = Path(ed2kConfig.installFolder.value)- if folder.exists():- shutil.rmtree(folder)-- async def installTask(self):- from app.models.task import TaskOptions- from app.install import InstallTask+ async def createInstallTask(self):+ from app.install import FetchStep, InstallTaskfrom .task import ED2kInstallStepassetName = _assetName()url = f"{RELEASE_BASE}/{assetName}"- installFolder = Path(ed2kConfig.installFolder.value)+ folder = self.installFolder()binaryName = "goed2kd.exe" if sys.platform == "win32" else "goed2kd"- binaryPath = toPosixPath(installFolder / binaryName)-- download = await self.parse(- TaskOptions(url=url, outputFolder=installFolder)- )- downloadStep = download.steps[0]- downloadStep.stepIndex = 1- downloadStep.outputFile = binaryPath+ binaryPath = toPosixPath(folder / binaryName)task = InstallTask(name=f"goed2kd 安装 ({assetName})",url=url,packId="ed2k",- fileSize=download.fileSize,- outputFolder=installFolder,- installFolder=str(installFolder),+ fileSize=0,+ outputFolder=folder,+ installFolder=str(folder),)- task.addStep(downloadStep)+ task.addStep(FetchStep(stepIndex=1, url=url, outputFile=binaryPath))task.addStep(ED2kInstallStep(stepIndex=2, binaryPath=binaryPath))return taskdiff --git a/features/ffmpeg_pack/config.py b/features/ffmpeg_pack/config.pyindex d65ba94a..6b3de454 100644--- a/features/ffmpeg_pack/config.py+++ b/features/ffmpeg_pack/config.py@@ -10,8 +10,7 @@ from qfluentwidgets import FluentIconfrom app.config.cfg import ConfigItemfrom app.config.paths import APP_DATA_DIR-from app.models.pack import BinaryRuntime, PackConfig-from app.models.task import Task+from app.models.pack import BinaryRuntime, PackConfig, VersionInfofrom app.platform.android import IS_ANDROID, nativeLibraryDirfrom app.platform.filesystem import findExecutable@@ -63,6 +62,9 @@ class FFmpegRuntime(BinaryRuntime):icon = FluentIcon.VIDEOisRecommended = True+ def installFolder(self) -> Path:+ return Path(ffmpegConfig.installFolder.value)+def path(self) -> str:if IS_ANDROID:nativeDir = nativeLibraryDir()@@ -70,11 +72,7 @@ class FFmpegRuntime(BinaryRuntime):return ""binary = Path(nativeDir) / "libffmpeg.so"return str(binary) if binary.exists() else ""- return findExecutable(Path(ffmpegConfig.installFolder.value), "ffmpeg", "bin")-- def isAppManaged(self) -> bool:- p = self.path()- return bool(p) and Path(p).is_relative_to(Path(ffmpegConfig.installFolder.value))+ return findExecutable(self.installFolder(), "ffmpeg", "bin")def ffprobePath(self) -> str:if IS_ANDROID:@@ -83,17 +81,17 @@ class FFmpegRuntime(BinaryRuntime):return ""binary = Path(nativeDir) / "libffprobe.so"return str(binary) if binary.exists() else ""- return findExecutable(Path(ffmpegConfig.installFolder.value), "ffprobe", "bin")+ return findExecutable(self.installFolder(), "ffprobe", "bin")- async def probeVersion(self) -> str:+ async def probeVersion(self) -> VersionInfo:path = self.path()if not path:- return ""- versionFile = Path(ffmpegConfig.installFolder.value) / "VERSION"+ return VersionInfo("")+ versionFile = self.installFolder() / "VERSION"if versionFile.is_file():tag = versionFile.read_text().strip()if tag:- return tag+ return VersionInfo(tag)process = await asyncio.create_subprocess_exec(path, "-version",stdin=asyncio.subprocess.DEVNULL,@@ -102,21 +100,16 @@ class FFmpegRuntime(BinaryRuntime):)stdout, _ = await process.communicate()if process.returncode != 0:- return ""+ return VersionInfo("")line = stdout.decode("utf-8", errors="ignore").splitlines()[0].strip()- return line.removeprefix("ffmpeg version ").split(" Copyright", 1)[0].strip() or line+ version = line.removeprefix("ffmpeg version ").split(" Copyright", 1)[0].strip() or line+ return VersionInfo(version)async def fetchLatestVersion(self) -> str:from app.update import fetchGitHubLatestTagreturn await fetchGitHubLatestTag("XiaoYouChR/Ghost-Downloader-FFmpeg")- def delete(self) -> None:- import shutil- folder = Path(ffmpegConfig.installFolder.value)- if folder.exists():- shutil.rmtree(folder)-- async def installTask(self) -> Task:+ async def createInstallTask(self):from app.install import createInstallTasktarget = ffmpegAssetTarget()@@ -126,10 +119,9 @@ class FFmpegRuntime(BinaryRuntime):("ffmpeg.exe", "ffprobe.exe") if sys.platform == "win32"else ("ffmpeg", "ffprobe"))- return await createInstallTask(- self.parse,+ return createInstallTask(url=url,- outputFolder=Path(ffmpegConfig.installFolder.value),+ outputFolder=self.installFolder(),name=f"FFmpeg 安装 ({target})",executableNames=executableNames,sha256Url=f"{url}.sha256",diff --git a/features/m3u8_pack/config.py b/features/m3u8_pack/config.pyindex eed711ff..5cb7e81a 100644--- a/features/m3u8_pack/config.py+++ b/features/m3u8_pack/config.py@@ -18,7 +18,6 @@ from qfluentwidgets import (from app.config.paths import APP_DATA_DIRfrom app.models.pack import BinaryRuntime, PackConfig-from app.models.task import Taskfrom app.platform.android import IS_ANDROID, nativeLibraryDirfrom app.platform.filesystem import findExecutable@@ -141,12 +140,16 @@ m3u8Config = M3U8Config()class M3U8Runtime(BinaryRuntime):name = "N_m3u8DL-RE"+ binaryName = "N_m3u8DL-RE"canInstall = not IS_ANDROIDtitle = N("BinaryRuntime", "M3U8 / 直播下载")description = N("BinaryRuntime", "支持 HLS、DASH 等流媒体协议,可录制直播流")icon = FluentIcon.MEDIAisRecommended = True+ def installFolder(self) -> Path:+ return Path(m3u8Config.installFolder.value)+def path(self) -> str:if IS_ANDROID:nativeDir = nativeLibraryDir()@@ -154,23 +157,13 @@ class M3U8Runtime(BinaryRuntime):return ""binary = Path(nativeDir) / "libnm3u8dlre.so"return str(binary) if binary.exists() else ""- return findExecutable(Path(m3u8Config.installFolder.value), "N_m3u8DL-RE")-- def isAppManaged(self) -> bool:- p = self.path()- return bool(p) and Path(p).is_relative_to(Path(m3u8Config.installFolder.value))+ return findExecutable(self.installFolder(), "N_m3u8DL-RE")async def fetchLatestVersion(self) -> str:from app.update import fetchGitHubLatestTagreturn await fetchGitHubLatestTag(M3U8_REPO)- def delete(self) -> None:- import shutil- folder = Path(m3u8Config.installFolder.value)- if folder.exists():- shutil.rmtree(folder)-- async def installTask(self) -> Task:+ async def createInstallTask(self):machine = platform.machine().lower()if sys.platform == "win32":if machine in {"amd64", "x86_64"}:@@ -190,10 +183,9 @@ class M3U8Runtime(BinaryRuntime):from app.install import createInstallTaskbinaryName = "N_m3u8DL-RE.exe" if sys.platform == "win32" else "N_m3u8DL-RE"- return await createInstallTask(- self.parse,+ return createInstallTask(url=url,- outputFolder=Path(m3u8Config.installFolder.value),+ outputFolder=self.installFolder(),name=f"N_m3u8DL-RE {tag} ({target})",executableNames=(binaryName,),)diff --git a/features/yt_dlp_pack/config.py b/features/yt_dlp_pack/config.pyindex 0602c4db..9c3a266c 100644--- a/features/yt_dlp_pack/config.py+++ b/features/yt_dlp_pack/config.py@@ -13,7 +13,7 @@ from qfluentwidgets import ()from app.config.paths import APP_DATA_DIR-from app.models.pack import BinaryRuntime, PackConfig+from app.models.pack import BinaryRuntime, PackConfig, VersionInfofrom app.platform.android import IS_ANDROIDfrom app.platform.filesystem import findExecutable@@ -139,31 +139,32 @@ class YouTubeRuntime(BinaryRuntime):icon = FluentIcon.GLOBEisRecommended = True+ def installFolder(self) -> Path:+ return Path(ytDlpConfig.installFolder.value)+def path(self) -> str:- folder = Path(ytDlpConfig.installFolder.value)+ folder = self.installFolder()if not (folder / "yt_dlp" / "__init__.py").is_file():return ""return self.qjsPath()def isAppManaged(self) -> bool:- folder = Path(ytDlpConfig.installFolder.value)- return (folder / "yt_dlp" / "__init__.py").is_file()+ return (self.installFolder() / "yt_dlp" / "__init__.py").is_file()def ytDlpFolder(self) -> Path:- return Path(ytDlpConfig.installFolder.value)+ return self.installFolder()def qjsPath(self) -> str:if IS_ANDROID:from app.platform.android import nativeLibraryDirbinary = Path(nativeLibraryDir()) / "libqjs.so"return str(binary) if binary.is_file() else ""- return findExecutable(Path(ytDlpConfig.installFolder.value), "qjs")+ return findExecutable(self.installFolder(), "qjs")- async def probeVersion(self) -> str:- ytDlpDir = Path(ytDlpConfig.installFolder.value) / "yt_dlp"- versionFile = ytDlpDir / "version.py"+ async def probeVersion(self) -> VersionInfo:+ versionFile = self.installFolder() / "yt_dlp" / "version.py"if not versionFile.is_file():- return ""+ return VersionInfo("")ytDlpVersion = ""try:@@ -191,12 +192,10 @@ class YouTubeRuntime(BinaryRuntime):else:isQjsOk = False- parts = []- if ytDlpVersion:- parts.append(f"yt-dlp {ytDlpVersion}")- if isQjsOk:- parts.append("QuickJS ✓")- return " | ".join(parts) if parts else ""+ return VersionInfo(+ version=ytDlpVersion,+ detail="QuickJS ✓" if isQjsOk else "",+ )async def fetchLatestVersion(self) -> str:from app.client import buildClient@@ -209,33 +208,13 @@ class YouTubeRuntime(BinaryRuntime):finally:client.close()- def isNewer(self, installed: str, latest: str) -> bool:- if not installed or not latest:- return False- prefix = "yt-dlp "- if prefix not in installed:- return False- from PySide6.QtCore import QVersionNumber- current = installed.split(prefix, 1)[1].split(" ", 1)[0].split("|", 1)[0].strip()- v1 = QVersionNumber.fromString(current)- v2 = QVersionNumber.fromString(latest)- return v2 > v1-- def delete(self) -> None:- import shutil- folder = Path(ytDlpConfig.installFolder.value)- if folder.exists():- shutil.rmtree(folder)-- async def installTask(self):- from app.config.cfg import cfg, currentHeaders- from app.install import ExtractStep, InstallTask- from http_pack.task import HttpTaskStep+ async def createInstallTask(self):+ from app.install import BinaryInstallStep, ExtractStep, FetchStep, InstallTaskwhlUrl, whlSize = await self._fetchWhlAsset()- installFolder = Path(ytDlpConfig.installFolder.value)- installFolder.mkdir(parents=True, exist_ok=True)+ folder = self.installFolder()+ folder.mkdir(parents=True, exist_ok=True)archiveName = "yt_dlp.zip"if IS_ANDROID:@@ -244,65 +223,49 @@ class YouTubeRuntime(BinaryRuntime):url=whlUrl,packId="disk",fileSize=whlSize,- outputFolder=installFolder,- installFolder=str(installFolder),+ outputFolder=folder,+ installFolder=str(folder),)- task.addStep(HttpTaskStep(- stepIndex=1,- url=whlUrl,- fileSize=whlSize,- headers=currentHeaders(),- subworkerCount=cfg.preBlockNum.value,- canUseRangeRequests=True,- outputFile=str(installFolder / archiveName),+ task.addStep(FetchStep(+ stepIndex=1, url=whlUrl,+ outputFile=str(folder / archiveName),))task.addStep(ExtractStep(stepIndex=2,- archivePath=str(installFolder / archiveName),- outputFolder=str(installFolder),+ archivePath=str(folder / archiveName),+ outputFolder=str(folder),archiveSize=whlSize,))return task- from app.install import BinaryInstallStep- from app.models.task import TaskOptions-qjsBinaryName = "qjs.exe" if sys.platform == "win32" else "qjs"- qjsDownload = await self.parse(TaskOptions(- url=f"{QJS_RELEASE_BASE}/{_qjsAssetName()}",- outputFolder=installFolder,- ))- qjsStep = qjsDownload.steps[0]- qjsStep.stepIndex = 2- qjsStep.outputFile = str(installFolder / qjsBinaryName)+ qjsUrl = f"{QJS_RELEASE_BASE}/{_qjsAssetName()}"task = InstallTask(name="YouTube 运行环境安装",url=whlUrl,packId="disk",- fileSize=whlSize + max(0, qjsDownload.fileSize),- outputFolder=installFolder,- installFolder=str(installFolder),+ fileSize=0,+ outputFolder=folder,+ installFolder=str(folder),)- task.addStep(HttpTaskStep(- stepIndex=1,- url=whlUrl,- fileSize=whlSize,- headers=currentHeaders(),- subworkerCount=cfg.preBlockNum.value,- canUseRangeRequests=True,- outputFile=str(installFolder / archiveName),+ task.addStep(FetchStep(+ stepIndex=1, url=whlUrl,+ outputFile=str(folder / archiveName),+ ))+ task.addStep(FetchStep(+ stepIndex=2, url=qjsUrl,+ outputFile=str(folder / qjsBinaryName),))- task.addStep(qjsStep)task.addStep(ExtractStep(stepIndex=3,- archivePath=str(installFolder / archiveName),- outputFolder=str(installFolder),+ archivePath=str(folder / archiveName),+ outputFolder=str(folder),archiveSize=whlSize,))task.addStep(BinaryInstallStep(stepIndex=4,- binaryPath=str(installFolder / qjsBinaryName),+ binaryPath=str(folder / qjsBinaryName),))return task