diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-06 15:29:58 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-06 15:29:58 +0200 |
commit | ad05cb18f03f3a97a918e090c38ba760147a0bb6 (patch) | |
tree | 233097b3ccbf1a4fef18a291d0d8fda3fba34c03 /bin/menuscripts/mplay | |
parent | 1a7e35285abb5db60d2e1544ce0100e82c5d3490 (diff) | |
parent | 511b6c1bc9acd9e6029d08a6c448f6e0037755fb (diff) |
Merge branch 'main' of db:dotfiles
Diffstat (limited to 'bin/menuscripts/mplay')
-rwxr-xr-x | bin/menuscripts/mplay | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/bin/menuscripts/mplay b/bin/menuscripts/mplay new file mode 100755 index 0000000..57af631 --- /dev/null +++ b/bin/menuscripts/mplay @@ -0,0 +1,76 @@ +#!/bin/sh + +MUSIC="$HOME/music" + + +list_dirs() +{ + find -L "$1" \ + -mindepth 1 -maxdepth 1 \ + -not -name "*.cue" | + sed "s@^$1/@@" | sort; +} + +find_song() +{ + file="$MUSIC" + while [ -d "$file" ] + do + choice="$(list_dirs "$file" | commander -clx)" + [ "$choice" ] || return + file="$file/$choice" + done + printf '%s' "${file##"$MUSIC/"}" +} + +play_song() +{ + printf '%s\n' "$1" | tr '\n' '\0' | + xargs -0I{} mpc insert "{}" || return + mpc next 2> /dev/null + mpc play 2> /dev/null +} + +main() +{ + choice="$(printf 'volume\nsearch\ncommand\nall_search\nquit' | commander -c -w 5 -y 1)" + case "$choice" in + volume) + # Change volume while no error + while true + do + volume="$(mpc volume | awk -F '[ %]' '{print $2}')" + nb="$(printf 'p\nm' | commander -c -y 2 -p "$volume" | tr 'pm' '+-')" + [ "$nb" ] || break + change="$(commander -ci -p "$volume$nb")" + mpc volume "$nb$change" || break + done ;; + + search) + song="$(find_song)" + [ "$song" ] || return + + choice="$(printf 'insert\nadd\nplay' | commander -c -w 3 -y 1)" + case "$choice" in + insert|add) mpc "$choice" "$song" ;; + play) play_song "$song" ;; + esac ;; + + command) + mpc "$(printf 'next\nprevious\nclear\nstop\ntoggle' | + commander -c -w 8 -y 5)" ;; + + all_search) + song="$(mpc listall | commander -cxh)" + [ "$song" ] || return + play_song "$song";; + quit) return 1 ;; + + *) return 1 ;; + esac + return 0 +} + +while main +do :; +done |