# along with xbmc-groove. If not, see <http://www.gnu.org/licenses/>.
-import urllib, sys, os, shutil, re, pickle, time, traceback, xbmcaddon, xbmcplugin, xbmcgui, xbmc
+import urllib, urllib2, sys, os, shutil, re, pickle, time, traceback, xbmcaddon, xbmcplugin, xbmcgui, xbmc
__addon__ = xbmcaddon.Addon('plugin.audio.groove')
__addonname__ = __addon__.getAddonInfo('name')
if (query != ''):
artists = groovesharkApi.getArtistSearchResults(query, limit = self.artistsearchlimit)
if (len(artists) > 0):
- artist = artists[0]
+ # check for artist name match, first result is sometimes not the closest lexical match
+ artist = next ((a for a in artists if a[0].lower() == query.lower()), artists[0])
artistID = artist[1]
if __debugging__ :
xbmc.log("Found " + artist[0] + "...")
if (query != ''):
artists = groovesharkApi.getArtistSearchResults(query, limit = self.artistsearchlimit)
if (len(artists) > 0):
- artist = artists[0]
+ # check for exact artist name match, sometimes a more
+ # popular artist is returned first (e.g. 'Angel Dust'
+ # gets you 'Faith No More' because of their popular
+ # album 'Angel Dust')
+ artist = next ((a for a in artists if a[0].lower() == query.lower()), artists[0])
artistID = artist[1]
if __debugging__ :
xbmc.log("Found " + artist[0] + "...")
localThumb = os.path.join(xbmc.translatePath(os.path.join(thumbDir, str(songid)))) + '.tbn'
try:
if os.path.isfile(localThumb) == False:
- loc = urllib.URLopener()
- loc.retrieve(url, localThumb)
+ headers = { 'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.102 Chrome/32.0.1700.102 Safari/537.36' }
+ req = urllib2.Request(url, None, headers)
+ loc = urllib2.urlopen(req)
+ output = open(localThumb,'wb')
+ output.write(loc.read())
+ output.close()
except:
shutil.copy2(thumbDef, localThumb)
return os.path.join(os.path.join(thumbDir, str(songid))) + '.tbn'
while i < n:
album = albums[i]
albumID = album[3]
- if isverified or groovesharkApi.getDoesAlbumExist(albumID):
+ if isverified:
albumArtistName = album[0]
albumName = album[2]
albumImage = self._get_icon(album[4], 'album-' + str(albumID))
while i < n:
artist = artists[i]
artistID = artist[1]
- if groovesharkApi.getDoesArtistExist(artistID):
- artistName = artist[0]
- self._add_dir(artistName, '', MODE_ARTIST, self.artistImg, artistID, itemsExisting)
- else:
- itemsExisting = itemsExisting - 1
+ artistName = artist[0]
+ self._add_dir(artistName, '', MODE_ARTIST, self.artistImg, artistID, itemsExisting)
i = i + 1
xbmcplugin.setContent(self._handle, 'artists')
xbmcplugin.addSortMethod(self._handle, xbmcplugin.SORT_METHOD_ARTIST_IGNORE_THE)
def _getSongStream(self, songid):
idSong = int(songid)
stream = None
- streams = []
+ streams = {}
path = os.path.join(cacheDir, 'streams.dmp')
try:
f = open(path, 'rb')
streams = pickle.load(f)
- for song in streams:
- if song[0] == idSong:
- duration = song[1]
- url = song[2]
- key = song[3]
- server = song[4]
- stream = [idSong, duration, url, key, server]
- if __debugging__ :
- xbmc.log("Found " + str(idSong) + " in stream cache")
- break;
+ song = streams[songid]
+
+ duration = song[1]
+ url = song[2]
+ key = song[3]
+ server = song[4]
+ stream = [idSong, duration, url, key, server]
+
+ if __debugging__ :
+ xbmc.log("Found " + str(idSong) + " in stream cache")
+
f.close()
except:
pass
def _addSongStream(self, stream):
streams = self._getStreams()
- streams.append(stream)
+ streams[int(stream[0])] = stream
path = os.path.join(cacheDir, 'streams.dmp')
try:
f = open(path, 'wb')
stream[1] = self._setDuration(stream[1])
streams = self._getStreams()
path = os.path.join(cacheDir, 'streams.dmp')
- i = 0
- for song in streams:
- if song[0] == idStream:
- streams[i] = stream
- try:
- f = open(path, 'wb')
- pickle.dump(streams, f, protocol=pickle.HIGHEST_PROTOCOL)
- f.close()
- if __debugging__ :
- xbmc.log("Updated " + str(idStream) + " in stream cache")
- break;
- except:
- xbmc.log("An error occurred setting stream")
- i = i + 1
+ try:
+ streams[idStream] = stream
+ f = open(path, 'wb')
+ pickle.dump(streams, f, protocol=pickle.HIGHEST_PROTOCOL)
+ f.close()
+ if __debugging__ :
+ xbmc.log("Updated " + str(idStream) + " in stream cache")
+
+ except:
+ xbmc.log("An error occurred setting stream")
def _getStreams(self):
path = os.path.join(cacheDir, 'streams.dmp')
streams = pickle.load(f)
f.close()
except:
- streams = []
+ streams = {}
pass
return streams