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-15 10:05:29 +00:00
|
|
|
# depends: xargs mpc realpath
|
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
|
|
|
|
test "$1" = "-v" && verbose=-v && shift
|
|
|
|
for arg;
|
2021-10-16 10:16:04 +00:00
|
|
|
do
|
|
|
|
path="$(test -e "$arg" && realpath "$arg" ||
|
2021-10-16 09:24:14 +00:00
|
|
|
( test -e "$MUSIC/$arg" && realpath "$MUSIC/$arg") ||
|
|
|
|
( test -e "$PLAYLISTS/$arg" && realpath "$PLAYLISTS/$arg") )"
|
2021-10-16 10:16:04 +00:00
|
|
|
test -n "$verbose" && echo "Scanning path '$path' $(test "$arg" != "$path" && echo "from '$arg' ")(MUSIC: '$MUSIC')" >&2
|
2021-10-16 09:24:14 +00:00
|
|
|
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' "$0" $verbose -r && popd >/dev/null
|
|
|
|
else
|
|
|
|
find "$path" -name "*.flac" -o -name "*.mp3" | while read file
|
|
|
|
do case "$path" in
|
2021-10-16 10:16:04 +00:00
|
|
|
($MUSIC/*) echo "${file#$MUSIC/}";;
|
2021-10-16 09:24:14 +00:00
|
|
|
(*) mkdir -p "$LINKS" && ln -fs "$file" "$LINKS/$(basename "$file")" && echo "${LINKS#$MUSIC/}/$(basename "$file")";;
|
|
|
|
esac done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
test "$1" = "-q" && quiet=-q && shift
|
2021-10-16 10:16:04 +00:00
|
|
|
test -n "$(mpc playlist)" && next=-q
|
|
|
|
{ "$0" -r "$@" && mpc -q update --wait; } | #>/tmp/mp 2>&1
|
2021-10-16 09:24:14 +00:00
|
|
|
xargs --delim='\n' mpc insert
|
2021-10-16 10:16:04 +00:00
|
|
|
mpc ${quiet:-$next} play
|
|
|
|
test -n "$next" && mpc $quiet next
|
2021-10-16 08:46:54 +00:00
|
|
|
fi
|