Youtube Music - Media Browser

No, I followed the steps that are currently in the github readme.

  • Copy files -> custom components
  • Get the token from youtube music
  • restart home assistant, add integration and paste token (exactly the part in the screenshot from readme)
  • add package to configuration and add my speakers to it

after restart, “loading” and above error message.

1 Like

ah! great, thanks for pointing that out … there is still the path in the example package … I’ve removed it now

please also remove the header_path from your package yaml … my bad …

1 Like

Nice, i changed that and no more error about tokens and headers.

The speakers have appeared in the front-end, but playlist is still stuck on “loading” and no other options.

I found a new error:

2020-11-30 13:33:42 ERROR (MainThread) [homeassistant] 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 "/home/pi/.homeassistant/custom_components/ytube_music_player/media_player.py", line 333, in _update_sources
    self._update_playlists()
  File "/home/pi/.homeassistant/custom_components/ytube_music_player/media_player.py", line 357, in _update_playlists
    self._playlists[idx]['count'] = int(extra_info['duration'].replace(' songs',''))
ValueError: invalid literal for int() with base 10: '1,097'

edit:

I think i found a hint for that specific number: I have a playlist ‘likes’ (the old gmusic thumbs up playlist) that contains 1096 songs.

wow … nice one :slight_smile: you’re catching quite a lot of those new feature errors … who would have thought that your playlist is >>1000 entries long … give me 3 minutes to fix this :slight_smile:

Edit: done, just because it seams like your not using the HACS update feature: only the media_player.py changed …

edit2: This is in fact an annoying feature of the music api. It won’t tell how many tracks are in the “your likes” playlist. All other playlists have a ‘count’ attribute. The good thing is that the ‘your likes’ playlist has an attribute “length” that says “1,097 songs” so I’m trying to get the number of entries from there. but that requires a bit of text parsing … and that just failed …

1 Like

640kB ought to be enough for everyone, right :wink:
thanks for the quick response!

edit:

It works like a charm! thanks again, great job.

1 Like

Ok, now I’d like to point you to the alexa players again. It is still not possible, to start these players. Obviously they cannot execute the links.

Will there be a chance to fix that?
Or other question, will there be another media player instead of google, which might work?
I could install a player for my pioneer receiver. Haven’t tested that so far - on business travel.

hehe … I didn’t forget it … it’s just … complicated … I’ve created a ticket as a reminder.

If you can tell me which service to call with the URL then I’m sure that I’ll find a way to integrate that into the component.
Some sort of media_player_alexa.play_media with the entity id + url or so …
honestly: this is more an issue with the alexa integration and not really with this component.
JKW

@JKW the latest build resolved my ‘loading’ issue. thanks!

also, is there a write up somewhere that explains the different PlayMode options?

1 Like

That’s right. It is more a problem of the media player.
I will investigate as soon as I’m back in Home Office.

1 Like

As I had some time, I searched a little.
Unfortunately I fear, that it will not be possible, to play internet-content on alexa speakers.
I found this: https://github.com/custom-components/alexa_media_player/wiki#play-music
which more or less pointed out, that you can play amazon based music, tuniIn, sounds and speech but not something else. That’s what I understood.
I will try to activate the pioneer component. Maybe this works. :roll_eyes:

Honestly, looking at https://github.com/home-assistant/core/blob/14d1466400ee37c41b5b57146666913a4feb5254/homeassistant/components/pioneer/media_player.py … I don’t thing so. It’s quite surprising to see how few media play support “play this url”
My yamaha also lacks that feature.
Jkw

If so, then I’m sad to say that I have no use case for this component.
My hope was to have an opportunity to use my huge YouTube Content, already transformed from Play Music, on Alexas and my Receiver.
I don’t like to search for the mobile, start blutooth, connect etc. :wink:
And build up a nas only for music is too expensive in relation to the use.

Well one option would be to buy a chromecast … But I guess this is something you’ve already figured out yourself.
Really surprised that alexa doesn’t work.
Jkw

@Pirol62 I know I said this before but see if https://www.home-assistant.io/integrations/media_extractor/ will work for you as it creates a local feed from HA instead of the URL.

1 Like

I hate to say just buy another device, but two alternatives that are much cheaper than a NAS -

  1. Chromecast Audio connected to receiver

  2. Raspberry pi connected to receiver. I have not tried this but some possibilities are

@ stboch Thanks, I will check it out

@troy the chromecast audio is worth to dig in a little deeper. Thank you

Hi, I installed everything via HACS, activated the integration as per instructions, load all the playlists, but when I play a song, I hear the google_home activation sound but the song does not start and the log gives me this result (PS I’m under docker)

2020-12-01 13:00:36 ERROR (SyncWorker_18) [custom_components.ytube_music_player.media_player] Failed to get own(!) URL for track, further details below. Will not try YouTube method
2020-12-01 13:00:36 ERROR (SyncWorker_18) [custom_components.ytube_music_player.media_player] Traceback (most recent call last):
File “/config/custom_components/ytube_music_player/media_player.py”, line 528, in _get_track
streamingData=self._api.get_song(_track[‘videoId’])[‘streamingData’]
File “/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/browsing.py”, line 545, in get_song
song_meta[‘streamingData’] = player_response[‘streamingData’]
KeyError: ‘streamingData’
2020-12-01 13:00:36 ERROR (SyncWorker_18) [custom_components.ytube_music_player.media_player] 0dljyOUJhc4
2020-12-01 13:00:37 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140188445426640] ‘streamingData’
Traceback (most recent call last):
File “/config/custom_components/ytube_music_player/media_player.py”, line 528, in _get_track
streamingData=self._api.get_song(_track[‘videoId’])[‘streamingData’]
File “/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/browsing.py”, line 545, in get_song
song_meta[‘streamingData’] = player_response[‘streamingData’]
KeyError: ‘streamingData’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py”, line 135, in handle_call_service
await hass.services.async_call(
File “/usr/src/homeassistant/homeassistant/core.py”, line 1451, in async_call
task.result()
File “/usr/src/homeassistant/homeassistant/core.py”, line 1486, 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 499, 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 536, in _handle_entity_call
await result
File “/usr/src/homeassistant/homeassistant/components/media_player/init.py”, line 547, in async_turn_on
await self.hass.async_add_executor_job(self.turn_on)
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 232, in turn_on
self._load_playlist()
File “/config/custom_components/ytube_music_player/media_player.py”, line 430, in _load_playlist
self._play()
File “/config/custom_components/ytube_music_player/media_player.py”, line 463, in _play
self._get_track()
File “/config/custom_components/ytube_music_player/media_player.py”, line 561, in _get_track
_LOGGER.error(self._api.get_song(_track[‘videoId’]))
File “/usr/local/lib/python3.8/site-packages/ytmusicapi/mixins/browsing.py”, line 545, in get_song
song_meta[‘streamingData’] = player_response[‘streamingData’]
KeyError: ‘streamingData’
2020-12-01 13:00:38 ERROR (Thread-12) [homeassistant.components.cast.media_player] Failed to cast media https://www.home-assistant.io/images/cast/splash.png. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address

hmm interesting … very interesting … so you’re able to get your playlist … hmmm so the login worked.
But the api didn’t return a ‘streamingData’ field, but you’ve given the api a valid videoId … hmmm honestly … no idea … I can add some more debug info to catch this type of error, but I don’t really see what is causing it

… so I’ve added some debug and both methods fail to get the stream url …

and then I’ve tried to open your video myself … and it is a private video. Never seen this before, but is this some kind of self_uploaded music?

edit: just did some checking: Most (all but one) of my playlists are private, but non of the songs in them … there must be something special about your track (0dljyOUJhc4) can you open it on youtube? https://youtube.com/watch?v=0dljyOUJhc4

JKW

Pytube doesn’t support authentication so if the video is private it won’t be able to be played. There was an older version of pytube python 2 that supported auth but when it was rewritten for 3 it wasn’t implemented. Not sure where it is in development I know the current pytube is looking for support.

True but only half way. The first attempt is to decipher the video link without pytube. And that first attempt uses auth (ytmusicapi) that’s what I’ve posted here Youtube Music - Media Browser
Jkw