Youtube Music - Media Browser

I have managed to install and configure this. The component loads my playlists, etc. However, I am finding that most of the songs don’t play. All of them error with the “Failed to get URL for track” exception.

I don’t believe these are songs I uploaded. I searched and added random songs to the playlists but no luck.

Some example tracks:

  • Hx4nWW9z0ig
  • 1LPNuFkteI8

This one works

  • -ldeCgy2ado

Edit: I want to add that even the song that works throws the exception but plays correctly. I am really confused now.

Edit: I think the one that works falls back to the Youtube stack and picks a url.

@r4nd0mbr1ck strang because Hx4nWW9z0ig worked fine for me.

Are you a youtube premium subscriber? I wonder if there is something weird with your cookie.

Can you paste some more of the error logs.

Yeah worked!
In case anyone else needs similar, here is nodered automation that turns on youtube music playlist on specific google home device after input boolean set to on:

[{"id":"b996d556.efe6b8","type":"ha-api","z":"cbaf2713.743e38","name":"Playlist","server":"532aa922.484e68","debugenabled":false,"protocol":"http","method":"post","path":"states/input_select.ytube_music_player_playlist","data":"{\"state\":\"Tranquil Spa Day\"}","dataType":"json","location":"payload","locationType":"msg","responseType":"json","x":620,"y":860,"wires":[["53a92c65.c659c4"]]},{"id":"d8b2c8ea.d68e78","type":"api-call-service","z":"cbaf2713.743e38","name":"Play","server":"532aa922.484e68","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_play","entityId":"media_player.ytube_music_player_speakers","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1090,"y":940,"wires":[[]]},{"id":"53a92c65.c659c4","type":"ha-api","z":"cbaf2713.743e38","name":"Playmode - Random","server":"532aa922.484e68","debugenabled":false,"protocol":"http","method":"post","path":"states/input_select.ytube_music_player_playmode","data":"{\"state\":\"Random\"}","dataType":"json","location":"payload","locationType":"msg","responseType":"json","x":840,"y":860,"wires":[["f97860e4.ce0b8"]]},{"id":"f97860e4.ce0b8","type":"ha-api","z":"cbaf2713.743e38","name":"Source - Playlist","server":"532aa922.484e68","debugenabled":false,"protocol":"http","method":"post","path":"states/input_select.ytube_music_player_source","data":"{\"state\":\"Playlist\"}","dataType":"json","location":"payload","locationType":"msg","responseType":"json","x":640,"y":940,"wires":[["e943a087.3c2f"]]},{"id":"e943a087.3c2f","type":"ha-api","z":"cbaf2713.743e38","name":"Speaker - bedroom_speaker","server":"532aa922.484e68","debugenabled":false,"protocol":"http","method":"post","path":"states/input_select.ytube_music_player_speakers","data":"{\"state\":\"bedroom_speaker\"}","dataType":"json","location":"payload","locationType":"msg","responseType":"json","x":880,"y":940,"wires":[["d8b2c8ea.d68e78"]]},{"id":"e194d5e3.7ca668","type":"api-current-state","z":"cbaf2713.743e38","name":"Is paused","server":"532aa922.484e68","version":1,"outputs":2,"halt_if":"paused|idle","halt_if_type":"re","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.bedroom_speaker","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":440,"y":800,"wires":[["427c0296.146b3c"],["b996d556.efe6b8"]]},{"id":"427c0296.146b3c","type":"api-call-service","z":"cbaf2713.743e38","name":"Resume speaker","server":"532aa922.484e68","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_play","entityId":"media_player.bedroom_speaker","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":650,"y":800,"wires":[[]]},{"id":"e929dd65.09047","type":"server-state-changed","z":"cbaf2713.743e38","name":"Bedroom Routine Started","server":"532aa922.484e68","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.bedtime_routine","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":110,"y":820,"wires":[["9ccf68f.c79ab98"]]},{"id":"9ccf68f.c79ab98","type":"switch","z":"cbaf2713.743e38","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":820,"wires":[["e194d5e3.7ca668"],["30e8ed0e.ab8482"]]},{"id":"30e8ed0e.ab8482","type":"api-call-service","z":"cbaf2713.743e38","name":"Pause speaker","server":"532aa922.484e68","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_pause","entityId":"media_player.bedroom_speaker","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":440,"y":1000,"wires":[[]]},{"id":"532aa922.484e68","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

:dancing_women: :dancing_men:

Hi guys, I got it to play after struggling a bit with the token, I am now trying to incorporate it is my aitomations but not winning, gmusic player had a script in the yaml and that was used to trigger the automation. With ytube_music_player, I tried:

  - service: media_player.turn_on
    entity_id: media_player.ytube_music_player
    data:
      speakers: mainbedroom_speaker
      source: playlist
      name: Good Morning Coronas 

when I trigger the automation, it does not turn the media player on.

please assist :blush:

Hi @alexbell, thanks for the advise, where do you put this code, and where do you get the parameters for each variable :blush: I already have the trigger set up.

hi @Caswell1000 i use this automation in Nodered: Home Assistant Community Add-on: Node-RED

In nodered just click hamburger icon at top-right cornet and then Import, there you can copy paste this code (please update the playlist and speaker nodes accordingly).

Also i jut updated the code in original post a little.

You need a sequence … first input.select speaker, second input.select the playlist third, input.select source, forth: Mediaplayer turn on
Jkw

alias: Start_radio
sequence:
  - service: input_select.select_option
    data:
      option: Your Likes
    entity_id: input_select.ytube_music_player_playlist
  - service: input_select.select_option
    data:
      option: jkw_cast2
    entity_id: input_select.ytube_music_player_speakers
  - service: input_select.select_option
    data:
      option: Playlist Radio
    entity_id: input_select.ytube_music_player_source
  - service: media_player.turn_on
    data: {}
    entity_id: media_player.ytube_music_player
mode: single

actually something that you can very comfortably click together in the GUI (never used before but works really great)

HA! post withdrawn See above…

Although yours looked nicer :wink: but I’m not sure if that would still work … Will try later

Maybe you can add it back, if it doesn’t work. I think I can at least point out in the previous mess of code, how that worked.

Thanks, I have not used a sequence before, so I am not sure where to put it, I am busy reading up though :roll_eyes:

use the GUI based thingy … configuration -> scripts -> add script … that’ll be the easiest …

(else you can place in into a script section)
JKW

I prefer the manual script route, but I am getting some dictionary errors :unamused:

media_player:
  - platform: ytube_music_player
    # if your speaker is called media_player.speaker123, add speaker123 here to preselect it.
    speakers:
      - mainbedroom_speaker
      - mainbedroom_tv


input_select:
  ytube_music_player_source:
    name: Source
    icon: mdi:music-box-multiple
    options: # don't change
    - "Playlist Radio"
    - "Playlist"

  ytube_music_player_speakers:
    name: Speakers
    icon: mdi:speaker
    options: # don't change
    - "loading"

  ytube_music_player_playlist:
    name: Playlist
    icon: mdi:playlist-music
    options: # don't change
    - "loading"

  ytube_music_player_playmode:
    name: Playmode
    icon: mdi:playlist-music
    options: ## Should be empty
    - "Shuffle"
    - "Random"
    - "Shuffle Random"
    - "Direct"
script:
  alias: Start_radio
  sequence:
    - service: input_select.select_option
      data:
        option: Good Morning Coronas
      entity_id: input_select.ytube_music_player_playlist
    - service: input_select.select_option
      data:
        option: mainbedroom_speaker
      entity_id: input_select.ytube_music_player_speakers
    - service: input_select.select_option
      data:
        option: Playlist
      entity_id: input_select.ytube_music_player_source
    - service: media_player.turn_on
      data: {}
      entity_id: media_player.ytube_music_player
  mode: single

Invalid config for [script]: expected a dictionary for dictionary value @ data['script']['alias']. Got 'Start_radio' expected a dictionary for dictionary value @ data['script']['mode']. Got 'single' expected a dictionary for dictionary value @ data['script']['sequence']. Got [OrderedDict([('service', 'input_select.select_option'), ('data', OrderedDict([('option', 'Good Morning Coronas')])), ('entity_id', 'input_select.ytube_music_player_playlist')]), OrderedDict([('service', 'input_select.select_option'), ('data', OrderedDict([('option', 'mainbedroom_speaker')])), ('entity_id', 'input_select.ytube_music_player_speakers')]), OrderedDict([('service', 'input_select.select_option'), ('data', OrderedDict([('option', 'Playlist')])), ('entity_id', 'input_select.ytube_mu.... (See /config/configuration.yaml, line 48).

was missing a name, sorted and restarting, will test if it fires up

It’s now working when I trigger it, thank you :space_invader: :space_invader: :space_invader:

1 Like

Awesome!! Great work! Thank you!
Looking forward for full integration!
Setup worked flawlessly - anyway!

Since i have no idea how the communication to youtube api is working - a possible stuipid request:
make albums or single songs selectable?
maybe a select option as editable free text?

Regards!

Hi @JKW I’m very excited to try this - I’ve been looking for something like this and it seems perfect!

I got through all the installation steps with no issues but the ‘Playlist’ Input Select only shows “loading”.

I’ve seen at least one other case like this in this thread but it appears to be unrelated (different error). My error is as follows

Logger: homeassistant
Source: custom_components/ytube_music_player/media_player.py:387
First occurred: 8:46:09 PM (1 occurrences)
Last logged: 8:46:09 PM

Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  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 356, in _update_sources
    self._update_playlists()
  File "/config/custom_components/ytube_music_player/media_player.py", line 387, in _update_playlists
    self._playlists = self._api.get_library_playlists(limit = 99)
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/library.py", line 39, in get_library_playlists
    get_continuations(results, 'gridContinuation', limit - len(playlists),
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 67, in get_continuations
    contents = get_continuation_contents(results, parse_func)
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 110, in get_continuation_contents
    return parse_func(continuation[term])
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/library.py", line 37, in <lambda>
    parse_func = lambda contents: parse_content_list(contents, parse_playlist)
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/browsing.py", line 139, in parse_content_list
    contents.append(parse_func(result['musicTwoRowItemRenderer']))
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/browsing.py", line 176, in parse_playlist
    'title': nav(data, TITLE_TEXT),
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 148, in nav
    raise err
  File "/usr/local/lib/python3.8/site-packages/ytmusicapi/parsers/utils.py", line 142, in nav
    root = root[k]
KeyError: 'runs'

I wasn’t able to determine a problem from it, perhaps you or someone else can? I’d be very grateful, and am indeed already grateful for the effort to make this work for everyone here!

hi, I don’t think that we should implement that although it would be possible.
this is something that should be implemented in the media_browser extension.
@stboch already opened a ticket for the same issue https://github.com/KoljaWindeler/ytube_music_player/issues/14

@tismondo those errors are coming from underlaying ytmusicapi. i’ll add some wrapper around it.
but can’t really help. my best guess woul be a problem with brand id / cookie or you don’t have playlists?

jkw

edit: ticket opened https://github.com/sigma67/ytmusicapi/issues/119
@tismondo, please have a look and see if you can help https://github.com/sigma67/ytmusicapi/issues/119#issuecomment-743127102

I was getting the same error. It turns out I had some empty playlists in Youtube Music. After deleting them, it started working.

1 Like

I think probably needs to be an issue opened in ytmusicapi for the empty Playlist and no Playlist issues.