« get me outta code hell

Pass YouTube playlist URLs directly to mtui - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/index.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-06-26 12:01:43 -0300
committerFlorrie <towerofnix@gmail.com>2018-06-26 12:01:45 -0300
commit992911a021e2f2cccfbc63e554a3f34bd997cd91 (patch)
treed0cfdce2b2a5b47b699befc830f8c0b204d19be5 /index.js
parent84ad73f638fe0b03e173b8ffb545d8edb43acc3c (diff)
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!
Diffstat (limited to 'index.js')
-rwxr-xr-xindex.js22
1 files changed, 11 insertions, 11 deletions
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)