2021-10-16 08:46:54 +00:00
|
|
|
#!/bin/sh
|
2021-10-14 18:26:08 +00:00
|
|
|
# Play given files on mpd, enabling playing of external files through symlinking and recursively resolving playlists
|
2021-10-17 10:23:29 +00:00
|
|
|
# depends: xargs realpath mpc
|
2021-10-14 18:26:08 +00:00
|
|
|
# env: MUSIC
|
2021-10-16 10:16:04 +00:00
|
|
|
MUSIC="${MUSIC:-$(cat ${XDG_CONFIG_HOME:-$HOME/.config}/mpd/mpd.conf | grep music_directory | cut -d'"' -f2 | sed "s|~|$HOME|")}"
|
2021-10-16 08:46:54 +00:00
|
|
|
PLAYLISTS="$MUSIC/Playlists"
|
|
|
|
LINKS="$MUSIC/links"
|
2021-10-16 09:24:14 +00:00
|
|
|
if test "$1" = "-r"
|
|
|
|
then shift
|
2021-12-02 22:32:11 +00:00
|
|
|
test "$1" = "-v" && verbose=-v && shift
|
|
|
|
for arg
|
2022-01-30 21:17:45 +00:00
|
|
|
do filepath="$({ find "$(dirname "$arg")" -maxdepth 1 -name "$(basename "$arg")*" -exec realpath {} + ||
|
2022-01-30 11:33:19 +00:00
|
|
|
find "$MUSIC/$(dirname "$arg")" "$MUSIC/Playlists/$(dirname "$arg")" -maxdepth 1 \
|
|
|
|
-name "$(basename "$arg")*" -exec realpath {} +; } 2>/dev/null)"
|
2022-01-30 21:17:45 +00:00
|
|
|
test -n "$verbose" && echo "Scanning path '$filepath' $(
|
|
|
|
test "$arg" != "$filepath" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2
|
|
|
|
test $(printf "$filepath" | wc -l) -gt 0 && printf "$filepath" | xargs --delim='\n' "$0" -r $verbose && continue
|
|
|
|
test -n "$filepath" || continue
|
|
|
|
if { file "$filepath" | grep -i ' playlist' || expr "$filepath" : ".*\.m3u8\?$"; } >/dev/null
|
|
|
|
then pushd "$(dirname "$filepath")" >/dev/null &&
|
|
|
|
cat "$filepath" | sed '/#.*/D' | xargs --delim='\n' "$0" -r $verbose &&
|
2022-01-30 11:33:19 +00:00
|
|
|
popd >/dev/null
|
2021-12-02 22:32:11 +00:00
|
|
|
else
|
2022-01-30 11:33:19 +00:00
|
|
|
test -n "$verbose" &&
|
2022-01-30 21:17:45 +00:00
|
|
|
echo "Running find in path '$filepath' $(test "$arg" != "$filepath" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2
|
|
|
|
find "$filepath" -iname "*.flac" -o -iname "*.mp3" -o -iname "*.ogg" -o -iname "*.opus" |
|
|
|
|
sort | while read file
|
|
|
|
do case "$filepath" in
|
2021-12-02 22:32:11 +00:00
|
|
|
($MUSIC/*) echo "${file#$MUSIC/}";;
|
2022-01-30 11:33:19 +00:00
|
|
|
(*) mkdir -p "$LINKS" &&
|
|
|
|
ln -fs "$file" "$LINKS/$(basename "$file")" &&
|
|
|
|
echo "${LINKS#$MUSIC/}/$(basename "$file")";;
|
2021-12-02 22:32:11 +00:00
|
|
|
esac done
|
|
|
|
fi
|
|
|
|
done
|
2021-10-16 09:24:14 +00:00
|
|
|
else
|
2021-12-02 22:32:11 +00:00
|
|
|
test "$1" = "-q" && quiet=-q && shift
|
2022-01-31 09:36:25 +00:00
|
|
|
test -n "$(mpc playlist)" -a "$(mpc status | wc -l)" -gt 1 && next=-q
|
2021-12-02 22:32:11 +00:00
|
|
|
test "$1" = "--seek" && seek=-q
|
2022-01-30 21:17:45 +00:00
|
|
|
( "$0" -r "$@" && mpc -q update --wait ) | #tee /tmp/mp 2>&1
|
2021-12-02 22:32:11 +00:00
|
|
|
xargs --delim='\n' mpc insert
|
|
|
|
mpc ${quiet:-${next:-$seek}} play
|
|
|
|
test -z "$next" || mpc ${quiet:-$seek} next
|
|
|
|
test -z "$seek" || mpc $quiet seek "30%"
|
2021-10-16 08:46:54 +00:00
|
|
|
fi
|