More playlist functions.
authorstephendenham <stephendenham@2dec19e3-eb1d-4749-8193-008c8bba0994>
Fri, 17 Dec 2010 13:39:31 +0000 (13:39 +0000)
committerstephendenham <stephendenham@2dec19e3-eb1d-4749-8193-008c8bba0994>
Fri, 17 Dec 2010 13:39:31 +0000 (13:39 +0000)
git-svn-id: svn://svn.code.sf.net/p/xbmc-groove/code@16 2dec19e3-eb1d-4749-8193-008c8bba0994

addon.xml
changelog.txt
default.py
description.xml
resources/img/listbackground.png [new file with mode: 0644]

index 4792124..a223cdb 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 for XBMC"
-       version="0.1.0" provider-name="Stephen Denham">
+<addon id="plugin.audio.groove" name="Grooveshark XBMC"
+       version="0.1.1" provider-name="Stephen Denham">
        <requires>
                <import addon="xbmc.python" version="1.0" />
        </requires>
index c30d1db..1fb643c 100644 (file)
@@ -1,3 +1,7 @@
+0.1.1:
+
+More Grooveshark playlist support.
+
 0.1.0:
 
 Grooveshark playlist support.
index da4f67f..8b6cf1a 100644 (file)
@@ -19,6 +19,7 @@ MODE_RENAME_PLAYLIST = 16
 MODE_REMOVE_PLAYLIST_SONG = 17
 MODE_ADD_PLAYLIST_SONG = 18
 
+ACTION_MOVE_LEFT = 1
 ACTION_MOVE_UP = 3
 ACTION_MOVE_DOWN = 4
 ACTION_PAGE_UP = 5
@@ -50,38 +51,35 @@ class _Info:
         
 class GroovesharkPlaylistSelect(xbmcgui.WindowDialog):
     
-    def __init__(self, title, items=[], width=100):
-        w = int(self.getWidth()*width)
-        pad = int(self.getHeight()/100)
-        hCnt = 30
-        yo = 30
-        self.selected = [-1, -1]
-        h = self.getHeight()-30*pad
+    def __init__(self, items=[]):
+        w = int(self.getWidth()*0.5)
+        gap = int(self.getHeight()/100)
+        titleH = 30
+        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(0+x-30,0+y-30,w+60,h+60, os.path.join(mediaDir,'gs-bg-menu.png'))
-        #self.addControl(self.imgBg)
-        self.imgBg = xbmcgui.ControlImage(0+x+pad,5*pad+y,w-2*pad,h-5*pad, listBackground)
+        self.imgBg = xbmcgui.ControlImage(x+gap, 5*gap+y, w-2*gap, h-5*gap, listBackground)
         self.addControl(self.imgBg)
         
-        self.labelTitle = xbmcgui.ControlLabel(0+x, 0+y, w, hCnt, title, 'font14', '0xFFFFFFFF', alignment=2)
-        self.addControl(self.labelTitle)
+        self.title = xbmcgui.ControlLabel(x, 5*gap+y, w, titleH, 'GROOVESHARK - PLAYLISTS', textColor='0xFFFFFFFF', alignment=2)
+        self.addControl(self.title)
         
-        self.cntList = xbmcgui.ControlList(2*pad+x, yo+y+3*pad, w-4*pad, h-10*pad, font='font12', textColor='0xFFFFFFFF', selectedColor='0xFFFF4242', space=0, itemHeight=7*pad)
-        self.addControl(self.cntList)
+        self.playlistControl = xbmcgui.ControlList(2*gap+x, titleH+y+3*gap, w-4*gap, h-10*gap, textColor='0xFFFFFFFF', selectedColor='0xFFFF4242')
+        self.addControl(self.playlistControl)
+
         self.lastPos = 0
         self.isSelecting = False
+        self.selected = -1
         listitems = []
-        listitems.append(xbmcgui.ListItem('first'))
         for playlist in items:
-            print "playlist is " + playlist[0]
             listitems.append(xbmcgui.ListItem(playlist[0]))
-        self.cntList.addItems(listitems)
-        self.setFocus(self.cntList)
-        item = self.cntList.getListItem(self.lastPos)
+        listitems.append(xbmcgui.ListItem('New...'))
+        self.playlistControl.addItems(listitems)
+        self.setFocus(self.playlistControl)
+        item = self.playlistControl.getListItem(self.lastPos)
         item.select(True)
 
     # Highlight selected item
@@ -91,28 +89,28 @@ class GroovesharkPlaylistSelect(xbmcgui.WindowDialog):
         else:
             self.isSelecting = True
         
-        pos = self.cntList.getSelectedPosition()
+        pos = self.playlistControl.getSelectedPosition()
         if pos >= 0:
-            item = self.cntList.getListItem(self.lastPos)
+            item = self.playlistControl.getListItem(self.lastPos)
             item.select(False)
-            item = self.cntList.getListItem(pos)
+            item = self.playlistControl.getListItem(pos)
             item.select(True)
             self.lastPos = pos
         self.isSelecting = False
 
     def onAction(self, action):
-        if action == ACTION_PREVIOUS_MENU:
-            self.selected = [-1, -1]
-            print 'close'
-            self.close()
-        elif action == ACTION_MOVE_UP or action == ACTION_MOVE_DOWN or action == ACTION_PAGE_UP or action == ACTION_PAGE_DOWN == 6:
-            print 'up down'
-            self.setHighlight()
-        elif action == ACTION_SELECT_ITEM:
-            #self.selected = [-1, self.cntList.getSelectedPosition()]
-            #self.close()
-            print "Selected"
-        else:
+        try:
+            if action == ACTION_MOVE_LEFT:
+                self.selected = self.playlistControl.getSelectedPosition()
+                self.close()
+            elif 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()
+        except: 
+            xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Press left arrow to make selection, 1000, ' + thumbDef + ')')
             pass  
         
 class Groveshark:
@@ -132,6 +130,7 @@ class Groveshark:
     artistsearchlimit = settings.getSetting('artistsearchlimit')
     username = settings.getSetting('username')
     password = settings.getSetting('password')
+    userid = 0
     
     def __init__( self ):
         self._handle = int(sys.argv[1])
@@ -140,7 +139,7 @@ class Groveshark:
 
         xbmc.log(self.username + ", limits: " + str(self.songsearchlimit) + ", " + str(self.albumsearchlimit) + ", "  + str(self.artistsearchlimit))
         
-        userid = self._get_login()
+        self.userid = self._get_login()
         
         # Setup
         xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg)
@@ -151,7 +150,7 @@ class Groveshark:
         self._add_dir('Search albums', '', MODE_SEARCH_ALBUMS, self.albumImg, 0)
         self._add_dir('Search artists', '', MODE_SEARCH_ARTISTS, self.artistImg, 0)
         self._add_dir('Popular songs', '', MODE_POPULAR_SONGS, self.popularSongsImg, 0)
-        if (userid != 0):
+        if (self.userid != 0):
             self._add_dir('Favorites', '', MODE_FAVORITES, self.favoritesImg, 0)
             self._add_dir('Playlists', '', MODE_PLAYLISTS, self.playlistImg, 0)
             
@@ -164,7 +163,7 @@ class Groveshark:
                 self._add_songs_directory(songs)
             else:
                 dialog = xbmcgui.Dialog()
-                dialog.ok('Grooveshark for XBMC', 'No matching songs.')
+                dialog.ok('Grooveshark XBMC', 'No matching songs.')
                 self.categories()
         else:
             self.categories()
@@ -177,7 +176,7 @@ class Groveshark:
                 self._add_albums_directory(albums)
             else:
                 dialog = xbmcgui.Dialog()
-                dialog.ok('Grooveshark for XBMC', 'No matching albums.')
+                dialog.ok('Grooveshark XBMC', 'No matching albums.')
                 self.categories()
         else:
             self.categories()
@@ -190,7 +189,7 @@ class Groveshark:
                 self._add_artists_directory(artists)
             else:
                 dialog = xbmcgui.Dialog()
-                dialog.ok('Grooveshark for XBMC', 'No matching artists.')
+                dialog.ok('Grooveshark XBMC', 'No matching artists.')
                 self.categories()
         else:
             self.categories()
@@ -203,7 +202,7 @@ class Groveshark:
                 self._add_songs_directory(favorites, isFavorites=True)
             else:
                 dialog = xbmcgui.Dialog()
-                dialog.ok('Grooveshark for XBMC', 'You have no favorites.')
+                dialog.ok('Grooveshark XBMC', 'You have no favorites.')
                 self.categories()
     
     def popularSongs(self):
@@ -212,7 +211,7 @@ class Groveshark:
             self._add_songs_directory(popular)
         else:
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'No popular songs.')
+            dialog.ok('Grooveshark XBMC', 'No popular songs.')
             self.categories()
 
     def popularAlbums(self):
@@ -221,7 +220,7 @@ class Groveshark:
             self._add_albums_directory(popular)
         else:
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'No popular albums.')
+            dialog.ok('Grooveshark XBMC', 'No popular albums.')
             self.categories()
 
     def popularArtists(self):
@@ -230,7 +229,7 @@ class Groveshark:
             self._add_artists_directory(popular)
         else:
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'No popular artists.')
+            dialog.ok('Grooveshark XBMC', 'No popular artists.')
             self.categories()
                  
     def playlists(self):
@@ -241,11 +240,11 @@ class Groveshark:
                 self._add_playlists_directory(playlists)
             else:
                 dialog = xbmcgui.Dialog()
-                dialog.ok('Grooveshark for XBMC', 'You have no playlists.')
+                dialog.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.')
                 self.categories()
         else:
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'You must be logged in ', ' to see your playlists.')
+            dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to see your Grooveshark playlists.')
                 
                 
     def favorite(self, songid):
@@ -253,22 +252,22 @@ class Groveshark:
         if (userid != 0):
             xbmc.log("Favorite song: " + str(songid))
             groovesharkApi.favoriteSong(songID = songid)
-            xbmc.executebuiltin('XBMC.Notification(Grooveshark, Added to favorites, 1000, ' + thumbDef + ')')
+            xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added to favorites, 1000, ' + thumbDef + ')')
         else:
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'You must be logged in', 'to add favorites.')
+            dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to add favorites.')
     
     def unfavorite(self, songid, prevMode):
         userid = self._get_login()
         if (userid != 0):
             xbmc.log("Unfavorite song: " + str(songid) + ', previous mode was ' + str(prevMode))
             groovesharkApi.unfavoriteSong(songID = songid)
-            xbmc.executebuiltin('XBMC.Notification(Grooveshark for XBMC, Removed from favorites, 1000, ' + thumbDef + ')')
+            xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Removed from favorites, 1000, ' + thumbDef + ')')
             if (int(prevMode) == MODE_FAVORITES):
                 xbmc.executebuiltin("Container.Update(" + favoritesUrl + ")")
         else:
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'You must be logged in', 'to remove favorites.')
+            dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to remove favorites.')
 
     def frown(self, songid):
         userid = self._get_login()
@@ -277,10 +276,10 @@ class Groveshark:
             if groovesharkApi.radioFrown(songId = songid) != True:
                 xbmc.log("Unable to frown song " + str(songid))
             else:
-                xbmc.executebuiltin('XBMC.Notification(Grooveshark for XBMC, Frowned, 1000, ' + thumbDef + ')')
+                xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Frowned, 1000, ' + thumbDef + ')')
         else:
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'You must be logged in', 'to frown a song.')
+            dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to frown a song.')
 
     def similarArtists(self, artistId):
         similar = groovesharkApi.artistGetSimilar(artistId, limit = self.artistsearchlimit)
@@ -288,7 +287,7 @@ class Groveshark:
             self._add_artists_directory(similar)
         else:
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'No similar artists.')
+            dialog.ok('Grooveshark XBMC', 'No similar artists.')
             self.categories()
             
     def makePlaylist(self, albumid, name):
@@ -296,66 +295,88 @@ class Groveshark:
         if (userid != 0):
             re.split(' - ',name,1)
             nameTokens = re.split(' - ',name,1)
-            name = self._get_keyboard(default=nameTokens[0], heading="Playlist name")
+            name = self._get_keyboard(default=nameTokens[0], heading="Grooveshark playlist name")
             if name != '':
                 groovesharkApi.setRemoveDuplicates(True)
                 album = groovesharkApi.albumGetSongs(albumid, self.songsearchlimit)
                 songids = []
                 for song in album:
                     songids.append(song[1])
-                id = groovesharkApi.playlistCreateUnique(name, songids)
-                if id == 0:
+                if groovesharkApi.playlistCreateUnique(name, songids) == 0:
                     dialog = xbmcgui.Dialog()
-                    dialog.ok('Grooveshark for XBMC', 'Cannot create playlist ', name)
+                    dialog.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name)
                 else:
-                    xbmc.executebuiltin('XBMC.Notification(Grooveshark for XBMC, Playlist created, 1000, ' + thumbDef + ')')
+                    xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef + ')')
         else:
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'You must be logged in ', ' to create a playlist.')
+            dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to create a Grooveshark playlist.')
             
     def removePlaylist(self, playlistid, name):
         dialog = xbmcgui.Dialog()
-        if dialog.yesno('Grooveshark for XBMC', name, 'Delete this playlist?') == True:
+        if dialog.yesno('Grooveshark XBMC', name, 'Delete this Grooveshark playlist?') == True:
             userid = self._get_login()
             if (userid != 0):
                 groovesharkApi.playlistDelete(playlistid)
                 xbmc.executebuiltin("Container.Refresh(" + playlistsUrl + ")")
             else:
                 dialog = xbmcgui.Dialog()
-                dialog.ok('Grooveshark for XBMC', 'You must be logged in ', ' to delete a playlist.')
+                dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a Grooveshark playlist.')
 
     def removePlaylistSong(self, playlistid, playlistname, songpos):
         dialog = xbmcgui.Dialog()
-        if dialog.yesno('Grooveshark for XBMC', 'Delete this song from the playlist?') == True:
+        if dialog.yesno('Grooveshark XBMC', 'Delete this song from the Grooveshark playlist?') == True:
             userid = self._get_login()
             if (userid != 0):
                 if groovesharkApi.playlistDeleteSong(playlistid, songpos) == 0:
                     dialog = xbmcgui.Dialog()
-                    dialog.ok('Grooveshark for XBMC', 'Failed to remove ', ' song from playlist.')
+                    dialog.ok('Grooveshark XBMC', 'Failed to remove ', ' song from Grooveshark playlist.')
                 else:
                     xbmc.executebuiltin("Container.Refresh(" + playlistUrl + "&id="+str(playlistid) + "&name=" + playlistname + ",replace)")
             else:
                 dialog = xbmcgui.Dialog()
-                dialog.ok('Grooveshark for XBMC', 'You must be logged in ', ' to delete a song from a playlist.')
+                dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a song from a Grooveshark playlist.')
 
     def addPlaylistSong(self, songid):
         userid = self._get_login()
         if (userid != 0):
             playlists = groovesharkApi.userGetPlaylists()
             if (len(playlists) > 0):
-                print "make window"
-                playlistSelect = GroovesharkPlaylistSelect(title='Playlists', items=playlists, width=0.5)
+                ret = 0
+                playlistSelect = GroovesharkPlaylistSelect(items=playlists)
+                playlistSelect.setFocus(playlistSelect.playlistControl)
                 playlistSelect.doModal()
-                print playlistSelect.selected
-                print "done"
+                i = playlistSelect.selected
                 del playlistSelect
+                if i > -1:
+                    # New playlist
+                    if i >= len(playlists):
+                        name = self._get_keyboard(default='', heading="Grooveshark playlist name")
+                        if name != '':
+                            songIds = []
+                            songIds.append(songid)
+                            if groovesharkApi.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 = groovesharkApi.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 for XBMC', 'You have no playlists.')
+                dialog.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.')
                 self.categories()
         else:
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'You must be logged in ', ' to add a song to a playlist.')
+            dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to add a song to a Grooveshark playlist.')
 
     def renamePlaylist(self, playlistid, name):
         userid = self._get_login()
@@ -365,12 +386,12 @@ class Groveshark:
                 return
             elif groovesharkApi.playlistRename(playlistid, newname) == 0:
                 dialog = xbmcgui.Dialog()
-                dialog.ok('Grooveshark for XBMC', 'Cannot rename playlist ', name)
+                dialog.ok('Grooveshark XBMC', 'Cannot rename Grooveshark playlist ', name)
             else:
                 xbmc.executebuiltin("Container.Refresh")
         else:
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'You must be logged in ', ' to rename a playlist.')
+            dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to rename a Grooveshark playlist.')
     
     def album(self, albumid):
         groovesharkApi.setRemoveDuplicates(True)
@@ -388,7 +409,7 @@ class Groveshark:
             self._add_songs_directory(songs, playlistid, playlistname)
         else:
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'You must be logged in', 'to get playlists.')
+            dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to get Grooveshark playlists.')
             
     def playSong(self, item):
         url = item.getProperty('url')
@@ -424,18 +445,17 @@ class Groveshark:
     def _get_login(self):
         if (self.username == "" or self.password == ""):
             dialog = xbmcgui.Dialog()
-            dialog.ok('Grooveshark for XBMC', 'Unable to login.', 'Check username and password in settings.')
+            dialog.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.')
             return 0
         else:
-            if groovesharkApi.loggedInStatus() == 1:
-                groovesharkApi.logout()
-            userid = groovesharkApi.loginExt(self.username, self.password)
-            if (userid != 0):
+            if self.userid == 0:
+                uid = groovesharkApi.loginExt(self.username, self.password)
+            if (uid != 0):
                 xbmc.log("Logged in")
-                return userid
+                return uid
             else:
                 dialog = xbmcgui.Dialog()
-                dialog.ok('Grooveshark for XBMC', 'Unable to login.', 'Check username and password in settings.')
+                dialog.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.')
                 return 0
     
     def _get_song_item(self, song):
index ccb00b9..a2ef3c5 100644 (file)
        <type>9</type>
 
        <!-- (required) Title -->
-       <title>Grooveshark for XBMC.</title>
+       <title>Grooveshark XBMC.</title>
 
        <!-- (required) Major.minor.build -->
-       <version>0.1.0</version>
+       <version>0.1.1</version>
 
        <!--
                (required) author name & email. at least one author name is required
diff --git a/resources/img/listbackground.png b/resources/img/listbackground.png
new file mode 100644 (file)
index 0000000..7db508c
Binary files /dev/null and b/resources/img/listbackground.png differ