Browse Source

Implement playlist and download mode

Playlist mode makes the program print the URLs of all songs by the
selected artists. Download mode downloads them in the current directory.
Matteo Zeccoli Marazzini 4 years ago
parent
commit
e3b677deef
2 changed files with 31 additions and 5 deletions
  1. 5 2
      README.md
  2. 26 3
      vaporget

+ 5 - 2
README.md

@@ -16,11 +16,14 @@ Tested on `GNU/Linux`, expected to work on every system with a `POSIX` Shell and
 ## Usage
 After launching the script, if the connection with the music library succeeds a menu with a list of artists will appear.
 Select the artists you want to listen to (with the spacebar) and then press enter.
-`mpv` will fetch the music and reproduce it.
-
+If no option is provided to `vaporget`, `mpv` will fetch the music and reproduce it.
 To pass options (both long and short) directly to `mpv`, use `-m "[mpv_option_1],[mpv_option_2],..."`.
 For example to pass `mpv` options `--shuffle`, `--start=50%` and `-v` use:
 ```
 vaporget -m "shuffle,start=50%,v"
 ```
+If the program is called with `-p`, the list of URLs of the songs by the selected artists will be printed to standard output.
+If the program is called with `-d`, all the songs by the selected artists will be downloaded in the current directory.
+If a combination of `-p` and `-d` is used, only the operation corresponding to the last option written will be executed.
+
 See `MPV(1)` for command line options and interactive use of the music player.

+ 26 - 3
vaporget

@@ -17,6 +17,8 @@
 
 # Global Variables
 WEBSITE="https://vaporwave.ivan.moe/list/"
+USAGE="Usage: $0 [-pdh] [-m \"mpv_option_1[, mpv_option_2, mpv_option_3 ...]]\""
+MODE="play"
 
 ###############################################################################
 # USEFUL FUNCTIONS                                                            #
@@ -78,13 +80,24 @@ handle_term()
 ###############################################################################
 # MAIN SECTION                                                                #
 ###############################################################################
-
 # Parse command line
-while getopts m: f; do
+while getopts pdm:h f; do
 	case $f in
+		p)
+			MODE="playlist"
+		;;
+		d)
+			MODE="download"
+		;;
 		m)
 			MPV_CMDLINE=$(echo "${OPTARG}" | sed -e 's/[[:space:]]//g' -e 's/[^,]\{2,\}/--& /g' -e 's/\(^\|,\)[[:alnum:]]\($\|,\)/ -& /g' -e 's/,//g')
 		;;
+		h)
+			echo "${USAGE}" && exit 0
+		;;
+		\?)
+			echo "${USAGE}" && exit 1
+		;;
 	esac
 done
 shift $(( $OPTIND - 1 ))
@@ -102,4 +115,14 @@ if [ -z "${CHOICES}" ]; then	# User didn't select any artist
 fi
 
 # Play the music
-prepare_playlist "${CHOICES}" | play_music
+case $MODE in
+	"play")
+		prepare_playlist "${CHOICES}" | play_music
+	;;
+	"playlist")
+		prepare_playlist "${CHOICES}" 2>/dev/null
+	;;
+	"download")
+		prepare_playlist "${CHOICES}" | wget -i -
+	;;
+esac