Created
February 25, 2013 14:33
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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." | |
#Get all of the users songs. | |
print "Loading library..." | |
library = api.get_all_songs() | |
print len(library), "tracks detected." | |
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