Update app.js
Browse files
app.js
CHANGED
|
@@ -14,9 +14,8 @@ app.get('/', async (req, res) => {
|
|
| 14 |
return res.status(200).json({ success: true, message: 'DOWNLOADER' });
|
| 15 |
});
|
| 16 |
|
| 17 |
-
// Main API route to handle MediaFire URL via GET
|
| 18 |
app.get('/mediafire', async (req, res) => {
|
| 19 |
-
const { url } = req.query;
|
| 20 |
|
| 21 |
if (!url) {
|
| 22 |
return res.status(400).json({ success: false, message: 'URL is required' });
|
|
@@ -49,8 +48,6 @@ async function mediafire(url) {
|
|
| 49 |
const fileSizeText = downloadLinkElement ? downloadLinkElement.textContent : '';
|
| 50 |
const sizeMatch = fileSizeText.match(/\(([^)]+)\)/);
|
| 51 |
const fileSize = sizeMatch ? sizeMatch[1] : '';
|
| 52 |
-
|
| 53 |
-
// Ambil informasi meta
|
| 54 |
const metaTags = Array.from(document.querySelectorAll('meta')).reduce((acc, meta) => {
|
| 55 |
const name = meta.getAttribute('name') || meta.getAttribute('property');
|
| 56 |
const content = meta.getAttribute('content');
|
|
@@ -66,25 +63,21 @@ async function mediafire(url) {
|
|
| 66 |
};
|
| 67 |
});
|
| 68 |
|
| 69 |
-
// Jika tautan unduhan tidak valid, tutup browser dan buka tautan baru
|
| 70 |
if (!downloadInfo.downloadLink.startsWith('https://down')) {
|
| 71 |
-
await browser.close();
|
| 72 |
-
|
| 73 |
const newBrowser = await chromium.launch({ headless: true });
|
| 74 |
const newContext = await newBrowser.newContext({
|
| 75 |
userAgent: 'Mozilla/5.0 (Linux; Android 6.0; iris50) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Mobile Safari/537.36',
|
| 76 |
});
|
| 77 |
const newPage = await newContext.newPage();
|
| 78 |
-
|
| 79 |
await newPage.goto(downloadInfo.downloadLink);
|
| 80 |
-
|
| 81 |
const updatedInfo = await newPage.evaluate(() => {
|
| 82 |
const downloadLink = document.querySelector('#downloadButton')?.href || '';
|
| 83 |
return { downloadLink };
|
| 84 |
});
|
| 85 |
|
| 86 |
downloadInfo.downloadLink = updatedInfo.downloadLink;
|
| 87 |
-
await newBrowser.close();
|
| 88 |
}
|
| 89 |
|
| 90 |
return downloadInfo;
|
|
@@ -93,7 +86,7 @@ async function mediafire(url) {
|
|
| 93 |
return { success: false, message: error.message };
|
| 94 |
} finally {
|
| 95 |
if (browser) {
|
| 96 |
-
await browser.close();
|
| 97 |
}
|
| 98 |
}
|
| 99 |
}
|
|
@@ -105,27 +98,19 @@ app.get('/ytdl', async (req, res) => {
|
|
| 105 |
return res.status(400).send('Parameter "id" is required.');
|
| 106 |
}
|
| 107 |
|
| 108 |
-
|
| 109 |
-
const
|
| 110 |
-
const
|
| 111 |
-
const apiUrl = `https://api.allorigins.win/raw?url=${encodedUrl}`;
|
| 112 |
|
| 113 |
try {
|
| 114 |
-
// Meluncurkan browser Playwright
|
| 115 |
const browser = await chromium.launch({ headless: true });
|
| 116 |
const context = await browser.newContext({
|
| 117 |
userAgent: 'Mozilla/5.0 (Linux; Android 6.0; iris50) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Mobile Safari/537.36',
|
| 118 |
});
|
| 119 |
const page = await context.newPage();
|
| 120 |
-
|
| 121 |
-
// Memuat halaman API
|
| 122 |
await page.goto(apiUrl, { waitUntil: 'load' });
|
| 123 |
-
|
| 124 |
-
// Mengambil teks dari body halaman
|
| 125 |
const rawText = await page.evaluate(() => document.body.innerText);
|
| 126 |
await browser.close();
|
| 127 |
-
|
| 128 |
-
// Mengirimkan teks mentah tanpa parsing
|
| 129 |
res.send(rawText);
|
| 130 |
} catch (error) {
|
| 131 |
console.error(error);
|
|
@@ -141,11 +126,9 @@ app.get('/ace', async (req, res) => {
|
|
| 141 |
}
|
| 142 |
|
| 143 |
try {
|
| 144 |
-
|
| 145 |
const apiUrl = `https://www.acethinker.com/downloader/api/video_info.php?url=https://www.youtube.com/watch?v=${id}&israpid=1&ismp3=0`;
|
| 146 |
const response = await fetch(apiUrl);
|
| 147 |
if (!response.ok) throw new Error('AceThinker API request failed');
|
| 148 |
-
|
| 149 |
const processedData = await response.json();
|
| 150 |
res.json(processedData);
|
| 151 |
} catch (error) {
|
|
@@ -154,10 +137,8 @@ app.get('/ace', async (req, res) => {
|
|
| 154 |
}
|
| 155 |
});
|
| 156 |
|
| 157 |
-
// Fungsi sederhana untuk menghasilkan ID spinner
|
| 158 |
const genSpinner = () => Math.random().toString(36).substring(2, 10);
|
| 159 |
|
| 160 |
-
// Rute API untuk /ytdl
|
| 161 |
app.get("/y232", async (req, res) => {
|
| 162 |
const id = req.query.id;
|
| 163 |
|
|
@@ -166,24 +147,15 @@ app.get("/y232", async (req, res) => {
|
|
| 166 |
}
|
| 167 |
|
| 168 |
try {
|
| 169 |
-
|
| 170 |
const spinnerid = genSpinner();
|
| 171 |
const socket = io("https://api.y232.live");
|
| 172 |
-
|
| 173 |
-
// Emit event "limits"
|
| 174 |
-
// socket.emit("limits", {});
|
| 175 |
-
|
| 176 |
-
// Emit event "getInfoEvent" dengan data
|
| 177 |
const data = { url: `https://www.youtube.com/watch?v=${id}`, spinnerid, method: "streams" };
|
| 178 |
socket.emit("getInfoEvent", data);
|
| 179 |
-
|
| 180 |
-
// Tangkap event "done"
|
| 181 |
socket.on("done", (response) => {
|
| 182 |
res.status(200).send(response);
|
| 183 |
-
socket.close();
|
| 184 |
});
|
| 185 |
|
| 186 |
-
// Tangkap event error dari socket
|
| 187 |
socket.on("error", (err) => {
|
| 188 |
res.status(500).send({ success: false, error: err.message });
|
| 189 |
socket.close();
|
|
@@ -199,10 +171,8 @@ const PORT = process.env.PORT || 7860;
|
|
| 199 |
|
| 200 |
app.listen(PORT, async () => {
|
| 201 |
console.log(`Server running on port ${PORT}`);
|
| 202 |
-
//await utils.initialize();
|
| 203 |
});
|
| 204 |
|
| 205 |
process.on('SIGINT', async () => {
|
| 206 |
-
//await utils.close();
|
| 207 |
process.exit(0);
|
| 208 |
});
|
|
|
|
| 14 |
return res.status(200).json({ success: true, message: 'DOWNLOADER' });
|
| 15 |
});
|
| 16 |
|
|
|
|
| 17 |
app.get('/mediafire', async (req, res) => {
|
| 18 |
+
const { url } = req.query;
|
| 19 |
|
| 20 |
if (!url) {
|
| 21 |
return res.status(400).json({ success: false, message: 'URL is required' });
|
|
|
|
| 48 |
const fileSizeText = downloadLinkElement ? downloadLinkElement.textContent : '';
|
| 49 |
const sizeMatch = fileSizeText.match(/\(([^)]+)\)/);
|
| 50 |
const fileSize = sizeMatch ? sizeMatch[1] : '';
|
|
|
|
|
|
|
| 51 |
const metaTags = Array.from(document.querySelectorAll('meta')).reduce((acc, meta) => {
|
| 52 |
const name = meta.getAttribute('name') || meta.getAttribute('property');
|
| 53 |
const content = meta.getAttribute('content');
|
|
|
|
| 63 |
};
|
| 64 |
});
|
| 65 |
|
|
|
|
| 66 |
if (!downloadInfo.downloadLink.startsWith('https://down')) {
|
| 67 |
+
await browser.close();
|
|
|
|
| 68 |
const newBrowser = await chromium.launch({ headless: true });
|
| 69 |
const newContext = await newBrowser.newContext({
|
| 70 |
userAgent: 'Mozilla/5.0 (Linux; Android 6.0; iris50) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Mobile Safari/537.36',
|
| 71 |
});
|
| 72 |
const newPage = await newContext.newPage();
|
|
|
|
| 73 |
await newPage.goto(downloadInfo.downloadLink);
|
|
|
|
| 74 |
const updatedInfo = await newPage.evaluate(() => {
|
| 75 |
const downloadLink = document.querySelector('#downloadButton')?.href || '';
|
| 76 |
return { downloadLink };
|
| 77 |
});
|
| 78 |
|
| 79 |
downloadInfo.downloadLink = updatedInfo.downloadLink;
|
| 80 |
+
await newBrowser.close();
|
| 81 |
}
|
| 82 |
|
| 83 |
return downloadInfo;
|
|
|
|
| 86 |
return { success: false, message: error.message };
|
| 87 |
} finally {
|
| 88 |
if (browser) {
|
| 89 |
+
await browser.close();
|
| 90 |
}
|
| 91 |
}
|
| 92 |
}
|
|
|
|
| 98 |
return res.status(400).send('Parameter "id" is required.');
|
| 99 |
}
|
| 100 |
|
| 101 |
+
const rawUrl = ` -j`;
|
| 102 |
+
const encodedUrl = encodeURI(rawUrl);
|
| 103 |
+
const apiUrl = `https://api.allorigins.win/raw?url=https://ytdlp.online/stream?command=https://www.youtube.com/watch?v=${id}${encodedUrl}`;
|
|
|
|
| 104 |
|
| 105 |
try {
|
|
|
|
| 106 |
const browser = await chromium.launch({ headless: true });
|
| 107 |
const context = await browser.newContext({
|
| 108 |
userAgent: 'Mozilla/5.0 (Linux; Android 6.0; iris50) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Mobile Safari/537.36',
|
| 109 |
});
|
| 110 |
const page = await context.newPage();
|
|
|
|
|
|
|
| 111 |
await page.goto(apiUrl, { waitUntil: 'load' });
|
|
|
|
|
|
|
| 112 |
const rawText = await page.evaluate(() => document.body.innerText);
|
| 113 |
await browser.close();
|
|
|
|
|
|
|
| 114 |
res.send(rawText);
|
| 115 |
} catch (error) {
|
| 116 |
console.error(error);
|
|
|
|
| 126 |
}
|
| 127 |
|
| 128 |
try {
|
|
|
|
| 129 |
const apiUrl = `https://www.acethinker.com/downloader/api/video_info.php?url=https://www.youtube.com/watch?v=${id}&israpid=1&ismp3=0`;
|
| 130 |
const response = await fetch(apiUrl);
|
| 131 |
if (!response.ok) throw new Error('AceThinker API request failed');
|
|
|
|
| 132 |
const processedData = await response.json();
|
| 133 |
res.json(processedData);
|
| 134 |
} catch (error) {
|
|
|
|
| 137 |
}
|
| 138 |
});
|
| 139 |
|
|
|
|
| 140 |
const genSpinner = () => Math.random().toString(36).substring(2, 10);
|
| 141 |
|
|
|
|
| 142 |
app.get("/y232", async (req, res) => {
|
| 143 |
const id = req.query.id;
|
| 144 |
|
|
|
|
| 147 |
}
|
| 148 |
|
| 149 |
try {
|
|
|
|
| 150 |
const spinnerid = genSpinner();
|
| 151 |
const socket = io("https://api.y232.live");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
const data = { url: `https://www.youtube.com/watch?v=${id}`, spinnerid, method: "streams" };
|
| 153 |
socket.emit("getInfoEvent", data);
|
|
|
|
|
|
|
| 154 |
socket.on("done", (response) => {
|
| 155 |
res.status(200).send(response);
|
| 156 |
+
socket.close();
|
| 157 |
});
|
| 158 |
|
|
|
|
| 159 |
socket.on("error", (err) => {
|
| 160 |
res.status(500).send({ success: false, error: err.message });
|
| 161 |
socket.close();
|
|
|
|
| 171 |
|
| 172 |
app.listen(PORT, async () => {
|
| 173 |
console.log(`Server running on port ${PORT}`);
|
|
|
|
| 174 |
});
|
| 175 |
|
| 176 |
process.on('SIGINT', async () => {
|
|
|
|
| 177 |
process.exit(0);
|
| 178 |
});
|