randydev commited on
Commit
dd65ea5
·
verified ·
1 Parent(s): 207597a

Create mediafire/mediafire.js

Browse files
Files changed (1) hide show
  1. lib/mediafire/mediafire.js +38 -0
lib/mediafire/mediafire.js ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import got from 'got'
2
+ import * as cheerio from 'cheerio'
3
+ import { DEFAULT_HEADERS } from '../constant.js'
4
+ import { parseFileSize } from '../util.js'
5
+ import { MediafiredlArgsSchema, MediafiredlSchema } from '../types/mediafire-dl.js'
6
+
7
+ export async function mediafiredl (url: string) {
8
+ MediafiredlArgsSchema.parse(arguments)
9
+
10
+ const data = await got(url, {
11
+ headers: {
12
+ ...DEFAULT_HEADERS
13
+ }
14
+ }).text()
15
+ const $ = cheerio.load(data);
16
+ const Url = ($('#downloadButton').attr('href') || '').trim();
17
+ const url2 = ($('#download_link > a.retry').attr('href') || '').trim();
18
+ const $intro = $('div.dl-info > div.intro');
19
+ const filename = $intro.find('div.filename').text().trim();
20
+ const filetype = $intro.find('div.filetype > span').eq(0).text().trim();
21
+ const ext = /\(\.(.*?)\)/.exec($intro.find('div.filetype > span').eq(1).text())?.[1]?.trim() || 'bin';
22
+ const $li = $('div.dl-info > ul.details > li');
23
+ const aploud = $li.eq(1).find('span').text().trim();
24
+ const filesizeH = $li.eq(0).find('span').text().trim():
25
+ const filesize = parseFileSize(filesizeH);
26
+
27
+ const result = {
28
+ url: Url || url2,
29
+ url2,
30
+ filename,
31
+ filetype,
32
+ ext,
33
+ aploud,
34
+ filesizeH,
35
+ filesize
36
+ }
37
+ return MediafiredlSchema.parse(result);
38
+ }