Youtube Music - Media Browser

Some questions ?

Is it a template way:

  • to show the duration of a playlist ?
  • to show the duration of an album ?
  • to show the duration of songs in playlist track list ?

It will be fine to have a “spaghetti mode” play all you want (album, playlist) only for 10 minutes…

No, none of it. Sorry.
Duration isn’t something that I forward to the attributes.
Jkw

Sorry, I just can’t figure out how to get the dropdowns to show on the dashboard. I’m able to choose media from the media control card and it plays on my defined default media player but i have no idea how to integrate the markdown.yaml to get the dropdowns to show and change the values of the media and players. I’m running this in docker so i don’t have HACS and installed this manually. Is there idiot-proof documentation somewhere that I’m missing? Thanks.

Have you got this in configuration.yaml. ?

to integrate markdown.yaml go to the lovelace editor on the right corner on the dahboard

the full example is here

you can create this view and then edit accordingly

I’ve tried putting that in configuration.yaml, adding the whole package folder to the /config directory and adding the files in custom_components/ytube_music_player. not sure exactly which section of the config to add it to and then after adding it, not sure which card to add to get the view.

Ok sorry… i was a little slow. I figured out i needed to add this to a dashboard using the Edit Dashboard -> Raw Configuration Editor. I kept thinking i had to add it to configuration.yaml. Now I just need to get the dropdown piece working. getting errors for entities not available…

Again, I put the config in the wrong place. I tried putting it in the media player section with the rest of the ytube_music_player config but it needs to be in the completely separate input_select section. Finally got it all working now. Did I mention I’m still learning??? lol. Thanks.

2 Likes

Hello !!

Some times I’ve got this error

(loading) is not a valid media player.

and the music don’t start, i’m not able to find why …

Hmm that’s strange, loading is the default value of the input select … is that input select always populated?

Suddenly, at restart, i got this:

Schermata 2021-02-07 alle 14.42.20

And nothing is working…
In the log i have:

2021-02-07 14:47:14 ERROR (SyncWorker_22) [custom_components.ytube_music_player.const] Running get_library_songs resulted in an exception, no idea why.. honestly
2021-02-07 14:47:14 ERROR (SyncWorker_22) [custom_components.ytube_music_player.const] Please see below
2021-02-07 14:47:14 ERROR (SyncWorker_22) [custom_components.ytube_music_player.const] Traceback (most recent call last):
  File "/config/custom_components/ytube_music_player/const.py", line 299, in try_login
    api.get_library_songs()
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/library.py", line 74, in get_library_songs
    response = parse_func(request_func(None))
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/library.py", line 66, in <lambda>
    request_func = lambda additionalParams: self._send_request(endpoint, body)
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/ytmusic.py", line 116, in _send_request
    raise Exception(message + error)
Exception: Server returned HTTP 403: Forbidden.
The caller does not have permission

Reinstalling the integration i see the following:
Schermata 2021-02-07 alle 15.58.18
What’s the meaning?

Seems to be an issue with the authentication cookie.

If not already done, i would try to do these steps again:

https://github.com/KoljaWindeler/ytube_music_player

Blockquote
1. Basic steps for grabbing

  1. Open the development tools (I’ve used google chrome) [Crtl+Shift+I / F12]
  2. Open the Network tab
  3. Open https://music.youtube.com, log out, log in, browse a bit around like clicking on the library in the top menu
  4. Search for “browse” (for me only one item shows up)
  5. Go to “headers” → “request headers”
  6. copy everything starting after the "accept: / " (mark with a mouse and copy to clipboard)

2. Please use the config flow of Home Assistant

  1. Open Configuration → Integrations → “add integration” → “YouTube Music Player”
  2. If the integration didn’t show up in the list please REFRESH the page
  3. Paste the cookie into the indicated field, all other fields are optional or provide default values
  4. It is highly recommended to enter the entity_id of your default output player, otherwise you have to set that after every reboot
  5. The second page shows several entity_ids for dropdown field. You can leave the default values, even if you don’t want to use those field and don’t add them to your configuration… or clear the field … both will work fine (see below)

Although YAML configuration is still possible: Please remove it and configure the player via config_flow or several functions will be missing

1 Like

Yes, i re-did all the steps and now all is working again…

hi, the new release will show more detailed error messages.
But your cookie will need to be refreshed from time to time … e.g. when you log out in the browser. … the same happened to me the other day … glad that you were able to fix it yourself.
JKW

Anyone else using this in Node Red? I’m having an issue with it not refreshing my playlist when I switch between them (see below).

The five second time is just to let all the new settings ‘stick’, and probably doesn’t need to be that high.

Toggling between the two playlists updates the Lovelace front end, but not the actual playing playlist.

Have you tried direct service calls instead of manipulation of the the drop downs?


The first example is what I’m running every single morning … sets the output, playlist …

I do all my stuff in Node Red, and aren’t too familiar with the HA side of things.

it’s odd that manually changing the playlist thru lovelace will play the correct playlist, but not when set thru NR doing a service call (in which case the lovelace is updating to the new playlist name)

Hi,

  1. let me tell you that this is a great addon!
  2. did anything changed in the last update ?

I am no longer able to start the YT player and I get the following error in the notification box:
“Failed to call service media_player/play_media. local variable ‘_remote_player’ referenced before assignment”

HA Version:

Core Version - core-2021.2.3
Supervisor Version - supervisor-2021.02.9
HACS Version - Firmware: 1.11.3
TY Plugin Version: - “ytmusicapi==0.14.2”, “pytube==10.0.0”, “integrationhelper==0.2.2”

The Log shows the following, but I’m not able to find out what is the root cause.

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/ytube_music_player/media_player.py:463
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 6:29:13 PM (9 occurrences)
Last logged: 6:30:29 PM

[1810975304] local variable '_remote_player' referenced before assignment
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 136, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1455, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1490, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 595, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 664, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 632, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 630, in async_play_media
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/ytube_music_player/media_player.py", line 1067, in play_media
    self.prepare_play()
  File "/config/custom_components/ytube_music_player/media_player.py", line 354, in prepare_play
    if not self._update_remote_player():
  File "/config/custom_components/ytube_music_player/media_player.py", line 463, in _update_remote_player
    if self.hass.states.get(_remote_player) is None:
UnboundLocalError: local variable '_remote_player' referenced before assignment

Any feedback is appreciated!
And again, congratulations for this addon

Damn, my bad. Will fix shortly

Edit: published

1 Like

Many thanks Kolja!
I’ve updated to the new release and it worked perfectly! :slight_smile:

Great addon and great work!!!

Best regards
Bogdan

1 Like