Pre-eden
[clinton/xbmc-groove.git] / default.py
index a98dc09..34f3814 100644 (file)
@@ -77,7 +77,7 @@ libDir = xbmc.translatePath(os.path.join(resDir,  'lib'))
 imgDir = xbmc.translatePath(os.path.join(resDir,  'img'))
 cacheDir = os.path.join(xbmc.translatePath('special://masterprofile/addon_data/'), os.path.basename(baseDir))
 thumbDirName = 'thumb'
-thumbDir = os.path.join('special://masterprofile/addon_data/', os.path.basename(baseDir), thumbDirName)
+thumbDir = os.path.join(xbmc.translatePath('special://masterprofile/addon_data/'), os.path.basename(baseDir), thumbDirName)
 
 baseModeUrl = 'plugin://plugin.audio.groove/'
 playlistUrl = baseModeUrl + '?mode=' + str(MODE_PLAYLIST)
@@ -240,7 +240,7 @@ class Grooveshark:
     popularSongsArtistImg = xbmc.translatePath(os.path.join(imgDir, 'popularSongsArtist.png'))
     songImg = xbmc.translatePath(os.path.join(imgDir, 'song.png'))
     defImg = xbmc.translatePath(os.path.join(imgDir, 'default.tbn'))
-    fanImg = xbmc.translatePath(os.path.join(baseDir, 'fanart.png'))
+    fanImg = xbmc.translatePath(os.path.join(baseDir, 'fanart.jpg'))
 
     settings = xbmcaddon.Addon(id='plugin.audio.groove')
     songsearchlimit = int(settings.getSetting('songsearchlimit'))
@@ -353,7 +353,7 @@ class Grooveshark:
                 artistID = artist[1]
                 if __debugging__ :
                     xbmc.log("Found " + artist[0] + "...")
-                albums = groovesharkApi.getArtistAlbums(artistID, limit = self.albumsearchlimit)
+                albums = groovesharkApi.getArtistAlbums(artistID, self.albumsearchlimit)
                 if (len(albums) > 0):
                     self._add_albums_directory(albums, artistID)
                 else:
@@ -440,7 +440,7 @@ class Grooveshark:
     # Show selected artist
     def artist(self, artistid):
         albums = groovesharkApi.getArtistAlbums(artistid, limit = self.albumsearchlimit)
-        self._add_albums_directory(albums, artistid)
+        self._add_albums_directory(albums, artistid, True)
     
     # Show selected playlist
     def playlist(self, playlistid, playlistname):
@@ -480,6 +480,7 @@ class Grooveshark:
     def playSong(self, item):
         global playTimer
         global player
+        player.stop()
         if item != None:
             url = ''
             songid = item.getProperty('songid')
@@ -796,7 +797,7 @@ class Grooveshark:
         xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg)
     
     # Add albums to directory
-    def _add_albums_directory(self, albums, artistid=0):
+    def _add_albums_directory(self, albums, artistid=0, isverified=False):
         n = len(albums)
         itemsExisting = n
         if __debugging__ :
@@ -805,7 +806,7 @@ class Grooveshark:
         while i < n:
             album = albums[i]
             albumID = album[3]
-            if groovesharkApi.getDoesAlbumExist(albumID):                    
+            if isverified or groovesharkApi.getDoesAlbumExist(albumID):                    
                 albumArtistName = album[0]
                 albumName = album[2]
                 albumImage = self._get_icon(album[4], 'album-' + str(albumID))
@@ -909,7 +910,7 @@ class Grooveshark:
         id = int(songid)
         duration = -1
         durations = []
-        path = os.path.join(cacheDir, 'durations.dmp')
+        path = os.path.join(cacheDir, 'duration.dmp')
         try:
             f = open(path, 'rb')
             durations = pickle.load(f)
@@ -921,12 +922,13 @@ class Grooveshark:
         except:
             pass
 
-        # Not in cache but exists
-        if duration < 0 and groovesharkApi.getDoesSongExist(songid):
+        # Not in cache
+        if duration < 0:
             stream = groovesharkApi.getSubscriberStreamKey(songid)
-            duration = self._setDuration(stream['uSecs'])
-            song = [id, duration]
-            self._setSongDuration(song, durations)
+            if stream != False and stream['url'] != '':
+                duration = self._setDuration(stream['uSecs'])
+                song = [id, duration]
+                self._setSongDuration(song, durations)
 
         return duration
         
@@ -936,7 +938,7 @@ class Grooveshark:
             # Create the cache directory if it doesn't exist.
             if not os.path.exists(cacheDir):
                 os.makedirs(cacheDir)
-            path = os.path.join(cacheDir, 'durations.dmp')
+            path = os.path.join(cacheDir, 'duration.dmp')
             f = open(path, 'wb')
             pickle.dump(durations, f, protocol=pickle.HIGHEST_PROTOCOL)
             f.close()