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

Commit

Permalink
minor cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
fent committed May 17, 2013
1 parent f64ff44 commit af3a82c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
12 changes: 6 additions & 6 deletions example/download.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
var ytdl = require('..');


dl = ytdl.download('http://www.youtube.com/watch?v=90AiXO1pAiA',
var dl = ytdl.download('http://www.youtube.com/watch?v=90AiXO1pAiA',
__dirname,
// optional arguments passed to youtube-dl
// Optional arguments passed to youtube-dl.
['--max-quality=18']);


// will be called when the download starts
// Will be called when the download starts.
dl.on('download', function(data) {
console.log('Download started');
console.log('filename: ' + data.filename);
console.log('size: ' + data.size);
});

// will be called during download progress of a video
// Will be called during download progress of a video.
dl.on('progress', function(data) {
process.stdout.write(data.eta + ' ' + data.percent + '% at ' + data.speed + '\r');
});

// catches any errors
// Catches any errors.
dl.on('error', function(err) {
throw err;
});

// called when youtube-dl finishes
// Called when youtube-dl finishes.
dl.on('end', function(data) {
console.log('\nDownload finished!');
console.log('Filename: ' + data.filename);
Expand Down
4 changes: 2 additions & 2 deletions example/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var ytdl = require('..');

ytdl.info('http://www.youtube.com/watch?v=WKsjaOqDXgg',

// called when video page is downloaded and info extracted
// Called when video page is downloaded and info extracted.
function(err, info) {
if (err)
throw err;
Expand All @@ -13,6 +13,6 @@ ytdl.info('http://www.youtube.com/watch?v=WKsjaOqDXgg',
console.log('filename: ' + info.filename);
}

// optional arguments passed to youtube-dl
// Optional arguments passed to youtube-dl.
// ['--username=user', '--password=hunter2']
);
40 changes: 20 additions & 20 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ var spawn = require('child_process').spawn
;


// arguments we dont want users to use with youtube-dl
// because they will break the module
// Arguments we dont want users to use with youtube-dl
// because they will break the module.
var badArgs = [
'-h', '--help'
, '-v', '--version'
Expand All @@ -24,7 +24,7 @@ var badArgs = [
, '--console-title'
];

// helps parse options used in youtube-dl command
// Helps parse options used in youtube-dl command.
var parseOpts = function(args) {
var pos;
for (var i = 0, len = badArgs.length; i < len; i++) {
Expand All @@ -35,7 +35,7 @@ var parseOpts = function(args) {
return args;
};

// check that youtube-dl file exists
// Check that youtube-dl file exists.
var file = path.join(__dirname, '..', 'bin', 'youtube-dl');
fs.exists(file, function(exists) {
if (exists) return;
Expand All @@ -49,14 +49,14 @@ fs.exists(file, function(exists) {
});


// rounds a number to n decimal places
// Rounds a number to n decimal places.
var round = function(num, n) {
var dec = Math.pow(10, n);
return Math.round(num * dec + 0.1) / dec;
};


// converst from bytes kb, mb, and gb to bytes
// Converst from bytes kb, mb, and gb to bytes.
var toBytes = function(s) {
var speed = parseFloat(s.substring(0, s.length - 1));
switch (s.substr(-1, 1).toLowerCase()) {
Expand All @@ -72,8 +72,8 @@ var toBytes = function(s) {
};


// converst bytes to human readable unit
// thank you Amir from StackOverflow
// Converst bytes to human readable unit.
// Thank you Amir from StackOverflow.
var units = ' KMGTPEZYXWVU';
var getHumanSize = function(bytes) {
if (bytes <= 0) { return 0; }
Expand All @@ -83,7 +83,7 @@ var getHumanSize = function(bytes) {
};


// converts ms to human readable time
// Converts ms to human readable time.
var getHumanTime = function(ms) {
var d, h, m, s, set, str, x;
x = ms / 1000;
Expand Down Expand Up @@ -118,9 +118,9 @@ var getHumanTime = function(ms) {

var regex = /(\d+\.\d)% of (\d+\.\d+\w+) at\s+([^\s]+) ETA ((\d|-)+:(\d|-)+)/;

// main download function
// Main download function.
exports.download = function(url, dest, args) {
// setup settings
// Setup settings.
dest = dest || process.cwd();
if (args == null) {
args = [];
Expand All @@ -129,7 +129,7 @@ exports.download = function(url, dest, args) {
}
args.push(url);

// call youtube-dl
// Call youtube-dl.
var youtubedl = spawn(file, args, { cwd: dest });
var speed = [];
var start = Date.now();
Expand All @@ -143,11 +143,11 @@ exports.download = function(url, dest, args) {
line.on('data', function(data) {
var pos, result;

// check if video is uploading so script can start
// calling the download progress function
// Check if video is uploading so script can start
// calling the download progress function.
if (state === 'download' && (result = regex.exec(data))) {

// if this is the first progress display, grab file size
// If this is the first progress display, grab file size.
if (!size) {
emitter.emit(state, {
filename : filename
Expand All @@ -164,12 +164,12 @@ exports.download = function(url, dest, args) {
, eta : result[4]
});

// about to start downloading video
// About to start downloading video.
} else if ((pos = data.indexOf('[download] ')) === 0) {
state = 'download';
filename = data.slice(24);

// check if this is any other state
// Check if this is any other state.
} else if ((pos = data.indexOf(']')) !== -1) {
state = data.slice(pos + 2);
emitter.emit(state);
Expand Down Expand Up @@ -204,9 +204,9 @@ exports.download = function(url, dest, args) {
};


// gets info from a video
// Gets info from a video.
exports.info = function(url, callback, args) {
// setup settings
// Setup settings.
if (args == null) {
args = [];
} else {
Expand All @@ -221,7 +221,7 @@ exports.info = function(url, callback, args) {
].concat(args);
args.push(url);

// call youtube-dl
// Call youtube-dl.
execFile(file, args, function(err, stdout, stderr) {
if (err) return callback(err);
if (stderr) return callback(new Error(stderr.slice(7)));
Expand Down
6 changes: 3 additions & 3 deletions scripts/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ var dir = path.join(__dirname, '..', 'bin')
;


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

// download youtube-dl
// Download youtube-dl.
http.get({
host: 'youtube-dl.org'
, path: '/downloads/2013.05.14/youtube-dl'
Expand All @@ -27,7 +27,7 @@ http.get({

res.pipe(fs.createWriteStream(filepath));
res.on('end', function() {
// make file executable
// Make file executable.
fs.chmodSync(filepath, 457);
console.log('Finished!');
});
Expand Down
4 changes: 2 additions & 2 deletions test/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ vows.describe('download').addBatch({

'file was downloaded': function(err, data) {
process.nextTick(function() {
// delete file after each test
// Delete file after each test.
fs.unlink(filepath);
});

// check existance
// Check existance.
var filepath = path.join(__dirname, data.filename);
assert.isTrue(existsSync(filepath));
}
Expand Down

0 comments on commit af3a82c

Please sign in to comment.