Youtube Music - Media Browser

Ya sorry I knew I wasn’t doing a good job explaining it.

Now that I think about it my problem probably lies outside your app.

I was basically looking for Speaker Group Management to work with Google devices as it does with Sonos in the mini media player. So instead of having to have many groups of all the speaker combinations, I can just select the speakers to start playing. It’s been awhile since I’ve tried to get this working with Google so it could be I was just doing it wrong. Sorry for the confusion.

No worries. But i guess you’re right. The integration can’t do much about it. Starting playback on multiple single devices will never be in sync.

So, I just installed the integration. I’ve been waiting a long time for a YTM integration. This is how I’m planning to use it:

Q1 - I’m planning to use both the media browser and the service calls. I’m not really a fan of using input selects myself, but I’ve used it before to choose radio stations and the output speaker(groups).

Q2 - Would it be an option to have a switch for each attribute so that you can hide the stuff you don’t use and only see the relevant things?

Q3 - I’d love to see the installation made easier. Just providing the YTM credentials instead of copying stuff from the network tab of the console. Another thing I’ve been thinking about: I don’t have a standard speaker. Playing from the media browser always starts the music at the one default speaker. What if you could choose a mediaplayer to play from after hitting the play button?

The integration already looks fantastic. I can’t imagine how much work you’ve already put in it. Thank you very much!

Roy

1 Like

Regarding 2: well I guess most won’t use the extra sensor so I’d keep it simple and only add one switch.

Regarding 3.1: installation is a pain. Agreed. But i have no idea how to simplify the cookie process. There is an open ticket at the APIs repository but even nobody over there has an idea.

3.2: how can you have no standard player? Isn’t the setup procedure forcing you to choose one? Changing the player while playing should already work. It should even seek to the same position within the track if both (the old and the new player) support it

Jkw

3.2: I did choose a standard player during installation. I meant that I don’t have a favorite speaker in my house. I’m using multiple speakers with different chromecast audio’s, depending on in which room I am. This means that my standaard player (living room) isn’t always the place I want to turn the music on.

I’ll take a look at changing the player. I didn’t know this was possible. Thanks!

I see …
Changing the player is fairly easy via the media_browser. Simply open the “playback device” item, that should show all players.
But you can also call the media_player.select_source service (yep “source” is a bit confusing, but there is no select_target service)

I actually have multiple shortcuts on the Mini-Media-Player to “take my music with me” … basically quick change the output

Got this error just after updating to 2021.9.5

============= ytube_music_player Integration Error ================
2021-09-09 15:07:28 ERROR (MainThread) [custom_components.ytube_music_player.media_player] unfortunately we hit an error, please open a ticket at
2021-09-09 15:07:28 ERROR (MainThread) [custom_components.ytube_music_player.media_player] https://github.com/KoljaWindeler/ytube_music_player/issues
2021-09-09 15:07:28 ERROR (MainThread) [custom_components.ytube_music_player.media_player] and paste the following output:

2021-09-09 15:07:28 ERROR (MainThread) [custom_components.ytube_music_player.media_player] Traceback (most recent call last):
  File "/config/custom_components/ytube_music_player/media_player.py", line 1018, in async_update_playlists
    extra_info = await self.hass.async_add_executor_job(self._api.get_playlist,playlist['playlistId'])
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/ytmusicapi/mixins/playlists.py", line 66, in get_playlist
    response = self._send_request(endpoint, body)
  File "/usr/local/lib/python3.9/site-packages/ytmusicapi/ytmusic.py", line 134, in _send_request
    raise Exception(message + error)
Exception: Server returned HTTP 404: Not Found.
Requested entity was not found.

2021-09-09 15:07:28 ERROR (MainThread) [custom_components.ytube_music_player.media_player] 
thanks, Kolja
2021-09-09 15:07:28 ERROR (MainThread) [custom_components.ytube_music_player.media_player] ============= ytube_music_player Integration Error ================

Hello, any chance I could get a pointer on what i am doing wrong?
Installation was ok i think, and I am trying to play to a dlna_dmr media_player, a Samsung soundbar.

Sadly I am getting a “resource not found” error:

Logger: homeassistant.core
Source: components/dlna_dmr/media_player.py:324
First occurred: 11:36:11 PM (1 occurrences)
Last logged: 11:36:11 PM

Error executing service: <ServiceCall media_player.play_media (c:d8f04ad245a2c7734bbab8f0b5d2df69): entity_id=['media_player.av_samsung_soundbar_n950'], extra=metadata=metadataType=3, title=Blame It on Me, artist=George Ezra, images=[{'url': 'https://lh3.googleusercontent.com/63vYRlqZbgobhbBuCUwqOFzzWa91Ko_gF6r_812rJCk2bJHaV5RMAarkX9dqz3-ClsFB1IOJTtZFdB0=w120-h120-l90-rj'}], media_type=music, media_id=https://r2---sn-gqn-vu2e7.googlevideo.com/videoplayback?expire=1631******************==>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1508, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1527, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 843, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/dlna_dmr/media_player.py", line 77, in wrapper
    return await func(self, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/dlna_dmr/media_player.py", line 324, in async_play_media
    await self._device.async_set_transport_uri(media_id, title)
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/profiles/dlna.py", line 673, in async_set_transport_uri
    await action.async_call(
  File "/usr/local/lib/python3.9/site-packages/async_upnp_client/client.py", line 541, in async_call
    raise UpnpError(
async_upnp_client.exceptions.UpnpError: Error during async_call(), status: 500, body: <?xml version="1.0" encoding="utf-8"?><s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring>UPnPError</faultstring><detail><UPnPError xmlns="urn:schemas-upnp-org:control-1-0"><errorCode>716</errorCode><errorDescription>Resource not found</errorDescription></UPnPError></detail></s:Fault></s:Body></s:Envelope>

The media_player seems to be propretly integrated, i am able to outpt url media to it with play_media.
The media browser loads my playlist and seems to get pointed to the right song also.

Interesting. Can you give me an example. Like what url ans what type works?
Have you tried the proxy mode?
Jkw

I am able to play back from http://192.168.1.xxx:8123/local or any other external url.
But on the other hand i have the same issue when i try to TTS into this media_player, i get the same error as your integration.

I havent tryied the sonos/proxy mode, I will give it a got in 10 hours or so.

Thank you.

I’m trying to implement a search option via Lovelace but having a bit of trouble. I created an input_text and then can successfully call the search service from the dev tool, but using that in Lovelace isn’t working.

input_text:
  ytube_music_player_search:
    name: YouTube Music Search
    icon: mdi:magnify

From dev tool, this works correctly:

service: ytube_music_player.search
data:
  entity_id: media_player.ytube_music_player
  query: "{{  states('input_text.ytube_music_player_search')  }}"

Lovelace:

type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: input_text.ytube_music_player_search
    show_header_toggle: false
  - type: button
    tap_action:
      action: call-service
      service: ytube_music_player.search
      service_data:
        entity_id: media_player.ytube_music_player
        query: '{{  states(''input_text.ytube_music_player_search'')  }}'
      target: {}
    show_name: false
    show_icon: true
    icon: mdi:magnify
    icon_height: 50px

The lovelace search isn’t working properly and give me this in the Media Browser:
image

I also tried with just input_text.ytube_music_player_search for the query but that had the same result.

Any ideas how to fix this?

1 Like

Hi, firstly - great add-on!

I am using mini-media-player and have two questions reagarding to use Ytube Music in it:

  1. is there possibility to have currently chosen playlist name on the button? Something like:
shortcuts:
  buttons:
    - name: {{input_select.ytube_music_player_playlist}}
    - ...
  1. I can not find, is there possibility to use mini-media-player buttons to play playlist chosen via helper. If it is possilbe, how the code should looks like? (I found only examples without buttons or with buttons but with playlist harcoded). I use other buttons to start other radios.

hi QbaF, as per my understanding your number 1 question is really a question for mini-media-player but I had a similar question a while back that might solve your usecase: https://github.com/kalkih/mini-media-player/issues/471

regarding question 2: so you want to select a playlist in a drop down and then hit a “play” button on the mini-media-player to start playing the selected playlist, correct? isn’t that simply possible by hitting the “power on” button?

JKW

honestly …that should be possible but i’m not a script guy :smiley: … did you figure it out?

I gave a try config-template-card. Unfortunately no success. It even did not want to save changes. Maybe something wrong with my code. Most probably because the type is used for mmp buttons;)

    - name: "${states['input_select.ytube_music_player_playlist'].state}"
      type: 'custom:config-template-card'

I asked this add-on forum/developer, maybe there will be some solution.

Regarding Q2: I meant I want to select the playlist in a drop down and then hit the mmp button (no play icon)
image

Ad. 1. - It is possible I made it works. You have to use it as:

type: custom:config-template-card

entities:    # to bo honest I am not sure why here have to be entities if the are below as well, but looks like it is syntax
  -
  -
  ...

card:
  type: entities
  entities:
    - entity: media_player.ytoube_music
      type: custom:mini-media-player
      ...
      shortcuts:
        buttons:
          - name: ${states['input_select.ytube_music_player_playlist'].state}
            ...
1 Like

I use nodered a lot. here to start my ytube in the morning but how do I select a specific playlist id? tried various option in the json section but get api errors.
It starts the music fine with it empty but only the default.

Got it sorted:

1 Like

Still looking for dynamic buttons - Is it possible to have in input_select.ytube_music_player_playlist attribute media_id in format that is needed for service media_player.play_media?

Hello,

In the google home app I can select the chromecasts I want playing, without stopping playback or disconnecting. Would this be impossible to integrate?