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

Commit

Permalink
now uses emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
fent committed Aug 27, 2011
1 parent 5c6ff08 commit 7063855
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 137 deletions.
85 changes: 40 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,52 @@
A [youtube-dl][] driver for node.

Usage
------------------

youtubedl = require('youtube-dl');

###Downloading videos

youtubedl.download('http://www.youtube.com/watch?v=90AiXO1pAiA',
dl = youtubedl.download('http://www.youtube.com/watch?v=90AiXO1pAiA',
'./videos',

// will be called when a state changes
function(state, data) {
console.log(state);
if (state == 'Downloading video') {
console.log('Video size: ' + data.size);
}
},

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

// called when youtube-dl finishes
function(err, data) {
if (err)
throw err;
console.log('Download finished!')
console.log('Time Taken: ' + data.timeTaken);
console.log('Time Taken in ms: ' + data.timeTakenms);
console.log('Average Speed: ' + data.averageSpeed);
console.log('Average Speed in Bytes: ' + data.averageSpeedBytes);
},

// optional arguments passed to youtube-dl
['--max-quality=18']);

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

// 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
dl.on('error', function(err) {
throw err;
});

// called when youtube-dl finishes
dl.on('end', function(data) {
console.log('\nDownload finished!');
console.log('Time Taken: ' + data.timeTaken);
console.log('Time Taken in ms: ' + data.timeTakenms);
console.log('Average Speed: ' + data.averageSpeed);
console.log('Average Speed in Bytes: ' + data.averageSpeedBytes);
});


This example can be found in the *example* folder, and will produce an output that looks like the following when ran.

Setting language
Downloading video webpage
Downloading video info webpage
Extracting video information
Downloading video
Download started
Video size: 918.31k
--:-- 0.1% at ---b/s
--:-- 0.3% at ---b/s
00:12 0.8% at 75.62k/s
00:06 1.6% at 135.69k/s
00:03 3.4% at 223.15k/s
00:04 6.9% at 171.27k/s
00:05 13.8% at 135.40k/s
00:03 26.1% at 194.62k/s
00:03 50.5% at 140.90k/s
00:02 62.8% at 169.02k/s
00:00 87.3% at 210.18k/s
00:00 100.0% at 181.41k/s
00:00 100.0% at 206.12k/s
Download finished!
Time Taken: 7 seconds, 27 ms
Time Taken in ms: 7027
Average Speed: 333.74KB/s
Average Speed in Bytes: 341750.78


###Getting video information

Expand Down Expand Up @@ -94,6 +83,12 @@ Install

This will install this node module along with the latest version of [youtube-dl][] into your module folder. It will also create a symlink to youtube-dl so you run it from the command line.


### API Change

Note that the API has changed in version 1.1.0. It now uses emitters to handle the download, progress, and finished events. I'm sorry for any of the invonvenience this may have caused but I'm new at this node.js thing and I just found out emitters are the best way to do this.


Issues and the Future
---------------------

Expand Down
40 changes: 21 additions & 19 deletions example/download.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
youtubedl = require('./../lib/youtube-dl');


// will be called when a state changes
stateChange = function(state, data) {
console.log(state);
if (state == 'Downloading video') {
console.log('Video size: ' + data.size);
}
}
dl = youtubedl.download('http://www.youtube.com/watch?v=90AiXO1pAiA', './',
// optional arguments passed to youtube-dl
['--max-quality=18']);


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

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

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

// called when youtube-dl finishes
finished = function(err, data) {
if (err)
throw err;
dl.on('end', function(data) {
console.log('\nDownload finished!');
console.log('Time Taken: ' + data.timeTaken);
console.log('Time Taken in ms: ' + data.timeTakenms);
console.log('Average Speed: ' + data.averageSpeed);
},

youtubedl.download('http://www.youtube.com/watch?v=90AiXO1pAiA', './',
stateChange, progress, finished,

// optional arguments passed to youtube-dl
['--max-quality=18']);
console.log('Average Speed in Bytes: ' + data.averageSpeedBytes);
});
66 changes: 39 additions & 27 deletions lib/youtube-dl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "youtube-dl",
"description": "youtube-dl driver for node",
"keywords": ["youtube", "download"],
"version": "1.0.4",
"version": "1.1.0",
"homepage": "https://github.com/fent/node-youtube-dl",
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit 7063855

Please sign in to comment.