Youtube Music - Media Browser

Hi guys - first of all thanks for all of your work on this - its really fantastic, but I am having a an issue setting up, getting the cookie and submitting the change to the configuration. I am not sure if this is the right place to ask the question but anyhow maybe my stupidity will help out someone else along the way…

I am using a raspberry pi running the latest buster and xubuntu on the workstation but I don’t think that’s relevant right now.

  1. Ideally I would like to be able to stream to a squeezebox - that should be possible right? Anyway even if it is not I still want to use the integration “in anger”.
  2. When trying to find and cut&paste the cookie I get 3 entries under browse. I have tried various of the ones listed in the attached screenshot but end up with the same result. If I copy the whole section under Request Headers (ie :authority all the way to x-youtube-utc-offset: 120) or whether I just take from accept:/ to offset I get the same result and am unable to click on submit (“Not all required fields are filled in”). I am also unable to do anything in the “select the default output device” field.

Any ideas what I am doing wrong?

hi @dabailey2009,
first regarding the empty “default output device” list … that should show all available media_player … don’t you have any? I don’t have a squeezebox device … it should work as long as it can play a URL that homeassistant sends … give it a try … or buy a chromecast :smiley:

now regarding the header: please take the REQUEST header as shown here GitHub - KoljaWindeler/ytube_music_player: YouTube music player for homeassistant

The ytubemusicapi recently change and includes now MORE information from the cookie (Release v0.17.0 · sigma67/ytmusicapi · GitHub). this results in a 403 error for me as well. I’ve created a ticket (good vs bad header fields · Issue #199 · sigma67/ytmusicapi · GitHub) to find out what is going on and release a new beta version of this integration (Release Added more header fields · KoljaWindeler/ytube_music_player · GitHub) please see if this helps in the meantime

edit1: the current beta release also adds “extra information” to the play command … this will send the title / artist and the cover to the player. as a result my chromecast now shows those information on the screen and I can even ask my home mini what song is currently playing … fancy. Thanks @stboch

jkw

I have never been able to select a song and get a radio playlist to automatically play based on that. It just plays the first song and stops. Is this still working? Further to this, is there a way to search for a song? So far I have only managed to select a song from an existing playlist or album etc.

and no … searching isn’t implemented as of now

A new feature :partying_face:

Todays BETA release contains a new feature: searching on youTube music (initial testing version)
To understand HOW to search (it’s a bit tricky) please have a look at
a) the readme faq section
b) watch directly this little video

Please provide feedback so we can lift this from beta → stable

Open items with feedback request (not only bug reporting, also every “works fine” helps me) :

  1. Searching
  2. extra info (is it still working on non-chromecast devices? is it showing those extra infos on all you chromecast devices?)
  3. (for those who set it up the first time): is the setup routine working for you

Thanks JKW

Edit:

… so @sparkydave / @Cloos that’s obviously not true anymore :smiley:

6 Likes

Firstly I want to say THANK YOU for setting this up. Out of desperation I even shifted over to Spotify for a while, since that integration works well. However I really like YT Music, so thanks for making it easier to use along with my Home Assistant.

Secondly, a question. How can I have it play only one random track from a playlist? I have a playlist (OLAK5uy_mglMcr0dcPByxyvGITmi9sNw-mRzfnW7s) of bedtime stories and I want it to select a random one and read just that at baby’s bedtime. What is the trigger at the end of the first track to tell it to stop playing? Grateful for any help.

Thanks

You might be able to stop when the player (the Chromecast / Google mini, not the youtube_music_player) changes it’s state from “playing” to “idle”. Untested but could work :wink:

A script could turn on your playlist in random mode and enable an automation that’s look like this

alias: stop after track
description: ''
trigger:
  - platform: state
    entity_id: media_player.mini1
    from: playing
    to: idle
condition: []
action:
  - service: homeassistant.turn_off
    target:
      entity_id: media_player.ytube_music_player
mode: single

Yeah, that logic makes sense. Thanks for even providing a first go at the code!
I already use your example on Github for starting a shuffled playlist!

@JKW First of all, thanks for keeping the player alive and up to the changes in the api.
By now i can’t give any of the requested feedback.
All features used by me seem to run fine in the latest version. Although i get an error message opening the cast link on my chromecast device. It starts playing anyway - so not sure why it throws that error. Might be that it is just a network issue… (i shortened the link to post here)

2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_select_source(media_player.kid1_zimmer)
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_update_remote_player(Input media_player.kid1_zimmer/ current media_player.kid1_zimmer)
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player]  no change [E]
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - Choosing media_player.kid1_zimmer as player
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [E] async_select_source
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] set_shuffle: False
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] _tracks_to_attribute [E]
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] set_repeat: off
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [E] set_repeat: off
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] play_media, media_type: album, media_id: MPREb_tPx9LR7Uwr2
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_prepare_play
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_check_api [E]
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_update_remote_player(Input / current media_player.kid1_zimmer)  [E]
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_turn_on_media_player [E]
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_get_cipher
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.kid1_zimmer: off -> unknown ... not playing [E]
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.kid1_zimmer: unknown -> unknown ... not playing [E]
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.kid1_zimmer: unknown -> idle ... not playing [E]
2021-05-26 10:13:29 ERROR (Thread-11) [homeassistant.components.cast.media_player] Failed to cast media https://www.home-assistant.io/images/cast/splash.png. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
2021-05-26 10:13:29 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.kid1_zimmer: idle -> idle ... not playing [E]
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [E] async_get_cipher
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [E] async_prepare_play
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] get_album(browseId=MPREb_tPx9LR7Uwr2)
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] _tracks_to_attribute [E]
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] _play
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_get_track
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - Playing track nr 0 / 7
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_get_url
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_check_api [E]
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - try to find URL on our own
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - found stream with audioQuality AUDIO_QUALITY_MEDIUM (12)
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - found stream with audioQuality AUDIO_QUALITY_HIGH (13)
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - found stream with audioQuality AUDIO_QUALITY_LOW (14)
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - found stream with audioQuality AUDIO_QUALITY_LOW (15)
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - found stream with audioQuality AUDIO_QUALITY_MEDIUM (16)
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - found stream with audioQuality AUDIO_QUALITY_LOW (17)
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - found stream with audioQuality AUDIO_QUALITY_MEDIUM (18)
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - using stream 13
2021-05-26 10:13:31 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - self decoded URL via cipher
2021-05-26 10:13:32 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [E] async_get_url
2021-05-26 10:13:32 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] - forwarding url to player media_player.kid1_zimmer
2021-05-26 10:13:32 ERROR (Thread-11) [homeassistant.components.cast.media_player] Failed to cast media https://r5---sn-i5h7lned.googlevideo.com/videoplayback?expire=1622038411&ei=KwOuYNr4Ms_w1gK_mYTYBg&ip=77.1.44.[...]. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
2021-05-26 10:13:32 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.kid1_zimmer: idle -> idle [E]
2021-05-26 10:13:32 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [E] async_get_track
2021-05-26 10:13:32 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [E] play_media
2021-05-26 10:13:32 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.kid1_zimmer: idle -> playing [E]
2021-05-26 10:13:33 DEBUG (MainThread) [custom_components.ytube_music_player.media_player] [S] async_sync_player ... media_player.kid1_zimmer: playing -> playing [E]
1 Like

:heart_eyes:

Well, if you’re talking about this error … that has been in my log forever … but as you can see:[homeassistant.components.cast.media_player] this is an error of the cast integration … not ytube_music_player so nothing I can do about it (+It seems to work fine :smiley: )

JKW

Thank you so much for working on this feature! Not really wife friendly for now but it’s a start :smiley: Any idea to make that sexier? :thinking:

Well … any Text input with a send button could call the service. The problem is that I can’t figure out how to open the media_browser, especially on a certain page … But that’s exactly why I didn’t implement it any earlier …

Thanks Kolja - that’s really helpful and much appreciated. I get to the 403 error now and am going to try the current beta now…

Hmmm I was forgetting that I am still learning my way around things with HASS and the Pi and just about everything else. What should I do with the tarball?

Nothing. Delete the tar ball, go to HACS and click on “update” at the ytube_music_player integration. Or on reinstall if you haven’t previously enabled beta versions
Jkw

1 Like

Hey man, my music bugged a few days ago, I clicked on play and it started but nothing happens.

I am trying to setup this again, but HA is telling me something is wrong with my cookies, this is wierd because I am copying it right.

the error message is “Format of cookie is NOT OK, likely missing ‘__Secure-3PAPISID’ or ‘__Secure-3PSID’”

I already checked my cookies and it has this “__Secure” thing.

Any ideas?

Not really, did you copy the correct cookie?
Have you checked the video that I’ve linked in the readme?
Jkw

Hi Everyone, i need your help please. I followed the installation steps and all working as expected, e.g. i can use mini-media-player to browse through my YouTube music library and i can select album and play on my default device.
The only issue I’m facing is, can’t play playlist. i can see my playlists available but when select one of them it doesn’t play. any suggestions please? thanks.

Hi All, i managed to find the issue, i did copy the wrong request header value.

In my case i have 2 request header values. everything worked fine including the playlist once i used the second request header, see screenshot below.

image

FYI, you have 1 Request Header and 1 Response Header