Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@LeoDJ
Created May 8, 2018 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeoDJ/1d797ac0ca01edfcce9f11d5cf3d9a7b to your computer and use it in GitHub Desktop.
Save LeoDJ/1d797ac0ca01edfcce9f11d5cf3d9a7b to your computer and use it in GitHub Desktop.
ISDT firmware download script
const cheerio = require('cheerio')
const request = require('request')
const fs = require('fs');
let subfolder = 'firmwares'
if(!fs.existsSync(subfolder))
fs.mkdirSync(subfolder);
consoleLog = console.log
console.log = (text) => {
consoleLog(text)
fs.appendFileSync('dl.log', text + '\n')
}
function scrape(html) {
const $ = cheerio.load(html)
let hrefs = $('a', '.panel').has('button').map((i, elem) => elem.attribs.href).get()
hrefs = hrefs.filter(el => el.indexOf('.zip') > -1 && el.indexOf('V') > -1) //filter all firmware downloads
hrefs.forEach(link => {
name = link.split('/').slice(-1)[0]
folder = subfolder + '/'
folder += name.split('V')[0].slice(0, -1)
path = folder + '/' + name
if(!fs.existsSync(folder)) {
fs.mkdirSync(folder);
}
if(!fs.existsSync(path)) {
console.log(new Date().toISOString() + ' - downloading new file: ' + path)
request(link).pipe(fs.createWriteStream(path))
}
})
}
request('http://www.isdt.co/download', (err, res, html) => {
scrape(html)
});
{
"dependencies": {
"cheerio": "^1.0.0-rc.2",
"request": "^2.85.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment