From d2b39830080b2455d657249624440e58fc961c5d Mon Sep 17 00:00:00 2001 From: tifroz Date: Sat, 10 Jan 2015 21:33:13 -0800 Subject: [PATCH] Added extractor API incl. tests and example code --- README.md | 19 +++++++++++++++++++ example/extractors.js | 12 ++++++++++++ lib/youtube-dl.js | 19 +++++++++++++++++++ test/extractors.js | 27 +++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 example/extractors.js create mode 100644 test/extractors.js diff --git a/README.md b/README.md index ac0d149..27ab6a9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/example/extractors.js b/example/extractors.js new file mode 100644 index 0000000..6926f4a --- /dev/null +++ b/example/extractors.js @@ -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') + } +}); \ No newline at end of file diff --git a/lib/youtube-dl.js b/lib/youtube-dl.js index b8dccbd..0ca0b92 100644 --- a/lib/youtube-dl.js +++ b/lib/youtube-dl.js @@ -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); +}; diff --git a/test/extractors.js b/test/extractors.js new file mode 100644 index 0000000..d536e9f --- /dev/null +++ b/test/extractors.js @@ -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); \ No newline at end of file