Skip to content

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

feat(yt_dlp_pack): 切换 yt-dlp 到 nightly 源,过滤 HLS 格式

XiaoYouChR4008b2c88f0c
diff --git a/app/config/paths.py b/app/config/paths.py
index 40da9c2c..b3cf785d 100644
--- a/app/config/paths.py
+++ b/app/config/paths.py
@@ -21,7 +21,11 @@ APP_DATA_DIR: str = (
PORTABLE_PATH = executableDir / "GhostDownloader"
SEED_FEATURES_DIR = executableDir / "features"
-FEATURES_DIR = Path(APP_DATA_DIR) / "features"
+FEATURES_DIR = (
+ SEED_FEATURES_DIR
+ if "__compiled__" not in globals()
+ else Path(APP_DATA_DIR) / "features"
+)
USER_PATH = Path(QStandardPaths.writableLocation(
QStandardPaths.StandardLocation.GenericDataLocation
)) / "GhostDownloader"
diff --git a/app/install.py b/app/install.py
index ec45ed27..97a388cf 100644
--- a/app/install.py
+++ b/app/install.py
@@ -46,18 +46,32 @@ class ExtractStep(TaskStep):
archivePath: str
outputFolder: str
archiveSize: int = 0
+ root: str = ""
+ subtree: str = ""
async def _extractZip(self, archive: Path, outputFolder: Path):
with zipfile.ZipFile(archive) as zf:
- files = [info for info in zf.infolist() if not info.is_dir()]
- totalSize = sum(info.file_size for info in files)
+ members = []
+ for info in zf.infolist():
+ if info.is_dir():
+ continue
+ name = info.filename
+ if self.root:
+ if not name.startswith(self.root):
+ continue
+ name = name[len(self.root):]
+ if self.subtree and not name.startswith(self.subtree):
+ continue
+ members.append((info, name))
+
+ totalSize = sum(info.file_size for info, _ in members)
self.task.fileSize = max(self.archiveSize + totalSize, self.archiveSize)
safeRoot = outputFolder.resolve()
extractedBytes = speedBytes = 0
speedTime = perf_counter()
- for info in files:
- memberPath = (outputFolder / info.filename).resolve()
+ for info, name in members:
+ memberPath = (outputFolder / name).resolve()
if safeRoot not in {memberPath, *memberPath.parents}:
raise TaskError("压缩包包含不安全路径:{path}", path=info.filename)
memberPath.parent.mkdir(parents=True, exist_ok=True)
@@ -76,15 +90,27 @@ class ExtractStep(TaskStep):
async def _extractTar(self, archive: Path, outputFolder: Path):
with tarfile.open(archive, "r:*") as tf:
- files = [m for m in tf.getmembers() if m.isfile()]
- totalSize = sum(m.size for m in files)
+ members = []
+ for m in tf.getmembers():
+ if not m.isfile():
+ continue
+ name = m.name
+ if self.root:
+ if not name.startswith(self.root):
+ continue
+ name = name[len(self.root):]
+ if self.subtree and not name.startswith(self.subtree):
+ continue
+ members.append((m, name))
+
+ totalSize = sum(m.size for m, _ in members)
self.task.fileSize = max(self.archiveSize + totalSize, self.archiveSize)
safeRoot = outputFolder.resolve()
extractedBytes = speedBytes = 0
speedTime = perf_counter()
- for member in files:
- memberPath = (outputFolder / member.name).resolve()
+ for member, name in members:
+ memberPath = (outputFolder / name).resolve()
if safeRoot not in {memberPath, *memberPath.parents}:
raise TaskError("压缩包包含不安全路径:{path}", path=member.name)
memberPath.parent.mkdir(parents=True, exist_ok=True)
diff --git a/app/loader.py b/app/loader.py
index eda467ca..c1dcbd38 100644
--- a/app/loader.py
+++ b/app/loader.py
@@ -17,7 +17,7 @@ if TYPE_CHECKING:
def seedPacks(seedDir: Path, targetDir: Path) -> None:
from PySide6.QtCore import QVersionNumber
- if not seedDir.exists():
+ if not seedDir.exists() or seedDir.resolve() == targetDir.resolve():
return
targetDir.mkdir(parents=True, exist_ok=True)
diff --git a/dist/packs/yt_dlp_pack.zip b/dist/packs/yt_dlp_pack.zip
index 43b60b54..8e5e2016 100644
Binary files a/dist/packs/yt_dlp_pack.zip and b/dist/packs/yt_dlp_pack.zip differ
diff --git a/features/yt_dlp_pack/config.py b/features/yt_dlp_pack/config.py
index 321b4526..23449884 100644
--- a/features/yt_dlp_pack/config.py
+++ b/features/yt_dlp_pack/config.py
@@ -16,9 +16,10 @@ from app.config.paths import APP_DATA_DIR
from app.models.pack import BinaryRuntime, PackConfig, VersionInfo
from app.platform.android import IS_ANDROID
from app.platform.filesystem import findExecutable
-from app.sources import Repo, fetchLatestRelease, fetchPypiJson, probeDownloadUrl
+from app.sources import Repo, fetchLatestRelease, probeDownloadUrl
QJS_REPO = Repo("quickjs-ng/quickjs", mirrors={"gitcode": "XiaoYouChR/quickjs-mirror"})
+YTDLP_NIGHTLY_REPO = Repo("yt-dlp/yt-dlp-nightly-builds")
COOKIE_DOMAIN = ".youtube.com"
AUTH_COOKIE_NAMES = ("LOGIN_INFO", "SAPISID", "__Secure-1PAPISID", "__Secure-3PAPISID")
@@ -198,37 +199,39 @@ class YouTubeRuntime(BinaryRuntime):
)
async def fetchLatestVersion(self) -> str:
- data = await fetchPypiJson("yt-dlp")
- self.pypi = data
- return data.get("info", {}).get("version", "")
+ release = await fetchLatestRelease(YTDLP_NIGHTLY_REPO)
+ self._latestRelease = release
+ return release.version
async def createInstallTask(self, version: str = ""):
from app.install import BinaryInstallStep, ExtractStep, FetchStep, InstallTask
- whlUrl, whlSize = await self._fetchWhlAsset()
+ tarballUrl, tarballSize = await self._fetchTarballAsset()
folder = self.installFolder()
folder.mkdir(parents=True, exist_ok=True)
- archiveName = "yt_dlp.zip"
+ archiveName = "yt_dlp.tar.gz"
if IS_ANDROID:
task = InstallTask(
name="yt-dlp 安装",
- url=whlUrl,
+ url=tarballUrl,
packId="disk",
- fileSize=whlSize,
+ fileSize=tarballSize,
outputFolder=folder,
installFolder=str(folder),
)
task.addStep(FetchStep(
- stepIndex=1, url=whlUrl,
+ stepIndex=1, url=tarballUrl,
outputFile=str(folder / archiveName),
))
task.addStep(ExtractStep(
stepIndex=2,
archivePath=str(folder / archiveName),
outputFolder=str(folder),
- archiveSize=whlSize,
+ archiveSize=tarballSize,
+ root="yt-dlp/",
+ subtree="yt_dlp/",
))
return task
@@ -238,14 +241,14 @@ class YouTubeRuntime(BinaryRuntime):
task = InstallTask(
name="YouTube 运行环境安装",
- url=whlUrl,
+ url=tarballUrl,
packId="disk",
fileSize=0,
outputFolder=folder,
installFolder=str(folder),
)
task.addStep(FetchStep(
- stepIndex=1, url=whlUrl,
+ stepIndex=1, url=tarballUrl,
outputFile=str(folder / archiveName),
))
task.addStep(FetchStep(
@@ -256,7 +259,9 @@ class YouTubeRuntime(BinaryRuntime):
stepIndex=3,
archivePath=str(folder / archiveName),
outputFolder=str(folder),
- archiveSize=whlSize,
+ archiveSize=tarballSize,
+ root="yt-dlp/",
+ subtree="yt_dlp/",
))
task.addStep(BinaryInstallStep(
stepIndex=4,
@@ -264,16 +269,15 @@ class YouTubeRuntime(BinaryRuntime):
))
return task
- async def _fetchWhlAsset(self) -> tuple[str, int]:
- data = getattr(self, "pypi", None)
- if data is None:
- data = await fetchPypiJson("yt-dlp")
- self.pypi = data
- urls = data.get("urls") or []
- for entry in urls:
- if entry.get("packagetype") == "bdist_wheel" and entry.get("filename", "").endswith(".whl"):
- return entry["url"], entry.get("size") or 0
- raise RuntimeError("未找到 yt-dlp wheel 安装包")
+ async def _fetchTarballAsset(self) -> tuple[str, int]:
+ release = getattr(self, "_latestRelease", None)
+ if release is None:
+ release = await fetchLatestRelease(YTDLP_NIGHTLY_REPO)
+ self._latestRelease = release
+ for asset in release.assets:
+ if asset.name == "yt-dlp.tar.gz":
+ return asset.downloadUrl, asset.size
+ raise RuntimeError("未找到 yt-dlp nightly tarball")
def _qjsAssetName() -> str:
machine = platform.machine().lower()
diff --git a/features/yt_dlp_pack/manifest.toml b/features/yt_dlp_pack/manifest.toml
index e0fcd227..92c72ad4 100644
--- a/features/yt_dlp_pack/manifest.toml
+++ b/features/yt_dlp_pack/manifest.toml
@@ -2,5 +2,5 @@
entry = "pack.py"
class = "YouTubePack"
dependencies = ["http_pack", "ffmpeg_pack"]
-version = "1.0.0"
-gdMinVersion = "4.2.0"
+version = "1.1.0"
+gdMinVersion = "4.3.2"
diff --git a/features/yt_dlp_pack/task.py b/features/yt_dlp_pack/task.py
index f6eae4f8..8a309889 100644
--- a/features/yt_dlp_pack/task.py
+++ b/features/yt_dlp_pack/task.py
@@ -104,9 +104,12 @@ def probePlaylist(url: str) -> list[dict]:
]
+DIRECT_PROTOCOLS = {"https", "http"}
+
+
def buildFormatPair(info: dict, task: YouTubeTask) -> tuple[dict | None, dict | None]:
from .config import ytDlpConfig
- formats = info.get("formats") or []
+ formats = [f for f in (info.get("formats") or []) if f.get("protocol") in DIRECT_PROTOCOLS]
shouldPreferMp4 = ytDlpConfig.shouldPreferMp4.value
audioFormats = [
diff --git a/versions.json b/versions.json
index f9b1bf5e..9e3738ea 100644
--- a/versions.json
+++ b/versions.json
@@ -94,10 +94,10 @@
"gdMinVersion": "4.2.0"
},
"yt_dlp_pack": {
- "version": "1.0.0",
+ "version": "1.1.0",
"file": "yt_dlp_pack.zip",
- "sha256": "7bf756a9a47b2c4e06070ce792d6cc9e08b56ec69d46b952e896aed9f1dcefef",
- "gdMinVersion": "4.2.0"
+ "sha256": "c1137b9b4ef782084dc39e2aa3e517a8af0ce3af0ef9040a5fd027cf064c779a",
+ "gdMinVersion": "4.3.2"
}
}
}