HerzaJ commited on
Commit
f8ae812
·
verified ·
1 Parent(s): 791bd63

Create mediafire.js

Browse files
Files changed (1) hide show
  1. plugins/mediafire.js +48 -0
plugins/mediafire.js ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const cheerio = require('cheerio');
2
+ const { basename, extname } = require('path');
3
+
4
+ async function mediafire(url) {
5
+ const $ = cheerio.load(await (await fetch(url.trim())).text())
6
+ const title = $("meta[property='og:title']").attr("content")?.trim() || "Unknown"
7
+ const size = /Download\s*\(([\d.]+\s*[KMGT]?B)\)/i.exec($.html())?.[1] || "Unknown"
8
+ const dl = $("a.popsok[href^='https://download']").attr("href")?.trim() || $("a.popsok:not([href^='javascript'])").attr("href")?.trim() || (() => { throw new Error("Download URL not found.") })()
9
+ return { name: title, filename: basename(dl), type: extname(dl), size, download: dl, link: url.trim() }
10
+ }
11
+
12
+ const handler = async (req, res) => {
13
+ try {
14
+ const { url } = req.query;
15
+
16
+ if (!url) {
17
+ return res.status(400).json({
18
+ success: false,
19
+ error: 'Missing required parameter: url'
20
+ });
21
+ }
22
+
23
+ const result = await mediafire(url);
24
+ res.json({
25
+ author: "Herza",
26
+ success: true,
27
+ data: result
28
+ });
29
+
30
+ } catch (error) {
31
+ res.status(500).json({
32
+ success: false,
33
+ error: error.message
34
+ });
35
+ }
36
+ };
37
+
38
+ module.exports = {
39
+ name: 'MediaFire DL',
40
+ description: 'Download File From Mediafire',
41
+ type: 'GET',
42
+ routes: ['api/download/mediafire'],
43
+ tags: ['downloader', 'tools', 'misc'],
44
+ parameters: ['url', 'key'],
45
+ enabled: true,
46
+ main: ['Downloader'],
47
+ handler
48
+ }