Youtube Music - Media Browser

Also getting the same issue with the “unknown error” message.

Using latest version of yTube Music Player from HACS and below HA setup.
Home Assistant 2023.1.7
Supervisor 2023.01.1
Operating System 9.4
Frontend 20230110.0 - latest

Receiving these messages within the logs…

1 - async_check_api failed
2 - Full log below…

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py”, line 27, in _handle_async_response
await func(hass, connection, msg)
File “/usr/src/homeassistant/homeassistant/components/media_player/init.py”, line 1225, in websocket_browse_media
payload = await player.async_browse_media(media_content_type, media_content_id)
File “/config/custom_components/ytube_music_player/media_player.py”, line 1979, in async_browse_media
response = await build_item_response(self, payload)
File “/config/custom_components/ytube_music_player/browse_media.py”, line 67, in build_item_response
media = await hass.async_add_executor_job(media_library.get_library_playlists, BROWSER_LIMIT)
File “/usr/local/lib/python3.10/concurrent/futures/thread.py”, line 58, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/local/lib/python3.10/site-packages/ytmusicapi/mixins/library.py”, line 27, in get_library_playlists
response = self._send_request(endpoint, body)
File “/usr/local/lib/python3.10/site-packages/ytmusicapi/ytmusic.py”, line 144, in _send_request
raise Exception(message + error)
Exception: Server returned HTTP 401: Unauthorized.
You must be signed in to perform this operation.

Hi, how do you get the player window so big?
what kind of card is that?
I use the custom:mini-media-player but the album image is always cropped.

Hi,
with card_mod.

    style: |
      ha-card {
        {% if is_state('media_player.ytube_music_player', 'playing') %}
          height: 350px;
        {% else %}
          height: 180px;
        {% endif %}         
      }
1 Like

I’m having the same problem, no playlists, but, “moods” seem to work fine.
So the integration seems connected to YT-Music, just not getting the personnal data. “PL’s”.
Did you manage to fix it?
How?

Has anyone found a fix yet?

Really strange that it is still working for me.
Maybe updating the ytubemusic API will fix it … but there are some breaking changes so the fix needs some attention… unfortunately I have very little time to fix it at the moment :confused:
Jkw

Edit: ok issue now also happening for me … so I’ve bumped the version up and it works now for me … can you please check?

2 Likes

All working for me again, after installing updates and re-copying cookie text as per setup instructions.

1 Like

that’s fun, I can’t find any request called with filter ‘Browse’. If I fetch a different POST to youtube I get a cookie which doesn’t work.

I was also trying to let the Google Assistant play music by sending the command ‘Play music’ which results in an ‘I don’t understand’…

1 Like

I encountered the same issue. Does anyone know how to get it fixed?

Hey, I need help!
I’m trying to install this and I’m getting stuck on adding integration (after I successfully downloaded the repo) with loader saying “Please wait, starting configuration wizard for yTubeMediaPlayer”:

Then it fails with this: https://i.imgur.com/7jq6sqz.png

Flow POST request looks to be timing out after 2 minutes: https://i.imgur.com/N0Hrog0.png

Alright, fixed it by hard resetting the raspi.

So your YouTube Music is working perfectly fine?

Seems to be, but I only tested it for a short time - I won’t be using this in the end, since the host media player device can’t skip tracks (like it can if the playlist was cast to it).

Hi, I tried to get ytube music player to work with eather Airfoil (Airplay Receiver) on my Mac and hifiberry an Airplay Receiver on an Raspberry Pi. It did not work. Is it because ytube music player does not support Airplay or is it because of my setup?

Hi, Ytube Player will send a “play this url” to the receiver. This works on mpd and on Google devices but it looks as if this is not supported by many other Mediaplayers out there.
Cheers

1 Like

What has happened to the latest version?
Stopped working asking for a token. Field for cookie taken away in options under config?

Hi, this is a non-beta of the recent oAuth changes. I guess this way more people will see and use it.
To change from header to Oauth simply remove the Integration entries and create new items. Once it is set up this way it should auto refresh the token and never expire anymore

What are the ‘Integration entries’ I need to remove?

Update: Fixed
Was easier than thought. Just pasted the url provided from new entry into my browser - authorised by google - submitted and saved

I upgraded to the latest beta release and loading again the integration all was ok, but suddenly i have this about playlists, sources and speakers:

Schermata 2023-11-22 alle 20.49.24

It’s always on ‘loading’… what happened?

I think I found a work-around for playing youtube music through Sonos. Based on this post: Youtube Music Multi Room Audio with Owntone (Supports both Airplay and chromecasts)

I have set up the hassio-addon-owntone (beta version as the older ‘stable’ one didn’t want to start up its web service) and added the pipe which will be used by OwnTone integration to stream the music from youtube_music_player into:
</s> <s>cd ~/media/music </s> <s>mkfifo librespot-java </s> <s>mkfifo librespot-java.metadata</s> <s> (seems to be not required and even not working as good as the source “Default (no pipe)”)

Then I installed the OwnTone HA integration which automatically detects and connects to the OwnTone Server addon.
OwnTone can now be selected as playback device in youtube_music_player (I needed to restart HA for it to appear) redirecting the stream to that pipe, which will then automatically be picked up by the OwnTone Server addon and start playing.

In the original post I used as as a reference, they would then call an automation to select an output on the OwnTone Server based on room precense. But in my case my Sonos is in a different subnet and I didn’t find immediately how to make OwnTone detect my Sonos. And also the OwnTone Server seems to detect a few other output devices like my amp and kodi instances, but then fails on them with connection timeouts in the logging, not giving me much confidence that I will get it working easily that way.

But OwnTone also supports streaming and exposes http://SERVER_ADDRESS:3689/stream.mp3 for any device to stream from OwnTone.
I currently have only one Sonos device so I just created an automation rule to automatically start streaming OwnTone to my Sonos whenever OwnTone Server would switch to ‘playing’ state:

alias: Play OwnTone stream on Sonos
trigger:
  - platform: state
    entity_id:
      - media_player.owntone_server
    to: playing
action:
  - service: media_player.play_media
    data:
      media_content_type: music
      media_content_id: http://[server IP]:3689/stream.mp3
    target:
      entity_id: media_player.sonos
mode: single

When I now start a playlist on youtube_music_player with OwnTone Server as playback device, OwnTone Server will start playing the stream, hence serving/filling the stream.mp3 file. The automation will kick in and will start playing the stream on my Sonos device. This works fine, with only a few seconds delay between starting a song and actually hearing the song through the speaker.

BUT…
for some reason youtube_music_player only wants to play 1 song from a playlist and then turns itself off at the end of the song.
Also when skipping to the next song manually, it shows the metadata of the next song, but then pauses playback. I have to manually press play again to start that next song. Even when skipping within a song: the progress bar jumps to the position I want to skip to, but then playback pauses and I have to press play again.
In HA logging I see this when skipping to the next track:

2023-12-06 11:21:05.723 ERROR (MainThread) [custom_components.ytube_music_player.media_player] - Playing track nr 1 / 25
2023-12-06 11:21:05.723 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_get_url
2023-12-06 11:21:05.723 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_check_api [E]
2023-12-06 11:21:05.723 ERROR (MainThread) [custom_components.ytube_music_player.media_player] - try to find URL on our own
2023-12-06 11:21:05.886 ERROR (MainThread) [custom_components.ytube_music_player.media_player] - self decoded URL via cipher
2023-12-06 11:21:05.995 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [E] async_get_url
2023-12-06 11:21:05.996 ERROR (MainThread) [custom_components.ytube_music_player.media_player] - forwarding url to player media_player.owntone_server
2023-12-06 11:21:05.996 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_update_extra_sensor [E]
2023-12-06 11:21:06.530 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: off -> paused ... not playing [E]
2023-12-06 11:21:06.530 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: off -> paused [E]
2023-12-06 11:21:06.533 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: paused -> paused ... not playing [E]
2023-12-06 11:21:06.533 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: paused -> paused [E]
2023-12-06 11:21:06.893 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_update_extra_sensor [E]
2023-12-06 11:21:06.894 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [E] async_get_track
2023-12-06 11:21:06.894 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [E] play_media
2023-12-06 11:21:08.550 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: paused -> playing ... not playing [E]
2023-12-06 11:21:08.550 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: paused -> playing [E]
2023-12-06 11:21:17.116 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_get_track
2023-12-06 11:21:17.116 ERROR (MainThread) [custom_components.ytube_music_player.media_player] - Playing track nr 2 / 25
2023-12-06 11:21:17.116 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_get_url
2023-12-06 11:21:17.116 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_check_api [E]
2023-12-06 11:21:17.116 ERROR (MainThread) [custom_components.ytube_music_player.media_player] - try to find URL on our own
2023-12-06 11:21:17.270 ERROR (MainThread) [custom_components.ytube_music_player.media_player] - self decoded URL via cipher
2023-12-06 11:21:17.343 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [E] async_get_url
2023-12-06 11:21:17.343 ERROR (MainThread) [custom_components.ytube_music_player.media_player] - forwarding url to player media_player.owntone_server
2023-12-06 11:21:17.343 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_update_extra_sensor [E]
2023-12-06 11:21:17.768 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: playing -> paused ... not playing [E]
2023-12-06 11:21:17.768 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: playing -> paused
2023-12-06 11:21:17.768 ERROR (MainThread) [custom_components.ytube_music_player.media_player] media_pause
2023-12-06 11:21:17.771 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: paused -> paused ... not playing [E]
2023-12-06 11:21:17.771 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: paused -> paused [E]
2023-12-06 11:21:18.178 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: paused -> paused ... not playing [E]
2023-12-06 11:21:18.178 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: paused -> paused [E]
2023-12-06 11:21:18.180 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: paused -> paused ... not playing [E]
2023-12-06 11:21:18.180 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: paused -> paused [E]
2023-12-06 11:21:18.181 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: paused -> paused ... not playing [E]
2023-12-06 11:21:18.181 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.owntone_server: paused -> paused [E]
2023-12-06 11:21:18.344 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_update_extra_sensor [E]
2023-12-06 11:21:18.345 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [E] async_get_track

Any idea what may causing this ? And how this can be fixed?
I’m not sure, but from what I understand from the logging, I think the OwnTone Server switches state to paused when current stream is interrupted (for skipping or for next song) and as a reaction to that state change, youtube_music_player takes over that state and also pauses playback. Is this possibly what happens ?

(also, on a sidenote, there is a small input bug in the youtube_music_player configuration flow: when a proxy is previously set, you are unable to unset the proxy settings by just clearing the fields. It says the configuration is saved, but the cleared proxy fields are reverted when checked again. Replacing the proxy field with a single space seemed to work however)

[EDIT: found out that using the pipe is optional and works less reliable than setting OwnTone source to “Default (no pipe)”]

I did a bit more research, experimenting and rebooting. And I think the OwnTone integration reacts as follows:

  • When a next track or a skip within track is performed in youtube_player, OwnTone server goes from playing → paused.
  • When a track is finished, OwnTone goes from playing → off.

When I execute the off_is_idle service call on youtube_player, it detects when OwnTone Server ends a track, and will start a new track automatically. This seems to work consistently.

Skipping within or to a next song behaves not so consistent. Sometimes it works (with a bit of a delay), sometimes all goes to paused. After a restart of HA it sometimes starts working, sometimes not…

1 Like

So I hacked together a custom card that makes the search feature more of a first class function for me.

gif-2023.12.22-23.17.49

I was wondering if there was already anyone working on something similar.

5 Likes