jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
543 stars 68 forks source link

Installed .so scripts not loaded #137

Closed bergercookie closed 3 years ago

bergercookie commented 3 years ago

Hi there,

Thanks for these awesome bindings!

I've successfully used python-mpv to play a radio stream and also grab the metadata using something the following:

player = mpv.MPV()

# Property access, these can be changed at runtime
@player.property_observer('metadata')
def observer(_name, value):
    print("_name: ", _name)
    print("value: ", value)
    print()

url = "https://somafm.com/defcon130.pls"
player.play(url)
player.wait_for_playback()

I have also installed mpv-pris shared object under ~/.config/mpv/scripts so that I can send the currently playing track via dbus and display it in my window manager toolbar.

When running the stream via the command line (mpv https://somafm.com/defcon130.pls), the script is utilised and the track name is displayed successfully. However, when running mpv via the python wrapper, that's not the case and it doesn't seem to pick up the mpris.so object installed under ~/.config/mpv/scripts.

Is there anything I'm missing? Any property I should be setting for it to do so? AFAICT player.load_scripts is set to True on the mpv.MPV object

Thanks

jaseg commented 3 years ago

Hey there,

the reason for this is that when run from libmpv (as happens in this python module), mpv by default does not load any user configuration--and that includes user lua scripts. See https://github.com/mpv-player/mpv/blob/e27c523a10708b7265c33a4bae631663df4bb297/libmpv/client.h#L434

To work around this, initialize the MPV object like mpv.MPV(config=True, ...). This will load the user's config, and will also load the user's scripts. If you just want to load a specific script, you can also pass the --scripts option: mpv.MPV(scripts=['/path/to/some/script.lua']). This will selectively load that script, without loading user config. If you want to ship your own config with your python script, you can do that using the --config-dir option along with config=True.

Best, jaseg

bergercookie commented 3 years ago

Cheers @jaseg ,

Using config=True indeed solves it and I can see in the debug logs (when using log_handler=debug_print) that it indeed tries to load the so script.

However, now I'm facing a different error which I've described in this ticket: https://github.com/hoyon/mpv-mpris/issues/43

Not sure if this is related to mpv-mpris or to your project though.. let me know if you have any hints otherwise feel free to close this.

jaseg commented 3 years ago

Your problem is with mpv-mpris. They use a function mpv_get_property instead of mpv_get_property_node or mpv_get_property_string in one place. That function seems to have disappeared from mpv recently, so it was probably deprecated API. mpv-mpris needs to replace that with one of the current public API functions from mpv's client.h.