feat: basic playback functionality

This commit is contained in:
2025-08-26 13:51:06 +02:00
parent 30b3a44a98
commit 053b594608
3 changed files with 166 additions and 8 deletions

View File

@@ -75,6 +75,7 @@ if [ "${1:-}" = "--play-release" ]; then
deco=${3}
base="$(dirname "$deco")"
echo "Playing release ($mbid) [$deco]" >>/tmp/foo
tmplist=$(mktemp)
mb_release "$mbid" |
$JQ -r --slurpfile deco "$deco" --arg base "$base" '$deco[].tracks as $filenames |
.media[] |
@@ -93,15 +94,47 @@ if [ "${1:-}" = "--play-release" ]; then
end
) |
sort_by([.pos, .number]) |
map($base + "/" + .file)[]' >>/tmp/foo
map($base + "/" + .file)[]' >"$tmplist"
if [ "${4:-}" ]; then
mpv_play_list "$tmplist"
else
mpv_queue_list "$tmplist"
fi
rm -f "$tmplist"
exit 0
fi
if [ "${1:-}" = "--play-recording" ]; then
echo "Playing recording $2" >>/tmp/foo
mpv_play_file "$2"
if [ "${3:-}" ]; then
mpv_play_file "$2"
else
mpv_queue_file "$2"
fi
exit 0
fi
if [ "${1:-}" = "--play-toggle" ]; then
mpv_toggle_pause
fi
if [ "${1:-}" = "--play-next" ]; then
mpv_next
fi
if [ "${1:-}" = "--play-previous" ]; then
mpv_prev
fi
if [ "${1:-}" = "--seek-forward" ]; then
mpv_seek_forward
fi
if [ "${1:-}" = "--seek-backward" ]; then
mpv_seek_backward
fi
if [ "${1:-}" = "--internal-preview-artist" ]; then
__preview_artist "$2"
exit 0
@@ -387,6 +420,9 @@ case "${1:-}" in
;;
esac
# Start mpv
mpv_start
while true; do
case "${1:-}" in
"--artist")
@@ -407,7 +443,7 @@ while true; do
--with-nth="{1}" \
--expect="ctrl-h,ctrl-a" \
--bind="alt-l:change-query($FORMAT_LOCAL )" \
--bind="load:unbind(enter)+transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l)\"" \
--bind="load:unbind(enter)+unbind(alt-enter)+transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l)\"" \
--bind="ctrl-l:accept" \
--bind="alt-b:execute-silent:xdg-open 'https://musicbrainz.org/release-group/{r2}' &" \
--bind="alt-1:change-query(!$secsymb ),alt-2:change-query($secsymb )" \
@@ -442,7 +478,18 @@ while true; do
--bind="alt-l:change-query($FORMAT_LOCAL )" \
--bind="load:transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l\"" \
--bind="enter:execute-silent:$0 --play-release {2} {3}" \
--bind="focus:transform:[ {3} ] && echo \"rebind:enter\" || echo \"unbind:enter\"" \
--bind="alt-enter:execute-silent:$0 --play-release {2} {3} q" \
--bind="space:execute-silent:$0 --play-toggle" \
--bind="ctrl-n:execute-silent:$0 --play-next" \
--bind="ctrl-p:execute-silent:$0 --play-previous" \
--bind="shift-right:execute-silent:$0 --seek-forward" \
--bind="shift-left:execute-silent:$0 --seek-backward" \
--bind="focus:transform:
[ {3} ] && c=rebind || c=unbind
for key in enter alt-enter space ctrl-n ctrl-p shift-right shift-left; do
printf \"+%s(%s)\" \"\$c\" \"\$key\"
done
" \
--bind="ctrl-l:accept" \
--bind="alt-b:execute-silent:xdg-open 'https://musicbrainz.org/release/{r2}' &" \
--bind="ctrl-d:half-page-down,ctrl-u:half-page-up"
@@ -474,7 +521,18 @@ while true; do
--expect="ctrl-h,ctrl-a" \
--bind="alt-l:change-query($FORMAT_LOCAL )" \
--bind="enter:execute-silent:$0 --play-recording {3}" \
--bind="focus:transform:[ {3} ] && echo \"rebind:enter\" || echo \"unbind:enter\"" \
--bind="alt-enter:execute-silent:$0 --play-recording {3} q" \
--bind="space:execute-silent:$0 --play-toggle" \
--bind="ctrl-n:execute-silent:$0 --play-next" \
--bind="ctrl-p:execute-silent:$0 --play-previous" \
--bind="shift-right:execute-silent:$0 --seek-forward" \
--bind="shift-left:execute-silent:$0 --seek-backward" \
--bind="focus:transform:
[ {3} ] && c=rebind || c=unbind
for key in enter alt-enter space ctrl-n ctrl-p shift-right shift-left; do
printf \"+%s(%s)\" \"\$c\" \"\$key\"
done
" \
--bind="alt-b:execute-silent:xdg-open 'https://musicbrainz.org/track/{r2}' &" \
--bind="ctrl-d:half-page-down,ctrl-u:half-page-up"
)
@@ -537,7 +595,7 @@ while true; do
--expect="ctrl-/" \
--bind="alt-l:change-query($FORMAT_LOCAL )" \
--bind="start:transform:[ \"${2:-}\" ] && echo \"change-query:${2:-}\"" \
--bind="load:unbind(enter)+transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l\"" \
--bind="load:unbind(enter)+unbind(alt-enter)+transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l\"" \
--bind="ctrl-l:accept" \
--bind="ctrl-d:half-page-down,ctrl-u:half-page-up" \
--bind="alt-b:execute-silent:xdg-open 'https://musicbrainz.org/release-group/{r2}' &" \
@@ -575,7 +633,7 @@ while true; do
--expect="ctrl-/" \
--bind="alt-l:change-query($FORMAT_LOCAL )" \
--bind="start:transform:[ \"${2:-}\" ] && echo \"change-query:${2:-}\"" \
--bind="load:unbind(enter)+transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l\"" \
--bind="load:unbind(enter)+unbind(alt-enter)+transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l\"" \
--bind="ctrl-l:accept" \
--bind="ctrl-d:half-page-down,ctrl-u:half-page-up" \
--bind="down:preview-half-page-down,up:preview-half-page-up" \
@@ -611,7 +669,18 @@ while true; do
--bind="alt-l:change-query($FORMAT_LOCAL )" \
--bind="load:transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l\"" \
--bind="enter:execute-silent:$0 --play-release {2} {3}" \
--bind="focus:transform:[ {3} ] && echo \"rebind:enter\" || echo \"unbind:enter\"" \
--bind="alt-enter:execute-silent:$0 --play-release {2} {3} q" \
--bind="space:execute-silent:$0 --play-toggle" \
--bind="ctrl-n:execute-silent:$0 --play-next" \
--bind="ctrl-p:execute-silent:$0 --play-previous" \
--bind="shift-right:execute-silent:$0 --seek-forward" \
--bind="shift-left:execute-silent:$0 --seek-backward" \
--bind="focus:transform:
[ {3} ] && c=rebind || c=unbind
for key in enter alt-enter space ctrl-n ctrl-p shift-right shift-left; do
printf \"+%s(%s)\" \"\$c\" \"\$key\"
done
" \
--bind="ctrl-l:accept" \
--bind="alt-b:execute-silent:xdg-open 'https://musicbrainz.org/release/{r2}' &" \
--bind="ctrl-d:half-page-down,ctrl-u:half-page-up" || true
@@ -646,7 +715,7 @@ while true; do
--expect="ctrl-c,ctrl-q,tab" \
--expect="ctrl-/" \
--bind="alt-l:change-query($FORMAT_LOCAL )" \
--bind="load:unbind(enter)+transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l\"" \
--bind="load:unbind(enter)+unbind(alt-enter)+transform:[ \"\$FZF_TOTAL_COUNT\" -gt 0 ] && echo \"rebind:ctrl-l\" || echo \"unbind:ctrl-l\"" \
--bind="ctrl-l:accept" \
--bind="ctrl-d:half-page-down,ctrl-u:half-page-up" \
--bind="down:preview-half-page-down,up:preview-half-page-up" \