diff --git a/fuzique b/fuzique index 06176d5..1614931 100755 --- a/fuzique +++ b/fuzique @@ -29,9 +29,22 @@ if [ "${1:-}" = "--prompt" ]; then fi if [ "${1:-}" = "--preview" ]; then - echo "call to --preview" >>/tmp/foo shift file="$1" + [ ! -f "$file" ] && exit 0 + rel=${file#"$ROOT/"} + artist=$(echo "$rel" | cut -d "/" -f 1) + release=$(echo "$rel" | cut -d "/" -f 2) + track=$(echo "$rel" | cut -d "/" -f 3) + if [ "$track" ]; then + echo "Tracka info..." + echo "$track" + elif [ "$release" ]; then + echo "Release info..." + echo "$release" + elif [ "$artist" ]; then + echo "Artist info..." + fi tags=$(ffprobe -v quiet -show_entries format -of json "$file" | jq) { echo "## Lyrics" @@ -41,25 +54,49 @@ if [ "${1:-}" = "--preview" ]; then exit 0 fi +mpv_text() { + echo "{ \"command\": [\"expand-text\",\"$1\"] }" | socat - "$MPV_SOCKET" | jq -r '.data' +} + +tags_from_file() { + ffprobe \ + -v quiet \ + -show_entries format \ + -of json \ + "$1" | + jq -r '.format.tags | [ [.artist, .ARTIST], [.album, .ALBUM], [.title, .TITLE] ] | map(map(select(. != null))) | map(.[0]) | join("|")' +} + if [ "${1:-}" = "--show-playlist" ]; then - [ ! -S "${MPV_SOCKET:-}" ] && exit 1 - count=$(echo "{ \"command\": [\"expand-text\",\"\${playlist/count}\"] }" | socat - "$MPV_SOCKET" | jq -r '.data') + count=$(mpv_text '${playlist/count}') if [ "$count" -eq 0 ]; then printf "(empty playlist)\t\t%s\n" "$MODE_PLAYLIST" exit 0 fi + pos=$(mpv_text '${playlist-pos}') + cmd="" for i in $(seq 0 $((count - 1))); do - file=$(echo "{ \"command\": [\"expand-text\",\"\${playlist/$i/filename}\"] }" | socat - "$MPV_SOCKET" | jq -r '.data') - curr=$(echo "{ \"command\": [\"expand-text\",\"\${playlist/$i/current}\"] }" | socat - "$MPV_SOCKET" | jq -r '.data') - pnt=" " - [ "$curr" = "yes" ] && pnt="$PLAYLIST_POINTER" - artist=$(echo "$file" | rev | cut -d "/" -f 3 | rev) - release=$(echo "$file" | rev | cut -d "/" -f 2 | rev) - title=$(echo "$file" | rev | cut -d "/" -f 1 | rev | sed 's/\..*$//') + cmd="$cmd\${playlist/$i/filename}|" + done + fn=$(mpv_text "$cmd") + for i in $(seq 0 $((count - 1))); do + f=$(echo "$fn" | cut -d "|" -f "$((i + 1))") + [ ! "$f" ] && continue + if [ -f "$f" ]; then + tags=$(tags_from_file "$f") + artist=$(echo "$tags" | cut -d "|" -f 1) + release=$(echo "$tags" | cut -d "|" -f 2) + track=$(echo "$tags" | cut -d "|" -f 3) + fi + rel=${f#"$ROOT/"} + [ "${artist:-}" ] || artist=$(echo "$rel" | cut -d "/" -f 1) + [ "${release:-}" ] || release=$(echo "$rel" | cut -d "/" -f 2) + [ "${track:-}" ] || track=$(echo "$rel" | cut -d "/" -f 3 | sed 's/\..*$//') artist=$(printf "$AFMT" "$artist") release=$(printf "$RFMT" "$release") - title=$(printf "$TFMT" "$title") - printf "%s|%s|%s|%s\t%s\t%s\n" "$pnt" "$title" "$release" "$artist" "$file" "$MODE_PLAYLIST" + track=$(printf "$TFMT" "$track") + [ "$i" -eq "$pos" ] && pnt="$PLAYLIST_POINTER" || pnt=" " + printf "%s|%s|%s|%s\t%s\t%s\n" "$pnt" "$track" "$release" "$artist" "$f" "$MODE_PLAYLIST" done | grep '.' | column -t -s '|' @@ -79,7 +116,7 @@ CAT=${CAT:+$CAT --color=always --style=plain --language=md} CAT=${CAT:-cat} export CAT -if [ "${1:-}" = "--help" ]; then +if [ ! "${1:-}" ] || [ "${1:-}" = "--help" ]; then $CAT <> /tmp/foo [ {3} = \"$MODE_SEARCH\" ] && printf \"+hide-preview\" || printf \"+show-preview\" [ {3} = \"$MODE_PLAYLIST\" ] && printf \"+hide-input\" || printf \"+show-input\" - echo \"l3:{}\" >> /tmp/foo printf \"+transform-prompt:$0 --prompt {2} {3}\" - echo \"l4:{}\" >> /tmp/foo - echo \"load ended..\" >> /tmp/foo " \ --bind="ctrl-l:transform: printf \"clear-query+pos(1)\"