From 11b317833a8d5a332d8cba564edbcd68cf7f9a7a Mon Sep 17 00:00:00 2001 From: przemyslawpluta Date: Sun, 6 Apr 2014 19:37:29 +0100 Subject: handle youtube playlists --- lib/videos.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'lib/videos.js') 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 -- cgit v1.2.3