Playlist stuff.
[clinton/xbmc-groove.git] / default.py
index 72de575..d4c6dfa 100644 (file)
@@ -12,8 +12,15 @@ MODE_ALBUM = 10
 MODE_ARTIST = 11
 MODE_PLAYLIST = 12
 MODE_SONG_PAGE = 13
-MODE_SONG = 14
-MODE_FAVORITE = 15
+MODE_SIMILAR_ARTISTS = 14
+MODE_SONG = 15
+MODE_FAVORITE = 16
+MODE_UNFAVORITE = 17
+MODE_MAKE_PLAYLIST = 18
+MODE_REMOVE_PLAYLIST = 19
+MODE_RENAME_PLAYLIST = 20
+MODE_REMOVE_PLAYLIST_SONG = 21
+MODE_ADD_PLAYLIST_SONG = 22
 
 ACTION_MOVE_LEFT = 1
 ACTION_MOVE_UP = 3
@@ -40,10 +47,14 @@ playlistUrl = baseModeUrl + '?mode=' + str(MODE_PLAYLIST)
 playlistsUrl = baseModeUrl + '?mode=' + str(MODE_PLAYLISTS)
 favoritesUrl = baseModeUrl + '?mode=' + str(MODE_FAVORITES)
 
+searchArtistsAlbumsName = "Search for artist's albums..."
+
 thumbDef = os.path.join(imgDir, 'default.tbn')
+listBackground = os.path.join(imgDir, 'listbackground.png')
 
 sys.path.append (libDir)
 from GroovesharkAPI import GrooveAPI
+from GroovesharkAPI import GrooveAPIv1
 
 try:
     groovesharkApi = GrooveAPI()
@@ -59,6 +70,67 @@ class _Info:
     def __init__( self, *args, **kwargs ):
         self.__dict__.update( kwargs )
 
+# Window dialog to select a grooveshark playlist        
+class GroovesharkPlaylistSelect(xbmcgui.WindowDialog):
+    
+    def __init__(self, items=[]):
+        gap = int(self.getHeight()/100)
+        w = int(self.getWidth()*0.5)
+        h = self.getHeight()-30*gap
+        rw = self.getWidth()
+        rh = self.getHeight()
+        x = rw/2 - w/2
+        y = rh/2 -h/2
+        
+        self.imgBg = xbmcgui.ControlImage(x+gap, 5*gap+y, w-2*gap, h-5*gap, listBackground)
+        self.addControl(self.imgBg)
+
+        self.playlistControl = xbmcgui.ControlList(2*gap+x, y+3*gap+30, w-4*gap, h-10*gap, textColor='0xFFFFFFFF', selectedColor='0xFFFF4242', itemTextYOffset=0, itemHeight=50, alignmentY = 0)
+        self.addControl(self.playlistControl)
+
+        self.lastPos = 0
+        self.isSelecting = False
+        self.selected = -1
+        listitems = []
+        for playlist in items:
+            listitems.append(xbmcgui.ListItem(playlist[0]))
+        listitems.append(xbmcgui.ListItem('New...'))
+        self.playlistControl.addItems(listitems)
+        self.setFocus(self.playlistControl)
+        self.playlistControl.selectItem(0)
+        item = self.playlistControl.getListItem(self.lastPos)
+        item.select(True)
+
+    # Highlight selected item
+    def setHighlight(self):
+        if self.isSelecting:
+            return
+        else:
+            self.isSelecting = True
+        
+        pos = self.playlistControl.getSelectedPosition()
+        if pos >= 0:
+            item = self.playlistControl.getListItem(self.lastPos)
+            item.select(False)
+            item = self.playlistControl.getListItem(pos)
+            item.select(True)
+            self.lastPos = pos
+        self.isSelecting = False
+
+    # Control - select
+    def onControl(self, control):
+        if control == self.playlistControl:
+            self.selected = self.playlistControl.getSelectedPosition()
+            self.close()
+
+    # Action - close or up/down        
+    def onAction(self, action):
+        if action == ACTION_PREVIOUS_MENU:
+            self.selected = -1
+            self.close()
+        elif action == ACTION_MOVE_UP or action == ACTION_MOVE_DOWN or action == ACTION_PAGE_UP or action == ACTION_PAGE_DOWN == 6:
+            self.setFocus(self.playlistControl)
+            self.setHighlight()
      
 class Groveshark:
     
@@ -81,6 +153,7 @@ class Groveshark:
     songspagelimit = int(settings.getSetting('songspagelimit'))
     username = settings.getSetting('username')
     password = settings.getSetting('password')
+    sessionidv1 = settings.getSetting('sessionidv1')
     userid = 0
     
     def __init__( self ):
@@ -92,7 +165,9 @@ class Groveshark:
         if os.path.isdir(artDir) == False:
             os.makedirs(artDir)
             xbmc.log("Made " + artDir)
-
+            
+        self.groovesharkApiv1 = GrooveAPIv1(self.sessionidv1)
+            
     # Top-level menu
     def categories(self):
 
@@ -104,7 +179,7 @@ class Groveshark:
         self._add_dir('Search for songs...', '', MODE_SEARCH_SONGS, self.songImg, 0)
         self._add_dir('Search for albums...', '', MODE_SEARCH_ALBUMS, self.albumImg, 0)
         self._add_dir('Search for artists...', '', MODE_SEARCH_ARTISTS, self.artistImg, 0)
-        self._add_dir("Search for artist's albums...", '', MODE_SEARCH_ARTISTS_ALBUMS, self.artistsAlbumsImg, 0)
+        self._add_dir(searchArtistsAlbumsName, '', MODE_SEARCH_ARTISTS_ALBUMS, self.artistsAlbumsImg, 0)
         self._add_dir("Search for user's playlists...", '', MODE_SEARCH_PLAYLISTS, self.usersplaylistsImg, 0)
         self._add_dir('Popular songs for artist...', '', MODE_ARTIST_POPULAR, self.popularSongsArtistImg, 0)
         self._add_dir('Popular songs', '', MODE_POPULAR_SONGS, self.popularSongsImg, 0)
@@ -169,8 +244,8 @@ class Groveshark:
             self.categories()
 
     # Search for artists albums
-    def searchArtistsAlbums(self, artistName = ""):
-        if artistName == "":
+    def searchArtistsAlbums(self, artistName = None):
+        if artistName == None or artistName == searchArtistsAlbumsName:
             query = self._get_keyboard(default="", heading="Search for artist's albums")
         else:
             query = artistName
@@ -182,7 +257,7 @@ class Groveshark:
                 xbmc.log("Found " + artist[0] + "...")
                 albums = groovesharkApi.getArtistAlbums(artistID, limit = self.albumsearchlimit)
                 if (len(albums) > 0):
-                    self._add_albums_directory(albums)
+                    self._add_albums_directory(albums, artistID)
                 else:
                     dialog = xbmcgui.Dialog()
                     dialog.ok('Grooveshark XBMC', 'No matching albums.')
@@ -200,7 +275,7 @@ class Groveshark:
         if (userid != 0):
             favorites = groovesharkApi.getUserFavoriteSongs()
             if (len(favorites) > 0):
-                self._add_songs_directory(favorites)
+                self._add_songs_directory(favorites, isFavorites=True)
             else:
                 dialog = xbmcgui.Dialog()
                 dialog.ok('Grooveshark XBMC', 'You have no favorites.')
@@ -241,6 +316,21 @@ class Groveshark:
         else:
             dialog = xbmcgui.Dialog()
             dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to add favorites.')
+            
+    # Remove song from favorites
+    def unfavorite(self, songid, prevMode=0):
+        userid = self._get_login(version = 1)
+        if (userid != 0):
+            xbmc.log("Unfavorite song: " + str(songid) + ', previous mode was ' + str(prevMode))
+            self.groovesharkApiv1.unfavorite(songID = songid)
+            xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Removed from Grooveshark favorites, 1000, ' + thumbDef + ')')
+            # Refresh to remove item from directory
+            if (int(prevMode) == MODE_FAVORITES):
+                xbmc.executebuiltin("Container.Refresh(" + favoritesUrl + ")")
+        else:
+            dialog = xbmcgui.Dialog()
+            dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to remove Grooveshark favorites.')
+            
 
     # Show selected album
     def album(self, albumid):
@@ -250,14 +340,14 @@ class Groveshark:
     # Show selected artist
     def artist(self, artistid):
         albums = groovesharkApi.getArtistAlbums(artistid, limit = self.albumsearchlimit)
-        self._add_albums_directory(albums)
+        self._add_albums_directory(albums, artistid)
     
     # Show selected playlist
-    def playlist(self, playlistid):
+    def playlist(self, playlistid, playlistname):
         userid = self._get_login()
         if (userid != 0):
             songs = groovesharkApi.getPlaylistSongs(playlistid)
-            self._add_songs_directory(songs, trackLabelFormat=NAME_ALBUM_ARTIST_LABEL)
+            self._add_songs_directory(songs, trackLabelFormat=NAME_ALBUM_ARTIST_LABEL, playlistid=playlistid, playlistname=playlistname)
         else:
             dialog = xbmcgui.Dialog()
             dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to get Grooveshark playlists.')
@@ -299,7 +389,7 @@ class Groveshark:
     # Make a song directory item
     def songItem(self, songid, name, album, artist, coverart, trackLabelFormat=ARTIST_ALBUM_NAME_LABEL):
         songImg = self._get_icon(coverart, 'song-' + str(songid) + "-image")
-        if trackLabelFormat == NAME_ALBUM_ARTIST_LABEL:
+        if int(trackLabelFormat) == NAME_ALBUM_ARTIST_LABEL:
             trackLabel = name + " - " + album + " - " + artist
         else:
             trackLabel = artist + " - " + album + " - " + name
@@ -316,8 +406,133 @@ class Groveshark:
         return item
     
     # Next page of songs
-    def songPage(self, page, trackLabelFormat):
-        self._add_songs_directory([], trackLabelFormat, page)
+    def songPage(self, page, trackLabelFormat, playlistid = 0, playlistname = ''):
+        self._add_songs_directory([], trackLabelFormat, page, playlistid = playlistid, playlistname = playlistname)
+        
+    # Make a playlist from an album      
+    def makePlaylist(self, albumid, name):
+        userid = self._get_login(version = 1)
+        if (userid != 0):
+            re.split(' - ',name,1)
+            nameTokens = re.split(' - ',name,1) # suggested name
+            name = self._get_keyboard(default=nameTokens[0], heading="Grooveshark playlist name")
+            if name != '':
+                album = groovesharkApi.getAlbumSongs(albumid, limit = self.songsearchlimit)
+                songids = []
+                for song in album:
+                    songids.append(song[1])
+                if self.groovesharkApiv1.playlistCreateUnique(name, songids) == 0:
+                    dialog = xbmcgui.Dialog()
+                    dialog.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name)
+                else:
+                    xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef + ')')
+        else:
+            dialog = xbmcgui.Dialog()
+            dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to create a Grooveshark playlist.')
+    
+    # Rename a playlist
+    def renamePlaylist(self, playlistid, name):
+        userid = self._get_login(version = 1)
+        if (userid != 0):
+            newname = self._get_keyboard(default=name, heading="Grooveshark playlist name")
+            if newname == '':
+                return
+            elif self.groovesharkApiv1.playlistRename(playlistid, newname) == 0:
+                dialog = xbmcgui.Dialog()
+                dialog.ok('Grooveshark XBMC', 'Cannot rename Grooveshark playlist ', name)
+            else:
+                # Refresh to show new item name
+                xbmc.executebuiltin("Container.Refresh")
+        else:
+            dialog = xbmcgui.Dialog()
+            dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to rename a Grooveshark playlist.')
+        
+    # Remove a playlist
+    def removePlaylist(self, playlistid, name):
+        dialog = xbmcgui.Dialog()
+        if dialog.yesno('Grooveshark XBMC', name, 'Delete this Grooveshark playlist?') == True:
+            userid = self._get_login(version = 1)
+            if (userid != 0):
+                if self.groovesharkApiv1.playlistDelete(playlistid) == 0:
+                    dialog = xbmcgui.Dialog()
+                    dialog.ok('Grooveshark XBMC', 'Cannot remove Grooveshark playlist ', name)
+                else:
+                    # Refresh to remove item from directory
+                    xbmc.executebuiltin("Container.Refresh(" + playlistsUrl + ")")
+            else:
+                dialog = xbmcgui.Dialog()
+                dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a Grooveshark playlist.')
+
+    # Add song to playlist
+    def addPlaylistSong(self, songid):
+        userid = self._get_login(version = 1)
+        if (userid != 0):
+            playlists = groovesharkApi.getUserPlaylists()
+            if (len(playlists) > 0):
+                ret = 0
+                # Select the playlist
+                playlistSelect = GroovesharkPlaylistSelect(items=playlists)
+                playlistSelect.setFocus(playlistSelect.playlistControl)
+                playlistSelect.doModal()
+                i = playlistSelect.selected
+                del playlistSelect
+                if i > -1:
+                    # Add a new playlist
+                    if i >= len(playlists):
+                        name = self._get_keyboard(default='', heading="Grooveshark playlist name")
+                        if name != '':
+                            songIds = []
+                            songIds.append(songid)
+                            if self.groovesharkApiv1.playlistCreateUnique(name, songIds) == 0:
+                                dialog = xbmcgui.Dialog()
+                                dialog.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name)
+                            else:
+                                xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef + ')')
+                    # Existing playlist
+                    else:
+                        playlist = playlists[i]
+                        playlistid = playlist[1]
+                        xbmc.log("Add song " + str(songid) + " to playlist " + str(playlistid))
+                        ret = self.groovesharkApiv1.playlistAddSong(playlistid, songid, 0)
+                        if ret == 0:
+                            dialog = xbmcgui.Dialog()
+                            dialog.ok('Grooveshark XBMC', 'Cannot add to playlist ')
+                        else:    
+                            xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added song to Grooveshark playlist, 1000, ' + thumbDef + ')')
+            else:
+                dialog = xbmcgui.Dialog()
+                dialog.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.')
+                self.categories()
+        else:
+            dialog = xbmcgui.Dialog()
+            dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to add a song to a Grooveshark playlist.')
+
+    # Remove song from playlist
+    def removePlaylistSong(self, playlistid, playlistname, songpos):
+        dialog = xbmcgui.Dialog()
+        if dialog.yesno('Grooveshark XBMC', 'Delete this song from', 'the Grooveshark playlist?') == True:
+            userid = self._get_login(version = 1)
+            if (userid != 0):
+                if self.groovesharkApiv1.playlistDeleteSong(playlistid, songpos) == 0:
+                    dialog = xbmcgui.Dialog()
+                    dialog.ok('Grooveshark XBMC', 'Failed to remove', 'song from Grooveshark playlist.')
+                else:
+                    # Refresh to remove item from directory
+                    xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Removed song from Grooveshark playlist, 1000, ' + thumbDef + ')')
+                    xbmc.executebuiltin("Container.Update(" + playlistUrl + "&id="+str(playlistid) + "&name=" + playlistname + ")")
+            else:
+                dialog = xbmcgui.Dialog()
+                dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to delete a song from a Grooveshark playlist.')
+      
+    # Find similar artists to searched artist
+    def similarArtists(self, artistId):
+        similar = self.groovesharkApiv1.artistGetSimilar(artistId, limit = self.artistsearchlimit)
+        if (len(similar) > 0):
+            self._add_artists_directory(similar)
+        else:
+            dialog = xbmcgui.Dialog()
+            dialog.ok('Grooveshark XBMC', 'No similar artists.')
+            self.categories()
         
     # Get keyboard input
     def _get_keyboard(self, default="", heading="", hidden=False):
@@ -328,14 +543,17 @@ class Groveshark:
         return ''
     
     # Login to grooveshark
-    def _get_login(self):
+    def _get_login(self, version = 2):
         if (self.username == "" or self.password == ""):
             dialog = xbmcgui.Dialog()
             dialog.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.')
             return 0
         else:
             if self.userid == 0:
-                uid = groovesharkApi.login(self.username, self.password)
+                if version == 1:
+                    uid = self.groovesharkApiv1.login(self.username, self.password)
+                else:
+                    uid = groovesharkApi.login(self.username, self.password)
             if (uid != 0):
                 return uid
             else:
@@ -367,7 +585,7 @@ class Groveshark:
             return thumbDef
     
     # Add songs to directory
-    def _add_songs_directory(self, songs, trackLabelFormat=ARTIST_ALBUM_NAME_LABEL, page=0):
+    def _add_songs_directory(self, songs, trackLabelFormat=ARTIST_ALBUM_NAME_LABEL, page=0, playlistid=0, playlistname='', isFavorites=False):
 
         totalSongs = len(songs)
         page = int(page)
@@ -389,6 +607,7 @@ class Groveshark:
                 end = start + self.songspagelimit
                 songs = songs[start:end]
         
+        id = 0
         for song in songs:
             item = self._get_song_item(song, trackLabelFormat)
             coverart = item.getProperty('coverart')
@@ -401,21 +620,34 @@ class Groveshark:
             +"&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 = []
-            menuItems.append(("Grooveshark favorite", "XBMC.RunPlugin("+fav+")"))
+            if isFavorites == True:
+                unfav = unfav +str(MODE_FAVORITES)
+            else:
+                menuItems.append(("Grooveshark favorite", "XBMC.RunPlugin("+fav+")"))
+            if self.sessionidv1 != '':
+                menuItems.append(("Not Grooveshark favorite", "XBMC.RunPlugin("+unfav+")"))
+                if playlistid > 0:
+                    rmplaylstsong=sys.argv[0]+"?playlistid="+str(playlistid)+"&id="+str(id+1)+"&mode="+str(MODE_REMOVE_PLAYLIST_SONG)+"&name="+playlistname
+                    menuItems.append(("Remove from Grooveshark playlist", "XBMC.RunPlugin("+rmplaylstsong+")"))
+                else:
+                    addplaylstsong=sys.argv[0]+"?id="+str(songid)+"&mode="+str(MODE_ADD_PLAYLIST_SONG)
+                    menuItems.append(("Add to Grooveshark playlist", "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
 
         page = page + 1
         if totalSongs > page * self.songspagelimit:
-            u=sys.argv[0]+"?mode="+str(MODE_SONG_PAGE)+"&id=0"+"&page="+str(page)+"&label="+str(trackLabelFormat)
+            u=sys.argv[0]+"?mode="+str(MODE_SONG_PAGE)+"&id=playlistid"+"&page="+str(page)+"&label="+str(trackLabelFormat)+"&name="+playlistname
             self._add_dir('More songs...', u, MODE_SONG_PAGE, self.songImg, 0, totalSongs - (page * self.songspagelimit))
 
         xbmcplugin.setContent(self._handle, 'songs')
         xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg)
     
     # Add albums to directory
-    def _add_albums_directory(self, albums):
+    def _add_albums_directory(self, albums, artistid=0):
         n = len(albums)
         xbmc.log("Found " + str(n) + " albums...")
         i = 0
@@ -427,6 +659,8 @@ class Groveshark:
             albumImage = self._get_icon(album[4], 'album-' + str(albumID))
             self._add_dir(albumName + " - " + albumArtistName, '', MODE_ALBUM, albumImage, albumID, n)
             i = i + 1
+        if artistid > 0 and self.sessionidv1 != '':
+            self._add_dir('Similar artists...', '', MODE_SIMILAR_ARTISTS, self.artistImg, artistid)
         xbmcplugin.setContent(self._handle, 'albums')
         xbmcplugin.addSortMethod(self._handle, xbmcplugin.SORT_METHOD_ALBUM_IGNORE_THE)
         xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg)
@@ -463,12 +697,27 @@ class Groveshark:
       
     # Add whatever directory
     def _add_dir(self, name, url, mode, iconimage, id, items=1):
+
         if url == '':
             u=sys.argv[0]+"?mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&id="+str(id)
         else:
             u = url
         dir=xbmcgui.ListItem(name, iconImage=iconimage, thumbnailImage=iconimage)
         dir.setInfo( type="Music", infoLabels={ "title": name } )
+        
+        # Custom menu items
+        if self.sessionidv1 != '':
+            menuItems = []
+            if mode == MODE_ALBUM:
+                mkplaylst=sys.argv[0]+"?mode="+str(MODE_MAKE_PLAYLIST)+"&name="+name+"&id="+str(id)
+                menuItems.append(("Make Grooveshark playlist", "XBMC.RunPlugin("+mkplaylst+")"))
+            if mode == MODE_PLAYLIST:
+                rmplaylst=sys.argv[0]+"?mode="+str(MODE_REMOVE_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id)
+                menuItems.append(("Delete Grooveshark playlist", "XBMC.RunPlugin("+rmplaylst+")"))
+                mvplaylst=sys.argv[0]+"?mode="+str(MODE_RENAME_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id)
+                menuItems.append(("Rename Grooveshark playlist", "XBMC.RunPlugin("+mvplaylst+")"))
+            dir.addContextMenuItems(menuItems, replaceItems=False)
+        
         return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=dir,isFolder=True, totalItems=items)
     
     def _getSavedSongs(self):
@@ -495,8 +744,6 @@ class Groveshark:
             xbmc.log("An error occurred saving songs")
             pass
     
-
-
 # Parse URL parameters
 def get_params():
     param=[]
@@ -526,6 +773,9 @@ except: pass
 id=0
 try: id=int(params["id"])
 except: pass
+name = None
+try: name=urllib.unquote_plus(params["name"])
+except: pass
 
 # Call function for URL
 if mode==None:
@@ -541,10 +791,6 @@ elif mode==MODE_SEARCH_ARTISTS:
     grooveshark.searchArtists()
     
 elif mode==MODE_SEARCH_ARTISTS_ALBUMS:
-    try: name=urllib.unquote_plus(params["name"])
-    except: 
-        name = ""
-        pass
     grooveshark.searchArtistsAlbums(name)
     
 elif mode==MODE_SEARCH_PLAYLISTS:
@@ -567,11 +813,9 @@ elif mode==MODE_SONG_PAGE:
     except: pass
     try: label=urllib.unquote_plus(params["label"])
     except: pass
-    grooveshark.songPage(page, label)
+    grooveshark.songPage(page, label, id, name)
 
 elif mode==MODE_SONG:
-    try: name=urllib.unquote_plus(params["name"])
-    except: pass
     try: album=urllib.unquote_plus(params["album"])
     except: pass
     try: artist=urllib.unquote_plus(params["artist"])
@@ -588,10 +832,36 @@ elif mode==MODE_ALBUM:
     grooveshark.album(id)
     
 elif mode==MODE_PLAYLIST:
-    grooveshark.playlist(id)
+    grooveshark.playlist(id, name)
     
 elif mode==MODE_FAVORITE:
     grooveshark.favorite(id)
     
+elif mode==MODE_UNFAVORITE:
+    try: prevMode=int(urllib.unquote_plus(params["prevmode"]))
+    except:
+        prevMode = 0
+    grooveshark.unfavorite(id, prevMode)
+
+elif mode==MODE_SIMILAR_ARTISTS:
+    grooveshark.similarArtists(id)
+
+elif mode==MODE_MAKE_PLAYLIST:
+    grooveshark.makePlaylist(id, name)
+    
+elif mode==MODE_REMOVE_PLAYLIST:
+    grooveshark.removePlaylist(id, name)    
+
+elif mode==MODE_RENAME_PLAYLIST:
+    grooveshark.renamePlaylist(id, name)    
+
+elif mode==MODE_REMOVE_PLAYLIST_SONG:
+    try: playlistID=urllib.unquote_plus(params["playlistid"])
+    except: pass
+    grooveshark.removePlaylistSong(playlistID, name, id)
+
+elif mode==MODE_ADD_PLAYLIST_SONG:
+    grooveshark.addPlaylistSong(id)        
+    
 if mode < MODE_SONG:
     xbmcplugin.endOfDirectory(int(sys.argv[1]))