Helpers + Clean Download et Info

This commit is contained in:
MasterAcnolo
2025-11-09 10:35:19 +01:00
parent 4954de5f1a
commit 599e09fa9f
12 changed files with 178 additions and 326 deletions

View File

@@ -0,0 +1,34 @@
const path = require("path");
function buildYtDlpArgs({ url, audioOnly, quality, outputFolder }) {
const args = [
"--no-continue",
"--no-overwrites",
"--embed-thumbnail",
"--add-metadata",
"--concurrent-fragments", "8",
"--retries", "10",
"--fragment-retries", "10",
"--ffmpeg-location", path.join(process.resourcesPath, "ffmpeg.exe")
];
if (audioOnly) args.push("-f", "bestaudio", "--extract-audio", "--audio-format", "mp3");
else args.push("--merge-output", "mp4");
const qualityMap = {
best: "bestvideo+bestaudio/best/mp4",
medium: "bestvideo[height<=720]+bestaudio/best[height<=720]/mp4",
worst: "worstvideo+worstaudio/worst/mp4",
1080: "bestvideo[height<=1080]+bestaudio/best[height<=1080]/mp4",
720: "bestvideo[height<=720]+bestaudio/best[height<=720]/mp4",
480: "bestvideo[height<=480]+bestaudio/best[height<=480]/mp4",
};
args.push("-f", qualityMap[quality] || "best");
args.push("-o", path.join(outputFolder, "%(title)s.%(ext)s"));
args.push(url);
return args;
}
module.exports = { buildYtDlpArgs };

16
server/helpers/notify.js Normal file
View File

@@ -0,0 +1,16 @@
const { Notification, shell } = require("electron");
const path = require("path");
function notifyDownloadFinished(folder) {
const iconPath = path.join(process.resourcesPath, "confirm-icon.png");
const notif = new Notification({
title: "Freedom Loader",
body: "Ton téléchargement est terminé, clique ici pour l'ouvrir.",
icon: iconPath,
});
notif.on("click", () => shell.openPath(folder));
notif.show();
}
module.exports = { notifyDownloadFinished };

13
server/helpers/path.js Normal file
View File

@@ -0,0 +1,13 @@
const path = require("path");
const fs = require("fs");
const { app } = require("electron");
const userYtDlp = path.join(app.getPath("userData"), "yt-dlp.exe");
const sourceYtDlp = path.join(process.resourcesPath, "yt-dlp.exe");
if (!fs.existsSync(userYtDlp)) fs.copyFileSync(sourceYtDlp, userYtDlp);
module.exports = {
userYtDlp,
sourceYtDlp
};

View File

@@ -0,0 +1,19 @@
const path = require("path");
function isValidUrl(url) {
try {
new URL(url);
return true;
} catch {
return false;
}
}
function isSafePath(folder) {
if (!folder || folder.length < 3) return false;
const unsafe = ["System32", "/etc", "\\Windows"];
const resolved = path.resolve(folder);
return !unsafe.some(u => resolved.includes(u));
}
module.exports = { isValidUrl, isSafePath };