1

I wanted to append to my website a "what is he listening to now!" functionality for my website, which will say something like off-air, or whatever the current song is. I didnt know if there is a way to do that.

I wanted to find a way to spread music tastes around, it would be one of those things where if the person visiting my site had google music, they could listen to that song too OR click it to boot up their player to that song.

I didnt know if there were any APIs out there for a given Google Username, or anything like that.

Does anyone know IF / HOW this could be accomplished?

I was thinking i could have a script which could ping googles website, or maybe run a php script which will populate a list or database with information.

Fallenreaper
  • 8,518
  • 10
  • 53
  • 107

2 Answers2

2

According to the products page on Google Developers, there is no API relevant to Google Play Music.


You could create a bookmarklet or browser extension to pull the song title, etc. from the user and submit it to your server with ajax. To get the info with jQuery:
title = $("#playerSongTitle").text(); //Song title
artist = $("#player-artist").text(); //Song artist
album = $(".player-album:first").text(); //Album title
data = JSON.stringify([title, artist, album]); //Generate json string
$.post('http://www.example.com/postSong.php', data); //Send to server

Make sure to set the Access-Control-Allow-Origin header server-side to allow the incoming request.


Demo:

Here's a bookmarklet (vanilla JS):

javascript:alert('Title: '+document.getElementById('playerSongTitle').innerHTML+'. Artist: '+document.getElementById('player-artist').innerHTML+'. Album: '+document.getElementsByClassName('player-album')[0].innerHTML+'.');

This function will fail if the elements don't exist on the page. In production, use the following to check that the information is available:

if(document.getElementsByClassName('player-album').length > 0){
    //Music info is available
}else{
    //Music info is not available
}
Community
  • 1
  • 1
Mooseman
  • 18,150
  • 12
  • 67
  • 91
  • Ahh, so i guess i would just need to associate that extension to my Chrome/Google account and then while im listening to music, the extension would just push to myserver... and then people sitting on my site could just have a spinner that pings every minute, looking for a new DB entry? – Fallenreaper Jul 18 '14 at 18:58
  • Im going to look into this and see if i can do it. I think this would be an ideal way to do it. If i can make a rough example in any way ill give you the answer. :) – Fallenreaper Jul 18 '14 at 19:22
  • 1
    The extension doesn't need any authentication. I added a simple demo. A better way to watch for a change would be to continually check client-side if the title *or* artist changes, and send it to the server if it changes. – Mooseman Jul 18 '14 at 22:36
0

There is an open source project on Github: https://github.com/simon-weber/Unofficial-Google-Music-API which also references his website: http://unofficial-google-music-api.readthedocs.org/en/latest/

Now, from what i am seeing and managing is that while you cant see what someone is seeing persay, you can use this app to download to a computer or server, and then access those downloaded streams via your website.

YOU CANT SHARE THIS PUBLICLY THOUGH, as it breaks the EULA. Make sure you follow the rules with it, because i know i dont want to have issues. This can come in handy though if you have a brain server doing this computation, and then worker servers just pinging on an as needed basis. This is a side goal of what i wanted to do. Allow me to create a fading system to allow me to play music around the house dependant on what room i am in, instead of it always in the living room.

Now, if you want to break EULA (I Dont want you to, i know i am not), but you can store the current song on the server, and then each time the website loads, it would just lazyload the current file being played or the current playlist. Doing this though, as you can image means you cant play music on your devices because you can only have 1 access point to the music, so you as the individual would have to set the webserver to whatever you want to listen to, and then just stream it from the webserver instead of your device.

Thought you all out there would like to know. :)

Fallenreaper
  • 8,518
  • 10
  • 53
  • 107