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
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
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:
artistsearchlimit = settings.getSetting('artistsearchlimit')
username = settings.getSetting('username')
password = settings.getSetting('password')
+ userid = 0
def __init__( self ):
self._handle = int(sys.argv[1])
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)
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)
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()
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()
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()
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):
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):
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):
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):
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):
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()
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)
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):
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()
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)
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')
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):