dotfiles/.local/bin/scripts/mp

21 lines
954 B
Plaintext
Raw Normal View History

2021-10-14 18:26:08 +00:00
#!/bin/sh -e
# Play given files on mpd, enabling playing of external files through symlinking and recursively resolving playlists
2021-10-15 10:05:29 +00:00
# depends: xargs mpc realpath
2021-10-14 18:26:08 +00:00
# env: MUSIC
links="$MUSIC/links"
2021-10-15 10:05:29 +00:00
test "$1" = "-r" || next=true
{ for arg;
2021-10-14 18:26:08 +00:00
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
2021-10-15 10:05:29 +00:00
then pushd "$(dirname "$path")" >/dev/null && cat "$path" | xargs --delim='\n' play -r && popd >/dev/null
2021-10-14 18:26:08 +00:00
else
find "$path" -name "*.flac" -o -name "*.mp3" | while read file
do case "$path" in
($MUSIC/*) echo "${file/$MUSIC\/}";;
2021-10-15 10:05:29 +00:00
(*) mkdir -p "$links" && ln -fs "$file" "$links/$(basename "$file")" && echo "links/$(basename "$file")";;
2021-10-14 18:26:08 +00:00
esac done
fi
2021-10-15 10:05:29 +00:00
done && mpc update --wait -q; } | xargs --delim='\n' mpc insert
test "$next" && test "$(mpc status | wc -l)" -gt 1 || mpc play -q && mpc next