Spaces:
Sleeping
Sleeping
Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require("express");
|
| 2 |
+
const axios = require("axios");
|
| 3 |
+
const { youtube } = require("btch-downloader");
|
| 4 |
+
const app = express();
|
| 5 |
+
const PORT = 7860;
|
| 6 |
+
|
| 7 |
+
const headers = {
|
| 8 |
+
accept: "/",
|
| 9 |
+
"accept-language": "en-US,en;q=0.9",
|
| 10 |
+
"sec-ch-ua": '"Not A(Brand";v="8", "Chromium";v="132"',
|
| 11 |
+
"sec-ch-ua-mobile": "?1",
|
| 12 |
+
"sec-ch-ua-platform": '"Android"',
|
| 13 |
+
"sec-fetch-dest": "empty",
|
| 14 |
+
"sec-fetch-mode": "cors",
|
| 15 |
+
"sec-fetch-site": "cross-site",
|
| 16 |
+
Referer: "https://v4.mp3paw.link/",
|
| 17 |
+
"Referrer-Policy": "strict-origin-when-cross-origin",
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
async function download(youtubeUrl) {
|
| 21 |
+
try {
|
| 22 |
+
const apiKey = "30de256ad09118bd6b60a13de631ae2cea6e5f9d";
|
| 23 |
+
const downloadUrl = `https://p.oceansaver.in/ajax/download.php?copyright=0&format=mp3&url=${encodeURIComponent(youtubeUrl)}&api=${apiKey}`;
|
| 24 |
+
const { data: downloadData } = await axios.get(downloadUrl, { headers });
|
| 25 |
+
|
| 26 |
+
if (downloadData.success) {
|
| 27 |
+
const { id } = downloadData;
|
| 28 |
+
const progressUrl = `https://p.oceansaver.in/ajax/progress.php?id=${id}`;
|
| 29 |
+
const { data: progressData } = await axios.get(progressUrl, { headers });
|
| 30 |
+
|
| 31 |
+
if (progressData.success && progressData.download_url) {
|
| 32 |
+
const info = await youtube(youtubeUrl);
|
| 33 |
+
const title = info.title || "Unknown Title";
|
| 34 |
+
return {
|
| 35 |
+
Title: title,
|
| 36 |
+
url: progressData.download_url,
|
| 37 |
+
author: "Jonell Hutchin Magallanes",
|
| 38 |
+
};
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
return { success: false, message: "Failed to fetch download URL" };
|
| 42 |
+
} catch (error) {
|
| 43 |
+
return { success: false, message: error.message };
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
app.get("/ytdl", async (req, res) => {
|
| 48 |
+
const youtubeUrl = req.query.url;
|
| 49 |
+
if (!youtubeUrl) return res.status(400).json({ success: false, message: "Missing YouTube URL" });
|
| 50 |
+
const result = await download(youtubeUrl);
|
| 51 |
+
res.json(result);
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
app.listen(PORT, () => {
|
| 55 |
+
console.log(`Server running at http://localhost:${PORT}`);
|
| 56 |
+
});
|