From 992911a021e2f2cccfbc63e554a3f34bd997cd91 Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 26 Jun 2018 12:01:43 -0300 Subject: Pass YouTube playlist URLs directly to mtui Or any other crawler argument, and it'll (try to) guess which crawler you want to use automatically. Handy! --- index.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 3abbe83..59c91ec 100755 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ const { AppElement } = require('./ui') const { updatePlaylistFormat } = require('./playlist-utils') +const { getAllCrawlersForArg } = require('./crawlers') const fs = require('fs') const util = require('util') const processSmartPlaylist = require('./smart-playlist') @@ -67,21 +68,20 @@ async function main() { if (process.argv[2]) { console.log('Opening playlist...') - let grouplikeText - try { - grouplikeText = await readFile(process.argv[2]) - } catch (error) { - console.error('Error opening the passed file "' + process.argv[2] + '"!') + const crawlers = getAllCrawlersForArg(process.argv[2]) + + if (crawlers.length === 0) { + console.error(`No suitable playlist crawler for "${process.argv[2]}".`) process.exit(1) } - try { - grouplike = JSON.parse(grouplikeText) - } catch (error) { - flushable.write('Error parsing the passed file as JSON!') - flushable.flush() - process.exit(1) + const crawler = crawlers[0] + + if (crawlers.length > 1) { + console.warn(`More than one suitable crawler for "${process.argv[2]}" - using ${crawler.name}.`) } + + grouplike = await crawler(process.argv[2]) } grouplike = await processSmartPlaylist(grouplike) -- cgit 1.3.0-6-gf8a5