Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
more efficient youtube-dl download
Browse files Browse the repository at this point in the history
  • Loading branch information
fent committed Mar 10, 2012
1 parent 05c2ba3 commit 574cd7f
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions scripts/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ var fs = require('fs')
, exec = require('child_process').exec


var folder = path.join(__dirname, '..', 'bin')
, filename = '/youtube-dl'
, filepath = folder + filename
var dir = path.join(__dirname, '..', 'bin')
, filename = 'youtube-dl'
, filepath = path.join(dir, filename)
, n = 0
;


// make bin dir if it doesn't exists
if (!path.existsSync(dir)) {
fs.mkdirSync(dir, 0744);
}

// download latst version of youtube-dl
https.get({
host: 'raw.github.com'
Expand All @@ -18,23 +25,10 @@ https.get({
throw Error('Response Error: ' + res.statusCode);
}

var content = '';
res.on('data', function(data) {
return content += data;
});

res.pipe(fs.createWriteStream(filepath));
res.on('end', function() {
// make bin folder if it doesn't exists
if (!path.existsSync(folder)) {
fs.mkdirSync(folder, 0744);
}

// write file when finished
fs.writeFileSync(filepath, content);

// make it executable
// make file executable
fs.chmodSync(filepath, 0711);

console.log('Finished!');
});

Expand Down

0 comments on commit 574cd7f

Please sign in to comment.