From d57e17d63e5e8984936056f17819eae2052e84d5 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Thu, 26 Feb 2026 04:09:17 +0800 Subject: [PATCH 4/6] System yt-dlp --- src/qmplay2/YouTubeDL.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/qmplay2/YouTubeDL.cpp b/src/qmplay2/YouTubeDL.cpp index 897dddf4..760fde94 100644 --- a/src/qmplay2/YouTubeDL.cpp +++ b/src/qmplay2/YouTubeDL.cpp @@ -38,6 +38,11 @@ #include #include +/* Avoid bundled yt-dlp, it fails to work correctly. Use our port. */ +#ifndef BUNDLED_YTDLP +#define BUNDLED_YTDLP 0 +#endif + constexpr const char *g_name = "YouTubeDL"; static bool g_mustUpdate = true; #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) @@ -120,6 +125,18 @@ QString YouTubeDL::getFilePath() { if (auto customPath = getCustomFilePath(); !customPath.isEmpty()) return customPath; + +#ifdef Q_OS_MAC + // On macOS, prefer MacPorts yt-dlp or user-provided symlink + QString homeYtDlp = QDir::homePath() + "/.qmplay2/yt-dlp"; + if (QFileInfo(homeYtDlp).exists()) + return homeYtDlp; + + QString macPortsYtDlp = "@prefix@/bin/yt-dlp"; + if (QFileInfo(macPortsYtDlp).exists()) + return macPortsYtDlp; +#endif + return QMPlay2Core.getSettingsDir() + getYtDlpFileName(); } QStringList YouTubeDL::getCommonArgs() @@ -419,6 +436,7 @@ bool YouTubeDL::prepare() return false; } +#if BUNDLED_YTDLP #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) if (!QFileInfo::exists(m_ytDlPath)) #else @@ -449,6 +467,7 @@ bool YouTubeDL::prepare() } g_mustUpdate = false; } +#endif ensureExecutable(); @@ -456,6 +475,7 @@ bool YouTubeDL::prepare() return true; } +#if BUNDLED_YTDLP bool YouTubeDL::download() { // Mutex must be locked here @@ -517,6 +537,9 @@ bool YouTubeDL::download() qCritical() << "Unable to download \"youtube-dl\""; return false; } +#endif + +#if BUNDLED_YTDLP bool YouTubeDL::update() { if (QMPlay2Core.getSettings().getBool("YtDl/DontAutoUpdate")) @@ -570,6 +593,7 @@ bool YouTubeDL::update() QMPlay2Core.setWorking(false); return true; } +#endif void YouTubeDL::ensureExecutable() {