Python Plugin: Spotify

Python and python framework
Sjaakios
Posts: 20
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Python Plugin: Spotify

Post by Sjaakios » Friday 29 June 2018 9:53

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: 15
Joined: Tuesday 20 February 2018 13:33
Target OS: NAS (Synology & others)
Domoticz version: 8924
Location: Amsterdam
Contact:

Re: Python Plugin: Spotify

Post by Innovator » Friday 29 June 2018 20:29

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: 20
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Sjaakios » Friday 29 June 2018 23:17

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: 12
Joined: Friday 09 June 2017 6:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by mozo78 » 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.

User avatar
Egregius
Posts: 2715
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Python Plugin: Spotify

Post by Egregius » 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?

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

Re: Python Plugin: Spotify

Post by Sjaakios » Wednesday 04 July 2018 9:30

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: 20
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Sjaakios » Wednesday 04 July 2018 9:35

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: 2715
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Python Plugin: Spotify

Post by Egregius » Wednesday 04 July 2018 11:28

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: 20
Joined: Saturday 04 June 2016 23:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Sjaakios » Wednesday 04 July 2018 12:36

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: 2715
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Python Plugin: Spotify

Post by Egregius » Wednesday 04 July 2018 14:49

Yes, already tried 5 codes. The plugin never worked, it instantly drops the error in the logfile.

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

Re: Python Plugin: Spotify

Post by Sjaakios » Wednesday 04 July 2018 15:12

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: 12
Joined: Wednesday 04 July 2018 7:48
Target OS: NAS (Synology & others)
Domoticz version:
Location: NL
Contact:

Re: Python Plugin: Spotify

Post by eddieb » Wednesday 04 July 2018 18:46

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

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

Re: Python Plugin: Spotify

Post by Sjaakios » Thursday 05 July 2018 10:09

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: 12
Joined: Wednesday 04 July 2018 7:48
Target OS: NAS (Synology & others)
Domoticz version:
Location: NL
Contact:

Re: Python Plugin: Spotify

Post by eddieb » Thursday 05 July 2018 10:20

Hi,

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

Eddie

eddieb
Posts: 12
Joined: Wednesday 04 July 2018 7:48
Target OS: NAS (Synology & others)
Domoticz version:
Location: NL
Contact:

Re: Python Plugin: Spotify

Post by eddieb » Thursday 05 July 2018 12:10

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 ????

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

Re: Python Plugin: Spotify

Post by Sjaakios » Thursday 05 July 2018 12:19

ahhh do you have user authentication enabled for domoticz?

eddieb
Posts: 12
Joined: Wednesday 04 July 2018 7:48
Target OS: NAS (Synology & others)
Domoticz version:
Location: NL
Contact:

Re: Python Plugin: Spotify

Post by eddieb » Thursday 05 July 2018 12:22

No, not from 127.0.0.1 ...

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

Re: Python Plugin: Spotify

Post by Sjaakios » Thursday 05 July 2018 12:22

and changed port in spotify hardware parameters to 8084?

eddieb
Posts: 12
Joined: Wednesday 04 July 2018 7:48
Target OS: NAS (Synology & others)
Domoticz version:
Location: NL
Contact:

Re: Python Plugin: Spotify

Post by eddieb » Thursday 05 July 2018 12:27

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 947 times

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

Re: Python Plugin: Spotify

Post by Sjaakios » Thursday 05 July 2018 12:32

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