Spaces:
Sleeping
Sleeping
| const express = require("express"); | |
| const axios = require("axios"); | |
| const { youtube } = require("btch-downloader"); | |
| const app = express(); | |
| const PORT = 7860; | |
| const headers = { | |
| accept: "/", | |
| "accept-language": "en-US,en;q=0.9", | |
| "sec-ch-ua": '"Not A(Brand";v="8", "Chromium";v="132"', | |
| "sec-ch-ua-mobile": "?1", | |
| "sec-ch-ua-platform": '"Android"', | |
| "sec-fetch-dest": "empty", | |
| "sec-fetch-mode": "cors", | |
| "sec-fetch-site": "cross-site", | |
| Referer: "https://v4.mp3paw.link/", | |
| "Referrer-Policy": "strict-origin-when-cross-origin", | |
| }; | |
| async function download(youtubeUrl) { | |
| try { | |
| const apiKey = "30de256ad09118bd6b60a13de631ae2cea6e5f9d"; | |
| const downloadUrl = `https://p.oceansaver.in/ajax/download.php?copyright=0&format=mp3&url=${encodeURIComponent(youtubeUrl)}&api=${apiKey}`; | |
| const { data: downloadData } = await axios.get(downloadUrl, { headers }); | |
| if (downloadData.success) { | |
| const { id } = downloadData; | |
| const progressUrl = `https://p.oceansaver.in/ajax/progress.php?id=${id}`; | |
| const { data: progressData } = await axios.get(progressUrl, { headers }); | |
| if (progressData.success && progressData.download_url) { | |
| const info = await youtube(youtubeUrl); | |
| const title = info.title || "Unknown Title"; | |
| return { | |
| Title: title, | |
| url: progressData.download_url, | |
| author: "Jonell Hutchin Magallanes", | |
| }; | |
| } | |
| } | |
| return { success: false, message: "Failed to fetch download URL" }; | |
| } catch (error) { | |
| return { success: false, message: error.message }; | |
| } | |
| } | |
| app.get("/ytdl", async (req, res) => { | |
| const youtubeUrl = req.query.url; | |
| if (!youtubeUrl) return res.status(400).json({ success: false, message: "Missing YouTube URL" }); | |
| const result = await download(youtubeUrl); | |
| res.json(result); | |
| }); | |
| app.listen(PORT, () => { | |
| console.log(`Server running at http://localhost:${PORT}`); | |
| }); |