From 231496fc1ae91159d8422c51b2202eac4aa06b67 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 14 Oct 2021 20:26:08 +0200 Subject: [PATCH] bin: music utilities --- .local/bin/scripts/pl | 5 ++++- .local/bin/scripts/play | 20 ++++++++++++++++++++ .local/bin/scripts/scpr | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100755 .local/bin/scripts/play diff --git a/.local/bin/scripts/pl b/.local/bin/scripts/pl index 383b441..a6485d7 100755 --- a/.local/bin/scripts/pl +++ b/.local/bin/scripts/pl @@ -1,15 +1,18 @@ #!/bin/sh -# Playlist utilities +# Playlist management # optdepends: highlight python # env: MUSIC test $# -gt 0 && command=$1 && shift +test "$1" = '-v' && verbose='true' && shift || verbose='false' case $command in (update) for pl; do highlight $pl cat $pl | rev | cut -d'/' -f-2 | rev | while read f; do + $verbose && printf "\e[31;1mSearching for '$f'\e[0m\n" >&2 test -n "$f" || continue newpath="$(find $MUSIC -path "*${f#*../}" -prune | grep . || find $MUSIC -path "*${f##* - }" -o -path "*${f##*/}" | grep -m 1 .)" + $verbose && printf "\e[31;1mFound '$newpath'\e[0m\n" >&2 test -n "$newpath" && realpath --relative-to $(dirname "$pl") "$newpath" || echo "$f" done | tee $pl done;; diff --git a/.local/bin/scripts/play b/.local/bin/scripts/play new file mode 100755 index 0000000..b37d350 --- /dev/null +++ b/.local/bin/scripts/play @@ -0,0 +1,20 @@ +#!/bin/sh -e +# Play given files on mpd, enabling playing of external files through symlinking and recursively resolving playlists +# depends: mpc +# env: MUSIC +links="$MUSIC/links" +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 + 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)";; + esac done + fi +done | xargs --delim='\n' mpc insert +# TODO only call on exit point +mpc next diff --git a/.local/bin/scripts/scpr b/.local/bin/scripts/scpr index e8e6272..9034b9e 100755 --- a/.local/bin/scripts/scpr +++ b/.local/bin/scripts/scpr @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh -e # Copy recursively over ssh server="$1" folder="$2"