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

Commit

Permalink
Merge pull request #56 from tifroz/master
Browse files Browse the repository at this point in the history
Added extractor API including tests and example code
  • Loading branch information
fent committed Jan 15, 2015
2 parents a3f5202 + d2b3983 commit 628466d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ youtubedl.getSubs(url, options, function(err, files) {

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][].

## Getting the list of extractors

```js
var youtubedl = require('youtube-dl');
youtubedl.getExtractors(true, function(err, list) {
console.log('Found ' + list.length + ' extractors');
for (var i = 0; i < list.length; i++) {
console.log(list[i]);
}
});
```

Will print something like

Found 521 extractors
1up.com
220.ro
24video
3sat

# Install

Expand Down
12 changes: 12 additions & 0 deletions example/extractors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var ytdl = require('..');

ytdl.getExtractors(true, function(err, list) {
console.log('Found ' + list.length + ' extractors');
var show = 4;
for (var i = 0; i < Math.min(show, list.length); i++) {
console.log(list[i]);
}
if (list.length > show) {
console.log('...' + (list.length-show) + ' not shown')
}
});
19 changes: 19 additions & 0 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,22 @@ ytdl.getSubs = function(url, options, callback) {
callback(null, files);
});
};

/**
* @param {!Boolean} descriptions
* @param {!Object} options
* @param {Function(!Error, Object)} callback
*/
ytdl.getExtractors = function(descriptions, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
} else if (typeof descriptions === 'function') {
callback = descriptions;
options = {};
descriptions = false;
}

var args = descriptions ? ['--extractor-descriptions'] : ['--list-extractors'];
call(null, args, null, options, callback);
};
27 changes: 27 additions & 0 deletions test/extractors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var vows = require('vows');
var ytdl = require('..');
var assert = require('assert');

vows.describe('getExtractors').addBatch({
'plain extractors': {
'topic': function() {
ytdl.getExtractors(false, this.callback);
},

'extractors returned': function(err, extractors) {
assert.isNull(err);
assert.isArray(extractors);
}
},

'extractors with description': {
'topic': function() {
ytdl.getExtractors(true, this.callback);
},

'extractors returned': function(err, formats) {
assert.isNull(err);
assert.isArray(formats);
}
}
}).export(module);

0 comments on commit 628466d

Please sign in to comment.