Files
fuzic/src/sh/mpv.sh

68 lines
1.3 KiB
Bash

__mpv_command() {
printf "{ \"command\": [\"%s\"] }\n" "$1" | $SOCAT - "$MPV_SOCKET"
}
__mpv_command_with_arg() {
printf "{ \"command\": [\"%s\", \"%s\"] }\n" "$1" "$2" | $SOCAT - "$MPV_SOCKET"
}
__mpv_command_with_args2() {
printf "{ \"command\": [\"%s\", \"%s\", \"%s\"] }\n" "$1" "$2" "$3" | $SOCAT - "$MPV_SOCKET"
}
__mpv_get() {
__mpv_command_with_arg "expand-text" "$1" | $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 >/dev/null; 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_list() {
t=$(mktemp)
cat >"$t"
__mpv_command_with_arg "loadlist" "$t"
rm -f "$t"
}
mpv_queue_list() {
t=$(mktemp)
cat >"$t"
__mpv_command_with_args2 "loadlist" "$t" "append-play"
rm -f "$t"
}
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"
}