simon-weber / gmusicapi

An unofficial client library for Google Music.
https://unofficial-google-music-api.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.48k stars 258 forks source link

Get Playlists data #12

Closed Yosifz8 closed 12 years ago

Yosifz8 commented 12 years ago

Hi

i research about all google music stuff and use: http://music.google.com/music/services/loadalltracks?u=0&xt=? link to get all songs data from google music.

i try to search about another services of google music but didn't found anything for handle playlists and other stuff.

did you can help with stuff like this?

dpogue commented 12 years ago

You can already fetch playlists using this API: http://readthedocs.org/docs/unofficial-google-music-api/en/latest/#gmusicapi.api.Api.get_playlist_songs

If you're trying to write your own, you might be interested in looking into the Skyjam service API: my brief docs and my skyjam-enabled branch of this API

simon-weber commented 12 years ago

Right. If you just want to use the api, use get_playlists and then get_playlist_songs.

If you're interested in how it's actually implemented, you'll want to look in the code. get_playlists actually looks through the markup of the web client html to find ids and names. As far as I can tell, there's no other way for the web client to get playlist ids. get_playlist_songs uses a normal web client call with a playlist id to get the actual songs.

Does that help?

Yosifz8 commented 12 years ago

I want to use it in Objective-c code but i don't know how and if i can...

and i looking for urls in the code and didn.t find nothing

Yosifz8 commented 12 years ago

For example i try to use this code : class addplaylist(WC_Call): """Creates a new playlist."""

    @staticmethod
    def build_transaction(title): 
        """
        :param title: the title of the playlist to create.
        """

        req = {"title": title}

}

so i send this:

http://music.google.com/music/services/addplaylist?u=0&xt=%@

%@ = cookie and set the post key to :"title" and the value name.

but it always send me back a false.

simon-weber commented 12 years ago

Ah, ok. Like @dpogue said, you're probably better off using the Skyjam api rather than the web one for a port.

But, if you do want to use the web client, you're pretty close. You post just a single key called json and set that to your encoded request. Here's an example from the browser I captured with Fiddler (you want to use Fiddler - it'll make things much clearer), setting the title to today's date:

POST https://play.google.com/music/services/addplaylist?u=0&xt=<cookie>
Host: play.google.com
Connection: keep-alive
Content-Length: 51
Origin: https://play.google.com
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Accept: */*
Referer: https://play.google.com/music/listen?u=0
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: <my auth info>

json=%7B%22title%22%3A%22March%2015%2C%202012%22%7D

Check the comments, they explain the format of the protocol. Basically, most calls are made to music.google.com/music/services/<name>, and the WC_Call object is the name (addplaylist, in this example).

Does that clear it up?

Yosifz8 commented 12 years ago

Yesssss

thanks a lot for the help, unfortunately i can't check it because Google may change some stuff in their authentication process.

Yosifz8 commented 12 years ago

Edit:

I do like you said :

https://play.google.com/music/services/addplaylist?u=0&xt=%@
%@ = xt cookie

and set a post value

key-json , value-%7B%22title%22%3A%22March%2015%2C%202012%22%7D

and i still get : {"success":false}

and before this method i use : http://music.google.com/music/services/loadplaylist?u=0&xt=%@ %@ = xt cookie

and it work just fine, any idea why it give me this error again?

simon-weber commented 12 years ago

It's hard to say without seeing the exact requests you're making. Getting back "success":false usually means the actual request was malformed (like you left off a newline) or impossible to handle (like if you requested a non-existant playlist id). You'd see a different error if the authentication was invalid.

The easiest way to fix it is probably to fire up Fiddler and use it to proxy both your requests and the actual web client's requests. Then you can compare them and see what's different. Your requests have to be perfectly formatted for everything to work.

On a hunch, you might try changing the user agent; I know you need to be using a common one for the requests to work.

Yosifz8 commented 12 years ago

ok

like you suggest me i use Fiddler,and find where is the problem : the json need to be as a normal and not encoded

simon-weber commented 12 years ago

Intersting. I just tried my code, and it only works when encoded. Do you mean you had to send a post body of the form json={"playlistId"...?

Or maybe I'm just misunderstanding. Were you encoding the json= part? Or maybe you were encoding twice by accident?

Yosifz8 commented 12 years ago

No i just send "json" as the key and "{"playlistId"..." as the value and it work now,

thx for the help!!!

simon-weber commented 12 years ago

Glad I could help. I'm going to go ahead and close this ticket; feel free to open another if you have more questions.