Youtube Music - Media Browser

search is still very complicated … most because we’re missing a card that one could use to enter the search string and select from the results

You can call the service “ytube_music_player.search” and enter your keywords there (no nice UI).
Your results will be presented in the media_browser. You can also use some sort of background service like Appdeamon, e.g.

#wait for results 
self.listen_state(self.ytsearch,"sensor.ytube_music_player_keller_extra",attribute="search")
# call the search
self.call_service("ytube_music_player/search", entity_id="media_player.ytube_music_player_keller", query="Pink", limit="20")

# play first track from results
def ytsearch(self, entity="", attribute="", old="", new="", kwargs=""):
  for result in new:
    if(result['type']=='song'):
      self.call_service("media_player/play_media",entity_id='media_player.ytube_music_player_keller', media_content_type="track", media_content_id=result['id'])
      break

But again … there is no nice way to do this in the UI of homeassistant (currently)

1 Like

Hi, @Pablo_Gustavo_Fiscel there is no connection between this integration and your phone, running ytube_music_player.
JKW

ok. Thanks

I’m trying to get this to work in node red. I have got to the point of adding the YT media player, but I don’t know how to send a playlist to it.

Ideas?

hi, same as noted above in the appdeamon script

self.call_service("media_player/play_media",entity_id='media_player.ytube_music_player_keller', media_content_type="track", media_content_id=result['id'])

call the media_player.play_media service and submit media_content_type=“playlist” and the id of the playlist …

also mentioned in the automation section of the readme

1 Like

I put that code, changing the id with the letters and numbers after playlist?list= in the youtube music url, in the data field as in this image:

And I got this error in the debug window:

msg : string[72]
“Call-service error. required key not provided @ data[‘media_content_id’]”

Ideas?

the command above was for appdaemon … you have to define the two field media_content_type=“playlist”, media_content_id=“abcdefg your id goes here” directly …

edit: bascially click “load sample data” in nodered and fill those fields …

1 Like

yay!

Now I only have to figure out why my Sonos isn’t receiving the data… ugh… I had it before… with this very setup…

Can I ask how you got your background on that Media view to match the current playing entity_picture? I’m trying to figure that out but can’t nail it down.
Also, did you customise the mmp accent colour to have the progress bar, active source and volume controls that colour?

Hi, I’ve tried to update the readme to reflect our recent discussions here, could you have a look and see if that would have helped you?
GitHub - KoljaWindeler/ytube_music_player: YouTube music player for homeassistant .

I’ve also re-written the service section because it was hard to understand
GitHub - KoljaWindeler/ytube_music_player: YouTube music player for homeassistant .

And added some information (that you won’t like) to the sonos part
GitHub - KoljaWindeler/ytube_music_player: YouTube music player for homeassistant .

I’m open for feedback … :smiley:
JKW

Hi Kolja,

Do you know why the tracks and lyrics markdown would stop working? Mine used to work but hasn’t been working for a month or 2 now. I copy and pasted your markdown.yaml from the vertical stack line 45 down and the tracks and lyrics are still showing up blank. I’ve tried updating the cookie and clearing the cache and storage.

I know you have recently updated this yaml and I’ve tried it with the update and the tracks and lyrics markdown still show up blank.

One thing I did notice in that yaml irrelevant to this issue is line 74 {{state_attr("media_player.ytube_music_player","_player_id")}}

The correct state attribute that works for me in that line is
{{state_attr("media_player.ytube_music_player","remote_player_id")}}

Thanks again!

Jep the reason for the none working stuff is that some attributes moved to the “_extra” sensor … Ive updated the Markdown template (didn’t I?) … please check the latest version online

This is a screenshot of mine … working fine … sorry for no formating, I’m on my phone

The only difference I see is a typo in line 120 in the github markdown.yaml file.
{% if i == state_attr("media_player.ytube_music_player"current_track")

It is missing ", between media_player.ytube_music_player and current_track. Should be:
{% if i == state_attr("media_player.ytube_music_player","current_track")
But even fixing that the tracks are still blank.

Have you disabled the extra sensor? Or can you check if it is there and has the correct values?

Ahh there it is, the extra sensor was never created.

I went through the config again and saw the new check box (under advanced configuration) for extra sensor and it was unchecked.

Got both the tracks and lyrics working again. Thanks for the help!

1 Like

I also am finally getting around to updating my lyrics and track and everything works with 1 minor issue.
I think the ytube_music_player is zero based and ytube_music_player_extra is 1 based?
It shows the correct artist and song highlighted but the numbers are off by one.
Playing Track is 8 but the list is 9.
image

Also minor typo in your markdown.yaml on git.
Shows
state_attr("media_player.ytube_music_player"current_track")
should be

state_attr("media_player.ytube_music_player","current_track")

Yes, both right … the list is also 0 based, but I’ve added the +1 in the Markdown, didn’t I?

Didn’t even notice the +1 thanks.

wondering if someone could help im getting errors where i didnt before so i uninstalled the integration restarted reinstalled restarted configured again and still have the same errors.

EDIT: just found the github issue seems like its waiting on a merge :slight_smile:

Summary
2022-01-19 21:12:39 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_get_cipher
2022-01-19 21:12:39 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] play_media, media_type: playlist, media_id: PLvk72NjGMhzj1QMQEZDpNYr0AXaQZuVhb
2022-01-19 21:12:39 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_prepare_play
2022-01-19 21:12:39 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_check_api [E]
2022-01-19 21:12:39 ERROR (MainThread) [custom_components.ytube_music_player.media_player] [S] async_update_remote_player(Input / current media_player.living_room_speaker) [E]
2022-01-19 21:12:39 ERROR (MainThread) [custom_components.ytube_music_player.media_player] self._state is: (idle).
2022-01-19 21:12:42 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140613493093040] __init__: could not find match for ^\w+\W
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 209, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 663, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 896, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 700, in _handle_entity_call
await result
File "/config/custom_components/ytube_music_player/media_player.py", line 1428, in async_play_media
if(not(await self.async_prepare_play())):
File "/config/custom_components/ytube_music_player/media_player.py", line 555, in async_prepare_play
await self.async_get_cipher('BB2mjBuAtiQ')
File "/config/custom_components/ytube_music_player/media_player.py", line 672, in async_get_cipher
self._cipher = Cipher(js=self._js)
File "/usr/local/lib/python3.9/site-packages/pytube/cipher.py", line 39, in __init__
raise RegexMatchError(
pytube.exceptions.RegexMatchError: __init__: could not find match for ^\w+\W
1 Like

Hey everyone … it might take some time until the real fix is implemented at PyTube and I didn’t want to wait :smiley:
So I’ve published a hot fix, that will be removed once PyTube merged the real fix.

Let me know if that works (does here)

3 Likes