Last active
December 11, 2015 18:19
-
-
Save andrewytliu/4640389 to your computer and use it in GitHub Desktop.
Fixing encoding problem in Google Music
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 getpass import getpass | |
class Tagging: | |
def __init__(self): | |
self.api = Api() | |
logged_in = False | |
attempts = 0 | |
while not logged_in and attempts < 3: | |
email = raw_input("Email: ") | |
password = getpass() | |
logged_in = self.api.login(email, password) | |
attempts += 1 | |
def convert_library(self): | |
print ">>> Loading metadata from server..." | |
lib = self.api.get_all_songs() | |
for s in lib: | |
self.__convert_entry(s) | |
print ">>> Uploading changes..." | |
self.api.change_song_metadata(lib) | |
print ">>> Done" | |
def __convert_entry(self, entry): | |
for k in entry.keys(): | |
entry[k] = self.__ascii(entry[k]) | |
def __ascii(self, s): | |
if type(s) != unicode: | |
return s | |
try: | |
s.decode('ascii') | |
except UnicodeEncodeError: | |
try: | |
return unicode(s.encode('iso-8859-1'), 'cp950') | |
except: | |
return s | |
else: | |
return s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment