Skip to content

Instantly share code, notes, and snippets.

@mmai
Created February 25, 2013 14:33
Show Gist options
  • Save mmai/5030172 to your computer and use it in GitHub Desktop.
Save mmai/5030172 to your computer and use it in GitHub Desktop.
Retrieve all user songs from GMusic and save them in a CSV file.
#!/usr/bin/env python
from gmusicapi.api import Api
from django.utils.encoding import smart_str
import csv
from settings import settings
def main():
api = Api()
api.login(settings['email'], settings['password'])
if not api.is_authenticated():
print "Sorry, those credentials weren't accepted."
return
print "Successfully logged in."
print
#Get all of the users songs.
print "Loading library..."
library = api.get_all_songs()
print len(library), "tracks detected."
print
print "writing csv"
listWriter = csv.DictWriter(open('gmusiclibrary.csv', 'wb'), fieldnames=['id', 'rating', 'name', 'album', 'albumArtist', 'artist', 'composer', 'disc', 'genre', 'playCount', 'totalDiscs', 'totalTracks', 'track', 'year', 'type', 'comment', 'durationMillis', 'creationDate', 'matchedId', 'url', 'albumArtUrl'], delimiter='`', extrasaction='ignore')
for song in library:
songok = {k: smart_str(v).replace('`', "'") for k, v in song.items()}
listWriter.writerow(songok)
api.logout()
print "All done!"
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment