Thumbnail support

pull/171/head
Andrew 2 years ago
parent 7bf1f2e1e1
commit d159038d07

@ -8,7 +8,7 @@ const {
Menu, Menu,
clipboard, clipboard,
} = require("electron"); } = require("electron");
const { autoUpdater } = require("electron-updater"); const {autoUpdater} = require("electron-updater");
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true; process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true;
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
@ -236,7 +236,7 @@ ipcMain.on("select-location-secondary", () => {
}); });
ipcMain.on("select-config", () => { ipcMain.on("select-config", () => {
const location = dialog.showOpenDialogSync( { const location = dialog.showOpenDialogSync({
properties: ["openFile"], properties: ["openFile"],
}); });

@ -1,10 +1,10 @@
{ {
"dependencies": { "dependencies": {
"electron-updater": "^5.3.0", "electron-updater": "^5.3.0",
"yt-dlp-wrap-plus": "^2.3.16" "yt-dlp-wrap-plus": "^2.3.18"
}, },
"name": "ytdownloader", "name": "ytdownloader",
"version": "3.15.0-beta", "version": "3.15.0",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"start": "electron .", "start": "electron .",

@ -44,23 +44,7 @@ if (!fs.existsSync(ffmpegPath)) {
} }
console.log("ffmpeg:", ffmpeg); console.log("ffmpeg:", ffmpeg);
// Check for thumbnail embed support let embedThumbnail = true;
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 foldernameFormat = "%(playlist_title)s";
let filenameFormat = "%(playlist_index)s.%(title)s.%(ext)s"; let filenameFormat = "%(playlist_index)s.%(title)s.%(ext)s";
@ -165,7 +149,7 @@ function download(type) {
configArg, configArg,
configTxt, configTxt,
"--embed-metadata", "--embed-metadata",
videoType == "mp4" && embedThumbnail ? "--embed-thumbnail": "", videoType == "mp4" && embedThumbnail ? "--embed-thumbnail" : "",
`"${url}"`, `"${url}"`,
], ],
{shell: true, detached: false}, {shell: true, detached: false},
@ -198,7 +182,7 @@ function download(type) {
configArg, configArg,
configTxt, configTxt,
"--embed-metadata", "--embed-metadata",
embedThumbnail ? "--embed-thumbnail": "", embedThumbnail ? "--embed-thumbnail" : "",
`"${url}"`, `"${url}"`,
], ],
{shell: true, detached: false}, {shell: true, detached: false},

@ -14,8 +14,8 @@ const fs = require("fs");
///////////////////////////////////// /////////////////////////////////////
const path = require("path"); const path = require("path");
const { shell, ipcRenderer, clipboard } = require("electron"); const {shell, ipcRenderer, clipboard} = require("electron");
const { default: YTDlpWrap } = require("yt-dlp-wrap-plus"); const {default: YTDlpWrap} = require("yt-dlp-wrap-plus");
// Directories // Directories
const homedir = os.homedir(); const homedir = os.homedir();
@ -23,7 +23,7 @@ const appdir = path.join(homedir, "Downloads");
const hiddenDir = path.join(homedir, ".ytDownloader"); const hiddenDir = path.join(homedir, ".ytDownloader");
const i18n = new (require("../translations/i18n"))(); const i18n = new (require("../translations/i18n"))();
fs.mkdir(hiddenDir, { recursive: true }, () => {}); fs.mkdir(hiddenDir, {recursive: true}, () => {});
// System tray // System tray
const trayEnabled = localStorage.getItem("closeToTray"); const trayEnabled = localStorage.getItem("closeToTray");
@ -91,7 +91,7 @@ function downloadPathSelection() {
localStorage.setItem("downloadPath", appdir); localStorage.setItem("downloadPath", appdir);
} }
getId("path").textContent = downloadDir; getId("path").textContent = downloadDir;
fs.mkdir(downloadDir, { recursive: true }, () => {}); fs.mkdir(downloadDir, {recursive: true}, () => {});
} }
downloadPathSelection(); downloadPathSelection();
@ -117,35 +117,18 @@ async function downloadYtdlp() {
// Downloading appropriate version of yt-dlp // Downloading appropriate version of yt-dlp
if (os.platform() == "linux") { if (os.platform() == "linux") {
// Checking python version
try {
const result = cp.execSync("python3 --version", {
encoding: "utf-8",
});
const minorVersion = Number(result.split(" ")[1].split(".")[1]);
if (minorVersion >= 7) {
await YTDlpWrap.downloadFromGithub(ytdlpDownloadPath);
} else {
// Downloading full binary if python version is less than 3.7
await YTDlpWrap.downloadFromGithub(
ytdlpDownloadPath,
"",
"linux",
true
);
}
} catch (error) {
// Downloading full binary of python3 is not there
await YTDlpWrap.downloadFromGithub( await YTDlpWrap.downloadFromGithub(
ytdlpDownloadPath, ytdlpDownloadPath,
"", "",
"linux", "linux",
true true
); );
} localStorage.setItem("fullYtdlpBinPresent", "true");
} else { } else {
// In case of windows/mac // In case of windows/mac
await YTDlpWrap.downloadFromGithub(ytdlpDownloadPath); await YTDlpWrap.downloadFromGithub(ytdlpDownloadPath);
localStorage.setItem("fullYtdlpBinPresent", "true");
} }
getId("popupBox").style.display = "none"; getId("popupBox").style.display = "none";
@ -157,71 +140,44 @@ async function downloadYtdlp() {
} }
// Checking if yt-dlp has been installed by user // Checking if yt-dlp has been installed by user
cp.exec("yt-dlp --version", (error, stdout, stderr) => {
if (error) {
// Checking if yt-dlp has been installed by program
cp.exec(`${ytdlpPath} --version`, (error, stdout, stderr) => {
if (error) {
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 += `<button id="tryBtn">${i18n.__(
"Try again"
)}</button>`;
console.log("Failed to download yt-dlp");
getId("tryBtn").addEventListener("click", () => {
getId("popup").removeChild(getId("popup").lastChild);
downloadYtdlp();
});
});
downloadYtdlp(); const fullYtdlpBinIsPresent = !!localStorage.getItem("fullYtdlpBinPresent");
} else {
console.log("yt-dlp binary is present in PATH");
ytDlp = ytdlpPath;
ytdlp = new YTDlpWrap(ytDlp);
localStorage.setItem("ytdlp", ytDlp);
cp.spawn(`${ytDlp}`, ["-U"]).stdout.on("data", (data) =>
console.log(data.toString("utf8"))
);
getId("pasteUrl").style.display = "inline-block";
console.log("yt-dlp bin Path: " + ytDlp);
ipcRenderer.send("ready-for-links"); cp.exec(`${ytdlpPath} --version`, (error, stdout, stderr) => {
} if (error || !fullYtdlpBinIsPresent) {
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 += `<button id="tryBtn">${i18n.__(
"Try again"
)}</button>`;
console.log("Failed to download yt-dlp");
getId("tryBtn").addEventListener("click", () => {
getId("popup").removeChild(getId("popup").lastChild);
downloadYtdlp();
});
}); });
downloadYtdlp();
} else { } else {
console.log("yt-dlp binary is present in PATH"); console.log("yt-dlp binary is present in PATH");
ytDlp = "yt-dlp"; ytDlp = ytdlpPath;
ytdlp = new YTDlpWrap(ytDlp); ytdlp = new YTDlpWrap(ytDlp);
localStorage.setItem("ytdlp", ytDlp); localStorage.setItem("ytdlp", ytDlp);
cp.spawn(`${ytDlp}`, ["-U"]).stdout.on("data", (data) =>
console.log(data.toString("utf8"))
);
getId("pasteUrl").style.display = "inline-block"; getId("pasteUrl").style.display = "inline-block";
console.log("yt-dlp bin Path: " + ytDlp); console.log("yt-dlp bin Path: " + ytDlp);
ipcRenderer.send("ready-for-links"); ipcRenderer.send("ready-for-links");
} }
}); });
// Check for thumbnail embed support let embedThumbnail = true;
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() { function defaultVideoToggle() {
let defaultWindow = "video"; let defaultWindow = "video";
@ -402,8 +358,11 @@ async function getInfo(url) {
} }
} }
if (format.audio_ext === preferredAudioQuality || format.acodec === preferredAudioQuality){ if (
preferredAudioFormatLength ++; format.audio_ext === preferredAudioQuality ||
format.acodec === preferredAudioQuality
) {
preferredAudioFormatLength++;
} }
} }
for (let format of formats) { for (let format of formats) {
@ -423,7 +382,10 @@ async function getInfo(url) {
).toFixed(2); ).toFixed(2);
} else { } else {
if (format.tbr) { if (format.tbr) {
size = ((format.tbr * 128 * duration) / 1000000).toFixed(2) size = (
(format.tbr * 128 * duration) /
1000000
).toFixed(2);
} else { } else {
size = i18n.__("Unknown size"); size = i18n.__("Unknown size");
} }
@ -511,9 +473,15 @@ async function getInfo(url) {
} else { } else {
audio_ext = format.audio_ext; audio_ext = format.audio_ext;
} }
if (format.audio_ext === preferredAudioQuality || format.acodec === preferredAudioQuality) { if (
format.audio_ext === preferredAudioQuality ||
format.acodec === preferredAudioQuality
) {
preferredAudioFormatCount += 1; preferredAudioFormatCount += 1;
if (preferredAudioFormatCount === preferredAudioFormatLength){ if (
preferredAudioFormatCount ===
preferredAudioFormatLength
) {
audioSelectedText = " selected "; audioSelectedText = " selected ";
} }
} }
@ -966,7 +934,7 @@ function download(
subs2 || subLangs, subs2 || subLangs,
"--no-playlist", "--no-playlist",
"--embed-metadata", "--embed-metadata",
ext == "mp4" && embedThumbnail ? "--embed-thumbnail": "", ext == "mp4" && embedThumbnail ? "--embed-thumbnail" : "",
configArg, configArg,
configTxt, configTxt,
cookieArg, cookieArg,
@ -974,7 +942,7 @@ function download(
"--no-mtime", "--no-mtime",
`"${url}"`, `"${url}"`,
], ],
{ shell: true, detached: false }, {shell: true, detached: false},
controller.signal controller.signal
); );
} else if (type === "extract") { } else if (type === "extract") {
@ -1004,7 +972,10 @@ function download(
ffmpeg, ffmpeg,
"--no-playlist", "--no-playlist",
"--embed-metadata", "--embed-metadata",
(extractFormat1 == "m4a" || embedThumbnail) && extractFormat1 == "mp3" ? "--embed-thumbnail": "", (extractFormat1 == "m4a" || embedThumbnail) &&
extractFormat1 == "mp3"
? "--embed-thumbnail"
: "",
cookieArg, cookieArg,
browser, browser,
configArg, configArg,
@ -1012,7 +983,7 @@ function download(
"--no-mtime", "--no-mtime",
`"${url}"`, `"${url}"`,
], ],
{ shell: true, detached: false }, {shell: true, detached: false},
controller.signal controller.signal
); );
} }
@ -1034,7 +1005,9 @@ function download(
subs2 || subLangs, subs2 || subLangs,
"--no-playlist", "--no-playlist",
"--embed-metadata", "--embed-metadata",
(ext == "m4a" || ext == "mp4") && embedThumbnail ? "--embed-thumbnail": "", (ext == "m4a" || ext == "mp4") && embedThumbnail
? "--embed-thumbnail"
: "",
cookieArg, cookieArg,
browser, browser,
configArg, configArg,
@ -1042,7 +1015,7 @@ function download(
"--no-mtime", "--no-mtime",
`"${url}"`, `"${url}"`,
], ],
{ shell: true, detached: false }, {shell: true, detached: false},
controller.signal controller.signal
); );
} }

Loading…
Cancel
Save