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:

Re: Python Plugin: Spotify

Post by Sjaakios »

bartbosch wrote: Sunday 28 October 2018 23:49 Hi,

I have been able to find everything, but not my code

Code: copy the code received from the spotify redirect in the query parameters
Image

is there anyone who can help me with this problem?


My error in the log:
Spoiler: show
2018-10-28 23:13:09.674 Error: (Spotify) Error occured in request for getting acces_tokens from Spotify, error code: 400, reason: Bad Request. Seems either client_id, client_secret or code is incorrect. Please note that the code received from Spotify could only be used once. Please get a new one from spotify.
So you went to this url? https://accounts.spotify.com/authorize? ... back-state

After succesful login to your spotify account it it will redirect to page http://localhost.... and you get a white page.
In the url http://localhost/?code=[USE_THIS_CODE], there should be a code parameter, use that one to enter in your domoticz parameters.
Tobbo
Posts: 13
Joined: Monday 08 October 2018 13:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Tobbo »

I managed to get it to work, but I was wondering if anyone has managed to send a spotify playlist to a chromecast device using this plugin? If so, how did you get it to work?

What I would like to do is to set up a timed event that sends and starts the selected spotify playlist on my chromecast device.

Thanks
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Python Plugin: Spotify

Post by snellejellep »

i am getting this and no devices are created, am i doing something wrong?

Code: Select all

2018-12-04 18:58:11.337 Status: (Spotify) Entering work loop.
2018-12-04 18:58:11.338 Status: (Spotify) Initialized version 0.2, author 'djj'
2018-12-04 18:58:12.013 Error: (Spotify) 'onStart' failed 'AttributeError'.
2018-12-04 18:58:12.013 Error: (Spotify) ----> Line 491 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function onStart
2018-12-04 18:58:12.013 Error: (Spotify) ----> Line 99 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function onStart
2018-12-04 18:58:12.013 Error: (Spotify) ----> Line 110 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function checkDevices
2018-12-04 18:58:12.013 Error: (Spotify) ----> Line 127 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function buildDeviceSelector
2018-12-04 18:58:12.013 Error: (Spotify) ----> Line 181 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function spotDevices
and this

Code: Select all

2018-12-04 19:03:23.933 Error: (Spotify) 'onHeartbeat' failed 'URLError'.
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 495 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function onHeartbeat
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 404 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function onHeartbeat
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 369 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function spotCurrent
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 163 in '/usr/lib/python3.5/urllib/request.py', function urlopen
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 466 in '/usr/lib/python3.5/urllib/request.py', function open
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 484 in '/usr/lib/python3.5/urllib/request.py', function _open
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 444 in '/usr/lib/python3.5/urllib/request.py', function _call_chain
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 1297 in '/usr/lib/python3.5/urllib/request.py', function https_open
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 1260 in '/usr/lib/python3.5/urllib/request.py', function do_open
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
Tobbo
Posts: 13
Joined: Monday 08 October 2018 13:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Tobbo »

snellejellep wrote: Tuesday 04 December 2018 19:00 i am getting this and no devices are created, am i doing something wrong?

Code: Select all

2018-12-04 18:58:11.337 Status: (Spotify) Entering work loop.
2018-12-04 18:58:11.338 Status: (Spotify) Initialized version 0.2, author 'djj'
2018-12-04 18:58:12.013 Error: (Spotify) 'onStart' failed 'AttributeError'.
2018-12-04 18:58:12.013 Error: (Spotify) ----> Line 491 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function onStart
2018-12-04 18:58:12.013 Error: (Spotify) ----> Line 99 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function onStart
2018-12-04 18:58:12.013 Error: (Spotify) ----> Line 110 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function checkDevices
2018-12-04 18:58:12.013 Error: (Spotify) ----> Line 127 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function buildDeviceSelector
2018-12-04 18:58:12.013 Error: (Spotify) ----> Line 181 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function spotDevices
and this

Code: Select all

2018-12-04 19:03:23.933 Error: (Spotify) 'onHeartbeat' failed 'URLError'.
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 495 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function onHeartbeat
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 404 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function onHeartbeat
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 369 in '/home/pi/domoticz/plugins/domoticz-spotify/plugin.py', function spotCurrent
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 163 in '/usr/lib/python3.5/urllib/request.py', function urlopen
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 466 in '/usr/lib/python3.5/urllib/request.py', function open
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 484 in '/usr/lib/python3.5/urllib/request.py', function _open
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 444 in '/usr/lib/python3.5/urllib/request.py', function _call_chain
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 1297 in '/usr/lib/python3.5/urllib/request.py', function https_open
2018-12-04 19:03:23.933 Error: (Spotify) ----> Line 1260 in '/usr/lib/python3.5/urllib/request.py', function do_open
For me I had to reset my spotify client secret, re-enter domoticz ip (localhost in my case), port (8080 in my case), username and password (I have a username and password), entered the new client id, client secret and the new code from the url (https://accounts.spotify.com/authorize? ... back-state) Don't forget to put your client ID where it says "Your client id".
I assume you already did follow the steps on https://github.com/DaanJJansen/domoticz-spotify.
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 »

Tobbo wrote: Tuesday 04 December 2018 16:22 I managed to get it to work, but I was wondering if anyone has managed to send a spotify playlist to a chromecast device using this plugin? If so, how did you get it to work?

What I would like to do is to set up a timed event that sends and starts the selected spotify playlist on my chromecast device.

Thanks
Do you see your chromecast as option in the newly created device selector/e.g. does it support spotify connect? If so, update your user variable with the the search string you would like to play. And create a new timer event which selects the chromecast as option on the device selector
Tobbo
Posts: 13
Joined: Monday 08 October 2018 13:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Tobbo »

Sjaakios wrote: Thursday 06 December 2018 9:29
Tobbo wrote: Tuesday 04 December 2018 16:22 I managed to get it to work, but I was wondering if anyone has managed to send a spotify playlist to a chromecast device using this plugin? If so, how did you get it to work?

What I would like to do is to set up a timed event that sends and starts the selected spotify playlist on my chromecast device.

Thanks
Do you see your chromecast as option in the newly created device selector/e.g. does it support spotify connect? If so, update your user variable with the the search string you would like to play. And create a new timer event which selects the chromecast as option on the device selector
Thanks for the reply. What you are saying is already working just fine. I can play music on any device that has already spotify started. What I want to do is to trigger spotify to start on the chromecast before I start playing music. You can not send / push a song, playlist or other from Domoticz to Spotify unless the spotify client is already running on the unit.
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 »

Ahha, i c... Cannot help you with that..
I have an onkyo receiver, which is always 'awake' for spotify connect. If I start spotify on the onkyo, it wakes up on its own.
Tobbo
Posts: 13
Joined: Monday 08 October 2018 13:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Tobbo »

Sjaakios wrote: Thursday 06 December 2018 14:42 Ahha, i c... Cannot help you with that..
I have an onkyo receiver, which is always 'awake' for spotify connect. If I start spotify on the onkyo, it wakes up on its own.
I see, might look into getting one of does then. But I did find a plugin called SpotyPi, together with PyChromecast and this plugin I might be able to start the chromecast, then send the push to start songs via Domoticz. I'll return with an answer if I manage to solve it. Thanks anyway
mrminning
Posts: 1
Joined: Friday 07 December 2018 10:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by mrminning »

Tobbo wrote: Thursday 06 December 2018 18:56 I see, might look into getting one of does then. But I did find a plugin called SpotyPi, together with PyChromecast and this plugin I might be able to start the chromecast, then send the push to start songs via Domoticz. I'll return with an answer if I manage to solve it. Thanks anyway
I am also very keen to make a "press one button to play certain Spotify playlist on Chromecast audio group of speakers". Did you make any progress?
Tobbo
Posts: 13
Joined: Monday 08 October 2018 13:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Tobbo »

mrminning wrote: Friday 07 December 2018 10:31
Tobbo wrote: Thursday 06 December 2018 18:56 I see, might look into getting one of does then. But I did find a plugin called SpotyPi, together with PyChromecast and this plugin I might be able to start the chromecast, then send the push to start songs via Domoticz. I'll return with an answer if I manage to solve it. Thanks anyway
I am also very keen to make a "press one button to play certain Spotify playlist on Chromecast audio group of speakers". Did you make any progress?
I've made little progress.
1. From Domoticz, Starting up Harmony Hub Scene "Music" = TV Start, Surround Sound System Start, Switch to HMDI Imput for Chromecast.
2. I'm able to start any playlist on Spotify on a unit which already has Spotify running as an app from Domoticz.

Me and a friend is currently working with what is available to us using
* PyChromecast https://github.com/balloob/pychromecast
* Spotipy https://spotipy.readthedocs.io/en/latest/#
* Domoticz Spotify https://github.com/DaanJJansen/domoticz-spotify

We are currently trying to solve the issue of starting a app on the Chromecast from any type of code/script file using any type of programming language in a external script file. Currently we are writing on a file in Python.

I have contacted both Spotify here in Sweden and Google senior support without any help unfortunately. Best case scenario would be to get contact with some software developer for the chromecast and ask them how to use the "push" feature that you have on any apps to launch an app manually or via script file.
User avatar
Dnpwwo
Posts: 819
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python Plugin: Spotify

Post by Dnpwwo »

@Tobbo,

There are a number of plugin developments going on in this area, all seem to be taking slightly different approaches (which is great because someone may create the perfect solution 8-) ).

My (early dev version) might help because it allows you to select Spotify from a Domoticz script or 'Source' device but I have yet to add being able to trigger a specific playlist although I understand how that could be done.

Have a look at https://github.com/dnpwwo/Domoticz-Goog ... /plugin.py, line 354 starts Spotify if you pass in 'CC32E753' which is defined on line 52 or invoke 'Audio' from Blockly or Lua you can switch to Spotify.

The Chromecast API (from Balloob) would suggest that once the application has been selected all you need is the URL of the media (or playlist)

Code: Select all

    def play_media(self, url, content_type, title=None, thumb=None,
                   current_time=0, autoplay=True,
                   stream_type=STREAM_TYPE_BUFFERED,
                   metadata=None, subtitles=None, subtitles_lang='en-US',
                   subtitles_mime='text/vtt', subtitle_id=1):
I plan to match this with the 'Trigger' script command if I can. I'm assuming the URL can be found be triggering the URL through the Spotify App itself then looking in the 'Messages.log' to see what the URL actually is (TBC).
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Tobbo
Posts: 13
Joined: Monday 08 October 2018 13:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Tobbo »

Dnpwwo wrote: Wednesday 26 December 2018 12:25 @Tobbo,

There are a number of plugin developments going on in this area, all seem to be taking slightly different approaches (which is great because someone may create the perfect solution 8-) ).

My (early dev version) might help because it allows you to select Spotify from a Domoticz script or 'Source' device but I have yet to add being able to trigger a specific playlist although I understand how that could be done.

Have a look at https://github.com/dnpwwo/Domoticz-Goog ... /plugin.py, line 354 starts Spotify if you pass in 'CC32E753' which is defined on line 52 or invoke 'Audio' from Blockly or Lua you can switch to Spotify.

The Chromecast API (from Balloob) would suggest that once the application has been selected all you need is the URL of the media (or playlist)

Code: Select all

    def play_media(self, url, content_type, title=None, thumb=None,
                   current_time=0, autoplay=True,
                   stream_type=STREAM_TYPE_BUFFERED,
                   metadata=None, subtitles=None, subtitles_lang='en-US',
                   subtitles_mime='text/vtt', subtitle_id=1):
I plan to match this with the 'Trigger' script command if I can. I'm assuming the URL can be found be triggering the URL through the Spotify App itself then looking in the 'Messages.log' to see what the URL actually is (TBC).
I'm still not sure how to launch spotify from an external source, like domoticz or any scriptfile. That is were the core of the problem currently resides. I need to start spotify somehow on the chromecast before I can send music to it.
User avatar
Dnpwwo
Posts: 819
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python Plugin: Spotify

Post by Dnpwwo »

@Tobbo,

The same Chromecast object has a start_app API for that. Try something like:

Code: Select all

your_chromecast_object.start_app('CC32E753') # yep, Google uses magic codes for apps
or have a look at line 376 in the most recent version (1.2.1) of my plugin. That is linked to a Domoticz selector device that allows you to switch between the standard apps.

Not extensively tested but worked fine for an idle device, I don't know if you can send the play_media command right after or if you need to wait.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
assenzuid
Posts: 135
Joined: Friday 13 November 2015 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands, Emmen Area
Contact:

Re: Python Plugin: Spotify

Post by assenzuid »

Get this errpr

Code: Select all

Error calling 'http://localhost:8081/json.htm?vvalue=&vname=Spotify-refresh_token&vtype=2&param=saveuservariable&type=command'
Ewaldharmsen
Posts: 130
Joined: Tuesday 07 February 2017 15:00
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Ewaldharmsen »

Dnpwwo wrote: Wednesday 26 December 2018 12:25 @Tobbo,

There are a number of plugin developments going on in this area, all seem to be taking slightly different approaches (which is great because someone may create the perfect solution 8-) ).

My (early dev version) might help because it allows you to select Spotify from a Domoticz script or 'Source' device but I have yet to add being able to trigger a specific playlist although I understand how that could be done.

Have a look at https://github.com/dnpwwo/Domoticz-Goog ... /plugin.py, line 354 starts Spotify if you pass in 'CC32E753' which is defined on line 52 or invoke 'Audio' from Blockly or Lua you can switch to Spotify.

The Chromecast API (from Balloob) would suggest that once the application has been selected all you need is the URL of the media (or playlist)

Code: Select all

    def play_media(self, url, content_type, title=None, thumb=None,
                   current_time=0, autoplay=True,
                   stream_type=STREAM_TYPE_BUFFERED,
                   metadata=None, subtitles=None, subtitles_lang='en-US',
                   subtitles_mime='text/vtt', subtitle_id=1):
I plan to match this with the 'Trigger' script command if I can. I'm assuming the URL can be found be triggering the URL through the Spotify App itself then looking in the 'Messages.log' to see what the URL actually is (TBC).
Hi, you know I have also created a plugin like this?
https://github.com/Tsjippy/ChromecastPlugin

Maybe we can join forces?
Tobbo
Posts: 13
Joined: Monday 08 October 2018 13:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by Tobbo »

Dnpwwo wrote: Saturday 29 December 2018 23:46 @Tobbo,

The same Chromecast object has a start_app API for that. Try something like:

Code: Select all

your_chromecast_object.start_app('CC32E753') # yep, Google uses magic codes for apps
or have a look at line 376 in the most recent version (1.2.1) of my plugin. That is linked to a Domoticz selector device that allows you to switch between the standard apps.

Not extensively tested but worked fine for an idle device, I don't know if you can send the play_media command right after or if you need to wait.
Hey again, thanks for the response but all I get when running this script on my chromecast object is

Code: Select all

chromecasts.launch_app('CC32E753')
AttributeError: 'Chromecast' object has no attribute 'launch_app'
also tried

Code: Select all

start_app('CC32E753')
AttributeError: 'SpotifyController' object has no attribute 'start_app'
Ewaldharmsen wrote: Sunday 30 December 2018 13:38
Dnpwwo wrote: Wednesday 26 December 2018 12:25 @Tobbo,

There are a number of plugin developments going on in this area, all seem to be taking slightly different approaches (which is great because someone may create the perfect solution 8-) ).

My (early dev version) might help because it allows you to select Spotify from a Domoticz script or 'Source' device but I have yet to add being able to trigger a specific playlist although I understand how that could be done.

Have a look at https://github.com/dnpwwo/Domoticz-Goog ... /plugin.py, line 354 starts Spotify if you pass in 'CC32E753' which is defined on line 52 or invoke 'Audio' from Blockly or Lua you can switch to Spotify.

The Chromecast API (from Balloob) would suggest that once the application has been selected all you need is the URL of the media (or playlist)

Code: Select all

    def play_media(self, url, content_type, title=None, thumb=None,
                   current_time=0, autoplay=True,
                   stream_type=STREAM_TYPE_BUFFERED,
                   metadata=None, subtitles=None, subtitles_lang='en-US',
                   subtitles_mime='text/vtt', subtitle_id=1):
I plan to match this with the 'Trigger' script command if I can. I'm assuming the URL can be found be triggering the URL through the Spotify App itself then looking in the 'Messages.log' to see what the URL actually is (TBC).
Hi, you know I have also created a plugin like this?
https://github.com/Tsjippy/ChromecastPlugin

Maybe we can join forces?
Surething, I did not know about your plugin, but I'm trying out anything that's out there right now. Nice to see that there is more people working on a solution to this.

Edit: @Dnpwwo
Also I can't seem to get your plugin to work properly, I did follow the instructions you've listed for in the installation section and also took note of the domo and python versions required. Devices won't show up in domo unfortunatly.
PeterFleur
Posts: 32
Joined: Sunday 08 March 2015 13:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4739
Contact:

Re: Python Plugin: Spotify

Post by PeterFleur »

assenzuid wrote: Sunday 30 December 2018 0:02 Get this errpr

Code: Select all

Error calling 'http://localhost:8081/json.htm?vvalue=&vname=Spotify-refresh_token&vtype=2&param=saveuservariable&type=command'
I have exactly the same error.
It looks like the string of the Code part is too long for the user variables. So it cannot be stored there

Anybody resolved this?

Peter
RaspberryPI
ZWave
RFXtrx433E
GreenSmart01
Posts: 22
Joined: Sunday 01 January 2017 17:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10856
Location: Zeeland
Contact:

Re: Python Plugin: Spotify

Post by GreenSmart01 »

Hi,

I have tried to add this plugin to my domoticz installation on my rapberry pi. If I add this hardware to domoticz and fill in the data, and save it, domoticz will crash. I have been reasonably patient. but the webpage domoticz is no longer available. Only when I restart the raspberrypi and remove the folder cd ~ / domoticz / plugins / spotify does domoticz work.

how can I solve this :) ?
PeterFleur
Posts: 32
Joined: Sunday 08 March 2015 13:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4739
Contact:

Re: Python Plugin: Spotify

Post by PeterFleur »

I had the same but when I restarted domoticz the plugin worked. So you don't have to remove the plugin.
But it looks like the code Spotify is giving is too long for the user variables in Domoticz

Peter

Sent from my SM-G930F using Tapatalk

RaspberryPI
ZWave
RFXtrx433E
renerene
Posts: 316
Joined: Wednesday 03 August 2016 11:36
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin: Spotify

Post by renerene »

what is the status 2019?

Can I use this plugin to make a button (dashticz, alexa, harmony hub) that will start my playlist on my stereo, with th click of one dedicated button?
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest