dotfiles/.local/bin/scripts/play

21 lines
834 B
Bash
Executable File

#!/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