Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read a property from mpv #58

Open
notevenaperson opened this issue Mar 21, 2022 · 4 comments
Open

How to read a property from mpv #58

notevenaperson opened this issue Mar 21, 2022 · 4 comments

Comments

@notevenaperson
Copy link

notevenaperson commented Mar 21, 2022

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.

(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:"))))
@rndusr
Copy link
Collaborator

rndusr commented Mar 21, 2022 via email

@sachac
Copy link
Owner

sachac commented Apr 17, 2022

Do you want to take advantage of the subed-mpv-video-file variable for getting the path, at least? Maybe you can query it outside the mpv process and just ask the user which subtitle to use. I haven't figured out a good pattern for the other things you want to do yet, sorry.

@sachac
Copy link
Owner

sachac commented Apr 17, 2022

mpv.el (which subed doesn't use) has a mpv-run-command that blocks while waiting for a response. I wonder if we can use something like that...

@rndusr
Copy link
Collaborator

rndusr commented Apr 17, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants