npm.io
1.4.2 • Published yesterday

filehost-meta

Licence
MIT
Version
1.4.2
Deps
7
Size
46 kB
Vulns
0
Weekly
0

https://img.shields.io/npm/v/filehost-meta https://img.shields.io/npm/dw/filehost-meta

filehost-meta

Fetch basic file information from a download link.

Usage

const { getSources, getInfo } = require('filehost-meta')

// Get all supported hostnames
const sources = getSources()

// Get file information from a URL
// Returns an array of File objects: { name, size, views, downloads, createdAt, updatedAt }
getInfo(url)
  .then(files => console.log(files))
  .catch(console.error)

// With an HTTP proxy (http://<user>:<pass>@<ip>:<port>)
getInfo(url, { proxy: 'http://user:pass@127.0.0.1:8080' })
  .then(files => console.log(files))
  .catch(console.error)

Debug Mode

Log bandwidth used per request (where possible - not supported by mega.js).

const { setDebug } = require('filehost-meta')
setDebug(true)

Caching

Results are cached in-memory by URL (100MB max, 24h TTL) by default. Configure or disable it:

const { configureCache, clearCache } = require('filehost-meta')

configureCache({
  enabled: true,       // enable/disable caching
  maxSize: 100 * 1024 * 1024, // max total cache size in bytes
  ttl: 24 * 60 * 60 * 1000,   // per-entry expiry in ms
  store: 'memory',      // 'memory' or 'file'
  filePath: '/path/to/cache' // only used when store is 'file'
})

clearCache()

Supported Hosts

Host Domain Notes
Akirabox akirabox.com, akirabox.to Cloudflare Turnstile (requires xvfb on headless Linux)
Bowfile bowfile.com Shared folder support
Buzzheavier buzzheavier.com
Datanodes datanodes.to
Download.gg download.gg French locale (Mo/Go units)
Dropmefiles dropmefiles.com
Files.fm files.fm
Filesadmin filesadmin.com
Google Drive drive.google.com Requires GOOGLE_KEY env var
Gofile gofile.io Requires GOFILE_KEY env var
KrakenFiles krakenfiles.com
Mediafire mediafire.com
Mega mega.nz, mega.co.nz
Mixdrop mixdrop.co, mixdrop.ag, mixdrop.ps
Pixeldrain pixeldrain.com
Terminal.lc terminal.lc
Uploadhaven uploadhaven.com
ViKiNG FiLE vikingfile.com
Workupload workupload.com Requires xvfb on headless Linux

Adding a New Source

To add a new file host, create a new file in src/sources/. The file is auto-discovered — no registration needed.

Each source must export domains (array of hostnames) and get (async function):

// src/sources/example.js
const axios = require('axios')
const cheerio = require('cheerio')

const File = require('../classes/File')
const { proxyToAxios, sizeToBytes } = require('../utils')

exports.domains = ['example.com']

exports.get = async (url, proxy) => {
  const res = await axios({
    url,
    ...proxyToAxios(proxy)
  })

  if (res.status !== 200) {
    throw new Error(res.statusText)
  }

  const $ = cheerio.load(res.data)

  // Extract file info from page...
  const name = $('.filename').text().trim()
  const size = sizeToBytes($('.filesize').text().trim())

  return [
    new File({ name, size })
  ]
}

That's it. Drop the file in src/sources/ and it works.

TODO

  • Up2sha.re
  • Dropbox
  • Wetransfer
  • Megaup.net

Contributing

Go for it.

Keywords