Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

--onevent documentation #185

Closed
DavidM42 opened this issue Mar 10, 2018 · 11 comments
Closed

--onevent documentation #185

DavidM42 opened this issue Mar 10, 2018 · 11 comments
Labels

Comments

@DavidM42
Copy link

The documentation describes how to use the apparently older --onstart and --onstop event handler but the help text and the project itself demand a --onevent handler.
Sorry for my Noob question but I couldn't find any info on how to use it in the wiki or anywhre else. I searched for it on the issue tracker,Google,.. but still got no results.
I know there is a help text but it's pretty shortly explained there.
So to break it down could you please instruct me how the explicit event type get's passed and I would be happy to try to update your wiki on this option.

@2pl
Copy link

2pl commented Mar 10, 2018

As far as I could test, you get passed a "start" or "stop" value through environment variable PLAYER_EVENT. So you need to test the value of PLAYER_EVENT in your script and decide the appropriate action.

@kingosticks
Copy link
Contributor

You can find the code in question at https://github.com/librespot-org/librespot/blob/aa880f8888226a8e5fc6e1e54dfb7cf58176ac95/src/player_event_handler.rs and hopefully it's quite easy to follow. An updated wikipage would be great. We could also look at adding something (short) to the option's help text.

@DavidM42
Copy link
Author

Yeah thx for the quick help. I worked it out but it was a hard thing to do. I couldn't test for the environment variables because they were in the "raspotify" user account because I use that project which has librespot as it's core.
I'm now able to get the playback state in a python script which is the onevent handler. Sadly I still gave up for now because my plan to switch rc mains switches vía this script did not work for some damn reason I can't find.
Pain in the ass to get the permissions of files,gpio and everything else when It's run as service in another user account.

Update of the wikipage as well as the help text should not be that much work and it's pretty easy to use if it's standalone librespot.
I would like to help but I don't know if I undestand it enough for now to write an understandable explanation.

@madmodder123
Copy link

madmodder123 commented Mar 11, 2018

@DavidM42 Can you share the python code you use to grab the playback state? I am also using raspotify and I am trying to figure out a way to integrate Spotify functionality into my background music script.
Also... do you know if Raspotify uses this branch of librespot or the original one?

@michaelherger
Copy link
Contributor

michaelherger commented Mar 11, 2018

This is the very basic shell script I used for testing:

#!/bin/sh

echo Spotify event: ---------------------------------------------
echo PLAYER_EVENT: $PLAYER_EVENT
echo TRACK_ID:     $TRACK_ID
echo OLD_TRACK_ID: $OLD_TRACK_ID

I'm not a python guy, but the equivalent to echo $TRACK_ID seems to be:

import os
print(os.environ['TRACK_ID'])

The OLD_TRACK_ID variable would be set on change events: when a new track is being played.

@DavidM42
Copy link
Author

@madmodder123 @michaelherger
Michael's info was totally correct aswell as his Python example but still here is my Python script.
(if you use raspotify keep in mind that the script needs to be executable for raspotify user. I am not very experienced with permissions so I gave it an unsafe chmod 777 rights so everyone can do everything)

import os

if os.environ['PLAYER_EVENT'] == "start":
    os.system("/home/pi/raspberry-remote/send ***** 1 1")
elif os.environ['PLAYER_EVENT'] == "change":
    os.system("/home/pi/raspberry-remote/send ***** 1 1")
elif os.environ['PLAYER_EVENT'] == "stop":
    os.system("/home/pi/raspberry-remote/send ***** 1 0")

@ComlOnline
Copy link
Contributor

@DavidM42 File permissons 755 should work fine here (owner has full read write execute, all others have read and execute permissions).

The wiki does need some work, Feel free to update bits where you can :)

@madmodder123
Copy link

@DavidM42 @michaelherger
I am decent at working with scripts but I have never had to deal with environmental variables, so for some reason I cannot figure out how to get either of these scripts to work.
I try to run them by doing the following...

sudo runuser -l raspotify -c 'cd /home/pi/scripts && ./test.sh'
or
sudo runuser -l raspotify -c 'python /home/pi/scripts/test.py'

But nothing gets displayed in the terminal.
I also tried this command to see if the variables are attached to the user:
sudo runuser -u raspotify 'printenv'
But none of the relevant variables are displayed.

I feel stupid, and i'm sure it is something simple I am overlooking, help would be appreciated. :)

@michaelherger
Copy link
Contributor

Those environment variables are only exposed when one of the events is triggered. You don't run those scripts stand-alone, but tell librespot to call it when an event fires. librespot --onevent /path/to/your/script.

@madmodder123
Copy link

@michaelherger @DavidM42
Thanks, I knew it was something simple. Anyways I seem to have run into another problem.
When I start playing a song I look at the console output and it displays

PLAYER_EVENT: start
PLAYER_EVENT: stop
PLAYER_EVENT: start
PLAYER_EVENT: stop

Over and over...
Looking at my running processes it seems like librespot runs two processes and I imagine one of them is active and the other one isn't, which is causing this issue. Further proof of this is that I set the delay between each echo to 5s and like clockwork the echo messages come in pairs of start/stop.
I'm going to work with the code some more and figure out a way to only run the script once

@sashahilton00
Copy link
Member

sashahilton00 commented Mar 22, 2018

This is definitely an issue with the event system, as I'm seeing exactly the same thing when testing out #190. Will try and pinpoint what is causing it.

zteifel added a commit to zteifel/snapcast that referenced this issue Jun 26, 2019
Librespot is using onevent instead of onstart and onstop. 

librespot-org/librespot#185
zteifel added a commit to zteifel/snapcast that referenced this issue Jun 26, 2019
Update to replace onstart and onstop parameters with librespots onevent parameter.

librespot-org/librespot#185
badaix pushed a commit to badaix/snapcast that referenced this issue Sep 23, 2019
Update to replace onstart and onstop parameters with librespots onevent parameter.

librespot-org/librespot#185
@librespot-org librespot-org locked and limited conversation to collaborators Feb 23, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

7 participants