summaryrefslogtreecommitdiff
path: root/bin/menuscripts/mplay
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-06-19 10:30:03 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-06-19 10:30:03 +0200
commitff6c38d3364165a7bae431888a87aab1e53a80b9 (patch)
treec0ac13cdbf388d59193522eb8775788a6fae3e81 /bin/menuscripts/mplay
parent4bf952169c5d94044a6dd3c868c990716d22c58b (diff)
parent05e1216b45340702f82a4946002015a05cebe9b1 (diff)
Merge branch 'main' of debuc.com:dotfiles
Diffstat (limited to 'bin/menuscripts/mplay')
-rwxr-xr-xbin/menuscripts/mplay76
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