bin/mp: fix spurious symlinking

This commit is contained in:
xeruf 2022-01-31 14:39:25 +01:00
parent 20f18f49ed
commit 0ca87746d0
2 changed files with 10 additions and 9 deletions

View File

@ -7,7 +7,7 @@
for arg do for arg do
if test -r "$arg"; then if test -r "$arg"; then
fullpath="$(realpath "$arg")" fullpath="$(realpath "$arg")"
name="$(basename "${path%.*}")" name="$(basename "${fullpath%.*}")"
namepart="$name.part" namepart="$name.part"
( (
if test "$(ls -U | wc -l)" -gt 2; then if test "$(ls -U | wc -l)" -gt 2; then

View File

@ -9,25 +9,26 @@ if test "$1" = "-r"
then shift then shift
test "$1" = "-v" && verbose=-v && shift test "$1" = "-v" && verbose=-v && shift
for arg for arg
do filepath="$({ find "$(dirname "$arg")" -maxdepth 1 -name "$(basename "$arg")*" -exec realpath {} + || do filepath="$({ find "$(dirname -- "$arg")" -maxdepth 1 -name "$(basename -- "$arg")*" -exec realpath {} + ||
find "$MUSIC/$(dirname "$arg")" "$MUSIC/Playlists/$(dirname "$arg")" -maxdepth 1 \ arg-test find "$MUSIC/$(dirname -- "$arg")" "$MUSIC/Playlists/$(dirname -- "$arg")" -maxdepth 1 \
-name "$(basename "$arg")*" -exec realpath {} +; } 2>/dev/null)" -name "$(basename -- "$arg")*" -exec realpath {} +; } 2>/dev/null)"
test -n "$verbose" && echo "Scanning path '$filepath' $( test -n "$verbose" && echo "Scanning path '$filepath' $(
test "$arg" != "$filepath" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2 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 $(printf "$filepath" | wc -l) -gt 0 && printf "$filepath" | xargs --delim='\n' "$0" -r $verbose && continue
test -n "$filepath" || continue test -n "$filepath" || continue
if { file "$filepath" | grep -i ' playlist' || expr "$filepath" : ".*\.m3u8\?$"; } >/dev/null if { file -- "$filepath" | grep -i ' playlist' || expr "$filepath" : ".*\.m3u8\?$"; } >/dev/null
then pushd "$(dirname "$filepath")" >/dev/null && then pushd "$(dirname "$filepath")" >/dev/null &&
cat "$filepath" | sed '/#.*/D' | xargs --delim='\n' "$0" -r $verbose && cat "$filepath" | sed '/#.*/D' | xargs --delim='\n' "$0" -r $verbose &&
popd >/dev/null popd >/dev/null
else else
test -n "$verbose" && test -n "$verbose" &&
echo "Running find in path '$filepath' $(test "$arg" != "$filepath" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2 echo "Running find in path '$filepath' $(test "$arg" != "$filepath" && echo "from '$arg' ")" >&2
find "$filepath" -iname "*.flac" -o -iname "*.mp3" -o -iname "*.ogg" -o -iname "*.opus" | find "$filepath" -iname "*.flac" -o -iname "*.mp3" -o -iname "*.ogg" -o -iname "*.opus" |
sort | while read file sort | while read file
do case "$filepath" in do case "$file" in
($MUSIC/*) echo "${file#$MUSIC/}";; ($MUSIC/*) echo "${file#$MUSIC/}";;
(*) mkdir -p "$LINKS" && (*) test -n "$verbose" && echo "Linking $file into $LINKS" >&2
mkdir -p "$LINKS" &&
ln -fs "$file" "$LINKS/$(basename "$file")" && ln -fs "$file" "$LINKS/$(basename "$file")" &&
echo "${LINKS#$MUSIC/}/$(basename "$file")";; echo "${LINKS#$MUSIC/}/$(basename "$file")";;
esac done esac done
@ -36,7 +37,7 @@ then shift
else else
test "$1" = "-q" && quiet=-q && shift test "$1" = "-q" && quiet=-q && shift
test -n "$(mpc playlist)" -a "$(mpc status | wc -l)" -gt 1 && next=-q test -n "$(mpc playlist)" -a "$(mpc status | wc -l)" -gt 1 && next=-q
test "$1" = "--seek" && seek=-q test "$1" = "--seek" && seek=-q && shift
( "$0" -r "$@" && mpc -q update --wait ) | #tee /tmp/mp 2>&1 ( "$0" -r "$@" && mpc -q update --wait ) | #tee /tmp/mp 2>&1
xargs --delim='\n' mpc insert xargs --delim='\n' mpc insert
mpc ${quiet:-${next:-$seek}} play mpc ${quiet:-${next:-$seek}} play