This commit is contained in:
MasterAcnolo
2025-06-26 20:40:55 +02:00
parent 07485f39ba
commit c2c69935b1
5 changed files with 879 additions and 13 deletions

View File

@@ -1,16 +1,49 @@
const PORT_LISTEN = 8080
const express = require("express");
const { exec } = require("child_process");
const fs = require("fs");
const path = require("path");
http=require("http")
const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
const downloadDir = path.join(__dirname, "downloads");
if (!fs.existsSync(downloadDir)) {
fs.mkdirSync(downloadDir);
}
http.createServer((req,res) =>{
res.writeHead(200,{
"content-type":"text/json"
})
res.write('{"nom":"JeanKul","prenom":"TaMere"}')
res.end()
}).listen(PORT_LISTEN,()=>{
console.log("Je suis allumé 😊 et j'écoute sur le port " + PORT_LISTEN)
})
app.post("/download", (req, res) => {
const videoUrl = req.body.url;
if (!videoUrl) {
return res.status(400).send("❌ URL manquante !");
}
const safeUrl = `"${videoUrl.replace(/"/g, '\\"')}"`;
const command = `yt-dlp -o "downloads/%(title)s.%(ext)s" ${safeUrl}`;
console.log("▶️ Commande yt-dlp exécutée :", command);
exec(command, (error, stdout, stderr) => {
console.log("=== SORTIE ===");
console.log(stdout);
console.log("=== STDERR ===");
console.error(stderr);
if (error) {
console.error("=== ERREUR ===");
console.error(error);
return res.status(500).send(`❌ Erreur yt-dlp : ${stderr || error.message}`);
}
res.send("✅ Téléchargement lancé !");
});
});
const PORT = 8080;
app.listen(PORT, () => {
console.log(`🟢 Serveur prêt : http://localhost:${PORT}`);
});