« get me outta code hell

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:
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)