From 6f5338edcf2be642feea2e1c391593f49fb7cf36 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sat, 16 Oct 2021 10:46:54 +0200 Subject: [PATCH] bin: adjust music playing utilities --- .local/bin/scripts/fmpc | 3 +-- .local/bin/scripts/focus | 17 ++++++++++++----- .local/bin/scripts/mp | 25 +++++++++++++++++-------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.local/bin/scripts/fmpc b/.local/bin/scripts/fmpc index 9edb1a5..105f6f7 100755 --- a/.local/bin/scripts/fmpc +++ b/.local/bin/scripts/fmpc @@ -1,7 +1,6 @@ #!/bin/sh # Select a song in the mpd queue using fzf and mpc -local song_position song_position=$(mpc -f "%position%) %artist% - %title%" playlist | \ fzf-tmux --query="$1" --reverse --select-1 --exit-0 | \ sed -n 's/^\([0-9]\+\)).*/\1/p') || return 1 -[ -n "$song_position" ] && mpc -q play $song_position +test -n "$song_position" && mpc play $song_position diff --git a/.local/bin/scripts/focus b/.local/bin/scripts/focus index 2f7119a..6e7e407 100755 --- a/.local/bin/scripts/focus +++ b/.local/bin/scripts/focus @@ -1,7 +1,14 @@ +#!/bin/sh -e # launch my focus playlist playlistPath="$MUSIC/Playlists" -test -z "$1" && vp "$playlistPath/focus.m3u" || -(find -L $playlistPath -iname "focus-$1.m3u" -print0 | grep --null-data . || - find -L $playlistPath -iname "$1.m3u*" -print0 | grep --null-data . || - find -L $MUSIC -iname "*$1*" -prune -exec find {} -size +2M -type f -not -iregex ".*.\(jpe?g\|png\)" -print0 \;) | - xargs -0 vp +mpc clear +if test -z "$1" +then mp -q "$playlistPath/focus.m3u" +else + (find -L $playlistPath -iname "focus-$1.m3u" -print0 | grep --null-data . || + find -L $playlistPath -iname "$1.m3u*" -print0 | grep --null-data . || + find -L $MUSIC -iname "*$1*" -prune -exec find {} -size +2M -type f -not -iregex ".*.\(jpe?g\|png\)" -print0 \; ) | + xargs -0 mp -q +fi +mpc -q shuffle +mpc next diff --git a/.local/bin/scripts/mp b/.local/bin/scripts/mp index ae2c1d8..d6a5d69 100755 --- a/.local/bin/scripts/mp +++ b/.local/bin/scripts/mp @@ -1,20 +1,29 @@ -#!/bin/sh -e +#!/bin/sh # Play given files on mpd, enabling playing of external files through symlinking and recursively resolving playlists # depends: xargs mpc realpath # env: MUSIC -links="$MUSIC/links" -test "$1" = "-r" || next=true +PLAYLISTS="$MUSIC/Playlists" +LINKS="$MUSIC/links" +test "$1" = "-q" && quiet=-q && shift +test "$1" = "-v" && verbose=-v && shift +test "$1" = "-r" && shift || next=true { for arg; -do path="$(test -e "$MUSIC/$arg" && echo "$MUSIC/$arg" || realpath "$arg")" +do path="$(test -e "$arg" && realpath "$arg" || + ( test -e "$MUSIC/$arg" && realpath "$MUSIC/$arg") || + ( test -e "$PLAYLISTS/$arg" && realpath "$PLAYLISTS/$arg") )" + test -n "$verbose" && echo "Scanning path '$path' from '$arg'" >&2 test -n "$path" || continue if file "$path" | grep -i ' playlist' || expr "$path" : ".*\.m3u8\?$" >/dev/null - then pushd "$(dirname "$path")" >/dev/null && cat "$path" | xargs --delim='\n' play -r && popd >/dev/null + then pushd "$(dirname "$path")" >/dev/null && cat "$path" | xargs --delim='\n' "$0" $verbose -r && popd >/dev/null else find "$path" -name "*.flac" -o -name "*.mp3" | while read file do case "$path" in ($MUSIC/*) echo "${file/$MUSIC\/}";; - (*) mkdir -p "$links" && ln -fs "$file" "$links/$(basename "$file")" && echo "links/$(basename "$file")";; + (*) mkdir -p "$LINKS" && ln -fs "$file" "$LINKS/$(basename "$file")" && echo "${LINKS#$MUSIC/}/$(basename "$file")";; esac done fi -done && mpc update --wait -q; } | xargs --delim='\n' mpc insert -test "$next" && test "$(mpc status | wc -l)" -gt 1 || mpc play -q && mpc next +done && mpc -q update --wait; } | xargs --delim='\n' mpc insert + +if test "$next" +then test $(mpc status | wc -l) -gt 1 && mpc $quiet next || mpc $quiet play +fi