| const express = require("express"); | |
| const axios = require("axios"); | |
| const ytdl = require("@distube/ytdl-core"); | |
| const fs = require("fs"); | |
| const app = express(); | |
| const PORT = 7860; | |
| const headers = { | |
| "User-Agent": "Mozilla/5.1", | |
| 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", | |
| }; | |
| const cookies = fs.readFileSync("cookies.txt", "utf-8"); | |
| app.get("/ytdl", async (req, res) => { | |
| const youtubeUrl = req.query.url; | |
| if (!youtubeUrl) return res.status(400).json({ error: "Missing 'url' parameter" }); | |
| try { | |
| const info = await ytdl.getBasicInfo(youtubeUrl, { | |
| requestOptions: { | |
| headers: { cookie: cookies, "User-Agent": "Mozilla/5.1" }, | |
| }, | |
| }); | |
| const metadata = { | |
| title: info.videoDetails.title || "Unknown Title", | |
| thumbnail: info.videoDetails.thumbnails.pop().url || "No Thumbnail", | |
| }; | |
| 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 progressUrl = `https://p.oceansaver.in/ajax/progress.php?id=${downloadData.id}`; | |
| const { data: progressData } = await axios.get(progressUrl, { headers }); | |
| return res.json({ | |
| title: metadata.title, | |
| thumbnail: metadata.thumbnail, | |
| download_url: progressData.download_url || "Not Available", | |
| progress: progressData.progress || 0, | |
| author: "CC PROJECTS", | |
| }); | |
| } else { | |
| return res.status(500).json({ error: "Download request failed", details: downloadData }); | |
| } | |
| } catch (error) { | |
| return res.status(500).json({ error: "Internal server error", details: error.message }); | |
| } | |
| }); | |
| app.listen(PORT, () => console.log(`Server is running on http://localhost:${PORT}`)); |