diff --git a/example/download.js b/example/download.js index c868c44..2692748 100644 --- a/example/download.js +++ b/example/download.js @@ -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); diff --git a/example/info.js b/example/info.js index 5d79ebc..b4a47b8 100644 --- a/example/info.js +++ b/example/info.js @@ -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; @@ -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'] ); diff --git a/lib/youtube-dl.js b/lib/youtube-dl.js index 7911c80..4ddbca7 100644 --- a/lib/youtube-dl.js +++ b/lib/youtube-dl.js @@ -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' @@ -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++) { @@ -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; @@ -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()) { @@ -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; } @@ -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; @@ -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 = []; @@ -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(); @@ -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 @@ -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); @@ -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 { @@ -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))); diff --git a/scripts/download.js b/scripts/download.js index 828c040..7d7352e 100644 --- a/scripts/download.js +++ b/scripts/download.js @@ -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' @@ -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!'); }); diff --git a/test/download.js b/test/download.js index a2c9497..c928728 100644 --- a/test/download.js +++ b/test/download.js @@ -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)); }