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

@@ -4,6 +4,79 @@ USER_AGENT="$APP_NAME/$APP_VERSION ($APP_WEBSITE)"
SLEEP_ON_ERROR=1
export MB_BROWSE_STEPS
__mpv_command() {
echo "mpv_command: $*" >>/tmp/foo
printf "{ \"command\": [\"%s\"] }\n" "$1" | $SOCAT - "$MPV_SOCKET"
}
__mpv_command_with_arg() {
echo "mpv_command_1: $*" >>/tmp/foo
printf "{ \"command\": [\"%s\", \"%s\"] }\n" "$1" "$2" | $SOCAT - "$MPV_SOCKET"
}
__mpv_command_with_args2() {
echo "mpv_command_2: $*" >>/tmp/foo
printf "{ \"command\": [\"%s\", \"%s\", \"%s\"] }\n" "$1" "$2" "$3" | $SOCAT - "$MPV_SOCKET"
}
__mpv_get() {
__mpv_command_with_arg "expand-text" "$2" | $JQ -r '.data'
}
mpv_playlist_count() {
__mpv_get '${playlist/count}'
}
mpv_playlist_position() {
__mpv_get '${playlist-pos}'
}
mpv_quit() {
__mpv_command "quit"
}
mpv_start() {
MPV_SOCKET="$(mktemp --suffix=.sock)"
trap 'mpv_quit; rm -f "$MPV_SOCKET"' EXIT INT
$MPV --no-config --no-terminal --input-ipc-server="$MPV_SOCKET" --idle --no-osc --no-input-default-bindings &
}
mpv_play_file() {
__mpv_command_with_arg "loadfile" "$1"
}
mpv_queue_file() {
__mpv_command_with_args2 "loadfile" "$1" "append-play"
}
mpv_play_list() {
__mpv_command_with_arg "loadlist" "$1"
}
mpv_queue_list() {
__mpv_command_with_arg "loadlist" "$1" "append-play"
}
mpv_next() {
__mpv_command "playlist-next"
}
mpv_prev() {
__mpv_command "playlist-prev"
}
mpv_seek_forward() {
__mpv_command_with_arg "seek" "10"
}
mpv_seek_backward() {
__mpv_command_with_arg "seek" "-10"
}
mpv_toggle_pause() {
__mpv_command_with_arg "cycle" "pause"
}
__api_mb() {
tmpout=$(mktemp)
for _ in $(seq "$MB_MAX_RETRIES"); do

View File

@@ -21,3 +21,19 @@ else
exit 1
fi
export JQ
if command -v "mpv" >/dev/null; then
MPV="mpv"
else
err "Did not find mpv."
exit 1
fi
export MPV
if command -v "socat" >/dev/null; then
SOCAT="socat"
else
err "Did not find socat."
exit 1
fi
export SOCAT