impr: playlist readout
This commit is contained in:
69
fuzique
69
fuzique
@@ -29,9 +29,22 @@ if [ "${1:-}" = "--prompt" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${1:-}" = "--preview" ]; then
|
if [ "${1:-}" = "--preview" ]; then
|
||||||
echo "call to --preview" >>/tmp/foo
|
|
||||||
shift
|
shift
|
||||||
file="$1"
|
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)
|
tags=$(ffprobe -v quiet -show_entries format -of json "$file" | jq)
|
||||||
{
|
{
|
||||||
echo "## Lyrics"
|
echo "## Lyrics"
|
||||||
@@ -41,25 +54,49 @@ if [ "${1:-}" = "--preview" ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
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
|
if [ "${1:-}" = "--show-playlist" ]; then
|
||||||
[ ! -S "${MPV_SOCKET:-}" ] && exit 1
|
count=$(mpv_text '${playlist/count}')
|
||||||
count=$(echo "{ \"command\": [\"expand-text\",\"\${playlist/count}\"] }" | socat - "$MPV_SOCKET" | jq -r '.data')
|
|
||||||
if [ "$count" -eq 0 ]; then
|
if [ "$count" -eq 0 ]; then
|
||||||
printf "(empty playlist)\t\t%s\n" "$MODE_PLAYLIST"
|
printf "(empty playlist)\t\t%s\n" "$MODE_PLAYLIST"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
pos=$(mpv_text '${playlist-pos}')
|
||||||
|
cmd=""
|
||||||
for i in $(seq 0 $((count - 1))); do
|
for i in $(seq 0 $((count - 1))); do
|
||||||
file=$(echo "{ \"command\": [\"expand-text\",\"\${playlist/$i/filename}\"] }" | socat - "$MPV_SOCKET" | jq -r '.data')
|
cmd="$cmd\${playlist/$i/filename}|"
|
||||||
curr=$(echo "{ \"command\": [\"expand-text\",\"\${playlist/$i/current}\"] }" | socat - "$MPV_SOCKET" | jq -r '.data')
|
done
|
||||||
pnt=" "
|
fn=$(mpv_text "$cmd")
|
||||||
[ "$curr" = "yes" ] && pnt="$PLAYLIST_POINTER"
|
for i in $(seq 0 $((count - 1))); do
|
||||||
artist=$(echo "$file" | rev | cut -d "/" -f 3 | rev)
|
f=$(echo "$fn" | cut -d "|" -f "$((i + 1))")
|
||||||
release=$(echo "$file" | rev | cut -d "/" -f 2 | rev)
|
[ ! "$f" ] && continue
|
||||||
title=$(echo "$file" | rev | cut -d "/" -f 1 | rev | sed 's/\..*$//')
|
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")
|
artist=$(printf "$AFMT" "$artist")
|
||||||
release=$(printf "$RFMT" "$release")
|
release=$(printf "$RFMT" "$release")
|
||||||
title=$(printf "$TFMT" "$title")
|
track=$(printf "$TFMT" "$track")
|
||||||
printf "%s|%s|%s|%s\t%s\t%s\n" "$pnt" "$title" "$release" "$artist" "$file" "$MODE_PLAYLIST"
|
[ "$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 |
|
done |
|
||||||
grep '.' |
|
grep '.' |
|
||||||
column -t -s '|'
|
column -t -s '|'
|
||||||
@@ -79,7 +116,7 @@ CAT=${CAT:+$CAT --color=always --style=plain --language=md}
|
|||||||
CAT=${CAT:-cat}
|
CAT=${CAT:-cat}
|
||||||
export CAT
|
export CAT
|
||||||
|
|
||||||
if [ "${1:-}" = "--help" ]; then
|
if [ ! "${1:-}" ] || [ "${1:-}" = "--help" ]; then
|
||||||
$CAT <<EOF
|
$CAT <<EOF
|
||||||
Usage: \`$0 [ --help | [ MUSIC_DIRECTORY [ --reset-cache ] ] ]\`
|
Usage: \`$0 [ --help | [ MUSIC_DIRECTORY [ --reset-cache ] ] ]\`
|
||||||
|
|
||||||
@@ -117,7 +154,7 @@ EOF
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Load configuration
|
# Load configuration
|
||||||
[ "${1:-}" ] && ROOT="$(realpath "$1")" && shift
|
[ "${1:?"You did not specify the music directory. Run $0 --help."}" ] && ROOT="$(realpath "$1")" && shift
|
||||||
ROOT=${ROOT%%/}
|
ROOT=${ROOT%%/}
|
||||||
[ ! -d "${ROOT:-}" ] && echo "Faild to recognize music directory. Run $0 --help." && exit 1
|
[ ! -d "${ROOT:-}" ] && echo "Faild to recognize music directory. Run $0 --help." && exit 1
|
||||||
DEPTH=$(echo "$ROOT" | awk -F'/' '{ print NF }')
|
DEPTH=$(echo "$ROOT" | awk -F'/' '{ print NF }')
|
||||||
@@ -216,13 +253,9 @@ $FZF \
|
|||||||
--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" \
|
||||||
--bind="load:transform:
|
--bind="load:transform:
|
||||||
echo \"l2:{}\" >> /tmp/foo
|
|
||||||
[ {3} = \"$MODE_SEARCH\" ] && printf \"+hide-preview\" || printf \"+show-preview\"
|
[ {3} = \"$MODE_SEARCH\" ] && printf \"+hide-preview\" || printf \"+show-preview\"
|
||||||
[ {3} = \"$MODE_PLAYLIST\" ] && printf \"+hide-input\" || printf \"+show-input\"
|
[ {3} = \"$MODE_PLAYLIST\" ] && printf \"+hide-input\" || printf \"+show-input\"
|
||||||
echo \"l3:{}\" >> /tmp/foo
|
|
||||||
printf \"+transform-prompt:$0 --prompt {2} {3}\"
|
printf \"+transform-prompt:$0 --prompt {2} {3}\"
|
||||||
echo \"l4:{}\" >> /tmp/foo
|
|
||||||
echo \"load ended..\" >> /tmp/foo
|
|
||||||
" \
|
" \
|
||||||
--bind="ctrl-l:transform:
|
--bind="ctrl-l:transform:
|
||||||
printf \"clear-query+pos(1)\"
|
printf \"clear-query+pos(1)\"
|
||||||
|
Reference in New Issue
Block a user