Loading snippets...
get data url MediaFire dan direct download
/**
*
* base: https://mediafire.com
* Creator: ShanMolvyr
* reupload/modif cantumkan sumber ini woii parah
*
* Note: cek https://snippet.vyr.my.id/shanmolvyr/mediafire/README.md
* Sumber Scraper: https://whatsapp.com/channel/0029VbB4Kw8EFeXfeExaXc3Q
* "Kalau kamu benar seorang developer, kamu pasti paham bahwa credit bukan beban. Modifikasi sesukamu, jadikan API sesukamu, reupload pun silakan. Tapi jangan hilangkan sumber. Karena menghargai karya orang lain adalah etika, bukan kelemahan."
*/
const axios = require("axios");
const cheerio = require("cheerio");
const UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36";
const AUTHOR = "ShanMolvyr";
const AUTHOR_CRC = "580496c4";
function crc32(str) {
let crc = 0xFFFFFFFF;
for (let i = 0; i < str.length; i++) {
crc ^= str.charCodeAt(i);
for (let j = 0; j < 8; j++) crc = (crc & 1) ? (crc >>> 1) ^ 0xEDB88320 : crc >>> 1;
}
return ((crc ^ 0xFFFFFFFF) >>> 0).toString(16);
}
if (crc32(AUTHOR) !== AUTHOR_CRC) throw new Error("Integrity check failed");
function extractKey(url) {
const m = url.match(/\/file\/([a-zA-Z0-9]+)\//);
return m ? m[1] : null;
}
async function scrapeHtml(url) {
const res = await axios.get(url, {
headers: {
"User-Agent": UA,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
},
timeout: 15000,
});
const $ = cheerio.load(res.data);
const link = $("a[aria-label='Download file']").attr("href") || $("#downloadButton").attr("href");
if (!link || !link.startsWith("https://download")) throw new Error("Direct download link not found");
const title = $(".dl-btn-label").attr("title") || $(".dl-btn-label").text().trim();
const btnText = $("a[aria-label='Download file']").text().trim();
const sizeMatch = btnText.match(/\(([^)]+)\)/);
const size = sizeMatch ? sizeMatch[1] : "";
return { title, size, link };
}
async function getMetaFromApi(key) {
const res = await axios.get("https://www.mediafire.com/api/1.5/file/get_info.php", {
params: { quick_key: key, response_format: "json" },
headers: { "User-Agent": UA },
timeout: 10000,
});
const info = res.data?.response?.file_info;
if (!info) throw new Error("No file_info");
return { title: info.filename, size: formatSize(info.size) };
}
function formatSize(bytes) {
if (!bytes) return "";
const b = parseInt(bytes);
if (b >= 1073741824) return (b / 1073741824).toFixed(2) + "GB";
if (b >= 1048576) return (b / 1048576).toFixed(2) + "MB";
if (b >= 1024) return (b / 1024).toFixed(2) + "KB";
return b + "B";
}
async function mediafire(url) {
if (!url || !url.includes("mediafire.com")) throw new Error("Invalid MediaFire URL");
const data = await scrapeHtml(url);
if (!data.title || !data.size) {
const key = extractKey(url);
if (key) {
try {
const meta = await getMetaFromApi(key);
if (!data.title) data.title = meta.title;
if (!data.size) data.size = meta.size;
} catch {}
}
}
return {
status: true,
message: "success get data",
author: AUTHOR,
data,
};
}
if (process.argv[2]) {
mediafire(process.argv[2])
.then((r) => console.log(JSON.stringify(r, null, 2)))
.catch((e) => console.log(JSON.stringify({ status: false, message: e.message, data: null }, null, 2)));
}
module.exports = mediafire;
bashnpm install axios cheerio
bashnode mediafire.js <url>