Skip to content

Instantly share code, notes, and snippets.

@carlosvillu
Last active December 22, 2015 22:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosvillu/3f9635bebda56d662cbe to your computer and use it in GitHub Desktop.
Save carlosvillu/3f9635bebda56d662cbe to your computer and use it in GitHub Desktop.
Download Wallpapers from Blizzard
const range = require('lodash.range');
const flatten = require('flatten');
const Promise = require('bluebird');
const fs = require('fs');
const RANGE = 60;
const RESOLUTIONS = ['1440x900','1600x900'];
const STATUS_OK = 200;
const ENCODING_FILE = 'binary';
const request = Promise.promisify(require('request'));
const writeFile = Promise.promisify(fs.writeFile);
Array.prototype.flatten = function(){return flatten(this);};
Promise.all(
range(RANGE)
.map(number => {
return RESOLUTIONS.map(resolution => `http://media.blizzard.com/sc2/media/wallpapers/wall0${number}/wall0${number}-${resolution}.jpg`);
})
.flatten()
.map(url => request({url,encoding: ENCODING_FILE}))
)
.filter(req => req.statusCode === STATUS_OK)
.map((req, index) => writeFile(`${__dirname}/${index}.jpg`, req.body, ENCODING_FILE))
.catch(console.error.bind(console));
{
"name": "imagenes",
"private": true,
"version": "1.0.0",
"description": "",
"main": "download.js",
"scripts": {
"start": "node download"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bluebird": "3.1.1",
"flatten": "0.0.1",
"lodash.range": "3.0.1",
"request": "2.67.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment