Python Plugin: Spotify

Python and python framework

Moderator: leecollings

Sjaakios
Posts: 37
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Python Plugin: Spotify

Post by Sjaakios »

This plugin will use the spotify API's to start playback on your spotify connected device. A spotify premium account is required!

Having some time between project, i've decided to learn some python... So i'm far from a professional so it can still be buggy, let me know if you run into any issues. I've tested this having domoticz running on my Synology Nas, running version 3.8153.

Code + installation steps can be found here: https://github.com/DaanJJansen/domoticz-spotify

Let me know what you think.

ps. if anybody knows a better solution for the one off manual action to get the authorisation code from Spotify, i'm all ears.
User avatar
Innovator
Posts: 16
Joined: Tuesday 20 February 2018 12:33
Target OS: NAS (Synology & others)
Domoticz version: 8924
Location: Amsterdam
Contact:

Re: Python Plugin: Spotify

Post by Innovator »

Thank you for developing this plugin. I tried to get it started on my Synology DS918 + with Domoticz version 4.9700 today.

Until now no device has the following output:

Error: (Spotify) Error calling 'http: // localhost: 8080 / json.htm? Param = getuservariables & type = command'
Error: (Spotify) Can not read the uservariable holding the persistent variables.

Maybe I made a mistake but I think everything is correctly filled in at Spotify including http: // localhost
Synology DS918+ /DS412+
ASUS BRT-AC828, RT-AC86U, RT-AC68U
Sjaakios
Posts: 37
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Sjaakios »

This error is about not able to reach your domoticz system, it's trying to fetch some user variables. Is this the correct url + port to reach domoticz?
mozo78
Posts: 22
Joined: Friday 09 June 2017 6:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by mozo78 »

Hi,

Now I could add it, and a new switch appeared. The value of the switch is changing, it shows the current spotify device (phone, or PC). Can you help me how to use the user variables? That is not clear for me.
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Python Plugin: Spotify

Post by Egregius »

Hi, I'm having troubles retrieving the code. After entering the code I get this in the logfile:

Code: Select all

Error: (Spotify) Bad request to spotify, code entered in hardware parameters could one be used once. Please get a new one
Any ideas?
Sjaakios
Posts: 37
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Sjaakios »

mozo78 wrote: Wednesday 04 July 2018 0:16 Hi,

Now I could add it, and a new switch appeared. The value of the switch is changing, it shows the current spotify device (phone, or PC). Can you help me how to use the user variables? That is not clear for me.
You could update the user variable with your search string + type of search. Where type of search could be 'artist', 'playlist', 'track', 'album' and the search string is what you want to search.

E.g. update your user variable with 'artist coldplay'. After update, press on the new switch the spotify device (in your case phone or PC) on which you want to listen to coldplay.
Playback should start.
Sjaakios
Posts: 37
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Sjaakios »

Egregius wrote: Wednesday 04 July 2018 7:44 Hi, I'm having troubles retrieving the code. After entering the code I get this in the logfile:

Code: Select all

Error: (Spotify) Bad request to spotify, code entered in hardware parameters could one be used once. Please get a new one
Any ideas?
Hmmmmm... The code can only be used once to retrieve an access token. Did something else went wrong with the plugin before? Try getting a new code from spotify and try again.

To validate, spotify redirects you to http://localhost/?code=AQ......Cusmbo right? You've entered 'AQ......Cusmbo' in the code parameter?

ps. corrected the spelling mistake in error msg.....
Error: (Spotify) Bad request to spotify, code entered in hardware parameters could one only be used once. Please get a new one
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Python Plugin: Spotify

Post by Egregius »

Yes, I'm redirected to (just changed some of the numbers)

Code: Select all

http://localhost/?code=AQDDgWQ2tTz1ErSgQ_jkty4Viz7ZA7cpTKV01KRrZW5vdLd-CZ01uKPeESo5OJE36i1hMYPAhvhuCjtTY31Ukr3OUt_IzWKUMiDARF1UmHa2b8RnXjLJFkIIiJ5k9r3Uv11AcVofaWbxDoFFy-EwZ2gXRY6m49p7j3PPhIV_tz-2-jDzpXSicy_29nJVE_vIaua-Ydut8nYS-zvws9jkYalM0PNMrvqbjkX1EpPAj3werhkeddEbN07o1Wg
and then I past the 251 characters as code in the settings page

Code: Select all

AQDDgWQ2tTz1ErSgQ_jkty4Viz7ZA7cpTKV01KRrZW5vdLd-CZ01uKPeESo5OJE36i1hMYPAhvhuCjtTY31Ukr3OUt_IzWKUMiDARF1UmHa2b8RnXjLJFkIIiJ5k9r3Uv11AcVofaWbxDoFFy-EwZ2gXRY6m49p7j3PPhIV_tz-2-jDzpXSicy_29nJVE_vIaua-Ydut8nYS-zvws9jkYalM0PNMrvqbjkX1EpPAj3werhkeddEbN07o1Wg
I didn't used the plugin yet, just came across this topic ;)
Sjaakios
Posts: 37
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Sjaakios »

And you tried getting a new code, and enter this accordingly in the plugin?

Meant with using the plugin, it ran befor (e.g. already a call made to spotify using the entered code, making the code invallid as it can only be used once) :-)
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Python Plugin: Spotify

Post by Egregius »

Yes, already tried 5 codes. The plugin never worked, it instantly drops the error in the logfile.
Sjaakios
Posts: 37
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Sjaakios »

Hmmm, ok... weird

I've updated the script to provide some more debug information to get a better clue on what is going on.
The request that is failing is making a post call to spotify with your client_id, client_secret and the code. I've made the error more precise so we can see what code spotify is returning. Error code 400 means the client_id, client_secret or code is incorrect.

So if you would, please update your code with the latest version on GIT and PM me the debug log (as it will contain your client_id and secret).
eddieb
Posts: 279
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Python Plugin: Spotify

Post by eddieb »

Hmm,

just installed the spotify plugin ...
The handling on the api went as expected.

I get a "Cannot read the uservariable holding the persistent variables" error in the logging right after (re)starting the pluging from the hardware menu
It does not give any devices

Any seggestions ?

Eddie
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
Sjaakios
Posts: 37
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Sjaakios »

This error is about not being able to read the user variables from domoticz. It uses url + port set in hardware parameters.
In your log, is there also a line with:

Code: Select all

Error calling 'http://xxxxx/json.htm?type=command&param=getuservariables'
Can you validate from the machine running domoticz, that you able to make this call?
eddieb
Posts: 279
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Python Plugin: Spotify

Post by eddieb »

Hi,

I am running domoticz on Syno .. http://IP:8084/
I will try to run that command later today.

Eddie
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
eddieb
Posts: 279
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Python Plugin: Spotify

Post by eddieb »

root@diskstation:~# curl -v -L http://127.0.0.1:8084/json.htm?type=com ... rvariables
[1] 31159
root@diskstation:~# > GET /json.htm?type=command HTTP/1.1
> Host: 127.0.0.1:8084
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Length: 24
< Content-Type: application/json;charset=UTF-8
< Cache-Control: no-cache
< Pragma: no-cache
< Access-Control-Allow-Origin: *
<
{
"status" : "ERR"
}

suggestions ????
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
Sjaakios
Posts: 37
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Sjaakios »

ahhh do you have user authentication enabled for domoticz?
eddieb
Posts: 279
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Python Plugin: Spotify

Post by eddieb »

No, not from 127.0.0.1 ...
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
Sjaakios
Posts: 37
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Sjaakios »

and changed port in spotify hardware parameters to 8084?
eddieb
Posts: 279
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Python Plugin: Spotify

Post by eddieb »

As you see ...
Screen Shot 2018-07-05 at 12.25.42.png
Screen Shot 2018-07-05 at 12.25.42.png (78.07 KiB) Viewed 12682 times
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
Sjaakios
Posts: 37
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Sjaakios »

the error from your curl command is because request is incomplete...., somehow stripps the last query parameter. Try:
curl -v -L "http://127.0.0.1:8084/json.htm?type=com ... rvariables"

When i execute this on my Synology, i get a list of variables
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest