home-assistant-libs / pychromecast

Library for Python 3 to communicate with the Google Chromecast.
MIT License
2.52k stars 378 forks source link

How to work with spotify #769

Open Tsjippy opened 9 months ago

Tsjippy commented 9 months ago

Hello,

I have been using this library in 2020, and now I wanted to start again, but the spotify controller is gone. How do I work with spotify now?

I use pychromecast with domoticz, see my code here: https://github.com/Tsjippy/ChromecastPlugin

stackErr-NameNotResolved commented 9 months ago

Looks like Spotify support was removed in #535 because it was hosted by the spotcast project.

Unfortunately the spotcast project is not maintained anymore https://camo.githubusercontent.com/a9058f39b5fc70fadc797d9b38617c1fc7c6c3d8567744c67e247d0c341d047c/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323032322e737667

Tsjippy commented 9 months ago

So can we add the spotify controller again?

stackErr-NameNotResolved commented 9 months ago

I tried to hack in the latest available Spotify controller (release 9.2.0) in the 13.0.8 release.

When launching Spotify on the Google Nest Hub second gen, the Spotify UI splash screen keeps hanging and the launch app will timeout. This was done by using a "normal" Spotify token.

It looks like the 9.2.0 Spotify example is dependant on the spotify_token lib.. This lib will generate a "more permissions" token. However this lib seems to be broken for some time...

Currently I do not know if my attempt failed because i did something wrong, the old code does not integrate anymore or the token that I did use has not enough rights. I expect that the token might be the issue but I do not have the knowledge to debug that unfortunately.

Tsjippy commented 9 months ago

This is how you get spotify.

import spotipy
from spotipy.oauth2 import SpotifyOAuth

clientid        = 'SOME ID'
clientsecret    = 'SOME SECRET'

scope = "app-remote-control,playlist-modify-private,playlist-read-private,user-library-read,user-modify-playback-state,user-read-currently-playing,user-read-playback-position,user-read-playback-state"

oauth=SpotifyOAuth(scope=scope,client_id=clientid,client_secret=clientsecret,redirect_uri='http://localhost:9999',open_browser=False)
oauth.get_access_token()['access_token']

But apart from that I don't know how to start Spotify on Chromecast

kjstultz commented 8 months ago

Landed here after working on this same problem for a while, spotipy won't recognize the google assistant device if it's not already playing something.