-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Mpv's JSON IPC documentation describes getting replies, such as with the command get_property. Browsing in subed's code for examples, I was surprised subed doesn't rely on reading properties to work, rather its reply handling seems to be built around events (subed-mpv--client-filter and subed-mpv--client-handle-*). In summary I couldn't find examples of getting a property from mpv, so I'm asking here how to do that.
An extension I'm making to the subed package needs to read a few properties from mpv. subed-mpv--client-send can send commands to the JSON IPC, but I just can't figure out how to send a command and see the reply, or e.g. put in a variable.
To give some more background, this is a function in what I'm working on. For now, the function get_property is a placeholder.
Details
(defun subed-mpv--extract-current ()
"This function returns the full text of an embedded subtitle track currently selected in mpv.
I made this because embedded subs are very common, and I don't want to extract them manually
just to be able to see the file in Emacs."
(let ((trackno (get_property "current-tracks/sub/ff-index"))
(subformat (get_property "current-tracks/sub/codec"))
(container-path (get_property "path")))
(shell-command-to-string
(concat
"ffmpeg -nostdin -loglevel error -i " container-path
" -c:s copy -map :" trackno " -f " subformat " pipe:"))))