This repository has been archived by the owner on Dec 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
320 additions
and
181 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var ytdl = require('..'); | ||
var url = 'http://www.youtube.com/watch?v=WKsjaOqDXgg'; | ||
|
||
ytdl.getFormats(url, function(err, formats) { | ||
if (err) throw err; | ||
|
||
formats.forEach(function(format) { | ||
console.log(format); | ||
}); | ||
} | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var ytdl = require('..'); | ||
var url = 'http://www.youtube.com/watch?v=WKsjaOqDXgg'; | ||
|
||
ytdl.getInfo(url, function(err, info) { | ||
if (err) throw err; | ||
|
||
console.log('id:', info.id); | ||
console.log('title:', info.title); | ||
console.log('url:', info.url); | ||
console.log('thumbnail:', info.thumbnail); | ||
console.log('description:', info.description); | ||
console.log('filename:', info.filename); | ||
console.log('itag:', info.itag); | ||
console.log('resolution:', info.resolution); | ||
} | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
|
||
// Arguments we dont want users to use with youtube-dl | ||
// because they will break the module. | ||
var badArgs = [ | ||
'-h', '--help' | ||
, '-v', '--version' | ||
, '-U', '--update' | ||
, '-q', '--quiet' | ||
, '-s', '--simulate' | ||
, '-g', '--get-url' | ||
, '-e', '--get-title' | ||
, '--get-thumbnail' | ||
, '--get-description' | ||
, '--get-filename' | ||
, '--no-progress' | ||
, '--console-title' | ||
]; | ||
|
||
/** | ||
* Helps parse options used in youtube-dl command. | ||
* | ||
* @param {Array.<String>} | ||
* @return {Array.<String>} | ||
*/ | ||
exports.parseOpts = function(args) { | ||
var pos; | ||
for (var i = 0, len = badArgs.length; i < len; i++) { | ||
if ((pos = args.indexOf(badArgs[i])) !== -1) { | ||
args.splice(pos, 1); | ||
} | ||
} | ||
return args; | ||
}; | ||
|
||
|
||
/** | ||
* Rounds a number to n decimal places. | ||
* | ||
* @param {Number} num | ||
* @param {Number} n | ||
* @return {Number} | ||
*/ | ||
exports.round = function(num, n) { | ||
var dec = Math.pow(10, n); | ||
return Math.round(num * dec + 0.1) / dec; | ||
}; | ||
|
||
|
||
/** | ||
* Converts from bytes kb, mb, and gb to bytes. | ||
* | ||
* @param {String} s | ||
* @return {Number} | ||
*/ | ||
exports.toBytes = function(s) { | ||
var speed = parseFloat(s.substring(0, s.length - 1)); | ||
switch (s.substr(-1, 1).toLowerCase()) { | ||
case 'b': | ||
return speed; | ||
case 'k': | ||
return speed * 1024; | ||
case 'm': | ||
return speed * 1024 * 1024; | ||
case 'g': | ||
return speed * 1024 * 1024 * 1024; | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* Converst bytes to human readable unit. | ||
* Thank you Amir from StackOverflow. | ||
* | ||
* @param {Number} bytes | ||
* @return {String} | ||
*/ | ||
var units = ' KMGTPEZYXWVU'; | ||
exports.getHumanSize = function(bytes) { | ||
if (bytes <= 0) { return 0; } | ||
var t2 = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), 12); | ||
return (Math.round(bytes * 100 / Math.pow(1024, t2)) / 100) + | ||
units.charAt(t2).replace(' ', '') + 'B'; | ||
}; | ||
|
||
|
||
/** | ||
* Converts ms to human readable time. | ||
* | ||
* @param {Number} ms | ||
* @return {String} | ||
*/ | ||
exports.getHumanTime = function(ms) { | ||
var d, h, m, s, set, str, x; | ||
x = ms / 1000; | ||
ms %= 1000; | ||
s = Math.round(x % 60); | ||
x /= 60; | ||
m = Math.round(x % 60); | ||
x /= 60; | ||
h = Math.round(x % 24); | ||
d = Math.round(x / 24); | ||
|
||
str = ''; | ||
if (d > 0) { | ||
str += d + ' day' + (d > 1 ? 's' : '') + ', '; | ||
set = true; | ||
} | ||
if (set || h > 0) { | ||
str += h + ' hour' + (h > 1 ? 's' : '') + ', '; | ||
set = true; | ||
} | ||
if (set || m > 0) { | ||
str += m + ' minute' + (m > 1 ? 's' : '') + ', '; | ||
set = true; | ||
} | ||
if (set || s > 0) { | ||
str += s + ' second' + (s > 1 ? 's' : '') + ', '; | ||
} | ||
|
||
return str + ms + ' ms'; | ||
}; |
Oops, something went wrong.