mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-07-29 18:25:47 +02:00
Push
This commit is contained in:
@@ -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}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user