fondberg / spotcast

Home assistant custom component to start Spotify playback on an idle chromecast device as well as control spotify connect devices
Apache License 2.0
672 stars 96 forks source link

Cannot play content on Google Nest, but can browse folders and playlists #396

Closed pmkruyen closed 1 year ago

pmkruyen commented 1 year ago

Bug Ticket

Describe the bug

I cannot play Spotify content on a Google Nest player, but can browse (see) folders and playlists. I am unsure if this is caused by Spotcast, but that is my first guess.

I can load Spotify song and stream them through Music Assistant.

Any help is appreciated. Let me know if more info is needed. Thanks!

Troubleshooting

Make sure to validate all the elements before submitting the ticket (Exception to the steps marked as optional)

Environment

Configuration

# please remove any sensitive information like cookies and token keys
<insert configuration here>

Service Call

If relevant, provide a yaml of the service call or explain the action taken to replicate the issue.

<insert the yaml of the service call here>

Logs


Error executing service: <ServiceCall spotcast.start (c:01H5SY6B72S8GHYCBRXW4B479H): entity_id=media_player.nest_mini, uri=spotify:playlist:37i9dQZF1DXanDkFGa4syx, shuffle=False, offset=0, ignore_fully_played=False, start_volume=101, force_playback=False, repeat=off, limit=20, random_song=False>

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/core.py", line 1983, in catch_exceptions await coro_or_task File "/usr/src/homeassistant/homeassistant/core.py", line 2013, in _execute_service return await self._hass.async_add_executor_job( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/spotcast/init.py", line 221, in start_casting spotify_device_id = spotcast_controller.get_spotify_device_id( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/spotcast/spotcast_controller.py", line 244, in get_spotify_device_id spotify_cast_device = SpotifyCastDevice( ^^^^^^^^^^^^^^^^^^ File "/config/custom_components/spotcast/spotcast_controller.py", line 62, in init self.castDevice = self.getChromecastDevice(device_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/spotcast/spotcast_controller.py", line 88, in getChromecastDevice raise HomeAssistantError( homeassistant.exceptions.HomeAssistantError: Could not find device with name Nest mini

Additional context

pmkruyen commented 1 year ago

Found the issue after having found the logs.. the cast player was named differently in HA & the Google Home app 💃🏽

pmkruyen commented 1 year ago

Sorry, it is very unstable. I have not found out what the pattern is.

Logger: pychromecast.socket_client
Source: /usr/local/lib/python3.11/site-packages/pychromecast/socket_client.py:398 
First occurred: 18:01:14 (28 occurrences) 
Last logged: 18:08:00

[kamer(192.168.1.227):8009] Failed to connect to service ServiceInfo(type='mdns', data='Google-Nest-Mini-8194dfa89cb2a53a450f4f628098a18f._googlecast._tcp.local.'), retrying in 5.0s
[(192.168.1.227):8009] Failed to connect to service ServiceInfo(type='mdns', data='Google-Nest-Mini-8194dfa89cb2a53a450f4f628098a18f._googlecast._tcp.local.'), retrying in 5.0s

Source: custom_components/spotcast/spotify_controller.py:104 Integration: Spotcast (documentation, issues) First occurred: 17:59:43 (18 occurrences) Last logged: 18:01:05

Error executing service: <ServiceCall spotcast.start (c:01H5T0GRFT22J2J1RSB9F257VH): entity_id=media_player.kamer, uri=spotify:track:0QtHEI31mISpkS4T4rW4Nt, start_volume=101, random_song=False, force_playback=False, shuffle=False, ignore_fully_played=False, repeat=off, limit=20, offset=0> Error executing service: <ServiceCall spotcast.start (c:01H5T0GSEFC9YRAD4P0VR3FKAQ): entity_id=media_player. kamer, uri=spotify:playlist:08YOHsMJtNnrwuX8k9dNBu, start_volume=101, random_song=False, force_playback=False, shuffle=False, ignore_fully_played=False, repeat=off, limit=20, offset=0> Error executing service: <ServiceCall spotcast.start (c:01H5T0H0CTRP3Z8ZB2E9GDVH2B): entity_id=media_player.kamer, uri=spotify:track:1Kul5OlZRS4xcphQ1XX58H, start_volume=101, random_song=False, force_playback=False, shuffle=False, ignore_fully_played=False, repeat=off, limit=20, offset=0> Error executing service: <ServiceCall spotcast.start (c:01H5T0H1F35F0Q5XTN5C6VHX96): entity_id=media_player.kamer, uri=spotify:track:1Kul5OlZRS4xcphQ1XX58H, start_volume=101, random_song=False, force_playback=False, shuffle=False, ignore_fully_played=False, repeat=off, limit=20, offset=0> Error executing service: <ServiceCall spotcast.start (c:01H5T0H3M7TTDV2TTFFVX3PES8): entity_id=media_player.kamer, uri=spotify:playlist:08YOHsMJtNnrwuX8k9dNBu, start_volume=101, random_song=False, force_playback=False, shuffle=False, ignore_fully_played=False, repeat=off, limit=20, offset=0> Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/core.py", line 1983, in catch_exceptions await coro_or_task File "/usr/src/homeassistant/homeassistant/core.py", line 2013, in _execute_service return await self._hass.async_add_executor_job( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/spotcast/init.py", line 221, in start_casting spotify_device_id = spotcast_controller.get_spotify_device_id( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/spotcast/spotcast_controller.py", line 250, in get_spotify_device_id spotify_cast_device.startSpotifyController(access_token, expires) File "/config/custom_components/spotcast/spotcast_controller.py", line 95, in startSpotifyController sp.launch_app() File "/config/custom_components/spotcast/spotify_controller.py", line 104, in launch_app raise LaunchError( pychromecast.error.LaunchError: Timeout when waiting for status response from Spotify app

fcusson commented 1 year ago

@pmkruyen The problem is related to pychromecast unable to locate the device. Did you update the name of the device in home assistant to match google home

pmkruyen commented 1 year ago

Yes I did. It’s called Room-children now. After resetting it’s name in the Google Cast integration and after restarting HA, it works for a few playlists, but after trying to load the 5th or so playlist, nothing happens.

~It looks like the error log is different now?~

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1983, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 2013, in _execute_service
    return await self._hass.async_add_executor_job(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/spotcast/__init__.py", line 221, in start_casting
    spotify_device_id = spotcast_controller.get_spotify_device_id(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/spotcast/spotcast_controller.py", line 250, in get_spotify_device_id
    spotify_cast_device.startSpotifyController(access_token, expires)
  File "/config/custom_components/spotcast/spotcast_controller.py", line 95, in startSpotifyController
    sp.launch_app()
  File "/config/custom_components/spotcast/spotify_controller.py", line 104, in launch_app
    raise LaunchError(
pychromecast.error.LaunchError: Timeout when waiting for status response from Spotify app
pmkruyen commented 1 year ago

I restarted HA a couple of times. Everything seems to work now (tried over 20 playlists), except for 1 playlist (also having caused the previous issues above?).

It’s: uri=spotify:playlist:08YOHsMJtNnrwuX8k9dNBu. Ironically, the playlist that I needed the most. It contains stories for children, but is forbidden to listen to 😂.

I get this error, where I masked the device id (string of characters).

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/spotipy/client.py", line 271, in _internal_call
    response.raise_for_status()
  File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.spotify.com/v1/me/player/play?device_id=##################

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1983, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 2013, in _execute_service
    return await self._hass.async_add_executor_job(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/spotcast/__init__.py", line 256, in start_casting
    spotcast_controller.play(
  File "/config/custom_components/spotcast/spotcast_controller.py", line 323, in play
    client.start_playback(**kwargs)
  File "/usr/local/lib/python3.11/site-packages/spotipy/client.py", line 1821, in start_playback
    return self._put(
           ^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/spotipy/client.py", line 338, in _put
    return self._internal_call("PUT", url, payload, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/spotipy/client.py", line 293, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/player/play?device_id= ##################:
 Player command failed: Restriction violated, reason: UNKNOWN

Why is this playlist forbidden?

pmkruyen commented 1 year ago

Ok, I figured out the problem with this playlist is the first 5 songs. These songs aren’t shown if I open the playlist in the Spotify app on my cell phone.

Is this a sync issue?

pmkruyen commented 1 year ago

I have still issues with playing songs after a while. As this is unrelated to the first issue (naming of device) I start a new issue