X-Git-Url: http://git.hcoop.net/clinton/xbmc-groove.git/blobdiff_plain/3b4634dff7aea8ecaba563e8401d15a71a9c7b39..b244bfd68a6f12f7e5895c8f3dfcccf5332ba4da:/resources/lib/GroovesharkAPI.py diff --git a/resources/lib/GroovesharkAPI.py b/resources/lib/GroovesharkAPI.py index 2a164df..c34d3ea 100644 --- a/resources/lib/GroovesharkAPI.py +++ b/resources/lib/GroovesharkAPI.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with xbmc-groove. If not, see . -import urllib2, pprint, md5, os, pickle, tempfile, time, re, simplejson, base64, sys, socket +import urllib2, pprint, os, pickle, tempfile, time, re, simplejson, base64, sys, socket, hashlib, getpass from blowfish import Blowfish SESSION_EXPIRY = 1209600 # 2 weeks @@ -38,18 +38,18 @@ class GrooveAPI: _sessionID = '' _userID = 0 _lastSessionTime = 0 - _key = md5.new(os.path.basename("GroovesharkAPI.py")).hexdigest() + _key = hashlib.md5(os.path.basename("GroovesharkAPI.py")).hexdigest() _debugging = False # Constructor - def __init__(self, debug): + def __init__(self, debug, tempDir): self._debugging = debug self.simplejson = simplejson if "linux" in sys.platform.lower(): socket.setdefaulttimeout(30) - self.cacheDir = os.path.join(tempfile.gettempdir(), 'groovesharkapi') + self.cacheDir = tempDir if os.path.isdir(self.cacheDir) == False: os.makedirs(self.cacheDir) if self._debugging: @@ -129,7 +129,7 @@ class GrooveAPI: return '' def _getSavedSession(self): - path = os.path.join(self.cacheDir, 'session.dmp') + path = os.path.join(self.cacheDir, 'groovesharksession.dmp') try: f = open(path, 'rb') session = pickle.load(f) @@ -152,7 +152,7 @@ class GrooveAPI: # Create the directory if it doesn't exist. if not os.path.exists(self.cacheDir): os.makedirs(self.cacheDir) - path = os.path.join(self.cacheDir, 'session.dmp') + path = os.path.join(self.cacheDir, 'groovesharksession.dmp') f = open(path, 'wb') session = { 'sessionID' : self._sessionID, 'lastSessionTime' : self._lastSessionTime, 'userID': self._userID, 'ip' : self._ip, 'country' : self._country } pickle.dump(session, f, protocol=pickle.HIGHEST_PROTOCOL) @@ -188,7 +188,7 @@ class GrooveAPI: # Authenticates the user for current API session def _authenticate(self, login, password): - md5pwd = md5.new(password).hexdigest() + md5pwd = hashlib.md5(password).hexdigest() params = {'login': login, 'password': md5pwd} result = self._callRemote('authenticate', params) @@ -312,7 +312,7 @@ class GrooveAPI: if 'result' in result and 'SongID' in result['result']: info = result['result'] if 'CoverArtFilename' in info and info['CoverArtFilename'] != None: - info['CoverArtFilename'] = THUMB_URL+info['CoverArtFilename'].encode('ascii', 'ignore') + info['CoverArtFilename'] = THUMB_URL+info['CoverArtFilename'].encode('utf8', 'ignore') else: info['CoverArtFilename'] = 'None' return info @@ -401,7 +401,7 @@ class GrooveAPI: artists = items['result']['artists'] while(i < len(artists)): s = artists[i] - itemList.append([s['artistName'].encode('ascii', 'ignore'),\ + itemList.append([s['artistName'].encode('utf8', 'ignore'),\ s['artistID']]) i = i + 1 return itemList @@ -481,18 +481,22 @@ class GrooveAPI: info = self.getSongsInfo(s['SongID']) coverart = info['CoverArtFilename'] elif s['CoverArtFilename'] != None: - coverart = THUMB_URL+s['CoverArtFilename'].encode('ascii', 'ignore') + coverart = THUMB_URL+s['CoverArtFilename'].encode('utf8', 'ignore') else: coverart = 'None' if 'Name' in s: name = s['Name'] else: name = s['SongName'] - itemList.append([name.encode('ascii', 'ignore'),\ + if 'AlbumName' in s: + albumName = s['AlbumName'] + else: + albumName = "" + itemList.append([name.encode('utf8', 'ignore'),\ s['SongID'],\ - name,\ + albumName.encode('utf8', 'ignore'),\ s['AlbumID'],\ - s['ArtistName'].encode('ascii', 'ignore'),\ + s['ArtistName'].encode('utf8', 'ignore'),\ s['ArtistID'],\ coverart]) i = i + 1 @@ -508,7 +512,7 @@ class GrooveAPI: artists = items['result']['artists'] while(i < len(artists)): s = artists[i] - itemList.append([s['ArtistName'].encode('ascii', 'ignore'),\ + itemList.append([s['ArtistName'].encode('utf8', 'ignore'),\ s['ArtistID']]) i = i + 1 return itemList @@ -531,14 +535,14 @@ class GrooveAPI: while(i < l): s = albums[i] if 'Name' in s: - name = s['Name'].encode('ascii', 'ignore') + name = s['Name'].encode('utf8', 'ignore') else: - name = s['AlbumName'].encode('ascii', 'ignore') + name = s['AlbumName'].encode('utf8', 'ignore') if 'CoverArtFilename' in s and s['CoverArtFilename'] != None: - coverart = THUMB_URL+s['CoverArtFilename'].encode('ascii', 'ignore') + coverart = THUMB_URL+s['CoverArtFilename'].encode('utf8', 'ignore') else: coverart = 'None' - itemList.append([s['ArtistName'].encode('ascii', 'ignore'),\ + itemList.append([s['ArtistName'].encode('utf8', 'ignore'),\ s['ArtistID'],\ name,\ s['AlbumID'],\