-import urllib, urllib2, re, xbmcplugin, xbmcgui, xbmc, sys, os, time, pprint, shutil, xbmcaddon
+import urllib, urllib2, re, xbmcplugin, xbmcgui, xbmc, sys, os, time, pprint, shutil, xbmcaddon, pprint
MODE_SEARCH_SONGS = 1
MODE_SEARCH_ALBUMS = 2
MODE_REMOVE_PLAYLIST = 15
MODE_RENAME_PLAYLIST = 16
MODE_REMOVE_PLAYLIST_SONG = 17
+MODE_ADD_PLAYLIST_SONG = 18
+
+ACTION_MOVE_UP = 3
+ACTION_MOVE_DOWN = 4
+ACTION_PAGE_UP = 5
+ACTION_PAGE_DOWN = 6
+ACTION_SELECT_ITEM = 7
+ACTION_PREVIOUS_MENU = 10
baseDir = os.getcwd()
resDir = xbmc.translatePath(os.path.join(baseDir, 'resources'))
favoritesUrl = baseModeUrl + '?mode=' + str(MODE_FAVORITES)
thumbDef = os.path.join(os.path.basename(os.getcwd()), 'default.tbn')
+listBackground = os.path.join(imgDir, 'listbackground.png')
sys.path.append (libDir)
from GrooveAPI import *
def __init__( self, *args, **kwargs ):
self.__dict__.update( kwargs )
+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
+ 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.addControl(self.imgBg)
+
+ self.labelTitle = xbmcgui.ControlLabel(0+x, 0+y, w, hCnt, title, 'font14', '0xFFFFFFFF', alignment=2)
+ self.addControl(self.labelTitle)
+
+ 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.lastPos = 0
+ self.isSelecting = False
+ 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)
+ item.select(True)
+
+ # Highlight selected item
+ def setHighlight(self):
+ if self.isSelecting:
+ return
+ else:
+ self.isSelecting = True
+
+ pos = self.cntList.getSelectedPosition()
+ if pos >= 0:
+ item = self.cntList.getListItem(self.lastPos)
+ item.select(False)
+ item = self.cntList.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:
+ pass
+
class Groveshark:
- albumImg = xbmc.translatePath(os.path.join(imgDir, 'album.png'))
- artistImg = xbmc.translatePath(os.path.join(imgDir, 'artist.png'))
- favoritesImg = xbmc.translatePath(os.path.join(imgDir, 'favorites.png'))
- playlistImg = xbmc.translatePath(os.path.join(imgDir, 'playlist.png'))
- popularSongsImg = xbmc.translatePath(os.path.join(imgDir, 'popularSongs.png'))
- songImg = xbmc.translatePath(os.path.join(imgDir, 'song.png'))
- defImg = xbmc.translatePath(os.path.join(imgDir, 'default.tbn'))
+ albumImg = xbmc.translatePath(os.path.join(imgDir, 'album.png'))
+ artistImg = xbmc.translatePath(os.path.join(imgDir, 'artist.png'))
+ favoritesImg = xbmc.translatePath(os.path.join(imgDir, 'favorites.png'))
+ playlistImg = xbmc.translatePath(os.path.join(imgDir, 'playlist.png'))
+ popularSongsImg = xbmc.translatePath(os.path.join(imgDir, 'popularSongs.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'))
settings = xbmcaddon.Addon(id='plugin.audio.groove')
def searchSongs(self):
query = self._get_keyboard(default="", heading="Search songs")
- if (query):
+ if (query != ''):
groovesharkApi.setRemoveDuplicates(True)
songs = groovesharkApi.searchSongs(query, limit = self.songsearchlimit)
if (len(songs) > 0):
self._add_songs_directory(songs)
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'No matching songs.')
+ dialog.ok('Grooveshark for XBMC', 'No matching songs.')
self.categories()
+ else:
+ self.categories()
def searchAlbums(self):
query = self._get_keyboard(default="", heading="Search albums")
- if (query):
+ if (query != ''):
albums = groovesharkApi.searchAlbums(query, limit = self.albumsearchlimit)
if (len(albums) > 0):
self._add_albums_directory(albums)
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'No matching albums.')
+ dialog.ok('Grooveshark for XBMC', 'No matching albums.')
self.categories()
+ else:
+ self.categories()
def searchArtists(self):
query = self._get_keyboard(default="", heading="Search artists")
- if (query):
+ if (query != ''):
artists = groovesharkApi.searchArtists(query, limit = self.artistsearchlimit)
if (len(artists) > 0):
self._add_artists_directory(artists)
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'No matching artists.')
+ dialog.ok('Grooveshark for XBMC', 'No matching artists.')
self.categories()
+ else:
+ self.categories()
def favorites(self):
userid = self._get_login()
self._add_songs_directory(favorites, isFavorites=True)
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'You have no favorites.')
+ dialog.ok('Grooveshark for XBMC', 'You have no favorites.')
self.categories()
def popularSongs(self):
self._add_songs_directory(popular)
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'No popular songs.')
+ dialog.ok('Grooveshark for XBMC', 'No popular songs.')
self.categories()
def popularAlbums(self):
self._add_albums_directory(popular)
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'No popular albums.')
+ dialog.ok('Grooveshark for XBMC', 'No popular albums.')
self.categories()
def popularArtists(self):
self._add_artists_directory(popular)
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'No popular artists.')
+ dialog.ok('Grooveshark for XBMC', 'No popular artists.')
self.categories()
def playlists(self):
self._add_playlists_directory(playlists)
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'You have no playlists.')
+ dialog.ok('Grooveshark for XBMC', 'You have no playlists.')
self.categories()
+ else:
+ dialog = xbmcgui.Dialog()
+ dialog.ok('Grooveshark for XBMC', 'You must be logged in ', ' to see your playlists.')
+
def favorite(self, songid):
userid = self._get_login()
xbmc.executebuiltin('XBMC.Notification(Grooveshark, Added to favorites, 1000, ' + thumbDef + ')')
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'You must be logged in', 'to add favorites.')
+ dialog.ok('Grooveshark for 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, Removed from favorites, 1000, ' + thumbDef + ')')
+ xbmc.executebuiltin('XBMC.Notification(Grooveshark for XBMC, Removed from favorites, 1000, ' + thumbDef + ')')
if (int(prevMode) == MODE_FAVORITES):
- xbmc.executebuiltin("Container.Update(" + favoritesUrl + ",replace)")
+ xbmc.executebuiltin("Container.Update(" + favoritesUrl + ")")
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'You must be logged in', 'to remove favorites.')
+ dialog.ok('Grooveshark for 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, Frowned, 1000, ' + thumbDef + ')')
+ xbmc.executebuiltin('XBMC.Notification(Grooveshark for XBMC, Frowned, 1000, ' + thumbDef + ')')
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'You must be logged in', 'to frown a song.')
+ dialog.ok('Grooveshark for 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', 'No similar artists.')
+ dialog.ok('Grooveshark for XBMC', 'No similar artists.')
self.categories()
def makePlaylist(self, albumid, name):
id = groovesharkApi.playlistCreateUnique(name, songids)
if id == 0:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'Cannot create playlist ', name)
+ dialog.ok('Grooveshark for XBMC', 'Cannot create playlist ', name)
else:
- xbmc.executebuiltin('XBMC.Notification(Grooveshark, Playlist created, 1000, ' + thumbDef + ')')
+ xbmc.executebuiltin('XBMC.Notification(Grooveshark for XBMC, Playlist created, 1000, ' + thumbDef + ')')
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'You must be logged in ', ' to create a playlist.')
+ dialog.ok('Grooveshark for XBMC', 'You must be logged in ', ' to create a playlist.')
def removePlaylist(self, playlistid, name):
dialog = xbmcgui.Dialog()
- if dialog.yesno('Grooveshark', name, 'Delete this playlist?') == True:
+ if dialog.yesno('Grooveshark for XBMC', name, 'Delete this playlist?') == True:
userid = self._get_login()
if (userid != 0):
groovesharkApi.playlistDelete(playlistid)
- xbmc.executebuiltin("Container.Update(" + playlistsUrl + ",replace)")
+ xbmc.executebuiltin("Container.Refresh(" + playlistsUrl + ")")
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'You must be logged in ', ' to delete a playlist.')
+ dialog.ok('Grooveshark for XBMC', 'You must be logged in ', ' to delete a playlist.')
def removePlaylistSong(self, playlistid, playlistname, songpos):
dialog = xbmcgui.Dialog()
- if dialog.yesno('Grooveshark', 'Delete this song from the playlist?') == True:
+ if dialog.yesno('Grooveshark for XBMC', 'Delete this song from the playlist?') == True:
userid = self._get_login()
if (userid != 0):
if groovesharkApi.playlistDeleteSong(playlistid, songpos) == 0:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'Failed to remove ', ' song from playlist.')
+ dialog.ok('Grooveshark for XBMC', 'Failed to remove ', ' song from playlist.')
else:
- xbmc.executebuiltin("Container.Update(" + playlistUrl + "&id="+str(playlistid) + "&name=" + playlistname + ",replace)")
+ 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.')
+
+ 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)
+ playlistSelect.doModal()
+ print playlistSelect.selected
+ print "done"
+ del playlistSelect
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'You must be logged in ', ' to delete a song from a playlist.')
+ dialog.ok('Grooveshark for XBMC', 'You have no playlists.')
+ self.categories()
+ else:
+ dialog = xbmcgui.Dialog()
+ dialog.ok('Grooveshark for XBMC', 'You must be logged in ', ' to add a song to a playlist.')
def renamePlaylist(self, playlistid, name):
userid = self._get_login()
return
elif groovesharkApi.playlistRename(playlistid, newname) == 0:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'Cannot rename playlist ', name)
+ dialog.ok('Grooveshark for XBMC', 'Cannot rename playlist ', name)
else:
xbmc.executebuiltin("Container.Refresh")
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'You must be logged in ', ' to rename a playlist.')
+ dialog.ok('Grooveshark for XBMC', 'You must be logged in ', ' to rename a playlist.')
def album(self, albumid):
groovesharkApi.setRemoveDuplicates(True)
self._add_songs_directory(songs, playlistid, playlistname)
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'You must be logged in', 'to get playlists.')
+ dialog.ok('Grooveshark for XBMC', 'You must be logged in', 'to get 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', 'Unable to login.', 'Check username and password in settings.')
+ dialog.ok('Grooveshark for XBMC', 'Unable to login.', 'Check username and password in settings.')
return 0
else:
if groovesharkApi.loggedInStatus() == 1:
return userid
else:
dialog = xbmcgui.Dialog()
- dialog.ok('Grooveshark', 'Unable to login.', 'Check username and password in settings.')
+ dialog.ok('Grooveshark for XBMC', 'Unable to login.', 'Check username and password in settings.')
return 0
def _get_song_item(self, song):
if isFavorites == True:
unfav = unfav +str(MODE_FAVORITES)
else:
- menuItems.append(("Grooveshark Favorite", "XBMC.RunPlugin("+fav+")"))
- menuItems.append(("Not Grooveshark Favorite", "XBMC.RunPlugin("+unfav+")"))
+ menuItems.append(("Grooveshark favorite", "XBMC.RunPlugin("+fav+")"))
+ menuItems.append(("Not Grooveshark favorite", "XBMC.RunPlugin("+unfav+")"))
if playlistid > 0:
rmplaylstsong=sys.argv[0]+"?playlistid="+str(playlistid)+"&id="+str(i+1)+"&mode="+str(MODE_REMOVE_PLAYLIST_SONG)+"&name="+playlistname
menuItems.append(("Remove from 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=n)
i = i + 1
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&id="+str(id)
dir=xbmcgui.ListItem(name, iconImage=iconimage, thumbnailImage=iconimage)
dir.setInfo( type="Music", infoLabels={ "title": name } )
- # Codes from http://xbmc-scripting.googlecode.com/svn/trunk/Script%20Templates/common/gui/codes.py
menuItems = []
- menuItems.append(("Select", "XBMC.executebuiltin(Action(7))"))
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+")"))
menuItems.append(("Delete playlist", "XBMC.RunPlugin("+rmplaylst+")"))
mvplaylst=sys.argv[0]+"?mode="+str(MODE_RENAME_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id)
menuItems.append(("Rename playlist", "XBMC.RunPlugin("+mvplaylst+")"))
- dir.addContextMenuItems(menuItems, replaceItems=True)
+ dir.addContextMenuItems(menuItems, replaceItems=False)
return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=dir,isFolder=True, totalItems=items)
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]))