Skip to content

Instantly share code, notes, and snippets.

@rjyo
Created April 13, 2013 15:17
Show Gist options
  • Save rjyo/5378793 to your computer and use it in GitHub Desktop.
Save rjyo/5378793 to your computer and use it in GitHub Desktop.
node.js version to download slide from slideshare.net.
var fs = require('fs'),
request = require('request'),
sys = require('sys'),
exec = require('child_process').exec;
var url = 'http://image.slidesharecdn.com/leanstartupmetricsandanalytics-120929084139-phpapp01/95/';
var tmpPath = './slides/';
var pages = 115;
var workers = 10;
var count = 0;
function downloadSlide(slideId) {
var fname = 'slide-' + slideId + '-1024.jpg';
var nomalized = ('00000' + slideId).substr(-5);
console.log('Downloading: ' + fname);
var p = request(url + fname + '?1349231038').pipe(fs.createWriteStream(tmpPath + nomalized));
p.on('close', function() {
count += 1;
if (slideId + workers <= pages) {
downloadSlide(slideId + workers);
} else if (count === pages) {
convertToPDF();
}
});
}
function convertToPDF() {
console.log('Converting Images to PDF...');
exec('convert slides/0* ./slide.pdf', function (error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
} else {
console.log('PDF Genreated: ./slide.pdf');
}
});
}
fs.mkdirSync(tmpPath);
for (var i = 0; i < workers; i++) {
downloadSlide(i + 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment