From f022a98560d7055dce00d306c8f83ba94e8cc7e9 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Fri, 15 Oct 2021 12:05:29 +0200 Subject: [PATCH] bin: rename and fix play to mp --- .config/mpd/mpd.conf | 2 ++ .local/bin/scripts/{play => mp} | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) rename .local/bin/scripts/{play => mp} (61%) diff --git a/.config/mpd/mpd.conf b/.config/mpd/mpd.conf index 40f864c..c6b491e 100644 --- a/.config/mpd/mpd.conf +++ b/.config/mpd/mpd.conf @@ -17,3 +17,5 @@ playlist_plugin { replaygain "track" auto_update "yes" + +follow_outside_symlinks "yes" diff --git a/.local/bin/scripts/play b/.local/bin/scripts/mp similarity index 61% rename from .local/bin/scripts/play rename to .local/bin/scripts/mp index b37d350..ae2c1d8 100755 --- a/.local/bin/scripts/play +++ b/.local/bin/scripts/mp @@ -1,20 +1,20 @@ #!/bin/sh -e # Play given files on mpd, enabling playing of external files through symlinking and recursively resolving playlists -# depends: mpc +# depends: xargs mpc realpath # env: MUSIC links="$MUSIC/links" -for arg; +test "$1" = "-r" || next=true +{ for arg; do path="$(test -e "$MUSIC/$arg" && echo "$MUSIC/$arg" || realpath "$arg")" 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 && popd >/dev/null + then pushd "$(dirname "$path")" >/dev/null && cat "$path" | xargs --delim='\n' play -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 -s "$file" "$links/$(basename $file)" && echo "links/$(basename $file)";; + (*) mkdir -p "$links" && ln -fs "$file" "$links/$(basename "$file")" && echo "links/$(basename "$file")";; esac done fi -done | xargs --delim='\n' mpc insert -# TODO only call on exit point -mpc next +done && mpc update --wait -q; } | xargs --delim='\n' mpc insert +test "$next" && test "$(mpc status | wc -l)" -gt 1 || mpc play -q && mpc next