DanNixon / PlayMusicCL

A command line client for Google Play Music
Apache License 2.0
135 stars 21 forks source link

Support All Access tracks #21

Closed aqtrans closed 9 years ago

aqtrans commented 10 years ago

I cannot seem to get this working on ArchLinux running with Python 2.7.8, it spits out the following:

9146@11:42:23-aqtrans@homer|~/build/PlayMusicCL$ playmusiccl
** Message: pygobject_register_sinkfunc is deprecated (GstObject)
Logging in to Google Play Music...
Logging in to Last.fm...
Creating GStreamer player...
Updating local library from Google Play Music...
Traceback (most recent call last):
  File "/usr/bin/playmusiccl", line 9, in <module>
    load_entry_point('playmusiccl==0.6.0', 'console_scripts', 'playmusiccl')()
  File "/usr/lib/python2.7/site-packages/playmusiccl-0.6.0-py2.7.egg/playmusiccl/__init__.py", line 7, in run
    main()
  File "/usr/lib/python2.7/site-packages/playmusiccl-0.6.0-py2.7.egg/playmusiccl/playmusiccl.py", line 746, in main
    __MusicClient__.update_local_lib()
  File "/usr/lib/python2.7/site-packages/playmusiccl-0.6.0-py2.7.egg/playmusiccl/playmusiccl.py", line 111, in update_local_lib
    song = song_map[track["trackId"]]
KeyError: u'Thh4ppuotycvjyhlw2tkpxz7inm'

I installed both PlayMusicCL and Unofficial-Google-Music-API from git. I did have to make some slight modifications to the PlayMusicCL scripts in order to allow them to run properly in the python3/python2 ArchLinux environment:

9136@11:38:50-aqtrans@homer|~$ head -n1 /usr/lib/python2.7/site-packages/playmusiccl/playmusiccl.py
#!/usr/bin/python2
9137@11:38:56-aqtrans@homer|~$ head -n1 /usr/bin/playmusiccl 
#!/usr/bin/python2

The "Updating local library from Google Play Music..." bit seems to take a while, and stracing the process does show some successful communication, so I think it's logging in at least.

bedekelly commented 10 years ago

Same error on Ubuntu 14.04, Python 2.7.6. Login is definitely successful. Could this just be an encoding issue, say if the keys aren't stored as unicode? If that's the case, just a simple str() would solve the issue. Tried it, didn't work.

As a quick fix I just wrote this in:

for track in plist["tracks"]:
    try:
        song = song_map[track["trackId"]]
    except:
        pass
    else:
        self.playlists[plist_name].append(song)
DanNixon commented 10 years ago

Can you tell which playlist it is? Does it contain All Access tracks? I'm not really sure what would be causing this issue.

bedekelly commented 10 years ago

It's just the first one of my playlists; and yes, it has All Access tracks. Maybe the id of an All Access song doesn't work in the same way with the API? I haven't done too much reading on the All Access issue to be honest, I'm not even sure if the gmusicapi allows you to stream an All Access track... api.search_all_access() does return tracks with an 'nid' key but I can't see an 'id' key.

vulcanfk commented 10 years ago

Can confirm this issue. I'm also seeing it on Ubuntu 14.04 with Python 2.7.6. @bedekelly 's workaround is successful. However, the only songs that pass that check appear to be songs that have been purchased and are available for download.

This used to work for all access tracks (I added all access support earlier this year). I'll be looking into this further to try and find a workaround.

vulcanfk commented 10 years ago

Part of the issue here is this is limited to the songs returned by get_all_songs(). Don't have any more time right now to dig in, but I suspect this is only returning purchased songs.

DanNixon commented 10 years ago

I'm not convinced that is the issue, on the latest version of gmusicapi I still get music I have uploaded (I don't use All Access and only have about 2 purchased albums).

2014-10-08-221002_1366x768_scrot 2014-10-08-221033_1366x768_scrot

vulcanfk commented 10 years ago

Right...uploaded music is also available for download. If you upload a song or purchase a song, you are able to download that song. If you can download a song, it shows up in a playlist with the workaround mentioned above.

With All Access, you are able to add songs that you have not purchased or uploaded to a playlist. However, if you open the options for that song on Google Play Music, you do not have the option to download it. Those songs are not showing in playlists.

bedekelly commented 10 years ago

I think the underlying issue lies with gmusicapi itself; it doesn't treat All Access songs as belonging to your library. Perhaps Google is more restrictive about generating stream URLs for All Access songs? Could be beneficial to ask Simon Weber for clarification. Sorry, was thinking of non-library songs. My own player hasn't been experiencing any problems playing All Access songs (that have been added to the library), so I'm not sure what's going on here. For me, get_all_songs does return every song currently in my library, not just the ones I've uploaded.

vulcanfk commented 10 years ago

Yep, I wrote a quick script that calls get_all_user_playlist_contents() and then get_stream_url() for each track in a playlist. I am able to get stream URLs for every track, including All Access tracks.

The issue is with the implementation in playmusiccl. It is storing songs via get_all_songs(), and only allowing those songs to be played from your playlists. It appears get_all_songs() is only returning uploaded or purchased songs.

vulcanfk commented 10 years ago

I've created a simple script that takes 1 argument (name of a GPM playlist) and plays all songs in the playlist, including All Access tracks. It's a quick proof of concept that the API supports All Access. It's available here (http://pastebin.com/V7E8najs) if you want to check it out. Note that you'll have to enter your credentials at the top, and change the command used to play the stream if you don't have VLC installed or if it's installed in a different location.

DanNixon commented 10 years ago

I think there was a reason why I didn't originally do something like that, are the song dicts that get_all_user_playlist_contents() returns the same as get_all_songs()?

Usually I would take more time to look at this myself but since I don't use All Access I'm kind of stuck here.

vulcanfk commented 10 years ago

They are different. The tracks returned by get_all_user_playlist_contents() seem to have a subset of the song information returned by get_all_songs(). Tracks don't include things such as artist/album/rating/etc, so it would likely prevent (or at least require some workaround) to Thumbs Up/Down an All Access song.

DanNixon commented 10 years ago

That sounds familiar, missing out that information would be inhibiting to other features (rating, Last.fm, etc.).

vulcanfk commented 10 years ago

So, I'm not sure what your decision would be here. If you do not intend to support All Access due to the items mentioned, I think @bedekelly 's workaround should probably be implemented to prevent other people from experiencing the issue. Just my $.02.

DanNixon commented 10 years ago

I would like to support it, but not at the cost of other features. The fix you suggest would not be suitable since not all the track data would be available.

I'm sure there must be some way to get this data for All Access tracks.

nwalters512 commented 9 years ago

Is this issue ever going to be fixed? I just installed playmusiccl and got this error. I am using a Play Music All Access account on a Raspberry Pi running the latest version of Raspbian.

DanNixon commented 9 years ago

As per the conversation so far, supporting all access with the current API would break existing features (unless of course the API has since changed).

I have neither an all access account or the time to look at this right now.

lpar commented 9 years ago

How about making the README warn of the problem? Something like:

A command line client for Google Play Music. Note that it does not support Google Play All Access.

DanNixon commented 9 years ago

I give in, I'll try to fix all access if someone is available to test it for me.

lpar commented 9 years ago

I volunteer. I'm running Debian and installed PlayMusicCL using pip. I'm a sysadmin and developer, but not a Python developer.

DanNixon commented 9 years ago

Cool. I admit I may not get round to this for a few weeks as I'm fairly busy with full time and evening work at the moment.

lpar commented 9 years ago

This should make things easier: http://www.androidcentral.com/google-play-music-launches-free-ad-supported-version-us

DanNixon commented 9 years ago

I'm in the UK.

Besides I could just use the 30 day trial, the issue keeping me from finishing this at the moment is time.

DanNixon commented 9 years ago

PR #26 seems to have fixed this, my playlists with a combination of all access and uploaded tracks now work. If those originally having the problem are happy I will close this.