Getting event from MusicBox (Rapesberry pi)

Hi,
i’m trying to write a simple script in python to catch the events from the MusicBox in a Rapesberry pi zero (like track_playback_started and so on).
As far as i know i need to implement an Actor for monitoring Mopidy.Core.Corelistener events. But I’m failing.
Anyone achieved that?
Thanks a lot.

Hi! You can try to use https://github.com/ismailof/mopidy-json-client, which uses the websocket interface, and can be used to catch the mopidy events from a different script/process than mopidy itself (which I think is what you want to achieve)

There is barely no documentation (my apologies), but you can ask if you find any trouble.

Or use the python-mpd2 library. Something like:

from mpd import MPDClient
from select import select

client = MPDClient()
client.connect("localhost", 6600)
client.send_idle('player')
while True:
    if select([client], [], [], 0)[0]:
        client.fetch_idle()
        client.currentsong()
        client.send_idle('player')

Hi,
i tried your solution but i’m not sure to understand it 100%
How can i print in the shell the current song name?
Thanks a lot

I saw your solution, but unfortunately i couldn’t understand how to start the listener for events (I’m new to python language) since there’s no start method (as i espected).
Can you help me to build a very simple Listener for any events?
Thank a lot

The easiest way, I think, is using the bind_event method, where you provide the event name and the callback function for that event.

I was going to provide some example lines here, but since I wanted to try it first, I finally made a full example script. Please check: https://github.com/ismailof/mopidy-json-client/blob/master/examples/now_playing.py

Unluckily, there is no event loop in the code to make the program await only for events. It seems like a good addition, and I will look on how to implement it. By now, in my scripts I am using an infinite loop which can be stopped with ‘Ctrl-C’ (I know it’s ugly)

That’s exactly what i was looking for.
I tested all up on my raspberry p zero and worked like a charm!
Thank so much :slight_smile: