Last active
December 22, 2015 22:58
-
-
Save carlosvillu/3f9635bebda56d662cbe to your computer and use it in GitHub Desktop.
Download Wallpapers from Blizzard
This file contains 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 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)); |
This file contains 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": "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