Skip to content

Instantly share code, notes, and snippets.

@staydecent
Last active August 14, 2018 03:23
Show Gist options
  • Select an option

  • Save staydecent/c0741e1df90b4e80d7ebdb2c92748def to your computer and use it in GitHub Desktop.

Select an option

Save staydecent/c0741e1df90b4e80d7ebdb2c92748def to your computer and use it in GitHub Desktop.
Lil JS to make downloading images from London Drugs film scan pages easier.
// npm init -y
// npm install --save request
// mkdir downloads
// node downloader.js
const url = require('url')
const fs = require('fs')
const path = require('path')
const request = require('request')
const srcs = [/* PRINTED ARRAY FROM ABOVE SCRIPT GOES HERE */]
const download = (uri, filepath, callback) => setTimeout(() => {
request.head(uri, (err, res, body) => {
if (err) console.log({err})
console.log('content-type:', res.headers['content-type'])
console.log('content-length:', res.headers['content-length'])
request(uri).pipe(fs.createWriteStream(filepath)).on('close', callback)
})
}, 200)
for (let x = 0; x < srcs.length; x++) {
const u = new url.URL(srcs[x])
const filepath = path.resolve('downloads', `${u.searchParams.get('photo')}.jpeg`)
console.log({filepath})
if (!fs.existsSync(filepath)) {
download(srcs[x], filepath, () => {
console.log('done', u.searchParams.get('photo'))
})
}
}
imgs = $('.preview > img');
srcs = []
for (let x = imgs.length - 1; x >= 0; x--) {
srcs.push(imgs[x].src.replace('size=240', 'size=0'))
imgs[x].addEventListener('click', ev => {
ev.preventDefault();
window.open(imgs[x].src.replace('size=240', 'size=0'), '_blank');
});
}
console.log(JSON.stringify(srcs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment