mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-07-29 18:25:47 +02:00
Working V1
This commit is contained in:
31
server/fetch.html
Normal file
31
server/fetch.html
Normal file
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
// fetch("https://api.nobelprize.org/2.1/nobelPrizes")
|
||||
// .then(response => response.json())
|
||||
// .then(data => {
|
||||
// console.log(data);
|
||||
// return data;
|
||||
// // Faut prendre son temps et faire chaque chose en son temps
|
||||
// })
|
||||
// .then(data => document.write(JSON.stringify(data)))
|
||||
// .catch(error => console.log("Erreur:" , error))
|
||||
|
||||
fetch("https://api.chucknorris.io/jokes/random")
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
return data.value;
|
||||
})
|
||||
.then(jokes => document.write(JSON.stringify(jokes)))
|
||||
.catch(error => console.log("Erreur: ", error))
|
||||
|
||||
// Ne pas oublier de retourner les bons éléments au bon moment
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -4,45 +4,63 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use(express.json());
|
||||
app.use(express.json());
|
||||
|
||||
const downloadDir = path.join(__dirname, "downloads");
|
||||
if (!fs.existsSync(downloadDir)) {
|
||||
fs.mkdirSync(downloadDir);
|
||||
}
|
||||
|
||||
app.post("/download", (req, res) => {
|
||||
const allowedFormats = ["best", "mp3", "mp4"];
|
||||
|
||||
app.post("/download", (req, res) => {
|
||||
const videoUrl = req.body.url;
|
||||
let format = req.body.format || "best";
|
||||
|
||||
if (!videoUrl) {
|
||||
return res.status(400).send("❌ URL manquante !");
|
||||
return res.status(400).send("❌ Il faut envoyer une URL !");
|
||||
}
|
||||
|
||||
if (!allowedFormats.includes(format)) {
|
||||
format = "best";
|
||||
}
|
||||
|
||||
const safeUrl = `"${videoUrl.replace(/"/g, '\\"')}"`;
|
||||
|
||||
const command = `yt-dlp -o "downloads/%(title)s.%(ext)s" ${safeUrl}`;
|
||||
let command = "";
|
||||
|
||||
console.log("▶️ Commande yt-dlp exécutée :", command);
|
||||
if (format === "mp3") {
|
||||
command = `yt-dlp --extract-audio --audio-format mp3 -o "downloads/%(title)s.%(ext)s" ${safeUrl}`;
|
||||
} else {
|
||||
command = `yt-dlp -f ${format} -o "downloads/%(title)s.%(ext)s" ${safeUrl}`;
|
||||
}
|
||||
|
||||
console.log("▶️ Commande exécutée :", command);
|
||||
|
||||
exec(command, (error, stdout, stderr) => {
|
||||
console.log("=== SORTIE ===");
|
||||
console.log(stdout);
|
||||
|
||||
console.log("=== STDERR ===");
|
||||
console.error(stderr);
|
||||
if (stdout) console.log("=== SORTIE ===", stdout);
|
||||
if (stderr) console.error("=== STDERR ===", stderr);
|
||||
|
||||
if (error) {
|
||||
console.error("=== ERREUR ===");
|
||||
console.error(error);
|
||||
return res.status(500).send(`❌ Erreur yt-dlp : ${stderr || error.message}`);
|
||||
console.error("=== ERREUR ===", error);
|
||||
return res.status(500).send(`❌ Problème pendant le téléchargement : ${stderr || error.message}`);
|
||||
}
|
||||
|
||||
res.send("✅ Téléchargement lancé !");
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/downloads", (req, res) => {
|
||||
fs.readdir(downloadDir, (err, files) => {
|
||||
if (err) {
|
||||
return res.status(500).send("Erreur de lecture du dossier");
|
||||
}
|
||||
res.json(files);
|
||||
});
|
||||
});
|
||||
|
||||
const PORT = 8080;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`🟢 Serveur prêt : http://localhost:${PORT}`);
|
||||
|
||||
Reference in New Issue
Block a user