File size: 1,540 Bytes
572c75e
 
 
 
 
6083738
f81b225
572c75e
 
f81b225
572c75e
f81b225
572c75e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import got from 'got';
import * as cheerio from 'cheerio';
import { DEFAULT_HEADERS } from '../constant.js';
import { SfilemobidlArgsSchema, SfilemobidlSchema } from '../types/sfilemobi-dl-v1.js';

export async function sfilemobi(url) {
  SfilemobidlArgsSchema.parse({ url });

  const data = await got(url, {
    headers: { ...DEFAULT_HEADERS }
  }).text();

  const $ = cheerio.load(data);

  const dlUrl = $('#download').attr('href') || null;
  const filename = $('div.intro-container > img').attr('alt') || $('div.intro-container > h1').text() || null;
  const icon = $('div.intro-container > img').attr('src') || null;
  
  const typeMatch = icon ? /\/smallicon\/(.*?)\.svg/.exec(icon) : null;
  const type = typeMatch ? typeMatch[1] : null;

  const $list = $('div.list');
  const mimetype = $list.eq(0).text().split('-')[1]?.trim() || null;
  const uploaded = $list.eq(2).text().split('Uploaded:')[1]?.trim() || null;

  const $upload = $list.eq(1).find('a');
  const uploadby = $upload.eq(0).text() || null;
  const uploadbyUrl = $upload.eq(0).attr('href') || null;
  const uploadon = $upload.eq(1).text() || null;
  const uploadonUrl = $upload.eq(1).attr('href') || null;

  const downloadsText = $list.eq(3).text().split('Downloads:')[1];
  const downloads = downloadsText ? parseInt(downloadsText) : null;

  const result = {
    url: dlUrl,
    filename,
    icon,
    type,
    mimetype,
    uploaded,
    uploadby,
    uploadbyUrl,
    uploadon,
    uploadonUrl,
    downloads
  };

  return SfilemobidlSchema.parse(result);
}