json
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import gleam/json
|
||||
import gleam/result
|
||||
|
||||
import mpv/key.{type Key}
|
||||
import tcp/reason.{type Reason}
|
||||
import tcp/tcp.{type Socket}
|
||||
@@ -23,5 +26,28 @@ fn char_control(char: String) -> Result(Control, Nil) {
|
||||
}
|
||||
|
||||
pub fn toggle_play_pause(socket: Socket) -> Result(Nil, Reason) {
|
||||
tcp.send(socket, "{\"command\":[\"cycle\",\"pause\"]}\n")
|
||||
let command =
|
||||
json.object([#("command", json.array(["cycle", "pause"], of: json.string))])
|
||||
|
||||
result.map(send_command(socket, command), fn(_) { Nil })
|
||||
}
|
||||
|
||||
// https://mpv.io/manual/master/#command-interface-playback-time
|
||||
pub fn get_playback_time(socket: Socket) -> Result(String, Reason) {
|
||||
let command =
|
||||
json.object([
|
||||
#(
|
||||
"command",
|
||||
json.array(["get_property_string", "playback-time"], of: json.string),
|
||||
),
|
||||
])
|
||||
|
||||
send_command(socket, command)
|
||||
}
|
||||
|
||||
fn send_command(socket: Socket, command: json.Json) -> Result(String, Reason) {
|
||||
result.try(tcp.send(socket, json.to_string(command) <> "\n"), fn(_) {
|
||||
let timeout_ms = 10_000
|
||||
tcp.receive(socket, timeout_ms)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user