Permalink
Browse files

added filename to data returned

  • Loading branch information...
1 parent 1377915 commit 49909ca8387179e2c3115d09fa23b0baf6d05ca3 @fent fent committed Sep 16, 2011
Showing with 57 additions and 37 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 .npmignore
  3. +9 −1 README.md
  4. +4 −1 example/download.js
  5. +1 −0 example/info.js
  6. BIN example/lol
  7. +14 −14 lib/youtube-dl.js
  8. +4 −1 package.json
  9. +23 −20 src/youtube-dl.coffee
View
@@ -1,2 +1,3 @@
*.mp4
*.webm
+node_modules
View
@@ -1,2 +1,3 @@
*.mp4
*.webm
+node_modules
View
@@ -13,7 +13,8 @@ Usage
// will be called when the download starts
dl.on('download', function(data) {
console.log('Download started');
- console.log('Video size: ' + data.size);
+ console.log('filename: ' + data.filename);
+ console.log('size: ' + data.size);
});
// will be called during download progress of a video
@@ -29,6 +30,8 @@ Usage
// called when youtube-dl finishes
dl.on('end', function(data) {
console.log('\nDownload finished!');
+ console.log('Filename: ' + data.filename);
+ console.log('Size: ' + data.size);
console.log('Time Taken: ' + data.timeTaken);
console.log('Time Taken in ms: ' + data.timeTakenms);
console.log('Average Speed: ' + data.averageSpeed);
@@ -42,6 +45,8 @@ This example can be found in the *example* folder, and will produce an output th
Video size: 918.31k
00:00 100.0% at 206.12k/s
Download finished!
+ Filename: 90AiXO1pAiA.mp4
+ Size: 918.31k
Time Taken: 7 seconds, 27 ms
Time Taken in ms: 7027
Average Speed: 333.74KB/s
@@ -60,6 +65,7 @@ This example can be found in the *example* folder, and will produce an output th
console.log('url: ' + info.url);
console.log('thumbnail: ' + info.thumbnail);
console.log('description: ' + info.description);
+ console.log('filename: ' + info.filename);
}
// optional arguments passed to youtube-dl
@@ -72,6 +78,8 @@ Running that will produce something like
url: http://v2.lscache2.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0hPSFFQVF9FSkNOOV9JSlhJ&fexp=904410%2C907048%2C910100&algorithm=throttle-factor&itag=34&ipbits=0&burst=40&sver=3&signature=4093330AC1A5B0CAF8709A0416A4B593A75BB892.21F2F12C418003492D9877E1570DC7AEE6DBEEBA&expire=1303156800&key=yt1&ip=0.0.0.0&factor=1.25&id=58ab2368ea835e08
thumbnail: http://i4.ytimg.com/vi/WKsjaOqDXgg/default.jpg
description: An old Red Dwarf eposide where Ace Rimmer saves the Princess Bonjella.
+ filename: WKsjaOqDXgg.webm
+
For more usage info on youtube-dl and the arguments you can pass to it, do `youtube-dl -h` or go to the [youtube-dl documentation][].
View
@@ -9,7 +9,8 @@ dl = youtubedl.download('http://www.youtube.com/watch?v=90AiXO1pAiA', './',
// will be called when the download starts
dl.on('download', function(data) {
console.log('Download started');
- console.log('Video size: ' + data.size);
+ console.log('filename: ' + data.filename);
+ console.log('size: ' + data.size);
});
// will be called during download progress of a video
@@ -25,6 +26,8 @@ dl.on('error', function(err) {
// called when youtube-dl finishes
dl.on('end', function(data) {
console.log('\nDownload finished!');
+ console.log('Filename: ' + data.filename);
+ console.log('Size: ' + data.size);
console.log('Time Taken: ' + data.timeTaken);
console.log('Time Taken in ms: ' + data.timeTakenms);
console.log('Average Speed: ' + data.averageSpeed);
View
@@ -10,6 +10,7 @@ youtube.info('http://www.youtube.com/watch?v=WKsjaOqDXgg',
console.log('url: ' + info.url);
console.log('thumbnail: ' + info.thumbnail);
console.log('description: ' + info.description);
+ console.log('filename: ' + info.filename);
}
// optional arguments passed to youtube-dl
View
Binary file not shown.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -2,7 +2,7 @@
"name": "youtube-dl",
"description": "youtube-dl driver for node",
"keywords": ["youtube", "download"],
- "version": "1.1.2",
+ "version": "1.2.0",
"homepage": "https://github.com/fent/node-youtube-dl",
"repository": {
"type": "git",
@@ -18,6 +18,9 @@
"install": "node ./scripts/download.js",
"update": "node ./scripts/download.js"
},
+ "devDependencies": {
+ "vows": ">=0.5.11"
+ },
"engines": {
"node": "*"
},
View
@@ -55,8 +55,8 @@ round = (num, n) ->
# converts from bytes, kb, mb, and gb to bytes
toBytes = (s) ->
- speed = parseFloat(s.substring 0, s.length - 3)
- switch s.substr(-3, 1).toLowerCase()
+ speed = parseFloat(s.substring 0, s.length - 1)
+ switch s.substr(-1, 1).toLowerCase()
when 'b'
speed
when 'k'
@@ -103,8 +103,9 @@ getHumanTime = (ms) ->
"#{str}#{ms} ms"
-# main download function
regex = /(\d+\.\d)% of (\d+\.\d+\w) at\s+([^\s]+) ETA ((\d|-)+:(\d|-)+)/
+
+# main download function
module.exports.download = (url, dest = './', args = []) ->
# setup settings
args = parseOpts args
@@ -115,7 +116,7 @@ module.exports.download = (url, dest = './', args = []) ->
speed = []
start = Date.now()
- video = size = state = null
+ filename = size = state = null
emitter = new EventEmitter()
youtubedl.stdout.on 'data', (data) ->
@@ -124,13 +125,15 @@ module.exports.download = (url, dest = './', args = []) ->
# check if video is uploading so script can start
# calling the download progress function
if state is 'download' and result = regex.exec data
+
+ # if this is the first progress display, grab file size
if not size
emitter.emit state,
- video: video
+ filename: filename
size: size = result[2]
if result[3] isnt '---b/s'
- speed.push toBytes result[3]
+ speed.push toBytes result[3].substring(0, result[3].length - 2)
emitter.emit 'progress',
percent: result[1]
speed: result[3]
@@ -139,16 +142,12 @@ module.exports.download = (url, dest = './', args = []) ->
# about to start downloading video
else if (pos = data.indexOf '[download] ') is 0
state = 'download'
+ filename = data.substring(24, data.length - 1)
# check if this is any other state
else if (pos = data.indexOf ']') isnt -1
state = data.substring pos + 2, data.length - 1
-
- # get video name
- if (pos = state.indexOf ':') isnt -1
- video = state.substring 0, pos
- state = state.substring pos + 2
- emitter.emit state, video
+ emitter.emit state
youtubedl.stderr.on 'data', (data) ->
data = data.toString()
@@ -165,10 +164,12 @@ module.exports.download = (url, dest = './', args = []) ->
timeTaken = Date.now() - start
emitter.emit 'end',
- timeTakenms: timeTaken
- timeTaken: getHumanTime timeTaken
- averageSpeedBytes: round averageSpeed, 2
- averageSpeed: getHumanSize(averageSpeed) + '/s'
+ filename : filename
+ size : size
+ timeTakenms : timeTaken
+ timeTaken : getHumanTime timeTaken
+ averageSpeedBytes : round averageSpeed, 2
+ averageSpeed : getHumanSize(averageSpeed) + '/s'
emitter
@@ -182,6 +183,7 @@ module.exports.info = (url, callback, args = []) ->
'--get-title'
'--get-thumbnail'
'--get-description'
+ '--get-filename'
].concat args
args.push url
@@ -193,10 +195,11 @@ module.exports.info = (url, callback, args = []) ->
youtubedl.stdout.on 'data', (data) ->
data = data.toString().split "\n"
info =
- title: data[0]
- url: data[1]
- thumbnail: data[2]
- description: data[3]
+ title : data[0]
+ url : data[1]
+ thumbnail : data[2]
+ description : data[3]
+ filename : data[4]
youtubedl.stderr.on 'data', (data) ->
data = data.toString()

0 comments on commit 49909ca

Please sign in to comment.