From 7bf1f2e1e1aa525335ce8bbaaf3ae32bb3ace48e Mon Sep 17 00:00:00 2001 From: Andrew <66430340+aandrew-me@users.noreply.github.com> Date: Sat, 28 Oct 2023 22:32:28 +0300 Subject: [PATCH] Embed thumbnail and Fix Unknown size --- package.json | 2 +- src/playlist.js | 22 ++++++++++++++++++++-- src/renderer.js | 32 +++++++++++++++++++++++++++----- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index c156ced..3cdbb2e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "yt-dlp-wrap-plus": "^2.3.16" }, "name": "ytdownloader", - "version": "3.14.3", + "version": "3.15.0-beta", "main": "main.js", "scripts": { "start": "electron .", diff --git a/src/playlist.js b/src/playlist.js index 71a8a75..e754fa2 100644 --- a/src/playlist.js +++ b/src/playlist.js @@ -44,6 +44,24 @@ if (!fs.existsSync(ffmpegPath)) { } console.log("ffmpeg:", ffmpeg); +// Check for thumbnail embed support +let embedThumbnail = false; +if (os.platform() === "win32" || os.platform() === "darwin"){ + embedThumbnail = true; +} else { + try { + cp.execSync("ffprobe -version", { + encoding: "utf-8", + }); + console.log("ffprobe found") + embedThumbnail = true + + + } catch (error) { + console.log("ffprobe not found") + } +} + let foldernameFormat = "%(playlist_title)s"; let filenameFormat = "%(playlist_index)s.%(title)s.%(ext)s"; let playlistIndex = 1; @@ -147,7 +165,7 @@ function download(type) { configArg, configTxt, "--embed-metadata", - // videoType == "mp4" ? "--embed-thumbnail": "", + videoType == "mp4" && embedThumbnail ? "--embed-thumbnail": "", `"${url}"`, ], {shell: true, detached: false}, @@ -180,7 +198,7 @@ function download(type) { configArg, configTxt, "--embed-metadata", - // "--embed-thumbnail", + embedThumbnail ? "--embed-thumbnail": "", `"${url}"`, ], {shell: true, detached: false}, diff --git a/src/renderer.js b/src/renderer.js index 37e9da4..eccf1e4 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -205,6 +205,24 @@ cp.exec("yt-dlp --version", (error, stdout, stderr) => { } }); +// Check for thumbnail embed support +let embedThumbnail = false; +if (os.platform() === "win32" || os.platform() === "darwin"){ + embedThumbnail = true; +} else { + try { + cp.execSync("ffprobe -version", { + encoding: "utf-8", + }); + console.log("ffprobe found") + embedThumbnail = true + + + } catch (error) { + console.log("ffprobe not found") + } +} + function defaultVideoToggle() { let defaultWindow = "video"; if (localStorage.getItem("defaultWindow")) { @@ -404,7 +422,11 @@ async function getInfo(url) { 1000000 ).toFixed(2); } else { - size = i18n.__("Unknown size"); + if (format.tbr) { + size = ((format.tbr * 128 * duration) / 1000000).toFixed(2) + } else { + size = i18n.__("Unknown size"); + } } // For videos @@ -415,7 +437,7 @@ async function getInfo(url) { ) { if (size !== "Unknown size") { size = (Number(size) + 0 || Number(audioSize)).toFixed( - 2 + 1 ); size = size + " " + i18n.__("MB"); } @@ -944,7 +966,7 @@ function download( subs2 || subLangs, "--no-playlist", "--embed-metadata", - // ext == "mp4" ? "--embed-thumbnail": "", + ext == "mp4" && embedThumbnail ? "--embed-thumbnail": "", configArg, configTxt, cookieArg, @@ -982,7 +1004,7 @@ function download( ffmpeg, "--no-playlist", "--embed-metadata", - // extractFormat1 == "m4a" || extractFormat1 == "mp3" ? "--embed-thumbnail": "", + (extractFormat1 == "m4a" || embedThumbnail) && extractFormat1 == "mp3" ? "--embed-thumbnail": "", cookieArg, browser, configArg, @@ -1012,7 +1034,7 @@ function download( subs2 || subLangs, "--no-playlist", "--embed-metadata", - // ext == "m4a" || ext == "mp4" ? "--embed-thumbnail": "", + (ext == "m4a" || ext == "mp4") && embedThumbnail ? "--embed-thumbnail": "", cookieArg, browser, configArg,