diff options
author | przemyslawpluta <przemekpluta@hotmail.com> | 2014-04-06 19:37:29 +0100 |
---|---|---|
committer | przemyslawpluta <przemekpluta@hotmail.com> | 2014-04-06 19:37:29 +0100 |
commit | 11b317833a8d5a332d8cba564edbcd68cf7f9a7a (patch) | |
tree | 7529d9a469514db79053ea88f77a77d82f8f87a6 /lib/videos.js | |
parent | aa5184821120aac47547cf1745c350d1efa51c8f (diff) | |
download | mongo-edu-11b317833a8d5a332d8cba564edbcd68cf7f9a7a.zip |
handle youtube playlists
Diffstat (limited to 'lib/videos.js')
-rw-r--r-- | lib/videos.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/videos.js b/lib/videos.js index cb07cf8..017787a 100644 --- a/lib/videos.js +++ b/lib/videos.js @@ -14,6 +14,7 @@ var path = require('path'), request = require('request'), progress = require('request-progress'), colors = require('colors'), + execFile = require('child_process').execFile, _ = require('lodash'); var downloadPath = '', ncc = false, handout = false, cc = false; @@ -196,5 +197,35 @@ module.exports = { if (selected.length) { return handleList(selected); } } + }, + + listVideosFromPlaylist: function getIdsFromPlaylist(opt, argv, callback) { + + var isWin = /^win/.test(process.platform), + file = path.join(__dirname, '..', 'node_modules/youtube-dl/bin', 'youtube-dl'), + args = [opt.url, '--get-id', '--get-title'], + options = [file, (!argv.ncc) ? args : args.concat(['--no-check-certificate']), '']; + + if (isWin) { options = ['python', [file].concat(args), '\r']; } + + execFile(options[0], options[1], function(err, stdout, stderr) { + if (err !== null) { return callback(err); } + if (stderr) { return callback(new Error(stderr.slice(7))); } + + var data = stdout.trim().split(options[2] + '\n'); + var out = [], total = data.length, count = 0; + + if (data.length) { + + for (var i = 0; i < total / 2; i++) { + count = count + 1; + out.push({ name: data.shift(), value: 'https://www.youtube.com/watch?v=' + data.shift(), id: count}); + } + + out.unshift({name: 'All', value: 'all', checked: true}, {name: 'Cancel', value: 'cancel'}); + } + + callback(null, out, true); + }); } };
\ No newline at end of file |