scnario commited on
Commit
db14fe1
·
verified ·
1 Parent(s): 54deb2f

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +49 -53
server.js CHANGED
@@ -1,69 +1,65 @@
1
  const express = require("express");
2
  const axios = require("axios");
3
  const path = require("path");
4
-
5
  const app = express();
6
  const PORT = 7860;
7
 
8
- app.get("/", (req, res) => {
9
- res.send(`
10
- <!DOCTYPE html>
11
- <html lang="id">
12
- <head>
13
- <meta charset="UTF-8">
14
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
15
- <title>Fast File Downloader</title>
16
- <link rel="preconnect" href="https://fonts.googleapis.com">
17
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
18
- <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap" rel="stylesheet">
19
- <style>
20
- * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', sans-serif; }
21
- body { background-color: #09090b; color: #e4e4e7; display: flex; align-items: center; justify-content: center; height: 100vh; }
22
- .container { text-align: center; background: #18181b; padding: 25px; border-radius: 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4); width: 350px; }
23
- h1 { font-size: 1.8rem; font-weight: 600; margin-bottom: 15px; color: #fafafa; }
24
- p { font-size: 0.9rem; color: #a1a1aa; margin-bottom: 15px; }
25
- input { width: 100%; padding: 12px; margin-bottom: 12px; border: 1px solid #27272a; border-radius: 8px; background: #27272a; color: #fafafa; font-size: 1rem; }
26
- button { width: 100%; padding: 12px; background: #0070f3; color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 1rem; transition: 0.3s; }
27
- button:hover { background: #005ac1; }
28
- .footer { margin-top: 15px; font-size: 0.8rem; color: #71717a; }
29
- </style>
30
- </head>
31
- <body>
32
- <div class="container">
33
- <h1>Fast File Downloader</h1>
34
- <p>Unduh file dengan cepat menggunakan direct URL.</p>
35
- <input type="text" id="urlInput" placeholder="Masukkan URL file..." />
36
- <button onclick="downloadFile()">Download</button>
37
- <p class="footer">Made with ❤️ by Dev</p>
38
- </div>
39
 
40
- <script>
41
- function downloadFile() {
42
- const url = document.getElementById("urlInput").value;
43
- if (!url) return alert("Masukkan URL terlebih dahulu!");
44
- window.location.href = "/download?url=" + encodeURIComponent(url);
45
- }
46
- </script>
47
- </body>
48
- </html>
49
- `);
50
- });
51
 
52
- app.get("/download", async (req, res) => {
53
- try {
54
- const fileUrl = req.query.url;
55
- if (!fileUrl) return res.status(400).send("URL diperlukan");
56
 
57
- const response = await axios({ url: fileUrl, responseType: "stream" });
 
 
 
 
 
 
 
 
58
 
59
- const filename = path.basename(new URL(fileUrl).pathname);
60
- res.setHeader("Content-Disposition", `attachment; filename="${filename}"`);
61
- res.setHeader("Content-Type", response.headers["content-type"]);
 
62
 
63
- response.data.pipe(res);
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  } catch (error) {
65
- res.status(500).send("Gagal mengunduh file");
66
  }
 
 
 
 
 
 
67
  });
68
 
69
  app.listen(PORT, () => console.log(`Server berjalan di http://localhost:${PORT}`));
 
1
  const express = require("express");
2
  const axios = require("axios");
3
  const path = require("path");
4
+ const cheerio = require('cheerio');
5
  const app = express();
6
  const PORT = 7860;
7
 
8
+ async function yt5sIo(url) {
9
+ try {
10
+ const form = new URLSearchParams();
11
+ form.append("q", url);
12
+ form.append("vt", "home");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ const response = await axios.post('https://yt5s.io/api/ajaxSearch', form, {
15
+ headers: {
16
+ "Accept": "application/json",
17
+ "X-Requested-With": "XMLHttpRequest",
18
+ "Content-Type": "application/x-www-form-urlencoded",
19
+ },
20
+ });
 
 
 
 
21
 
22
+ if (response.data.status === "ok") {
23
+ const $ = cheerio.load(response.data.data);
 
 
24
 
25
+ if (/^(https?:\/\/)?(www\.)?(facebook\.com|fb\.watch)\/.+/i.test(url)) {
26
+ const videoQualities = [];
27
+ $('table tbody tr').each((index, element) => {
28
+ const quality = $(element).find('.video-quality').text().trim();
29
+ const downloadLink = $(element).find('a.download-link-fb').attr("href");
30
+ if (quality && downloadLink) {
31
+ videoQualities.push({ quality, downloadLink });
32
+ }
33
+ });
34
 
35
+ // Prioritize HD quality, fallback to SD
36
+ const hdVideo = videoQualities.find(v => v.quality.toLowerCase().includes('hd'));
37
+ const sdVideo = videoQualities.find(v => v.quality.toLowerCase().includes('sd'));
38
+ const videoUrl = hdVideo ? hdVideo.downloadLink : sdVideo ? sdVideo.downloadLink : null;
39
 
40
+ if (!videoUrl) throw new Error("Tidak ada link download yang tersedia.");
41
+ return { videoUrl };
42
+
43
+ } else if (/^(https?:\/\/)?(www\.)?instagram\.com\/(p|reel)\/.+/i.test(url)) {
44
+ const videoUrl = $('a[title="Download Video"]').attr("href");
45
+ if (!videoUrl) throw new Error("Tidak ada link download yang tersedia.");
46
+ return { videoUrl };
47
+
48
+ } else {
49
+ throw new Error("URL tidak valid. Harap masukkan URL Facebook atau Instagram.");
50
+ }
51
+ } else {
52
+ throw new Error("Gagal mengambil video: " + response.data.message);
53
+ }
54
  } catch (error) {
55
+ throw error;
56
  }
57
+ }
58
+
59
+ app.all("/", async (req, res) => {
60
+ const { url } = req.query || req.body;
61
+ if(/^(https?:\/\/)?(www\.)?instagram\.com\/(p|reel)\/.+/i.test(url)) res.json(await yt5sIo(url)) // instagram
62
+ if(/^(https?:\/\/)?(www\.)?(facebook\.com|fb\.watch)\/.+/i.test(url)) res.json(await yt5sIo(url)) // fesnuk
63
  });
64
 
65
  app.listen(PORT, () => console.log(`Server berjalan di http://localhost:${PORT}`));