X-Git-Url: http://git.hcoop.net/clinton/xbmc-groove.git/blobdiff_plain/28ca437aa35105cd05429687ef1f99fe0696f32b..54b424d28cbc56fd958c915170a0e4efd8b1eb39:/resources/lib/GroovesharkAPI.py diff --git a/resources/lib/GroovesharkAPI.py b/resources/lib/GroovesharkAPI.py index added07..fd09c16 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 from blowfish import Blowfish SESSION_EXPIRY = 1209600 # 2 weeks @@ -38,7 +38,7 @@ 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 @@ -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 @@ -397,14 +397,14 @@ class GrooveAPI: items = self._callRemote("getSimilarArtists", {"artistID": artistId, "limit": limit}) if 'result' in items: i = 0 - list = [] + itemList = [] artists = items['result']['artists'] while(i < len(artists)): s = artists[i] - list.append([s['artistName'].encode('ascii', 'ignore'),\ + itemList.append([s['artistName'].encode('utf8', 'ignore'),\ s['artistID']]) i = i + 1 - return list + return itemList else: return [] @@ -443,7 +443,7 @@ class GrooveAPI: def _parseSongs(self, items, limit=0): if 'result' in items: i = 0 - list = [] + itemList = [] index = '' l = -1 try: @@ -481,22 +481,26 @@ 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'] - list.append([name.encode('ascii', 'ignore'),\ + if 'AlbumName' in s: + albumName = s['AlbumName'] + else: + albumName = "" + itemList.append([name.encode('utf8', 'ignore'),\ s['SongID'],\ - s['AlbumName'].encode('ascii', 'ignore'),\ + albumName.encode('utf8', 'ignore'),\ s['AlbumID'],\ - s['ArtistName'].encode('ascii', 'ignore'),\ + s['ArtistName'].encode('utf8', 'ignore'),\ s['ArtistID'],\ coverart]) i = i + 1 - return list + return itemList else: return [] @@ -504,14 +508,14 @@ class GrooveAPI: def _parseArtists(self, items): if 'result' in items: i = 0 - list = [] + itemList = [] artists = items['result']['artists'] while(i < len(artists)): s = artists[i] - list.append([s['ArtistName'].encode('ascii', 'ignore'),\ + itemList.append([s['ArtistName'].encode('utf8', 'ignore'),\ s['ArtistID']]) i = i + 1 - return list + return itemList else: return [] @@ -519,7 +523,7 @@ class GrooveAPI: def _parseAlbums(self, items, limit=0): if 'result' in items: i = 0 - list = [] + itemList = [] try: albums = items['result']['albums'] except: @@ -530,23 +534,27 @@ class GrooveAPI: l = limit while(i < l): s = albums[i] + if 'Name' in s: + name = s['Name'].encode('utf8', 'ignore') + else: + 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' - list.append([s['ArtistName'].encode('ascii', 'ignore'),\ + itemList.append([s['ArtistName'].encode('utf8', 'ignore'),\ s['ArtistID'],\ - s['AlbumName'].encode('ascii', 'ignore'),\ + name,\ s['AlbumID'],\ coverart]) i = i + 1 - return list + return itemList else: return [] def _parsePlaylists(self, items): i = 0 - list = [] + itemList = [] if 'result' in items: playlists = items['result']['playlists'] elif len(items) > 0: @@ -556,6 +564,6 @@ class GrooveAPI: while (i < len(playlists)): s = playlists[i] - list.append([str(s['PlaylistName']).encode('utf-8'), s['PlaylistID']]) + itemList.append([unicode(s['PlaylistName']).encode('utf8', 'ignore'), s['PlaylistID']]) i = i + 1 - return list + return itemList