Skip to content

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

fix(yt-dlp): 自定义安装路径后 Draft 不再重置配置

XiaoYouChR93ffb267f4bd
diff --git a/features/yt_dlp_pack/cards.py b/features/yt_dlp_pack/cards.py
index 5b75b4ba..8d03b242 100644
--- a/features/yt_dlp_pack/cards.py
+++ b/features/yt_dlp_pack/cards.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+import asyncio
from pathlib import Path
from PySide6.QtCore import QCoreApplication, Qt, QT_TRANSLATE_NOOP as N
@@ -21,7 +22,7 @@ from app.view.components.track_bar import TrackBar, TrackButton
from app.view.components.tree_view import AutoSizingTreeView
from app.view.dialogs.subtitle_select import SubtitleSelectDialog
from .config import ytDlpConfig
-from .task import STEPS_PER_VIDEO, YouTubeCoverStep, YouTubeTask, buildFormatPair
+from .task import STEPS_PER_VIDEO, YouTubeCoverStep, YouTubeTask, buildFormatPair, probeFormats, probePlaylist
def toCodecName(codec: str) -> str:
@@ -498,10 +499,8 @@ class YtDlpDraftCard(DraftCard):
self._refreshFileIcon()
def _startMediaInfoFetch(self) -> None:
- from features.yt_dlp_pack.pack import YouTubeParser
- parser = YouTubeParser()
self._coroutineRunner.submit(
- parser.fetchFormats(self._task.url),
+ asyncio.to_thread(probeFormats, self._task.url),
done=self._onMediaInfoLoaded,
failed=self._onMediaInfoFailed,
owner=self,
@@ -626,10 +625,8 @@ class YtDlpDraftCard(DraftCard):
if not task.files:
self._videoSelectButton.hide()
self._playlistSpinner.show()
- from features.yt_dlp_pack.pack import YouTubeParser
- parser = YouTubeParser()
self._coroutineRunner.submit(
- parser.fetchPlaylist(task.url),
+ asyncio.to_thread(probePlaylist, task.url),
done=self._onPlaylistLoaded,
failed=self._onPlaylistFailed,
owner=self,
diff --git a/features/yt_dlp_pack/pack.py b/features/yt_dlp_pack/pack.py
index 3201f76a..c9d59969 100644
--- a/features/yt_dlp_pack/pack.py
+++ b/features/yt_dlp_pack/pack.py
@@ -1,6 +1,5 @@
from __future__ import annotations
-import asyncio
from urllib.parse import urlparse, parse_qs, quote
from app.models.pack import FeaturePack, TaskParser
@@ -10,7 +9,7 @@ from loguru import logger
from .cards import YtDlpDraftCard, YtDlpTaskCard
from .config import ytDlpConfig, youTubeRuntime
-from .task import YouTubeTask, buildStepGroup, probeFormats, probePlaylist
+from .task import YouTubeTask, buildStepGroup
YOUTUBE_HOSTS = ("youtube.com", "youtu.be")
@@ -45,28 +44,6 @@ class YouTubeParser(TaskParser):
task.addStep(step)
return task
- async def fetchFormats(self, url: str) -> dict:
- from .config import youTubeRuntime
- runtimePath = youTubeRuntime.path()
- if not runtimePath:
- logger.warning("fetchFormats skipped: runtime not found (installFolder={})", youTubeRuntime.ytDlpFolder())
- return {}
- try:
- return await asyncio.to_thread(probeFormats, url)
- except Exception as e:
- logger.opt(exception=e).warning("fetchFormats failed for {}", url)
- return {}
-
- async def fetchPlaylist(self, url: str) -> list[dict]:
- from .config import youTubeRuntime
- if not youTubeRuntime.path():
- return []
- try:
- return await asyncio.to_thread(probePlaylist, url)
- except Exception as e:
- logger.opt(exception=e).warning("fetchPlaylist failed for {}", url)
- return []
-
async def _fetchTitle(self, url: str) -> str:
from app.client import buildClient
oembedUrl = f"https://www.youtube.com/oembed?url={quote(url, safe='')}&format=json"