soulfx / gmusic-playlist

playlist scripts for gmusic
MIT License
158 stars 57 forks source link

Added exporting of Thumbs up playlist #18

Closed scowalt closed 9 years ago

scowalt commented 9 years ago

This resolves #6

I put this feature together as part of another project I'm working on, figured you may find it useful :)

Feel free to suggest changes and improvements. I made a big refactor and Python isn't my primary language. For example, I'm quite confident there's a more "idiomatic" or "code-golf"y way to do this

Thanks for making these very useful scripts!

soulfx commented 9 years ago

In the latest gmusicapi the get_thumbs_up_songs method has been renamed to get_promoted_songs. The change in name occured due to https://github.com/simon-weber/Unofficial-Google-Music-API/issues/282 Can you submit a change to your code so that it would be compatible with the latest version of gmusicapi?

Also, a call to the get_..._songs method (under both the new and old name) doesn't return as many results as I would have thought there should be. Have you noticed similar odd behavior? In my case I have over 1500 songs thumbed up, and it returned only about 300. The method comments indicate it only returns all access tracks that have been rated, but I know I have more than 300 all access tracks that I've thumbed up.

scowalt commented 9 years ago

Hey soulfx,

I should have actually checked the output of my change more closely! >_<

So get_thumbs_up_songs clearly doesn't return all of the songs in the Thumbs up playlist (it was about 100 out of 800 for me). The api.get_promoted_songs() returns a "has no attribute" error, so maybe the version of the library on pip doesn't include this change? I still need to look into that. However, it doesn't appear that this function call is intended to return the thumbs-up playlist. From the comments of the method: Promoted tracks are determined in an unknown fashion, but positively-rated library tracks are common.

Interestingly, the following code block also returns a subset of the Thumbs up playlist. I got about 700 of my 800 tracks using this

# get thumbs up playlist
thumbs_up_tracks = []
for track in library:
    if track.get('rating') is not None and int(track.get('rating')) > 1:
        thumbs_up_tracks.append(track)

Oddly enough, the subset this method return seems to be consistent. Since some of the tracks omitted were all-access tracks (and not personal uploaded tracks), I would imagine the this is due to gremlins in the API. However, I can update my code with the above snippet if it's the closest we'd be able to get.

soulfx commented 9 years ago

Hi scowalt,

I appreciate you looking into this. The code block that you provide seems like it would be closer to returning a list of thumbed up tracks than the api method. I suggest we go with implementing the suggest code block. It would give us something to build on.

I imagine that one could ensure that all thumbed up tracks are added to the library using the web interface prior to running the export script. It should then be able to export all tracks.

Regards, soul

scowalt commented 9 years ago

I changed my code to include the code block I posted above. I also squeezed my commits.

If I find a way to reliably get all of the Thumbs up tracks I will be sure to make a new pull request (or modify this one if left open)