Skip to content

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

feat(Runtime): 运行时更新检查与卸载

XiaoYouChRe8b64ef89c0a
diff --git a/app/client.py b/app/client.py
index dda31c2e..06c0c098 100644
--- a/app/client.py
+++ b/app/client.py
@@ -194,3 +194,5 @@ def matchEmulation(userAgent: str, host: Platform) -> Emulation | None:
return Emulation(profile=profile, platform=platform)
return None
+
+
diff --git a/app/models/pack.py b/app/models/pack.py
index a5589cc1..30d0f8c3 100644
--- a/app/models/pack.py
+++ b/app/models/pack.py
@@ -4,7 +4,7 @@ import asyncio
from dataclasses import dataclass
from typing import TYPE_CHECKING
-from PySide6.QtCore import QCoreApplication, Signal
+from PySide6.QtCore import QCoreApplication, QVersionNumber, Signal
from app.config.cfg import cfg, ConfigItem
@@ -120,6 +120,22 @@ class BinaryRuntime:
lines = stdout.decode("utf-8", errors="ignore").splitlines()
return lines[0].strip() if lines else ""
+ def isAppManaged(self) -> bool:
+ return False
+
+ async def fetchLatestVersion(self) -> str:
+ return ""
+
+ def isNewer(self, installed: str, latest: str) -> bool:
+ if not installed or not latest:
+ return False
+ v1 = QVersionNumber.fromString(installed.lstrip("vV"))
+ v2 = QVersionNumber.fromString(latest.lstrip("vV"))
+ return v2 > v1
+
+ def delete(self) -> None:
+ raise NotImplementedError
+
async def installTask(self) -> Task:
raise NotImplementedError
diff --git a/app/services/runtime_status.py b/app/services/runtime_status.py
index ec6df9cf..cb338706 100644
--- a/app/services/runtime_status.py
+++ b/app/services/runtime_status.py
@@ -1,6 +1,6 @@
from __future__ import annotations
-from dataclasses import dataclass
+from dataclasses import dataclass, replace
from typing import TYPE_CHECKING
from PySide6.QtCore import QObject, Signal
@@ -16,6 +16,7 @@ class RuntimeStatus:
name: str
path: str = ""
version: str = ""
+ latestVersion: str = ""
error: str = ""
isBusy: bool = False
@@ -28,6 +29,7 @@ class RuntimeStatusService(QObject):
self._coroutineRunner = coroutineRunner
self._statuses: dict[str, RuntimeStatus] = {}
self._workIds: dict[str, str] = {}
+ self._runtimes: dict[str, BinaryRuntime] = {}
def status(self, runtime: BinaryRuntime) -> RuntimeStatus:
status = self._statuses.get(runtime.runtimeId)
@@ -50,12 +52,14 @@ class RuntimeStatusService(QObject):
if workId:
self._coroutineRunner.cancel(workId)
self._workIds.pop(runtimeId, None)
+ self._runtimes.pop(runtimeId, None)
self._probe(runtime)
def _probe(self, runtime: BinaryRuntime) -> None:
runtimeId = runtime.runtimeId
path = runtime.path()
name = runtime.name
+ self._runtimes[runtimeId] = runtime
status = RuntimeStatus(runtimeId, name, path=path, isBusy=True)
self._statuses[runtimeId] = status
@@ -80,9 +84,41 @@ class RuntimeStatusService(QObject):
self._statuses[runtimeId] = status
self.statusChanged.emit(status)
+ runtime = self._runtimes.get(runtimeId)
+ if runtime and runtime.isAppManaged():
+ self._fetchLatest(runtime)
+ else:
+ self._runtimes.pop(runtimeId, None)
+
def _onProbeFailed(self, error: str, runtimeId: str, name: str, path: str) -> None:
self._workIds.pop(runtimeId, None)
+ self._runtimes.pop(runtimeId, None)
status = RuntimeStatus(runtimeId, name, path=path, error=error)
self._statuses[runtimeId] = status
self.statusChanged.emit(status)
+ def _fetchLatest(self, runtime: BinaryRuntime) -> None:
+ runtimeId = runtime.runtimeId
+ try:
+ self._workIds[runtimeId] = self._coroutineRunner.submit(
+ runtime.fetchLatestVersion(),
+ done=self._onFetchFinished,
+ failed=self._onFetchFailed,
+ runtimeId=runtimeId,
+ )
+ except Exception as e:
+ logger.opt(exception=e).debug("runtime fetch latest submit failed: {}", runtimeId)
+ self._runtimes.pop(runtimeId, None)
+
+ def _onFetchFinished(self, latestVersion: str, runtimeId: str) -> None:
+ self._workIds.pop(runtimeId, None)
+ self._runtimes.pop(runtimeId, None)
+ current = self._statuses.get(runtimeId)
+ if current and latestVersion:
+ status = replace(current, latestVersion=latestVersion)
+ self._statuses[runtimeId] = status
+ self.statusChanged.emit(status)
+
+ def _onFetchFailed(self, error: str, runtimeId: str) -> None:
+ self._workIds.pop(runtimeId, None)
+ self._runtimes.pop(runtimeId, None)
diff --git a/app/update.py b/app/update.py
index 1d77b6e5..5e70bc8f 100644
--- a/app/update.py
+++ b/app/update.py
@@ -74,6 +74,17 @@ async def fetchRelease() -> Release:
client.close()
+async def fetchGitHubLatestTag(repo: str) -> str:
+ client = buildClient(headers={"accept": "application/vnd.github+json"}, timeout=15)
+ try:
+ resp = await client.get(f"https://api.github.com/repos/{repo}/releases/latest")
+ resp.raise_for_status()
+ data = await resp.json()
+ return data.get("tag_name", "")
+ finally:
+ client.close()
+
+
def isOutdated(release: Release) -> bool:
current = QVersionNumber.fromString(VERSION.lstrip("vV"))
latest = QVersionNumber.fromString(release.version.lstrip("vV"))
diff --git a/app/view/components/setting_cards.py b/app/view/components/setting_cards.py
index 1f34256d..ea142840 100644
--- a/app/view/components/setting_cards.py
+++ b/app/view/components/setting_cards.py
@@ -681,6 +681,7 @@ class RuntimeCard(SettingCard):
self.installButton = PrimaryPushButton(self.tr("一键安装"), self)
self.refreshButton = ToolButton(FluentIcon.SYNC, self)
+ self.deleteButton = ToolButton(FluentIcon.DELETE, self)
self._initWidget()
self._initLayout()
@@ -690,6 +691,9 @@ class RuntimeCard(SettingCard):
def _initWidget(self) -> None:
if not self._runtime.canInstall:
self.installButton.hide()
+ self.deleteButton.hide()
+ self.deleteButton.setToolTip(self.tr("卸载"))
+ self.deleteButton.installEventFilter(ToolTipFilter(self.deleteButton))
self.refreshButton.setToolTip(self.tr("刷新"))
self.refreshButton.installEventFilter(ToolTipFilter(self.refreshButton))
@@ -697,11 +701,14 @@ class RuntimeCard(SettingCard):
self.hBoxLayout.addWidget(self.installButton, 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)
self.hBoxLayout.addSpacing(16)
def _bind(self) -> None:
self._runtimeStatusService.statusChanged.connect(self._onRuntimeStatusChanged)
self.installButton.clicked.connect(self._onInstallClicked)
+ self.deleteButton.clicked.connect(self._onDeleteClicked)
self.refreshButton.clicked.connect(self._onRefreshClicked)
def refreshStatus(self) -> None:
@@ -709,17 +716,47 @@ class RuntimeCard(SettingCard):
def updateStatus(self, status) -> None:
self.refreshButton.setEnabled(not status.isBusy)
+ isInstalled = bool(status.path)
+ isManaged = self._runtime.isAppManaged()
+ isUpdateAvailable = (
+ isInstalled and isManaged
+ and status.latestVersion
+ and (not status.version or self._runtime.isNewer(status.version, status.latestVersion))
+ )
+
if status.isBusy:
self.setContent(self.tr("正在检测运行时..."))
- elif status.error:
+ self.installButton.hide()
+ self.deleteButton.hide()
+ return
+
+ if status.error:
self.setContent(self.tr("检测运行时失败"))
- elif status.version and status.path:
- self.setContent(self.tr("版本: {0}\n路径: {1}").format(status.version, status.path))
- elif status.path:
- self.setContent(self.tr("路径: {0}").format(status.path))
+ 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)
+ elif status.latestVersion:
+ line1 = self.tr("最新版本: {0}").format(status.latestVersion)
+ else:
+ line1 = ""
+ line2 = self.tr("路径: {0}").format(status.path)
+ self.setContent(f"{line1}\n{line2}" if line1 else line2)
else:
self.setContent(self.tr("未检测到可用的 {0}").format(status.name))
+ if isUpdateAvailable:
+ self.installButton.setText(self.tr("更新到 {0}").format(status.latestVersion))
+ self.installButton.setVisible(True)
+ elif not isInstalled or not isManaged:
+ self.installButton.setText(self.tr("一键安装"))
+ self.installButton.setVisible(self._runtime.canInstall)
+ else:
+ self.installButton.hide()
+
+ self.deleteButton.setVisible(isInstalled and isManaged)
+
def _onRefreshClicked(self, *_args) -> None:
self._runtimeStatusService.invalidate(self._runtime)
@@ -768,3 +805,23 @@ class RuntimeCard(SettingCard):
position=InfoBarPosition.TOP,
parent=self.window(),
)
+
+ def _onDeleteClicked(self) -> None:
+ from qfluentwidgets import MessageBox
+
+ dialog = MessageBox(
+ self.tr("确认卸载"),
+ self.tr("确定要卸载 {0} 吗?").format(self._runtime.name),
+ self.window(),
+ )
+ if not dialog.exec():
+ return
+ try:
+ self._runtime.delete()
+ except Exception as e:
+ InfoBar.error(
+ self.tr("卸载失败"), str(e),
+ duration=-1, position=InfoBarPosition.TOP, parent=self.window(),
+ )
+ return
+ self._runtimeStatusService.invalidate(self._runtime)
diff --git a/features/ed2k_pack/config.py b/features/ed2k_pack/config.py
index 99b2ec9b..2bd5d491 100644
--- a/features/ed2k_pack/config.py
+++ b/features/ed2k_pack/config.py
@@ -72,6 +72,20 @@ class ED2kRuntime(BinaryRuntime):
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))
+
+ async def fetchLatestVersion(self) -> str:
+ from app.update import fetchGitHubLatestTag
+ return 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 disk_pack.task import InstallTask
diff --git a/features/ffmpeg_pack/config.py b/features/ffmpeg_pack/config.py
index 9a9f11c4..2e734e3c 100644
--- a/features/ffmpeg_pack/config.py
+++ b/features/ffmpeg_pack/config.py
@@ -72,6 +72,10 @@ class FFmpegRuntime(BinaryRuntime):
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))
+
def ffprobePath(self) -> str:
if IS_ANDROID:
nativeDir = nativeLibraryDir()
@@ -97,6 +101,16 @@ class FFmpegRuntime(BinaryRuntime):
line = stdout.decode("utf-8", errors="ignore").splitlines()[0].strip()
return line.removeprefix("ffmpeg version ").split(" Copyright", 1)[0].strip() or line
+ async def fetchLatestVersion(self) -> str:
+ from app.update import fetchGitHubLatestTag
+ return 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:
from app.models.task import BinaryInstallOptions
diff --git a/features/m3u8_pack/config.py b/features/m3u8_pack/config.py
index 7c17fa2e..07278f61 100644
--- a/features/m3u8_pack/config.py
+++ b/features/m3u8_pack/config.py
@@ -22,9 +22,7 @@ from app.models.task import Task
from app.platform.android import IS_ANDROID, nativeLibraryDir
from app.platform.filesystem import findExecutable
-RELEASE_TAG = "v0.6.0-beta"
-RELEASE_DATE = "20260629"
-RELEASE_BASE = f"https://github.com/nilaoda/N_m3u8DL-RE/releases/download/{RELEASE_TAG}"
+M3U8_REPO = "nilaoda/N_m3u8DL-RE"
class M3U8Config(PackConfig):
@@ -165,6 +163,20 @@ class M3U8Runtime(BinaryRuntime):
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))
+
+ async def fetchLatestVersion(self) -> str:
+ from app.update import fetchGitHubLatestTag
+ return 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:
machine = platform.machine().lower()
if sys.platform == "win32":
@@ -181,17 +193,35 @@ class M3U8Runtime(BinaryRuntime):
else:
raise RuntimeError(f"当前平台暂不支持一键安装 N_m3u8DL-RE: {sys.platform}")
- from app.models.task import BinaryInstallOptions
+ url, tag = await self._fetchAssetUrl(target)
- extension = "zip" if sys.platform == "win32" else "tar.gz"
- assetName = f"N_m3u8DL-RE_{RELEASE_TAG}_{target}_{RELEASE_DATE}.{extension}"
+ from app.models.task import BinaryInstallOptions
binaryName = "N_m3u8DL-RE.exe" if sys.platform == "win32" else "N_m3u8DL-RE"
return await self.parse(BinaryInstallOptions(
- url=f"{RELEASE_BASE}/{assetName}",
+ url=url,
outputFolder=Path(m3u8Config.installFolder.value),
- name=f"N_m3u8DL-RE 安装 ({target})",
+ name=f"N_m3u8DL-RE {tag} ({target})",
executableNames=(binaryName,),
))
+ async def _fetchAssetUrl(self, target: str) -> tuple[str, str]:
+ from app.client import buildClient
+ url = f"https://api.github.com/repos/{M3U8_REPO}/releases/latest"
+ client = buildClient(headers={"accept": "application/vnd.github+json"}, timeout=15)
+ try:
+ resp = await client.get(url)
+ resp.raise_for_status()
+ data = await resp.json()
+ finally:
+ client.close()
+
+ tag = data.get("tag_name", "")
+ extension = ".zip" if sys.platform == "win32" else ".tar.gz"
+ for asset in data.get("assets", []):
+ name = asset.get("name", "")
+ if target in name and name.endswith(extension):
+ return asset["browser_download_url"], tag
+ raise RuntimeError(f"未找到适配 {target} 的 N_m3u8DL-RE 安装包")
+
m3u8Runtime = M3U8Runtime()
diff --git a/features/yt_dlp_pack/config.py b/features/yt_dlp_pack/config.py
index 26fdae60..8ae2aa43 100644
--- a/features/yt_dlp_pack/config.py
+++ b/features/yt_dlp_pack/config.py
@@ -130,6 +130,10 @@ class YouTubeRuntime(BinaryRuntime):
return ""
return self.qjsPath()
+ def isAppManaged(self) -> bool:
+ folder = Path(ytDlpConfig.installFolder.value)
+ return (folder / "yt_dlp" / "__init__.py").is_file()
+
def ytDlpFolder(self) -> Path:
return Path(ytDlpConfig.installFolder.value)
@@ -176,9 +180,38 @@ class YouTubeRuntime(BinaryRuntime):
if ytDlpVersion:
parts.append(f"yt-dlp {ytDlpVersion}")
if isQjsOk:
- parts.append("qjs ✓")
+ parts.append("QuickJS ✓")
return " | ".join(parts) if parts else ""
+ async def fetchLatestVersion(self) -> str:
+ from app.client import buildClient
+ client = buildClient(timeout=15)
+ try:
+ resp = await client.get(PYPI_API)
+ resp.raise_for_status()
+ data = await resp.json()
+ return data.get("info", {}).get("version", "")
+ 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
from disk_pack.task import ExtractStep, InstallTask