bin/mp: add option to start track in the middle

This commit is contained in:
xeruf 2021-12-02 23:32:11 +01:00
parent d0715267f8
commit 3fc358fd1d
1 changed files with 26 additions and 25 deletions

View File

@ -7,30 +7,31 @@ PLAYLISTS="$MUSIC/Playlists"
LINKS="$MUSIC/links" LINKS="$MUSIC/links"
if test "$1" = "-r" 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 do path="$(test -e "$arg" && realpath "$arg" ||
path="$(test -e "$arg" && realpath "$arg" || ( test -e "$MUSIC/$arg" && realpath "$MUSIC/$arg") ||
( test -e "$MUSIC/$arg" && realpath "$MUSIC/$arg") || ( test -e "$PLAYLISTS/$arg" && realpath "$PLAYLISTS/$arg") )"
( test -e "$PLAYLISTS/$arg" && realpath "$PLAYLISTS/$arg") )" test -n "$verbose" && echo "Scanning path '$path' $(test "$arg" != "$path" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2
test -n "$verbose" && echo "Scanning path '$path' $(test "$arg" != "$path" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2 test -n "$path" || continue
test -n "$path" || continue if { file "$path" | grep -i ' playlist' || expr "$path" : ".*\.m3u8\?$"; } >/dev/null
if { file "$path" | grep -i ' playlist' || expr "$path" : ".*\.m3u8\?$"; } >/dev/null then pushd "$(dirname "$path")" >/dev/null && cat "$path" | sed '/#.*/D' | xargs --delim='\n' "$0" -r $verbose && popd >/dev/null
then pushd "$(dirname "$path")" >/dev/null && cat "$path" | sed '/#.*/D' | xargs --delim='\n' "$0" -r $verbose && popd >/dev/null else
else test -n "$verbose" && echo "Finding path '$path' $(test "$arg" != "$path" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2
test -n "$verbose" && echo "Finding path '$path' $(test "$arg" != "$path" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2 find "$path" -iname "*.flac" -o -iname "*.mp3" -o -iname "*.ogg" -o -iname "*.opus" | sort | while read file
find "$path" -iname "*.flac" -o -iname "*.mp3" -o -iname "*.ogg" -o -iname "*.opus" | sort | while read file do case "$path" in
do case "$path" in ($MUSIC/*) echo "${file#$MUSIC/}";;
($MUSIC/*) echo "${file#$MUSIC/}";; (*) mkdir -p "$LINKS" && ln -fs "$file" "$LINKS/$(basename "$file")" && echo "${LINKS#$MUSIC/}/$(basename "$file")";;
(*) mkdir -p "$LINKS" && ln -fs "$file" "$LINKS/$(basename "$file")" && echo "${LINKS#$MUSIC/}/$(basename "$file")";; esac done
esac done fi
fi done
done
else else
test "$1" = "-q" && quiet=-q && shift test "$1" = "-q" && quiet=-q && shift
test -n "$(mpc playlist)" && next=-q test -n "$(mpc playlist)" && next=-q
{ "$0" -r "$@" && mpc -q update --wait; } | #tee /tmp/mp 2>&1 test "$1" = "--seek" && seek=-q
xargs --delim='\n' mpc insert { "$0" -r "$@" && mpc -q update --wait; } | #tee /tmp/mp 2>&1
mpc ${quiet:-$next} play xargs --delim='\n' mpc insert
test -z "$next" || mpc $quiet next mpc ${quiet:-${next:-$seek}} play
test -z "$next" || mpc ${quiet:-$seek} next
test -z "$seek" || mpc $quiet seek "30%"
fi fi