Last active
November 21, 2017 21:31
-
-
Save xDimGG/d70051cb32af6f02acddfa62efa30b0c to your computer and use it in GitHub Desktop.
Download whole imgurs albums from the console.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createInterface } = require('readline'); | |
const { get } = require('snekfetch'); | |
const fs = require('fs'); | |
fs.existsSync('./pictures') || fs.mkdirSync('./pictures'); | |
const input = question => { | |
return new Promise(res => { | |
const rl = createInterface({ input: process.stdin, output: process.stdout }); | |
rl.question(question, answer => { | |
res(answer); | |
rl.close(); | |
}); | |
}); | |
}; | |
(album = async (firstAlbum = false) => { | |
const link = await input(`\n${firstAlbum ? '' : 'What\'s the link of the imgur album you\'d like to download?\n'}Example: https://imgur.com/gallery/TRf2s\n\n`); | |
if (!link.includes('imgur.com/gallery')) { | |
console.log('Invalid album link, retry.'); | |
return album(); | |
} | |
const { body } = await get(`https://imgur.com/ajaxalbums/getimages/${link.split('/')[link.includes('://') ? 4 : 2]}/hit.json`); | |
console.log(`\nDownloading ${body.data.images.length} images.`); | |
for (const image of body.data.images) { | |
const name = `${image.hash}${image.ext}`; | |
await get(`https://i.imgur.com/${name}`).pipe(fs.createWriteStream(`./pictures/${name}`)); | |
} | |
console.log('All images downloaded, press ctrl+c to exit, or paste another link.'); | |
album(true); | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "imgur-downloader", | |
"version": "1.0.0", | |
"description": "Download whole imgur albums", | |
"private": true, | |
"main": "app.js", | |
"dependencies": { | |
"snekfetch": "*" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment