Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import loved tracks to Google Play Music Highly rated tracks
#!/usr/bin/env python
import netrc, urllib, urllib2
from gmusicapi.api import Api
from xml.etree.ElementTree import *
lastfm__user = 'oquno'
api_key = 'your apikey'
def init():
api = Api()
(email, account, password) = netrc.netrc().hosts['']
logged_in = api.login(email, password)
if not logged_in:
api = None
return api
def get_loved():
loved = []
page = 1
while True:
url = ''
url = url % (lastfm_user, api_key, page)
tree = parse(urllib2.urlopen(url)).getroot()
tracks = tree.findall('lovedtracks/track')
for track in tracks:
title = track.find('name').text
artist = track.find('artist/name').text
if not len(tracks) == 50:
return loved
def main():
api = init()
if api == None:
print 'login error'
loved = get_loved()
if len(loved) == 0:
print 'no loved tracks'
songs = api.get_all_songs()
if len(songs) == 0:
print 'no songs in library'
favs = []
for song in songs:
if [song['artist'], song['name']] in loved:
song['rating'] = 5
print '☝: %s - %s' % (song['artist'], song['name'])
if __name__ == '__main__':
Copy link

samithaj commented Aug 8, 2013

Please tell me how to do it??

Copy link

Timmmm commented Sep 15, 2013

This is out of date. It won't work any more.

See my update here:

It uses Google Play Music All Access™. Not tested very much but you should be able to get it to work without too much hassle (most of the hassle I had was with pip and easy_install being shit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment