« get me outta code hell

Track-specific converter options - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/play.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2017-09-18 17:20:59 -0300
committerFlorrie <towerofnix@gmail.com>2017-09-18 17:21:00 -0300
commitfa41e5aae1c6874e730e6aff818f3ff57ba6d68e (patch)
tree3a1bd8fc64c4fd2b0eb4ed7b77ee1d10d787233c /src/play.js
parent1ee5c19fb3c458c9f2198362f4d4a9229eb5b314 (diff)
Track-specific converter options
See todo.txt, changes in the man page, and this example:
https://gist.github.com/towerofnix/9b1853ee74d30357e1b59d22c59aba2f
Diffstat (limited to 'src/play.js')
-rwxr-xr-xsrc/play.js77
1 files changed, 74 insertions, 3 deletions
diff --git a/src/play.js b/src/play.js
index 0fdebc7..c27d2f3 100755
--- a/src/play.js
+++ b/src/play.js
@@ -55,6 +55,16 @@ async function determineDefaultPlayer() {
   }
 }
 
+async function determineDefaultConverter() {
+  if (await commandExists('ffmpeg')) {
+    return 'ffmpeg'
+  } else if (await commandExists('avconv')) {
+    return 'avconv'
+  } else {
+    return null
+  }
+}
+
 async function main(args) {
   let sourcePlaylist = null
   let activePlaylist = null
@@ -63,6 +73,7 @@ async function main(args) {
   let pickerLoopMode = 'loop-regenerate'
   let shuffleSeed
   let playerCommand = await determineDefaultPlayer()
+  let converterCommand = await determineDefaultConverter()
 
   // WILL play says whether the user has forced playback via an argument.
   // SHOULD play says whether the program has automatically decided to play
@@ -70,6 +81,10 @@ async function main(args) {
   let shouldPlay = true
   let willPlay = null
 
+  // The same WILL/SHOULD rules apply here.
+  let shouldUseConverterOptions = true
+  let willUseConverterOptions = null
+
   let disablePlaybackStatus = false
 
   const keybindings = [
@@ -116,7 +131,7 @@ async function main(args) {
     sourcePlaylist = processedPlaylist
     activePlaylist = clone(processedPlaylist)
 
-    processArgv(processedPlaylist.options, optionFunctions)
+    await processArgv(processedPlaylist.options, optionFunctions)
   }
 
   async function openKeybindings(arg, add = true) {
@@ -378,6 +393,59 @@ async function main(args) {
       playerCommand = util.nextArg()
     },
 
+    '-converter': async function(util) {
+      const command = util.nextArg()
+
+      if (await commandExists(command)) {
+        converterCommand = command
+      } else {
+        console.warn(`Converter ${command} does not exist!`)
+        console.warn(
+          'Because of this, track-specific converter options are being' +
+          ' disabled. (Use --enable-converter-options to force usage of' +
+          ' them.)'
+        )
+
+        shouldUseConverterOptions = false
+      }
+    },
+
+    '-baz': function() {
+      // --baz
+      // Debugger argument used to print a message as soon as this it is
+      // processed. Handy for making sure the arguments are being processed
+      // in the right order.
+
+      console.log('Baz!')
+    },
+
+    '-foo': function(util) {
+      // --foo
+      // Similar to --baz, but logs the next argument rather than 'Baz!'.
+
+      console.log(util.nextArg())
+    },
+
+    '-enable-converter-options': function() {
+      // --enable-converter-options  (alias: --use-converter-options)
+      // Forces usage of track-specific converter options.
+
+      willUseConverterOptions = true
+    },
+
+    '-use-converter-options': util => util.alias('-enable-converter-options'),
+
+    '-disable-converter-options': function() {
+      // --disable-converter-options  (alias: --no-use-converter-options)
+      // Forces track-specific converter options to not be used.
+
+      willUseConverterOptions = false
+    },
+
+    '-no-use-converter-options': util => {
+      return util.alias('-disable-converter-options')
+    },
+
     '-disable-playback-status': function() {
       // --disable-playback-status  (alias: --hide-playback-status)
       // Hides the playback status line.
@@ -401,8 +469,8 @@ async function main(args) {
 
   if (willPlay || (willPlay === null && shouldPlay)) {
     console.log(`Using sort: ${pickerSortMode} and loop: ${pickerLoopMode}.`)
-
     console.log(`Using ${playerCommand} player.`)
+    console.log(`Using ${converterCommand} converter.`)
 
     const {
       promise: playPromise,
@@ -415,7 +483,10 @@ async function main(args) {
         sort: pickerSortMode,
         seed: shuffleSeed
       },
-      playerCommand,
+      playerCommand, converterCommand,
+      useConverterOptions: willUseConverterOptions || (
+        willUseConverterOptions === null && shouldUseConverterOptions
+      ),
       disablePlaybackStatus
     })