diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-01 13:32:36 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-01 13:34:53 +0200 |
commit | 82d07da3add2393c53d20e41e8aba383f058858f (patch) | |
tree | 20e62d7b1cc5428703f1cde9500efa54c52daf50 /bin/menuscripts/mplay | |
parent | cf01ac4c10ecd0cdffed722fd58301ebfddd0d61 (diff) |
checkpoint
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 |