Created
November 7, 2014 01:21
-
-
Save themasch/fb629f569f1db3a2dfd6 to your computer and use it in GitHub Desktop.
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
var Promise = require('bluebird') | |
var mkdirp = Promise.promisify(require('mkdirp')) | |
var fs = Promise.promisifyAll(require('fs')) | |
var request = require('request') | |
var resolutions = { | |
1: [ 1, 1 ], | |
2: [ 2, 2 ], | |
3: [ 5, 4 ], | |
4: [ 10, 9 ], | |
5: [ 23, 19 ], | |
6: [ 47, 39 ] | |
} | |
var prfx = 'http://promo.na.leagueoflegends.com/sru-map-assets/' | |
Promise.map(Object.keys(resolutions), function(idx) { | |
return mkdirp('map/' + idx) | |
.then(downloadMap.bind(this, idx)) | |
.then(function(x) { | |
console.log('...done') | |
return x | |
}) | |
}, { concurrency: 1 }).then(function() { | |
console.log('all downloads complete') | |
}) | |
function pad(n) { | |
return ('000' + n).substr(-2) | |
} | |
function downloadMap(idx) { | |
console.log('downloading resolution: ', idx) | |
var res = resolutions[idx]; | |
var urls = [] | |
for(var x=0;x<=res[0];x++) { | |
for(var y=0;y<=res[1];y++) { | |
var url = prfx + idx + '/' + x + '/' + y + '.png'; | |
var path = 'map/' + idx + '/' + pad(x) + 'x' + pad(y) + '.png'; | |
urls.push([ url, path ] ) | |
} | |
} | |
return Promise.map(urls, function(url) { | |
return new Promise(function(resolve, reject) { | |
request(url[0]) | |
.pipe( | |
fs.createWriteStream(url[1]) | |
).on('finish', resolve) | |
}) | |
}, { concurrency: 100 }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment