Compare commits

..

3 Commits

Author SHA1 Message Date
1373fd7bb8 imprv: main view 2025-07-18 09:27:24 +02:00
c85f3df62e imrv: style and preview handling 2025-07-18 09:17:31 +02:00
c3d5d324ab disable controls in mpv window 2025-07-17 21:29:15 +02:00

103
fuzique
View File

@@ -37,6 +37,31 @@ if [ "${1:-}" = "--mpv-toggle-pause" ]; then
exit 0 exit 0
fi fi
if [ "${1:-}" = "--browse" ]; then
rel=${3#"$ROOT/"}
d=$(echo "$rel" | awk -F'/' '{ print NF }')
if [ "$2" = "l" ]; then
if [ "$d" -eq 1 ]; then
grep -F "$3/" "$release_file_browse"
elif [ "$d" -eq 2 ]; then
grep -F "$3/" "$tracks_file_browse"
else
p=$(echo "$rel" | cut -d '/' -f 1,2)
grep -F "$ROOT/$p/" "$tracks_file_browse"
fi
elif [ "$2" = "h" ]; then
if [ "$d" -eq 3 ]; then
p=$(echo "$rel" | cut -d '/' -f 1)
grep -F "$ROOT/$p/" "$release_file_browse"
elif [ "$d" -eq 2 ]; then
cat "$artists_file_browse"
else
cat "$artists_file_browse"
fi
fi
exit 0
fi
if [ "${1:-}" = "--prompt" ]; then if [ "${1:-}" = "--prompt" ]; then
shift shift
file="$1" file="$1"
@@ -44,15 +69,16 @@ if [ "${1:-}" = "--prompt" ]; then
mode="$1" mode="$1"
case "$mode" in case "$mode" in
"$MODE_SEARCH") "$MODE_SEARCH")
printf "search> " printf "$SEARCH_PROMPT"
;; ;;
"$MODE_BROWSE") "$MODE_BROWSE")
rel=${file#"$ROOT/"} rel=${file#"$ROOT/"}
artist=$(echo "$rel" | cut -d "/" -f 1) artist=$(echo "$rel" | cut -d "/" -f 1)
release=$(echo "$rel" | cut -d "/" -f 2) release=$(echo "$rel" | cut -d "/" -f 2)
d=$(echo "$rel" | awk -F'/' '{ print NF }') d=$(echo "$rel" | awk -F'/' '{ print NF }')
[ "$d" -eq 2 ] && printf " $AFMT 〉 " "$artist" [ "$d" -eq 1 ] && printf "$BROWSE_PROMPT_ROOT"
[ "$d" -eq 3 ] && printf " $AFMT 》 $RFMT 〉 " "$artist" "$release" [ "$d" -eq 2 ] && printf "$BROWSE_PROMPT_ARTIST" "$artist"
[ "$d" -eq 3 ] && printf "$BROWSE_PROMPT_RELEASE" "$artist" "$release"
;; ;;
"$MODE_PLAYLIST") "$MODE_PLAYLIST")
printf "" printf ""
@@ -64,26 +90,17 @@ fi
if [ "${1:-}" = "--preview" ]; then if [ "${1:-}" = "--preview" ]; then
shift shift
file="$1" file="$1"
[ ! -f "$file" ] && exit 0
rel=${file#"$ROOT/"} rel=${file#"$ROOT/"}
artist=$(echo "$rel" | cut -d "/" -f 1) artist=$(echo "$rel" | cut -d "/" -f 1)
release=$(echo "$rel" | cut -d "/" -f 2) release=$(echo "$rel" | cut -d "/" -f 2)
track=$(echo "$rel" | cut -d "/" -f 3) track=$(echo "$rel" | cut -d "/" -f 3)
if [ "$track" ]; then if [ "$track" ]; then
echo "Tracka info..." echo "(not implemented: track info for $track)"
echo "$track"
elif [ "$release" ]; then elif [ "$release" ]; then
echo "Release info..." echo "(not implemented: release info for $release)"
echo "$release"
elif [ "$artist" ]; then elif [ "$artist" ]; then
echo "Artist info..." echo "(not implemented: artist info for $artist)"
fi fi
tags=$(ffprobe -v quiet -show_entries format -of json "$file" | jq)
{
echo "## Lyrics"
echo ""
printf "%s" "$tags" | jq -C -r '.format.tags.LYRICS'
} | $CAT
exit 0 exit 0
fi fi
@@ -103,7 +120,7 @@ tags_from_file() {
if [ "${1:-}" = "--show-playlist" ]; then if [ "${1:-}" = "--show-playlist" ]; then
count=$(mpv_text '${playlist/count}') count=$(mpv_text '${playlist/count}')
if [ "$count" -eq 0 ]; then if [ "$count" -eq 0 ]; then
printf "(empty playlist)\t\t%s\n" "$MODE_PLAYLIST" printf "$EMPTY_PLAYLIST_STRING\t\t%s\n" "$MODE_PLAYLIST"
exit 0 exit 0
fi fi
pos=$(mpv_text '${playlist-pos}') pos=$(mpv_text '${playlist-pos}')
@@ -202,10 +219,15 @@ ARTIST_COLOR=${ARTIST_COLOR:-'\033[38;5;202m'}
RELEASE_COLOR=${RELEASE_COLOR:-'\033[38;5;208m'} RELEASE_COLOR=${RELEASE_COLOR:-'\033[38;5;208m'}
TRACK_COLOR=${TRACK_COLOR:-'\033[38;5;215m'} TRACK_COLOR=${TRACK_COLOR:-'\033[38;5;215m'}
OFF="\033[m" OFF="\033[m"
AFMT="${AFTM:-"🎤 ${ARTIST_COLOR}%s${OFF}"}" AFMT="${AFMT:-"🎤 ${ARTIST_COLOR}%s${OFF}"}"
RFMT="${RFMT:-"💽 ${RELEASE_COLOR}%s${OFF}"}" RFMT="${RFMT:-"💽 ${RELEASE_COLOR}%s${OFF}"}"
TFMT="${TFMT:-"🎵 ${TRACK_COLOR}%s${OFF}"}" TFMT="${TFMT:-"🎵 ${TRACK_COLOR}%s${OFF}"}"
PLAYLIST_POINTER="${PLAYLIST_POINTER:-👉}" PLAYLIST_POINTER="${PLAYLIST_POINTER:-👉}"
EMPTY_PLAYLIST_STRING="${EMPTY_PLAYLIST_STRING:-"\033[38;5;251m(empty playlist)${OFF}"}"
SEARCH_PROMPT=${SEARCH_PROMPT:-"🔎 search〉"}
BROWSE_PROMPT_ROOT="${BROWSE_PROMPT_ROOT:-"$SEARCH_PROMPT"}"
BROWSE_PROMPT_ARTIST="${BROWSE_PROMPT_ARTIST:-"$AFMT 〉"}"
BROWSE_PROMPT_RELEASE="${BROWSE_PROMPT_RELEASE:-"$AFMT 》 $RFMT 〉"}"
# Modes # Modes
MODE_BROWSE="B" MODE_BROWSE="B"
@@ -215,9 +237,6 @@ MODE_PLAYLIST="P"
# Make socket # Make socket
MPV_SOCKET="$(mktemp --suffix=.sock)" MPV_SOCKET="$(mktemp --suffix=.sock)"
# Export
export ROOT MPV_SOCKET AFMT RFMT TFMT PLAYLIST_POINTER MODE_SEARCH MODE_BROWSE MODE_PLAYLIST
# Load # Load
if [ "${1:-}" = "--reset-cache" ] || [ ! -f "$CACHE_FILE" ]; then if [ "${1:-}" = "--reset-cache" ] || [ ! -f "$CACHE_FILE" ]; then
rm -f "$CACHE_FILE" rm -f "$CACHE_FILE"
@@ -231,11 +250,20 @@ fi
# Parse # Parse
artists_file_browse=$(mktemp) artists_file_browse=$(mktemp)
artists_file_search=$(mktemp)
release_file_browse=$(mktemp) release_file_browse=$(mktemp)
release_file_search=$(mktemp) release_file_search=$(mktemp)
tracks_file_browse=$(mktemp) tracks_file_browse=$(mktemp)
tracks_file_search=$(mktemp) tracks_file_search=$(mktemp)
# Export
export ROOT MPV_SOCKET \
AFMT RFMT TFMT \
PLAYLIST_POINTER EMPTY_PLAYLIST_STRING \
SEARCH_PROMPT BROWSE_PROMPT_ROOT BROWSE_PROMPT_ARTIST BROWSE_PROMPT_RELEASE \
MODE_SEARCH MODE_BROWSE MODE_PLAYLIST \
artists_file_browse release_file_browse tracks_file_browse \
tracks_file_search release_file_search
awk \ awk \
-F'/' \ -F'/' \
-v afmt="$AFMT" \ -v afmt="$AFMT" \
@@ -245,7 +273,6 @@ awk \
-v artists_file_browse="$artists_file_browse" \ -v artists_file_browse="$artists_file_browse" \
-v release_file_browse="$release_file_browse" \ -v release_file_browse="$release_file_browse" \
-v tracks_file_browse="$tracks_file_browse" \ -v tracks_file_browse="$tracks_file_browse" \
-v artists_file_search="$artists_file_search" \
-v release_file_search="$release_file_search" \ -v release_file_search="$release_file_search" \
-v tracks_file_search="$tracks_file_search" \ -v tracks_file_search="$tracks_file_search" \
-v mode_browse="$MODE_BROWSE" \ -v mode_browse="$MODE_BROWSE" \
@@ -262,24 +289,24 @@ NF >= depth + 3 { tr = $itrack; gsub(/\..*$/, "", tr); tr = sprintf(tfmt, tr) }
NF == depth + 1 { print ar, $0, mode_browse >> artists_file_browse } NF == depth + 1 { print ar, $0, mode_browse >> artists_file_browse }
NF == depth + 2 { print rl, $0, mode_browse >> release_file_browse } NF == depth + 2 { print rl, $0, mode_browse >> release_file_browse }
NF == depth + 3 { print tr, $0, mode_browse >> tracks_file_browse } NF == depth + 3 { print tr, $0, mode_browse >> tracks_file_browse }
NF == depth + 1 { print ar, $0, mode_search >> artists_file_search }
NF == depth + 2 { print rl "|" ar, $0, mode_search >> release_file_search } NF == depth + 2 { print rl "|" ar, $0, mode_search >> release_file_search }
NF == depth + 3 { print tr "|" rl "|" ar, $0, mode_search >> tracks_file_search } NF == depth + 3 { print tr "|" rl "|" ar, $0, mode_search >> tracks_file_search }
' <"$CACHE_FILE" ' <"$CACHE_FILE"
$MPV --no-config --no-terminal --input-ipc-server="$MPV_SOCKET" --idle & $MPV --no-config --no-terminal --input-ipc-server="$MPV_SOCKET" --idle --no-osc --no-input-default-bindings &
$FZF \ $FZF \
--reverse \ --reverse \
--ansi \ --ansi \
--no-sort \
--delimiter="\t" \ --delimiter="\t" \
--with-nth="{1}" \ --with-nth="{1}" \
--cycle \ --cycle \
--bind="ctrl-d:half-page-down,ctrl-u:half-page-up" \ --bind="ctrl-d:half-page-down,ctrl-u:half-page-up" \
--preview-window="down" \ --bind="down:preview-down,up:preview-up" \
--bind="ctrl-w:toggle-preview-wrap" \
--preview-window="right,30%" \
--preview="$0 --preview {2}" \ --preview="$0 --preview {2}" \
--bind="alt-1:reload:column -t -s '|' -E 0 \"$artists_file_search\"" \ --bind="alt-1:reload:cat \"$artists_file_browse\"" \
--bind="alt-2:reload:column -t -s '|' -E 0 \"$release_file_search\"" \ --bind="alt-2:reload:column -t -s '|' -E 0 \"$release_file_search\"" \
--bind="alt-3:reload:column -t -s '|' -E 0 \"$tracks_file_search\"" \ --bind="alt-3:reload:column -t -s '|' -E 0 \"$tracks_file_search\"" \
--bind="ctrl-p:reload:$0 --show-playlist" \ --bind="ctrl-p:reload:$0 --show-playlist" \
@@ -290,6 +317,7 @@ $FZF \
--bind="right:execute-silent:$0 --mpv-seekf" \ --bind="right:execute-silent:$0 --mpv-seekf" \
--bind="left:execute-silent:$0 --mpv-seekb" \ --bind="left:execute-silent:$0 --mpv-seekb" \
--bind="space:execute-silent:$0 --mpv-toggle-pause" \ --bind="space:execute-silent:$0 --mpv-toggle-pause" \
--bind="q:abort" \
--bind="load:transform: --bind="load:transform:
if [ {3} = \"$MODE_PLAYLIST\" ]; then if [ {3} = \"$MODE_PLAYLIST\" ]; then
printf \"+hide-input\" printf \"+hide-input\"
@@ -299,6 +327,7 @@ $FZF \
printf \"+rebind(right)\" printf \"+rebind(right)\"
printf \"+rebind(left)\" printf \"+rebind(left)\"
printf \"+rebind(space)\" printf \"+rebind(space)\"
printf \"+rebind(q)\"
fi fi
if [ {3} = \"$MODE_SEARCH\" ]; then if [ {3} = \"$MODE_SEARCH\" ]; then
printf \"+show-input\" printf \"+show-input\"
@@ -308,6 +337,7 @@ $FZF \
printf \"+unbind(right)\" printf \"+unbind(right)\"
printf \"+unbind(left)\" printf \"+unbind(left)\"
printf \"+unbind(space)\" printf \"+unbind(space)\"
printf \"+unbind(q)\"
fi fi
if [ {3} = \"$MODE_BROWSE\" ]; then if [ {3} = \"$MODE_BROWSE\" ]; then
printf \"+show-input\" printf \"+show-input\"
@@ -317,28 +347,17 @@ $FZF \
printf \"+unbind(right)\" printf \"+unbind(right)\"
printf \"+unbind(left)\" printf \"+unbind(left)\"
printf \"+unbind(space)\" printf \"+unbind(space)\"
printf \"+unbind(q)\"
fi fi
printf \"+transform-prompt:$0 --prompt {2} {3}\" printf \"+transform-prompt:$0 --prompt {2} {3}\"
" \ " \
--bind="ctrl-l:transform: --bind="ctrl-l:reload($0 --browse l {2})+clear-query+pos(1)" \
printf \"clear-query+pos(1)\" --bind="ctrl-h:reload($0 --browse h {2})+clear-query+pos(1)" \
d=\$(echo {2} | awk -F'/' '{ print NF }') <"$artists_file_browse" || true
[ \"\$d\" -eq \"$((DEPTH + 1))\" ] && echo \"+reload:grep -F {2}/ \\\"$release_file_browse\\\" | column -t -s '|' || true\"
[ \"\$d\" -eq \"$((DEPTH + 2))\" ] && echo \"+reload:grep -F {2}/ \\\"$tracks_file_browse\\\" | column -t -s '|' || true\"
" \
--bind="ctrl-h:transform:
printf \"clear-query+pos(1)\"
d=\$(echo {2} | awk -F'/' '{ print NF }')
p=\$(echo {2} | rev | cut -d '/' -f 3- | rev)
[ \"\$d\" -eq \"$((DEPTH + 3))\" ] && echo \"+reload:grep -F \\\"\$p/\\\" \\\"$release_file_browse\\\" | column -t -s '|' || true\"
[ \"\$d\" -eq \"$((DEPTH + 2))\" ] && echo \"+reload:grep -F \\\"\$p/\\\" \\\"$artists_file_browse\\\" | column -t -s '|' || true\"
" \
<"$artists_file_search" || true
printf '{ "command": ["quit"] }\n' | socat - "$MPV_SOCKET" printf '{ "command": ["quit"] }\n' | socat - "$MPV_SOCKET"
rm -f "$MPV_SOCKET" \ rm -f "$MPV_SOCKET" \
"$artists_file_browse" \ "$artists_file_browse" \
"$artists_file_search" \
"$release_file_browse" \ "$release_file_browse" \
"$release_file_search" \ "$release_file_search" \
"$tracks_file_browse" \ "$tracks_file_browse" \