Youtube Music - Media Browser

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.

have a look at

@mals @JKW Thank you both for your replies. I didn’t have any playlists with 0 songs but I did have two with only one song each (no idea why I had them!)

I deleted them and things began working normally - not 100% sure that’s what was wrong, as I also rebooted the supervisor and all docker containers at the same time. But it seems to me the most likely culprit.

@JKW Thank you for the development of this, I used the older gmusic integration a lot and it is nice to be able to continue in the same way.

I have a use case that is currently not working for me, playing a playlist and stopping when the list is done. At the moment the list just keeps playing from the start again when the last song is played, which I guess is not the intention.
I think that the problem is in _get_track(). When the list is done the internal track counter is set to 0 and the first track is loaded and started again as far as I can see. I have solved it locally by adding

self._turn_off_media_player()
return

after reloading the playlist, but that might not work well in all use cases. This is the most common one for me by far though.

Well that IS intended behavior. But I can see use cases for the opposite. . I’ve created a ticket: https://github.com/KoljaWindeler/ytube_music_player/issues/19

Jkw

1 Like

Ah, yes, repeat mode was the correct description. :slightly_smiling_face:

We have a playlist that we play for our daughter at bedtime, and that should only play the list, not continue when the list is done.

Alright, will implement something tomorrow.
Jkw

1 Like

Hello. First of all, I want to thank the author for the work done. gmusic I could not configure, and now the server closes altogether. But there were no problems with youtubemusic. I heard my favorite tracks right after installation. However, the playlist played one or two tracks and stopped. I was ready to put up with this, but after updating the component, the playlists stopped loading. I don’t hear my favorite music anymore. Help me please. What should I pay attention to? Thank you in advance.

1 Like

Please have a look in your log if it points out what is going wrong.
You can get extended info by adding this into your confirmation.yaml

logger:
    default: warning
    logs:
      custom_components.ytube_music_player: debug

Jkw

please check the latest version and add the input boolean ytube_music_player_playcontinuous to your config and UI. feedback is appreciated :slight_smile:

Updated and added the input boolean and I am happy to report that it works exactly like I hoped :grinning:

1 Like

This is great, thank you. I can now have my music automatically pause when a Teams Call comes in.

I am guessing that the API doesn’t expose this but, I am lazy and I don’t have any play lists and I just used the “My Mix” that music automatically creates. These are not shown as a Source, are they available and I just need to do some trickery to get them to show up?