Browse Source

Use -m to pass options to mpv

Since we plan to have different options for our program, to distinguish
the arguments to pass to mpv the user now has to invoke the program as:
vaporget -m "[mpv_opt_1], [mpv_opt_2], [mpv_opt_3]"
where [mpv_opt_n] is a long option (for example, shuffle).
Matteo Zeccoli Marazzini 4 years ago
parent
commit
0d749b14a5
2 changed files with 11 additions and 2 deletions
  1. 5 1
      README.md
  2. 6 1
      vaporget

+ 5 - 1
README.md

@@ -18,5 +18,9 @@ After launching the script, if the connection with the music library succeeds a
 Select the artists you want to listen to (with the spacebar) and then press enter.
 `mpv` will fetch the music and reproduce it.
 
-For now all the command line options are passed directly to `mpv`.
+To pass options to `mpv`, use `-m "[mpv_option_1], [mpv_option_2]`.
+For example:
+```
+vaporget -m "shuffle, start=50%"
+```
 See `MPV(1)` for command line options and interactive use of the music player.

+ 6 - 1
vaporget

@@ -17,7 +17,6 @@
 
 # Global Variables
 WEBSITE="https://vaporwave.ivan.moe/list/"
-MPV_CMDLINE=$@
 
 ###############################################################################
 # USEFUL FUNCTIONS                                                            #
@@ -79,6 +78,12 @@ handle_term()
 ###############################################################################
 # MAIN SECTION                                                                #
 ###############################################################################
+while getopts m: f; do
+	case $f in
+		m)      MPV_CMDLINE=$(echo "${OPTARG}" | sed -e 's/^ */--/' -e 's/, */ --/g');;
+	esac
+done
+shift `expr $OPTIND - 1`
 
 trap handle_term TERM	# Use our custom handler for the TERM signal