Home Assistant Community

Play music from google play music on media_players

#1

It would be nice to pass a album, playlist, whatever entity is out there from google music to a home assistant media_player.

The problem:

As far as I understand google play music does not provide link to the media file itself and therefore you can not pass the playlist or album url to the media_player as media_content_id like described here: https://www.home-assistant.io/components/media_player/#service-media_playerplay_media

One half breed workaround:

I tried to workaround that problem by using this project Google Assistant Webserver in a Docker container.
This simulates a mute google assistant where you can pass commands to.
This works almost except google play music does not allow to play a playlist!
See here: https://support.google.com/googlehome/answer/7211943?hl=en
A album works fine, but playlist do not.
And this is not a good workaround.

Gmusicproxy

I also did find the gmusicproxy which I did not play with yet. I am not sure if this would be a feasible way of solving the problem.

Edit:
I just tried that. It is just creating static url for your google play music stations and playlists.
Even though I could not pass this url to the media_player.play_media service:

{
  "entity_id": "media_player.schlafzimmer",
  "media_content_id":"http://IP:9999/get_playlist?id=e20c6cc9-b536-4bc3-83a8-890f4dc600bb",
  "media_content_type":"music"
}

I mean I could and the google home started the sound at the beginning when it is doing something and the home assistant media_player cards shows that it is playing something but there is no music coming out of that device.
I also changed the media_content_type to “playlist” but the music wasn streaming.
When opening that url with a browser or vlc media player it started to stream the media.

custom component

Some time back there was an unofficial component which could do that somehow which is no longer maintained. [Google music in HA]

Most of the projects use the unofficial https://github.com/simon-weber/gmusicapi, maybe that could also help to implement this.

Conclusion

I and maybe others would like to have this functionality directly integrated in home assistant without the need to have such a hassle despite the fact that the things I tried did not work properly.

If you have suggestions or I did something wrong please feel free to point out the mistakes.

0 Likes

Google Music in HA -- Using AppDaemon (WIP)
#2

yea, Danielhiversen made there an awesome tool. muchsad.jpg
I chould Imagene Google Music Desktop player could be another awnser to our prayers after there is an component. (Casting could bei an issue) Sadly I only have one slot left on my Account, So I didnt tryed it yet to integrate. would be nice if I could re use the old device_id

The Google Music Platform is very Awesome - after you can upload 20k of your own songs.

0 Likes

#3

Gmusicproxy

looks like a nice way to do this, once it’s all up and running you may be able to control it with the shell_command service in HA:

As for getting the MP3 files to HA, that’s a little more tricky, I’m running a squeezebox media device and it’s a little tricky to try and directly play an MP3.

If I make any progress I’ll post it here as I have quite a few songs in my google music account.

1 Like

#4

You can use that to get a list of the songs in the playlist.

curl -s http://IP:9999/get_playlist?id=e20c6cc9-b536-4bc3-83a8-890f4dc600bb

For example:

curl -s http://192.0.1.19:9999/get_playlist?id=ea7dd3af-8ea5-4f48-9c0d-c37a3446860c

#EXTM3U
#EXTINF:39,Shinedown - THE ENTRANCE
http://192.0.1.19:9999/get_song?id=Tkvbt5mciv2gk4t4fookzjodhxm
#EXTINF:208,Shinedown - DEVIL
http://192.0.1.19:9999/get_song?id=Toefdve3o3wj3uodxf7w5v3tyim
#EXTINF:203,Shinedown - BLACK SOUL
http://192.0.1.19:9999/get_song?id=Tuhz5loupjz2cm45vf75nahh7wm
#EXTINF:230,Shinedown - ATTENTION ATTENTION
http://192.0.1.19:9999/get_song?id=Tscf4m2vahago3g2ix434ehck6u
#EXTINF:232,Shinedown - KILL YOUR CONSCIENCE
http://192.0.1.19:9999/get_song?id=Taxzj52wzcskz32oc27bv7wt2ri

Or just the static address for each song

curl -s http://192.0.1.19:9999/get_playlist?id=ea7dd3af-8ea5-4f48-9c0d-c37a3446860c  | grep -v ^#

http://192.0.1.19:9999/get_song?id=Tkvbt5mciv2gk4t4fookzjodhxm
http://192.0.1.19:9999/get_song?id=Toefdve3o3wj3uodxf7w5v3tyim
http://192.0.1.19:9999/get_song?id=Tuhz5loupjz2cm45vf75nahh7wm
http://192.0.1.19:9999/get_song?id=Tscf4m2vahago3g2ix434ehck6u
http://192.0.1.19:9999/get_song?id=Taxzj52wzcskz32oc27bv7wt2ri

And now with the song ID you can call service media_player.play_media

{
  "entity_id": "media_player.bedroom_stereo",
  "media_content_id":"http://192.0.1.19:9999/get_song?id=Tscf4m2vahago3g2ix434ehck6u",
  "media_content_type":"music"
}

The song will play but still it lacks any song information or artwork.


I bet there’s a way to loop through the list of songs. It’s pretty easy to do with a simple bash script but I don’t how you would bring that into HA. Maybe a bash script could populate a list in HA somehow? Might be something easier for more people than trying to use the gmusicapi directly.

Probably something like this would be better written in python though (I just don’t know python or I’d try)

While I like and use GMusicProxy and it’s much easier to use – I think the ultimate HA integration would still just use gmusicapi directly

0 Likes

#5

Yep I agree gmusicapi is probably the way to go; I know a little python but not much, only enough to tweak and change existing components.

There is a commandline sensor for HA:

so you could in theory use Bash script to populate sensors, then use template sensors to get the values you need.

Not ideal but may work with no python needed.

0 Likes

#6

You know what? You’re correct and I don’t think I’ll have better motivation to learn python!

0 Likes

#8

That great that it’s working already good job. It’s nice to have some existing component to look at also, I was wondering how hard it would be to try and modify the old Danielhiversen component but I imagine quite a few things have changed since then, both with Home Assistant and Google music API.

I forgot to ask, what media player are you using? I know some media players can play mp3’s directly but with others it may be more tricky such as the alexa

0 Likes

#10

There are a few good thoughts about how you could get Google music running, sort of.

In my opinion these are more or less not that great workarounds.

The best approach IMIO would be directly using the gmusic API by home assistant.

If this will never be the case, for whatever reason, then I think building that gmusic proxy as an add on would be something which would be working as well.

0 Likes

#12

I think you can. I’ve been using a device_id from an old phone without issues

0 Likes