Verify items before adding to directories.
authorstephendenham <stephendenham@2dec19e3-eb1d-4749-8193-008c8bba0994>
Sun, 2 Oct 2011 13:37:07 +0000 (13:37 +0000)
committerstephendenham <stephendenham@2dec19e3-eb1d-4749-8193-008c8bba0994>
Sun, 2 Oct 2011 13:37:07 +0000 (13:37 +0000)
git-svn-id: svn://svn.code.sf.net/p/xbmc-groove/code@59 2dec19e3-eb1d-4749-8193-008c8bba0994

addon.xml
changelog.txt
default.py
description.xml
resources/language/English/strings.xml
resources/lib/GroovesharkAPI.py
resources/settings.xml

index 8b111ef..7827afb 100644 (file)
--- a/addon.xml
+++ b/addon.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <addon id="plugin.audio.groove" name="Grooveshark XBMC"
-       version="0.6.1" provider-name="Stephen Denham">
+       version="0.6.2" provider-name="Stephen Denham">
        <requires>
                <import addon="xbmc.python" version="1.0" />
                <import addon="script.module.simplejson"/>
@@ -12,7 +12,7 @@
                <platform>all</platform>
                <summary lang="en">Grooveshark addon for XBMC.</summary>
                <description lang="en">
-                       Grooveshark addon for XBMC. You should enter your Grooveshark username and password in the addon settings.
+                       Grooveshark addon for XBMC. You should enter your Grooveshark Anywhere username and password in the addon settings.
                </description>
        </extension>
 </addon>
index b373285..5608c3f 100644 (file)
@@ -1,3 +1,7 @@
+0.6.2
+
+Check item existence before adding to directory.
+
 0.6.1
 
 Some more changes for XBMC addon compliancy.
index cb8f31f..8ebbdd4 100644 (file)
@@ -25,6 +25,7 @@ __author__    = __addon__.getAddonInfo('author')
 __version__   = __addon__.getAddonInfo('version')
 __language__  = __addon__.getLocalizedString
 
+
 MODE_SEARCH_SONGS = 1
 MODE_SEARCH_ALBUMS = 2
 MODE_SEARCH_ARTISTS = 3
@@ -219,7 +220,7 @@ class PlayTimer(Thread):
         return self.iterations * self.interval
 
 
-class Groveshark:
+class Grooveshark:
     
     albumImg = xbmc.translatePath(os.path.join(imgDir, 'album.png'))
     artistImg = xbmc.translatePath(os.path.join(imgDir, 'artist.png'))
@@ -240,17 +241,21 @@ class Groveshark:
     songspagelimit = int(settings.getSetting('songspagelimit'))
     username = settings.getSetting('username')
     password = settings.getSetting('password')
+
     userid = 0
     
     def __init__( self ):
         self._handle = int(sys.argv[1])
+        self.setDebug()
         if os.path.isdir(cacheDir) == False:
             os.makedirs(cacheDir)
-            xbmc.log(__language__(30012) + " " + cacheDir)
+            if self.debug:
+                xbmc.log(__language__(30012) + " " + cacheDir)
         artDir = xbmc.translatePath(thumbDir)
         if os.path.isdir(artDir) == False:
             os.makedirs(artDir)
-            xbmc.log(__language__(30012) + " " + artDir)
+            if self.debug:
+                xbmc.log(__language__(30012) + " " + artDir)
             
     # Top-level menu
     def categories(self):
@@ -339,7 +344,8 @@ class Groveshark:
             if (len(artists) > 0):
                 artist = artists[0]
                 artistID = artist[1]
-                xbmc.log("Found " + artist[0] + "...")
+                if self.debug:
+                    xbmc.log("Found " + artist[0] + "...")
                 albums = groovesharkApi.getArtistAlbums(artistID, limit = self.albumsearchlimit)
                 if (len(albums) > 0):
                     self._add_albums_directory(albums, artistID)
@@ -395,7 +401,8 @@ class Groveshark:
     def favorite(self, songid):
         userid = self._get_login()
         if (userid != 0):
-            xbmc.log("Favorite song: " + str(songid))
+            if self.debug:
+                xbmc.log("Favorite song: " + str(songid))
             groovesharkApi.addUserFavoriteSong(songID = songid)
             xbmc.executebuiltin('XBMC.Notification(' + __language__(30008) + ', ' + __language__(30036) + ', 1000, ' + thumbDef + ')')
         else:
@@ -406,7 +413,8 @@ class Groveshark:
     def unfavorite(self, songid, prevMode=0):
         userid = self._get_login()
         if (userid != 0):
-            xbmc.log("Unfavorite song: " + str(songid) + ', previous mode was ' + str(prevMode))
+            if self.debug:
+                xbmc.log("Unfavorite song: " + str(songid) + ', previous mode was ' + str(prevMode))
             groovesharkApi.removeUserFavoriteSongs(songIDs = songid)
             xbmc.executebuiltin('XBMC.Notification(' + __language__(30008) + ', ' + __language__(30038) + ', 1000, ' + thumbDef + ')')
             # Refresh to remove item from directory
@@ -445,7 +453,8 @@ class Groveshark:
             if (len(artists) > 0):
                 artist = artists[0]
                 artistID = artist[1]
-                xbmc.log("Found " + artist[0] + "...")
+                if self.debug:
+                    xbmc.log("Found " + artist[0] + "...")
                 songs = groovesharkApi.getArtistPopularSongs(artistID, limit = self.songsearchlimit)
                 if (len(songs) > 0):
                     self._add_songs_directory(songs, trackLabelFormat=NAME_ALBUM_ARTIST_LABEL)
@@ -466,10 +475,13 @@ class Groveshark:
         global player
         if item != None:
             songid = item.getProperty('songid')
-            stream = groovesharkApi.getSubscriberStreamKey(songid)
-            url = stream['url']
+            url = item.getProperty('url')
+            if url == '':
+                stream = groovesharkApi.getSubscriberStreamKey(songid)
+                url = stream['url']
             item.setPath(url)
-            xbmc.log("Grooveshark playing: " + url)
+            if self.debug:
+                xbmc.log("Grooveshark playing: " + url)
             xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=item)
             # Wait for play then start time
             seconds = 0
@@ -496,7 +508,9 @@ class Groveshark:
             trackLabel = name + " - " + album + " - " + artist
         else:
             trackLabel = artist + " - " + album + " - " + name
-        duration = self._getSongDuration(songid)
+        stream = self._getSongStream(songid)
+        duration = stream['duration']
+        url = stream['url']
         item = xbmcgui.ListItem(label = trackLabel, thumbnailImage=songImg, iconImage=songImg)
         item.setInfo( type="music", infoLabels={ "title": name, "album": album, "artist": artist, "duration": duration} )
         item.setProperty('mimetype', 'audio/mpeg')
@@ -507,12 +521,13 @@ class Groveshark:
         item.setProperty('album', album)
         item.setProperty('artist', artist)
         item.setProperty('duration', str(duration))
+        item.setProperty('url', str(url))
         
         return item
     
     # Next page of songs
-    def songPage(self, page, trackLabelFormat, playlistid = 0, playlistname = ''):
-        self._add_songs_directory([], trackLabelFormat, page, playlistid = playlistid, playlistname = playlistname)
+    def songPage(self, offset, trackLabelFormat, playlistid = 0, playlistname = ''):
+        self._add_songs_directory([], trackLabelFormat, offset, playlistid = playlistid, playlistname = playlistname)
         
     # Make a playlist from an album      
     def makePlaylist(self, albumid, name):
@@ -597,7 +612,8 @@ class Groveshark:
                     else:
                         playlist = playlists[i]
                         playlistid = playlist[1]
-                        xbmc.log("Add song " + str(songid) + " to playlist " + str(playlistid))
+                        if self.debug:
+                            xbmc.log("Add song " + str(songid) + " to playlist " + str(playlistid))
                         songIDs=[]
                         songs = groovesharkApi.getPlaylistSongs(playlistid)
                         for song in songs:
@@ -649,6 +665,16 @@ class Groveshark:
             dialog = xbmcgui.Dialog()
             dialog.ok(__language__(30008), __language__(30068))
             self.categories()
+    
+    # Debug
+    def setDebug(self):
+        self.debug = self.settings.getSetting('debug')
+        if self.debug:
+            xbmc.log("Debug is on")
+
+    # Debug
+    def getDebug(self):
+        return self.debug
         
     # Get keyboard input
     def _get_keyboard(self, default="", heading="", hidden=False):
@@ -698,64 +724,73 @@ class Groveshark:
             return thumbDef
     
     # Add songs to directory
-    def _add_songs_directory(self, songs, trackLabelFormat=ARTIST_ALBUM_NAME_LABEL, page=0, playlistid=0, playlistname='', isFavorites=False):
+    def _add_songs_directory(self, songs, trackLabelFormat=ARTIST_ALBUM_NAME_LABEL, offset=0, playlistid=0, playlistname='', isFavorites=False):
 
         totalSongs = len(songs)
-        page = int(page)
+        offset = int(offset)
+        start = 0
+        end = totalSongs
 
         # No pages needed
-        if page == 0 and totalSongs <= self.songspagelimit:
-            xbmc.log("Found " + str(totalSongs) + " songs...")
+        if offset == 0 and totalSongs <= self.songspagelimit:
+            if self.debug:
+                xbmc.log("Found " + str(totalSongs) + " songs...")
         # Pages
         else:
-            # Cache all songs
-            if page == 0:
+            # Cache all next pages songs
+            if offset == 0:
                 self._setSavedSongs(songs)
             else:
                 songs = self._getSavedSongs()
                 totalSongs = len(songs)
                 
             if totalSongs > 0:
-                start = page * self.songspagelimit
-                end = start + self.songspagelimit
-                songs = songs[start:end]
+                start = offset
+                end = min(start + self.songspagelimit,totalSongs)
         
         id = 0
-        for song in songs:
-            item = self._get_song_item(song, trackLabelFormat)
-            coverart = item.getProperty('coverart')
-            songname = song[0]
+        n = start
+        items = end - start
+        while n < end:
+            song = songs[n]
             songid = song[1]
-            songalbum = song[2]
-            songartist = song[4]
-            
-            
-            u=sys.argv[0]+"?mode="+str(MODE_SONG)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid) \
-            +"&album="+urllib.quote_plus(songalbum) \
-            +"&artist="+urllib.quote_plus(songartist) \
-            +"&coverart="+urllib.quote_plus(coverart)
-            fav=sys.argv[0]+"?mode="+str(MODE_FAVORITE)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid)
-            unfav=sys.argv[0]+"?mode="+str(MODE_UNFAVORITE)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid)+"&prevmode="
-            menuItems = []
-            if isFavorites == True:
-                unfav = unfav +str(MODE_FAVORITES)
-            else:
-                menuItems.append((__language__(30071), "XBMC.RunPlugin("+fav+")"))
-            menuItems.append((__language__(30072), "XBMC.RunPlugin("+unfav+")"))
-            if playlistid > 0:
-                rmplaylstsong=sys.argv[0]+"?playlistid="+str(playlistid)+"&id="+str(songid)+"&mode="+str(MODE_REMOVE_PLAYLIST_SONG)+"&name="+playlistname
-                menuItems.append((__language__(30073), "XBMC.RunPlugin("+rmplaylstsong+")"))
+            stream = self._getSongStream(songid)
+            if stream['url'] != '':   
+                item = self._get_song_item(song, trackLabelFormat)
+                coverart = item.getProperty('coverart')
+                songname = song[0]
+                songalbum = song[2]
+                songartist = song[4]
+                u=sys.argv[0]+"?mode="+str(MODE_SONG)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid) \
+                +"&album="+urllib.quote_plus(songalbum) \
+                +"&artist="+urllib.quote_plus(songartist) \
+                +"&coverart="+urllib.quote_plus(coverart)
+                fav=sys.argv[0]+"?mode="+str(MODE_FAVORITE)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid)
+                unfav=sys.argv[0]+"?mode="+str(MODE_UNFAVORITE)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid)+"&prevmode="
+                menuItems = []
+                if isFavorites == True:
+                    unfav = unfav +str(MODE_FAVORITES)
+                else:
+                    menuItems.append((__language__(30071), "XBMC.RunPlugin("+fav+")"))
+                menuItems.append((__language__(30072), "XBMC.RunPlugin("+unfav+")"))
+                if playlistid > 0:
+                    rmplaylstsong=sys.argv[0]+"?playlistid="+str(playlistid)+"&id="+str(songid)+"&mode="+str(MODE_REMOVE_PLAYLIST_SONG)+"&name="+playlistname
+                    menuItems.append((__language__(30073), "XBMC.RunPlugin("+rmplaylstsong+")"))
+                else:
+                    addplaylstsong=sys.argv[0]+"?id="+str(songid)+"&mode="+str(MODE_ADD_PLAYLIST_SONG)
+                    menuItems.append((__language__(30074), "XBMC.RunPlugin("+addplaylstsong+")"))
+                item.addContextMenuItems(menuItems, replaceItems=False)
+                xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=item,isFolder=False, totalItems=items)
+                id = id + 1
             else:
-                addplaylstsong=sys.argv[0]+"?id="+str(songid)+"&mode="+str(MODE_ADD_PLAYLIST_SONG)
-                menuItems.append((__language__(30074), "XBMC.RunPlugin("+addplaylstsong+")"))
-            item.addContextMenuItems(menuItems, replaceItems=False)
-            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=item,isFolder=False, totalItems=len(songs))
-            id = id + 1
+                end = min(end + 1,totalSongs)
+                if self.debug:
+                    xbmc.log(song[0] + " does not exist.")
+            n = n + 1
 
-        page = page + 1
-        if totalSongs > page * self.songspagelimit:
-            u=sys.argv[0]+"?mode="+str(MODE_SONG_PAGE)+"&id=playlistid"+"&page="+str(page)+"&label="+str(trackLabelFormat)+"&name="+playlistname
-            self._add_dir(__language__(30075) + '...', u, MODE_SONG_PAGE, self.songImg, 0, totalSongs - (page * self.songspagelimit))
+        if totalSongs > end:
+            u=sys.argv[0]+"?mode="+str(MODE_SONG_PAGE)+"&id=playlistid"+"&offset="+str(end)+"&label="+str(trackLabelFormat)+"&name="+playlistname
+            self._add_dir(__language__(30075) + '...', u, MODE_SONG_PAGE, self.songImg, 0, totalSongs - end)
 
         xbmcplugin.setContent(self._handle, 'songs')
         xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg)
@@ -763,15 +798,20 @@ class Groveshark:
     # Add albums to directory
     def _add_albums_directory(self, albums, artistid=0):
         n = len(albums)
-        xbmc.log("Found " + str(n) + " albums...")
+        itemsExisting = n
+        if self.debug:
+            xbmc.log("Found " + str(n) + " albums...")
         i = 0
         while i < n:
             album = albums[i]
-            albumArtistName = album[0]
-            albumName = album[2]
             albumID = album[3]
-            albumImage = self._get_icon(album[4], 'album-' + str(albumID))
-            self._add_dir(albumName + " - " + albumArtistName, '', MODE_ALBUM, albumImage, albumID, n)
+            if groovesharkApi.getDoesAlbumExist(albumID):                    
+                albumArtistName = album[0]
+                albumName = album[2]
+                albumImage = self._get_icon(album[4], 'album-' + str(albumID))
+                self._add_dir(albumName + " - " + albumArtistName, '', MODE_ALBUM, albumImage, albumID, itemsExisting)
+            else:
+                itemsExisting = itemsExisting - 1
             i = i + 1
         # Not supported by key
         #if artistid > 0:
@@ -783,13 +823,18 @@ class Groveshark:
     # Add artists to directory
     def _add_artists_directory(self, artists):
         n = len(artists)
-        xbmc.log("Found " + str(n) + " artists...")
+        itemsExisting = n
+        if self.debug:
+            xbmc.log("Found " + str(n) + " artists...")
         i = 0
         while i < n:
             artist = artists[i]
-            artistName = artist[0]
             artistID = artist[1]
-            self._add_dir(artistName, '', MODE_ARTIST, self.artistImg, artistID, n)
+            if groovesharkApi.getDoesArtistExist(artistID):                    
+                artistName = artist[0]
+                self._add_dir(artistName, '', MODE_ARTIST, self.artistImg, artistID, itemsExisting)
+            else:
+                itemsExisting = itemsExisting - 1
             i = i + 1
         xbmcplugin.setContent(self._handle, 'artists')
         xbmcplugin.addSortMethod(self._handle, xbmcplugin.SORT_METHOD_ARTIST_IGNORE_THE)
@@ -798,7 +843,8 @@ class Groveshark:
     # Add playlists to directory          
     def _add_playlists_directory(self, playlists):
         n = len(playlists)
-        xbmc.log("Found " + str(n) + " playlists...")
+        if self.debug:
+            xbmc.log("Found " + str(n) + " playlists...")
         i = 0
         while i < n:
             playlist = playlists[i]
@@ -825,12 +871,12 @@ class Groveshark:
         if mode == MODE_ALBUM:
             mkplaylst=sys.argv[0]+"?mode="+str(MODE_MAKE_PLAYLIST)+"&name="+name+"&id="+str(id)
             menuItems.append((__language__(30076), "XBMC.RunPlugin("+mkplaylst+")"))
-        # Broken rename/delete are broken in API
         if mode == MODE_PLAYLIST:
             rmplaylst=sys.argv[0]+"?mode="+str(MODE_REMOVE_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id)
             menuItems.append((__language__(30077), "XBMC.RunPlugin("+rmplaylst+")"))
             mvplaylst=sys.argv[0]+"?mode="+str(MODE_RENAME_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id)
             menuItems.append((__language__(30078), "XBMC.RunPlugin("+mvplaylst+")"))
+
         dir.addContextMenuItems(menuItems, replaceItems=False)
         
         return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=dir,isFolder=True, totalItems=items)
@@ -859,46 +905,48 @@ class Groveshark:
             xbmc.log("An error occurred saving songs")
             pass
 
-    def _getSongDuration(self, songid):
-        path = os.path.join(cacheDir, 'duration.dmp')
+    def _getSongStream(self, songid):
         id = int(songid)
-        durations = []
         duration = -1
-        
-        # Try cache first
+        streams = []
+        url = ''
+        path = os.path.join(cacheDir, 'streams.dmp')
         try:
             f = open(path, 'rb')
-            durations = pickle.load(f)
-            for song in durations:
+            streams = pickle.load(f)
+            for song in streams:
                 if song[0] == id:
                     duration = song[1]
+                    url = song[2]
+                    break;
             f.close()
         except:
             pass
 
-        if duration < 0:
+        if duration < 0 and groovesharkApi.getDoesSongExist(songid):
             stream = groovesharkApi.getSubscriberStreamKey(songid)
+            url = stream['url']
             usecs = stream['uSecs']
             if usecs < 60000000:
                 usecs = usecs * 10 # Some durations are 10x to small
             duration = usecs / 1000000
-            song = [id, duration]
-            durations.append(song)                
-            self._setSongDuration(durations)
-        
-        return duration
+            song = [id, duration, url]
+            streams.append(song)                
+            self._setSongStream(streams)
 
-    def _setSongDuration(self, durations):            
+        return {'duration':duration, 'url':url}
+        
+    def _setSongStream(self, streams):            
         try:
             # Create the 'data' directory if it doesn't exist.
             if not os.path.exists(cacheDir):
                 os.makedirs(cacheDir)
-            path = os.path.join(cacheDir, 'duration.dmp')
+            path = os.path.join(cacheDir, 'streams.dmp')
             f = open(path, 'wb')
-            pickle.dump(durations, f, protocol=pickle.HIGHEST_PROTOCOL)
+            pickle.dump(streams, f, protocol=pickle.HIGHEST_PROTOCOL)
             f.close()
         except:
-            xbmc.log("An error occurred saving durations")
+            xbmc.log("An error occurred saving streams")
             pass
 
     
@@ -906,7 +954,8 @@ class Groveshark:
 def get_params():
     param=[]
     paramstring=sys.argv[2]
-    xbmc.log(paramstring)
+    if grooveshark.getDebug():
+        xbmc.log(paramstring)
     if len(paramstring)>=2:
         params=sys.argv[2]
         cleanedparams=params.replace('?','')
@@ -922,7 +971,9 @@ def get_params():
     return param
         
 # Main
-grooveshark = Groveshark();
+grooveshark = Grooveshark();
+grooveshark.setDebug()
+groovesharkApi.setDebug(grooveshark.getDebug())
 
 params=get_params()
 mode=None
@@ -967,11 +1018,11 @@ elif mode==MODE_PLAYLISTS:
     grooveshark.playlists()
     
 elif mode==MODE_SONG_PAGE:
-    try: page=urllib.unquote_plus(params["page"])
+    try: offset=urllib.unquote_plus(params["offset"])
     except: pass
     try: label=urllib.unquote_plus(params["label"])
     except: pass
-    grooveshark.songPage(page, label, id, name)
+    grooveshark.songPage(offset, label, id, name)
 
 elif mode==MODE_SONG:
     try: album=urllib.unquote_plus(params["album"])
index 8fb5ef5..420a647 100644 (file)
@@ -18,7 +18,7 @@
        <title>Grooveshark XBMC</title>
 
        <!-- (required) Major.minor.build -->
-       <version>0.6.1</version>
+       <version>0.6.2</version>
 
        <!--
                (required) author name & email. at least one author name is required
@@ -53,7 +53,7 @@
                all
        -->
        <platforms>
-               <platform>windows,linux</platform>
+               <platform>windows,linux, osx</platform>
        </platforms>
 
        <!--
index f671827..67b5ea0 100644 (file)
@@ -41,7 +41,7 @@
        <string id="30038">Removed from Grooveshark favorites</string>
        <string id="30039">to remove Grooveshark favorites.</string>    
        <string id="30040">to get Grooveshark playlists.</string>       
-       <string id="30041">Artist</string>
+       <string id="30041">Search for popular songs for artist powered by Grooveshark</string>
        <string id="30042">No popular songs.</string>
        <string id="30043">No matching artists.</string>
        <string id="30044">Unable to play song</string>
index 0cf9708..767c0fb 100644 (file)
@@ -41,6 +41,7 @@ class GrooveAPI:
        _lastStreamKey = ''
        _lastStreamServerID = ''
        _key = md5.new(os.path.basename("GroovesharkAPI.py")).hexdigest()
+       _apiDebug = False
 
        # Constructor
        def __init__(self):
@@ -49,7 +50,8 @@ class GrooveAPI:
                self.cacheDir = os.path.join(tempfile.gettempdir(), 'groovesharkapi')
                if os.path.isdir(self.cacheDir) == False:
                        os.makedirs(self.cacheDir)
-                       print "Made " + self.cacheDir
+                       if self._apiDebug:
+                               print "Made " + self.cacheDir
                self._getSavedSession()
                # session ids last 2 weeks
                if self._sessionID == '' or time.time()- self._lastSessionTime >= SESSION_EXPIRY:
@@ -57,7 +59,8 @@ class GrooveAPI:
                        if self._sessionID == '':
                                raise StandardError('Failed to get session id')
                        else:
-                               print "New GrooveAPI session id: " + self._sessionID
+                               if self._apiDebug:
+                                       print "New GrooveAPI session id: " + self._sessionID
                                self._ip = self._getIP()
                                self._country = self._getCountry()
                                self._setSavedSession()
@@ -75,8 +78,9 @@ class GrooveAPI:
                        req = urllib2.Request(url, postData)
                        response = urllib2.urlopen(req)
                        result = response.read()
-                       print "Response..."
-                       pprint.pprint(result)
+                       if self._apiDebug:
+                               print "Response..."
+                               pprint.pprint(result)
                        response.close()
                        result = simplejson.loads(result)
                        return result
@@ -102,8 +106,9 @@ class GrooveAPI:
                req = urllib2.Request(url)
                response = urllib2.urlopen(req)
                result = response.read()
-               print "Request..."
-               pprint.pprint(result)
+               if self._apiDebug:
+                       print "Request..."
+                       pprint.pprint(result)
                response.close()
                try:
                        result = simplejson.loads(result)
@@ -172,7 +177,8 @@ class GrooveAPI:
                try:
                        myip = urllib2.urlopen('http://whatismyip.org').read()
                        if re.match("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$", myip):
-                               print "IP is " + myip
+                               if self._apiDebug:
+                                       print "IP is " + myip
                                return myip
                except:
                        return '0.0.0.0'
@@ -272,7 +278,7 @@ class GrooveAPI:
                
        # Get artists albums
        def getArtistAlbums(self, artistID, limit=ALBUM_LIMIT):
-               result = self._callRemote('getArtistAlbums', {'artistID' : artistID})
+               result = self._callRemote('getArtistVerifiedAlbums', {'artistID' : artistID})
                if 'result' in result:
                        return self._parseAlbums(result, limit)
                else:
@@ -415,6 +421,27 @@ class GrooveAPI:
                else:
                        return []               
        
+       def getDoesArtistExist(self, artistId):
+               response = self._callRemote("getDoesArtistExist", {"artistID": artistId})
+               if 'result' in response and response['result'] == True:
+                       return True
+               else:
+                       return False
+
+       def getDoesAlbumExist(self, albumId):
+               response = self._callRemote("getDoesAlbumExist", {"albumID": albumId})
+               if 'result' in response and response['result'] == True:
+                       return True
+               else:
+                       return False
+
+       def getDoesSongExist(self, songId):
+               response = self._callRemote("getDoesSongExist", {"songID": songId})
+               if 'result' in response and response['result'] == True:
+                       return True
+               else:
+                       return False
+               
        # After 30s play time
        def markStreamKeyOver30Secs(self):
                params = { "streamKey" : self._lastStreamKey, "streamServerID" : self._lastStreamServerID }
@@ -425,6 +452,13 @@ class GrooveAPI:
                params = { "songID" : songid, "streamKey" : self._lastStreamKey, "streamServerID" : self._lastStreamServerID }
                self._callRemote("markSongComplete", params)
 
+       # Debug on off
+       def setDebug(self, state):
+               self._apiDebug = state
+               if (self._apiDebug):
+                       print "API debug is on"
+
+               
        # Extract song data     
        def _parseSongs(self, items, limit=0):
                if 'result' in items:
index 26de019..bc53b00 100644 (file)
@@ -9,4 +9,7 @@
    <setting id="artistsearchlimit" type="labelenum" label="30004" default="10" values="5|10|15|20|25|30|40|50|60|70|80|90|100" />
    <setting id="songspagelimit" type="labelenum" label="30005" default="100" values="10|20|30|40|50|60|70|80|90|100|200|500" />
    </category>
+   <category label="Other">
+               <setting id="debug" label="Debug" type="bool" default="false" />
+   </category>         
 </settings>