From 1438332b34ffd7cab2f1c02da4aae65c3115f260 Mon Sep 17 00:00:00 2001 From: aandrew-me Date: Sat, 16 Aug 2025 12:48:25 +0300 Subject: [PATCH] Macos ytdlp changes --- .github/workflows/main.yml | 2 +- assets/css/index.css | 4 +- html/index.html | 10 ++ package.json | 2 +- src/renderer.js | 269 +++++++++++++++++++++---------------- 5 files changed, 169 insertions(+), 118 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 996d026..e39a75f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,7 +23,7 @@ jobs: - name: Install Node.js, NPM and Yarn uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 - name: Linux Build if: matrix.os == 'ubuntu-latest' diff --git a/assets/css/index.css b/assets/css/index.css index 77b6f20..73c3513 100644 --- a/assets/css/index.css +++ b/assets/css/index.css @@ -154,7 +154,7 @@ body { transition: 0.4s; font-size: large; } -#popupBox { +#popupBox, #popupBoxMac { width: 100vw; height: 100vh; margin: 0; @@ -165,7 +165,7 @@ body { z-index: 2; display: none; } -#popup { +#popup, #popupMac { position: absolute; padding: 20px; top: 50%; diff --git a/html/index.html b/html/index.html index 6c381e4..0ea98dd 100644 --- a/html/index.html +++ b/html/index.html @@ -34,6 +34,16 @@ + +
+
+

You need to download yt-dlp from homebrew first

+ + Open Homebrew + +
+
+ Text copied diff --git a/package.json b/package.json index 004f0a6..faad039 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "yt-dlp-wrap-plus": "^2.3.20" }, "name": "ytdownloader", - "version": "3.19.1", + "version": "3.19.2-beta", "main": "main.js", "scripts": { "start": "electron .", diff --git a/src/renderer.js b/src/renderer.js index d35e72e..23bc69c 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -5,21 +5,20 @@ if (os.platform() === "win32") { ffmpeg = `"${__dirname}\\..\\ffmpeg.exe"`; } else if (os.platform() === "freebsd") { try { - ffmpeg = cp.execSync("which ffmpeg").toString("utf8").split("\n")[0].trim(); + ffmpeg = cp + .execSync("which ffmpeg") + .toString("utf8") + .split("\n")[0] + .trim(); } catch (error) { - console.log(error) + console.log(error); showPopup("No ffmpeg found in PATH."); } -} - else { +} else { ffmpeg = `"${__dirname}/../ffmpeg"`; } const fs = require("fs"); - -///////////////////////////////////// -// Do not change the lines at the top -///////////////////////////////////// const path = require("path"); const {shell, ipcRenderer, clipboard} = require("electron"); const {default: YTDlpWrap} = require("yt-dlp-wrap-plus"); @@ -71,7 +70,7 @@ let showMoreFormats = false; let configArg = ""; let configTxt = ""; let proxy = ""; -let downloadedItemList = [] +let downloadedItemList = []; if (localStorage.getItem("configPath")) { configArg = "--config-location"; @@ -145,12 +144,31 @@ downloadPathSelection(); let ytDlp; let ytdlpPath = path.join(os.homedir(), ".ytDownloader", "ytdlp"); +if (os.platform() === "darwin") { + try { + ytdlpPath = cp + .execSync("which yt-dlp") + .toString("utf8") + .split("\n")[0] + .trim(); + } catch (error) { + console.log(error); + getId("incorrectMsg").textContent = i18n.__( + "No yt-dlp found in PATH. Download it with homebrew." + ); + } +} + // Use system yt-dlp for freebsd if (os.platform() === "freebsd") { try { - ytdlpPath = cp.execSync('which yt-dlp').toString("utf8").split("\n")[0].trim(); + ytdlpPath = cp + .execSync("which yt-dlp") + .toString("utf8") + .split("\n")[0] + .trim(); } catch (error) { - console.log(error) + console.log(error); getId("incorrectMsg").textContent = i18n.__( "No yt-dlp found in PATH. Make sure you have the full executable. App will not work" ); @@ -165,6 +183,14 @@ if (os.platform() == "win32") { ytdlpDownloadPath = path.join(os.homedir(), ".ytDownloader", "ytdlp"); } +function showMacYtdlpPopup() { + getId("popupBoxMac").style.display = "block"; +} + +function hideMacYtdlpPopup() { + getId("popupBoxMac").style.display = "none"; +} + // Downloading yt-dlp async function downloadYtdlp() { document.querySelector("#popupBox p").textContent = i18n.__( @@ -186,37 +212,31 @@ async function downloadYtdlp() { // Checking if yt-dlp has been installed by user -// TODO: Remove this after some time const fullYtdlpBinIsPresent = !!localStorage.getItem("fullYtdlpBinPresent"); -const removedOldMacYtdlp = !!localStorage.getItem("removedOldMacYtdlp") - -// Removing old yt-dlp for macos -if (os.platform() === "darwin" && !removedOldMacYtdlp) { - if (fs.existsSync(ytdlpPath)) { - fs.rmSync(ytdlpPath) - localStorage.setItem('removedOldMacYtdlp', "true") - } -} cp.exec(`"${ytdlpPath}" --version`, (error, _stdout, _stderr) => { if ((error || !fullYtdlpBinIsPresent) && os.platform() !== "freebsd") { - getId("popupBox").style.display = "block"; - process.on("uncaughtException", (reason, promise) => { - document.querySelector("#popupBox p").textContent = i18n.__( - "Failed to download necessary files. Please check your network and try again" - ); - getId("popupSvg").style.display = "none"; - getId("popup").innerHTML += ``; - console.log("Failed to download yt-dlp"); - - getId("tryBtn").addEventListener("click", () => { - getId("popup").removeChild(getId("popup").lastChild); - downloadYtdlp(); + if (os.platform() == "darwin") { + showMacYtdlpPopup() + } else { + getId("popupBox").style.display = "block"; + process.on("uncaughtException", (reason, promise) => { + document.querySelector("#popupBox p").textContent = i18n.__( + "Failed to download necessary files. Please check your network and try again" + ); + getId("popupSvg").style.display = "none"; + getId("popup").innerHTML += ``; + console.log("Failed to download yt-dlp"); + + getId("tryBtn").addEventListener("click", () => { + getId("popup").removeChild(getId("popup").lastChild); + downloadYtdlp(); + }); }); - }); - downloadYtdlp(); + downloadYtdlp(); + } } else { console.log("yt-dlp binary is present in PATH"); ytDlp = ytdlpPath; @@ -232,7 +252,6 @@ cp.exec(`"${ytdlpPath}" --version`, (error, _stdout, _stderr) => { } }); - function defaultVideoToggle() { let defaultWindow = "video"; if (localStorage.getItem("defaultWindow")) { @@ -270,7 +289,11 @@ getId("closeHidden").addEventListener("click", () => { }); document.addEventListener("keydown", (event) => { - if (event.ctrlKey && event.key == "v" && document.activeElement.tagName !== "INPUT") { + if ( + event.ctrlKey && + event.key == "v" && + document.activeElement.tagName !== "INPUT" + ) { pasteUrl(); } }); @@ -293,7 +316,9 @@ async function getInfo(url) { // Cleaning text getId("videoFormatSelect").innerHTML = ""; getId("audioFormatSelect").innerHTML = ""; - getId("audioForVideoFormatSelect").innerHTML = ``; + getId( + "audioForVideoFormatSelect" + ).innerHTML = ``; const startTime = getId("startTime"); startTime.value = ""; @@ -348,15 +373,11 @@ async function getInfo(url) { configArg, configTxt, `"${url}"`, - ].filter(item => item) + ].filter((item) => item); - const infoProcess = cp.spawn( - `"${ytDlp}"`, - infoOptions, - { - shell: true, - } - ); + const infoProcess = cp.spawn(`"${ytDlp}"`, infoOptions, { + shell: true, + }); infoProcess.stdout.on("data", (data) => { info += data; @@ -392,7 +413,7 @@ async function getInfo(url) { id = parsedInfo.id; thumbnail = parsedInfo.thumbnail; duration = parsedInfo.duration; - extractor_key = parsedInfo.extractor_key + extractor_key = parsedInfo.extractor_key; /** * @typedef {import("./types").format} format * @type {format[]} @@ -433,13 +454,13 @@ async function getInfo(url) { if ( format.height <= preferredVideoQuality && format.height >= defaultVideoFormat && - (format.video_ext !== "none" && + format.video_ext !== "none" && !( format.video_ext === "mp4" && format.vcodec && format.vcodec.split(".")[0] === "vp09" - )) - && (!showMoreFormats ? format.video_ext !== "webm" : true) + ) && + (!showMoreFormats ? format.video_ext !== "webm" : true) ) { defaultVideoFormat = format.height; @@ -464,13 +485,16 @@ async function getInfo(url) { audioSize = Number(format.filesize || format.filesize_approx) / 1000000; - + if (!audioExtensionList.includes(format.audio_ext)) { audioExtensionList.push(format.audio_ext); } - if (format.format_note && format.format_note.length > maxAudioFormatNoteLength) { - maxAudioFormatNoteLength = format.format_note.length + if ( + format.format_note && + format.format_note.length > maxAudioFormatNoteLength + ) { + maxAudioFormatNoteLength = format.format_note.length; } } @@ -501,13 +525,13 @@ async function getInfo(url) { format.vcodec && format.vcodec.split(".")[0] === preferredVideoCodec && !selected && - (format.video_ext !== "none" && + format.video_ext !== "none" && !( format.video_ext === "mp4" && format.vcodec && format.vcodec.split(".")[0] === "vp09" - )) - && (!showMoreFormats ? format.video_ext !== "webm" : true) + ) && + (!showMoreFormats ? format.video_ext !== "webm" : true) ) { selectedText = " selected "; selected = true; @@ -525,7 +549,7 @@ async function getInfo(url) { // 1000000 // ).toFixed(2); // } else { - + // } size = i18n.__("Unknown size"); } @@ -533,13 +557,13 @@ async function getInfo(url) { // For videos if ( - (format.video_ext !== "none" && + format.video_ext !== "none" && !( format.video_ext === "mp4" && format.vcodec && format.vcodec.split(".")[0] === "vp09" - )) - && (!showMoreFormats ? format.video_ext !== "webm" : true) + ) && + (!showMoreFormats ? format.video_ext !== "webm" : true) ) { if (size !== i18n.__("Unknown size")) { size = (Number(size) + 0 || Number(audioSize)).toFixed( @@ -600,7 +624,7 @@ async function getInfo(url) { "| " + extension.padEnd(5, "\xa0") + "| " + - (vcodec ? vcodec + spaceAfterVcodec : '') + + (vcodec ? vcodec + spaceAfterVcodec : "") + size + (format.acodec !== "none" ? " 🔊" : "") + ""; @@ -642,10 +666,14 @@ async function getInfo(url) { const format_id = format.format_id + "|" + audio_ext; /**@type {string} */ - let formatNote = (i18n.__(format.format_note) || - i18n.__("Unknown quality")); + let formatNote = + i18n.__(format.format_note) || + i18n.__("Unknown quality"); - formatNote = formatNote.padEnd(maxAudioFormatNoteLength, "\xa0") + formatNote = formatNote.padEnd( + maxAudioFormatNoteLength, + "\xa0" + ); const element = "