Improve notifications.
[clinton/xbmc-groove.git] / default.py
CommitLineData
973b4c6c 1import urllib, urllib2, re, xbmcplugin, xbmcgui, xbmc, sys, os, time, pprint, shutil, xbmcaddon
8817bb2e 2
8817bb2e 3MODE_SEARCH_SONGS = 1
4MODE_SEARCH_ALBUMS = 2
5MODE_SEARCH_ARTISTS = 3
36cc00d7 6MODE_POPULAR_SONGS = 4
8817bb2e 7MODE_FAVORITES = 5
8MODE_PLAYLISTS = 6
9MODE_ALBUM = 7
10MODE_ARTIST = 8
11MODE_PLAYLIST = 9
406ab447 12MODE_SIMILAR_ARTISTS = 10
13MODE_SONG = 11
14MODE_FAVORITE = 12
15MODE_UNFAVORITE = 13
36cc00d7 16MODE_MAKE_PLAYLIST = 14
17MODE_REMOVE_PLAYLIST = 15
18MODE_RENAME_PLAYLIST = 16
8817bb2e 19
8817bb2e 20lastID = 0
21
6ae708d0 22baseDir = os.getcwd()
23resDir = xbmc.translatePath(os.path.join(baseDir, 'resources'))
8817bb2e 24libDir = xbmc.translatePath(os.path.join(resDir, 'lib'))
25imgDir = xbmc.translatePath(os.path.join(resDir, 'img'))
973b4c6c 26thumbDir = os.path.join('special://masterprofile/addon_data/', os.path.join(os.path.basename(os.getcwd()), 'thumb'))
3cfead3c 27playlistUrl = 'plugin://plugin.audio.groove/?mode=6'
28thumbDef = os.path.join(os.path.basename(os.getcwd()), 'default.tbn')
8817bb2e 29
30sys.path.append (libDir)
31from GrooveAPI import *
32groovesharkApi = GrooveAPI()
33
34class _Info:
35 def __init__( self, *args, **kwargs ):
36 self.__dict__.update( kwargs )
3fcef5ba 37
8817bb2e 38class Groveshark:
973b4c6c 39
8817bb2e 40 albumImg = xbmc.translatePath(os.path.join(imgDir, 'album.png'))
41 artistImg = xbmc.translatePath(os.path.join(imgDir, 'artist.png'))
42 favoritesImg = xbmc.translatePath(os.path.join(imgDir, 'favorites.png'))
43 playlistImg = xbmc.translatePath(os.path.join(imgDir, 'playlist.png'))
36cc00d7 44 popularSongsImg = xbmc.translatePath(os.path.join(imgDir, 'popularSongs.png'))
8817bb2e 45 songImg = xbmc.translatePath(os.path.join(imgDir, 'song.png'))
6ae708d0 46 defImg = xbmc.translatePath(os.path.join(imgDir, 'default.tbn'))
2254a6b5 47 fanImg = xbmc.translatePath(os.path.join(baseDir, 'fanart.png'))
8817bb2e 48
2254a6b5 49 settings = xbmcaddon.Addon(id='plugin.audio.groove')
973b4c6c 50 songsearchlimit = settings.getSetting('songsearchlimit')
51 albumsearchlimit = settings.getSetting('albumsearchlimit')
52 artistsearchlimit = settings.getSetting('artistsearchlimit')
2254a6b5 53 username = settings.getSetting('username')
54 password = settings.getSetting('password')
6ae708d0 55
8817bb2e 56 def __init__( self ):
57 self._handle = int(sys.argv[1])
b738088f 58
8817bb2e 59 def categories(self):
2254a6b5 60
61 xbmc.log(self.username + ", limits: " + str(self.songsearchlimit) + ", " + str(self.albumsearchlimit) + ", " + str(self.artistsearchlimit))
b738088f 62
8817bb2e 63 userid = self._get_login()
b738088f 64
65 # Setup
66 groovesharkApi.setRemoveDuplicates(True)
6ae708d0 67 xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg)
68 if os.path.isdir(thumbDir) == False:
69 os.makedirs(thumbDir)
70
3fcef5ba 71 self._add_dir('Search songs', '', MODE_SEARCH_SONGS, self.songImg, 0)
72 self._add_dir('Search albums', '', MODE_SEARCH_ALBUMS, self.albumImg, 0)
73 self._add_dir('Search artists', '', MODE_SEARCH_ARTISTS, self.artistImg, 0)
36cc00d7 74 self._add_dir('Popular songs', '', MODE_POPULAR_SONGS, self.popularSongsImg, 0)
8817bb2e 75 if (userid != 0):
3fcef5ba 76 self._add_dir('Favorites', '', MODE_FAVORITES, self.favoritesImg, 0)
77 self._add_dir('Playlists', '', MODE_PLAYLISTS, self.playlistImg, 0)
78
8817bb2e 79 def searchSongs(self):
80 query = self._get_keyboard(default="", heading="Search songs")
81 if (query):
2254a6b5 82 songs = groovesharkApi.searchSongs(query, limit = self.songsearchlimit)
8817bb2e 83 if (len(songs) > 0):
6ae708d0 84 self._add_songs_directory(songs)
8817bb2e 85 else:
86 dialog = xbmcgui.Dialog()
87 dialog.ok('Grooveshark', 'No matching songs.')
88 self.categories()
89
90 def searchAlbums(self):
91 query = self._get_keyboard(default="", heading="Search albums")
92 if (query):
2254a6b5 93 albums = groovesharkApi.searchAlbums(query, limit = self.albumsearchlimit)
8817bb2e 94 if (len(albums) > 0):
6ae708d0 95 self._add_albums_directory(albums)
8817bb2e 96 else:
97 dialog = xbmcgui.Dialog()
98 dialog.ok('Grooveshark', 'No matching albums.')
99 self.categories()
100
101 def searchArtists(self):
102 query = self._get_keyboard(default="", heading="Search artists")
103 if (query):
2254a6b5 104 artists = groovesharkApi.searchArtists(query, limit = self.artistsearchlimit)
8817bb2e 105 if (len(artists) > 0):
6ae708d0 106 self._add_artists_directory(artists)
8817bb2e 107 else:
108 dialog = xbmcgui.Dialog()
109 dialog.ok('Grooveshark', 'No matching artists.')
110 self.categories()
111
112 def favorites(self):
36cc00d7 113 userid = self._get_login()
114 if (userid != 0):
115 favorites = groovesharkApi.userGetFavoriteSongs(userid)
116 if (len(favorites) > 0):
117 self._add_songs_directory(favorites)
118 else:
119 dialog = xbmcgui.Dialog()
120 dialog.ok('Grooveshark', 'You have no favorites.')
121 self.categories()
8817bb2e 122
36cc00d7 123 def popularSongs(self):
2254a6b5 124 popular = groovesharkApi.popularGetSongs(limit = self.songsearchlimit)
8817bb2e 125 if (len(popular) > 0):
6ae708d0 126 self._add_songs_directory(popular)
8817bb2e 127 else:
128 dialog = xbmcgui.Dialog()
129 dialog.ok('Grooveshark', 'No popular songs.')
130 self.categories()
36cc00d7 131
132 def popularAlbums(self):
133 popular = groovesharkApi.popularGetAlbums(limit = self.albumsearchlimit)
134 if (len(popular) > 0):
135 self._add_albums_directory(popular)
136 else:
137 dialog = xbmcgui.Dialog()
138 dialog.ok('Grooveshark', 'No popular albums.')
139 self.categories()
140
141 def popularArtists(self):
142 popular = groovesharkApi.popularGetArtists(limit = self.artistsearchlimit)
143 if (len(popular) > 0):
144 self._add_artists_directory(popular)
145 else:
146 dialog = xbmcgui.Dialog()
147 dialog.ok('Grooveshark', 'No popular artists.')
148 self.categories()
8817bb2e 149
150 def playlists(self):
151 userid = self._get_login()
152 if (userid != 0):
153 playlists = groovesharkApi.userGetPlaylists()
154 if (len(playlists) > 0):
6ae708d0 155 self._add_playlists_directory(playlists)
8817bb2e 156 else:
157 dialog = xbmcgui.Dialog()
158 dialog.ok('Grooveshark', 'You have no playlists.')
159 self.categories()
160
161 def favorite(self, songid):
162 userid = self._get_login()
163 if (userid != 0):
406ab447 164 xbmc.log("Favorite song: " + str(songid))
8817bb2e 165 groovesharkApi.favoriteSong(songID = songid)
3cfead3c 166 xbmc.executebuiltin('XBMC.Notification(Grooveshark, Added to favorites, 1000, ' + thumbDef + ')')
8817bb2e 167 else:
168 dialog = xbmcgui.Dialog()
169 dialog.ok('Grooveshark', 'You must be logged in', 'to add favorites.')
170
171 def unfavorite(self, songid):
172 userid = self._get_login()
173 if (userid != 0):
406ab447 174 xbmc.log("Unfavorite song: " + str(songid))
8817bb2e 175 groovesharkApi.unfavoriteSong(songID = songid)
3cfead3c 176 xbmc.executebuiltin('XBMC.Notification(Grooveshark, Removed from favorites, 1000, ' + thumbDef + ')')
8817bb2e 177 else:
178 dialog = xbmcgui.Dialog()
179 dialog.ok('Grooveshark', 'You must be logged in', 'to remove favorites.')
3fcef5ba 180
181 def frown(self, songid):
182 userid = self._get_login()
183 if (userid != 0):
406ab447 184 xbmc.log("Frown song: " + str(songid))
3fcef5ba 185 if groovesharkApi.radioFrown(songId = songid) != True:
186 xbmc.log("Unable to frown song " + str(songid))
3cfead3c 187 else:
188 xbmc.executebuiltin('XBMC.Notification(Grooveshark, Frowned, 1000, ' + thumbDef + ')')
3fcef5ba 189 else:
190 dialog = xbmcgui.Dialog()
191 dialog.ok('Grooveshark', 'You must be logged in', 'to frown a song.')
192
406ab447 193 def similarArtists(self, artistId):
194 similar = groovesharkApi.artistGetSimilar(artistId, limit = self.artistsearchlimit)
195 if (len(similar) > 0):
196 self._add_artists_directory(similar)
3fcef5ba 197 else:
198 dialog = xbmcgui.Dialog()
406ab447 199 dialog.ok('Grooveshark', 'No similar artists.')
200 self.categories()
36cc00d7 201
202 def makePlaylist(self, albumid, name):
203 userid = self._get_login()
204 if (userid != 0):
3cfead3c 205 re.split(' - ',name,1)
206 nameTokens = re.split(' - ',name,1)
207 name = self._get_keyboard(default=nameTokens[0], heading="Playlist name")
208 if name != '':
209 album = groovesharkApi.albumGetSongs(albumid, self.songsearchlimit)
210 songids = []
211 for song in album:
212 songids.append(song[1])
213 id = groovesharkApi.playlistCreateUnique(name, songids)
214 if id == 0:
215 dialog = xbmcgui.Dialog()
216 dialog.ok('Grooveshark', 'Cannot create playlist ', name)
217 else:
218 xbmc.executebuiltin('XBMC.Notification(Grooveshark, Playlist created, 1000, ' + thumbDef + ')')
36cc00d7 219 else:
220 dialog = xbmcgui.Dialog()
221 dialog.ok('Grooveshark', 'You must be logged in ', ' to create a playlist.')
222
223 def removePlaylist(self, playlistid, name):
224 dialog = xbmcgui.Dialog()
225 if dialog.yesno('Grooveshark', name, 'Delete this playlist?') == True:
226 userid = self._get_login()
227 if (userid != 0):
228 groovesharkApi.playlistDelete(playlistid)
3cfead3c 229 xbmc.executebuiltin("Container.Update(" + playlistUrl + ",replace)")
36cc00d7 230 else:
231 dialog = xbmcgui.Dialog()
232 dialog.ok('Grooveshark', 'You must be logged in ', ' to delete a playlist.')
233
234 def renamePlaylist(self, playlistid, name):
235 userid = self._get_login()
236 if (userid != 0):
237 newname = self._get_keyboard(default=name, heading="Playlist name")
3cfead3c 238 if newname == '':
239 return
240 elif groovesharkApi.playlistRename(playlistid, newname) == 0:
36cc00d7 241 dialog = xbmcgui.Dialog()
242 dialog.ok('Grooveshark', 'Cannot rename playlist ', name)
243 else:
244 xbmc.executebuiltin("Container.Refresh")
245 else:
246 dialog = xbmcgui.Dialog()
247 dialog.ok('Grooveshark', 'You must be logged in ', ' to rename a playlist.')
8817bb2e 248
36cc00d7 249 def album(self, albumid):
2254a6b5 250 album = groovesharkApi.albumGetSongs(albumId = albumid, limit = self.songsearchlimit)
6ae708d0 251 self._add_songs_directory(album)
8817bb2e 252
253 def artist(self, artistid):
2254a6b5 254 albums = groovesharkApi.artistGetAlbums(artistId = artistid, limit = self.albumsearchlimit)
406ab447 255 self._add_albums_directory(albums, artistid)
8817bb2e 256
257 def playlist(self, playlistid):
258 userid = self._get_login()
259 if (userid != 0):
2254a6b5 260 songs = groovesharkApi.playlistGetSongs(playlistId = playlistid, limit = self.songsearchlimit)
6ae708d0 261 self._add_songs_directory(songs)
8817bb2e 262 else:
263 dialog = xbmcgui.Dialog()
264 dialog.ok('Grooveshark', 'You must be logged in', 'to get playlists.')
265
6ae708d0 266 def playSong(self, item):
267 url = item.getProperty('url')
9b1d8c96 268 xbmc.log("Playing: " + url)
2254a6b5 269 xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=item)
3fcef5ba 270
6ae708d0 271 def songItem(self, id, name, album, artist, duration, thumb, image):
272 url = groovesharkApi.getStreamURL(id)
e6ccfeca 273 # Only try to get the image
274 if image != "":
275 songImg = self._get_icon(image, 'song-' + str(id) + "-image")
276 songThm = songImg
277 else:
278 songThm = self._get_icon(thumb, 'song-' + str(id) + "-thumb")
279 songImg = songThm
6ae708d0 280 item = xbmcgui.ListItem(label = artist + " - " + album + " - " + name, path=url, thumbnailImage=songThm, iconImage=songImg)
2254a6b5 281 item.setInfo( type="music", infoLabels={ "title": name, "duration": duration, "album": album, "artist": artist} )
282 item.setProperty('mimetype', 'audio/mpeg')
283 item.setProperty("IsPlayable", "true")
6ae708d0 284 item.setProperty('url', url)
285 item.setProperty('thumb', songThm)
286 item.setProperty('image', songImg)
2254a6b5 287
6ae708d0 288 return item
2254a6b5 289
8817bb2e 290 def _get_keyboard(self, default="", heading="", hidden=False):
3cfead3c 291 kb = xbmc.Keyboard(default, heading, hidden)
292 kb.doModal()
293 if (kb.isConfirmed()):
294 return unicode(kb.getText(), "utf-8")
295 return ''
8817bb2e 296
297 def _get_login(self):
2254a6b5 298 if (self.username == "" or self.password == ""):
8817bb2e 299 dialog = xbmcgui.Dialog()
300 dialog.ok('Grooveshark', 'Unable to login.', 'Check username and password in settings.')
301 return 0
302 else:
303 if groovesharkApi.loggedInStatus() == 1:
304 groovesharkApi.logout()
2254a6b5 305 userid = groovesharkApi.loginExt(self.username, self.password)
8817bb2e 306 if (userid != 0):
307 xbmc.log("Logged in")
308 return userid
309 else:
310 dialog = xbmcgui.Dialog()
311 dialog.ok('Grooveshark', 'Unable to login.', 'Check username and password in settings.')
312 return 0
313
6ae708d0 314 def _get_song_item(self, song):
315 name = song[0]
316 id = song[1]
317 duration = song[2]
318 album = song[3]
319 artist = song[6]
320 thumb = song[8]
321 image = song[9]
322 return self.songItem(id, name, album, artist, duration, thumb, image)
323
324 # File download
325 def _get_icon(self, url, id):
6ae708d0 326 localThumb = os.path.join(xbmc.translatePath(os.path.join(thumbDir, str(id)))) + '.tbn'
327 try:
328 if os.path.isfile(localThumb) == False:
e6ccfeca 329 xbmc.log('Downloading ' + url + ' to ' + localThumb)
6ae708d0 330 loc = urllib.URLopener()
331 loc.retrieve(url, localThumb)
332 except:
333 xbmc.log('URL download failed of ' + url + ' to ' + localThumb)
2254a6b5 334 return(self.defImg)
6ae708d0 335
336 return os.path.join(os.path.join(thumbDir, str(id))) + '.tbn'
337
338 def _add_songs_directory(self, songs):
339 n = len(songs)
340 xbmc.log("Found " + str(n) + " songs...")
8817bb2e 341 i = 0
6ae708d0 342 while i < n:
8817bb2e 343 song = songs[i]
6ae708d0 344 item = self._get_song_item(song)
345 songurl = item.getProperty('url')
346 songthumb = item.getProperty('thumb')
347 songimage = item.getProperty('image')
348 songname = song[0]
349 songid = song[1]
350 songduration = song[2]
351 songalbum = song[3]
352 songartist = song[6]
6ae708d0 353 u=sys.argv[0]+"?url="+urllib.quote_plus(songurl) \
354 +"&mode="+str(MODE_SONG)+"&name="+urllib.quote_plus(songname)+"&id=" \
355 +str(songid) \
356 +"&album="+urllib.quote_plus(songalbum) \
357 +"&artist="+urllib.quote_plus(songartist) \
358 +"&duration="+str(songduration) \
359 +"&thumb="+urllib.quote_plus(songthumb) \
360 +"&image="+urllib.quote_plus(songimage)
361 fav=sys.argv[0]+"?url="+urllib.quote_plus(songurl)+"&mode="+str(MODE_FAVORITE)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid)
362 unfav=sys.argv[0]+"?url="+urllib.quote_plus(songurl)+"&mode="+str(MODE_UNFAVORITE)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid)
6ae708d0 363 menuItems = []
364 menuItems.append(("Grooveshark Favorite", "XBMC.RunPlugin("+fav+")"))
365 menuItems.append(("Not Grooveshark Favorite", "XBMC.RunPlugin("+unfav+")"))
6ae708d0 366 item.addContextMenuItems(menuItems, replaceItems=False)
31731635 367 xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=item,isFolder=False,totalItems=n)
8817bb2e 368 i = i + 1
369 xbmcplugin.setContent(self._handle, 'songs')
31731635 370 xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg)
8817bb2e 371
406ab447 372 def _add_albums_directory(self, albums, artistid=0):
31731635 373 n = len(albums)
374 xbmc.log("Found " + str(n) + " albums...")
8817bb2e 375 i = 0
31731635 376 while i < n:
8817bb2e 377 album = albums[i]
378 albumArtistName = album[0]
379 albumName = album[2]
380 albumID = album[3]
2254a6b5 381 albumImage = self._get_icon(album[4], 'album-' + str(albumID))
31731635 382 self._add_dir(albumName + " - " + albumArtistName, '', MODE_ALBUM, albumImage, albumID, n)
8817bb2e 383 i = i + 1
406ab447 384 if artistid > 0:
385 self._add_dir('Similar artists...', '', MODE_SIMILAR_ARTISTS, self.artistImg, artistid)
8817bb2e 386 xbmcplugin.setContent(self._handle, 'albums')
387 xbmcplugin.addSortMethod(self._handle, xbmcplugin.SORT_METHOD_ALBUM_IGNORE_THE)
31731635 388 xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg)
8817bb2e 389
6ae708d0 390 def _add_artists_directory(self, artists):
31731635 391 n = len(artists)
392 xbmc.log("Found " + str(n) + " artists...")
8817bb2e 393 i = 0
31731635 394 while i < n:
8817bb2e 395 artist = artists[i]
396 artistName = artist[0]
397 artistID = artist[1]
31731635 398 self._add_dir(artistName, '', MODE_ARTIST, self.artistImg, artistID, n)
8817bb2e 399 i = i + 1
400 xbmcplugin.setContent(self._handle, 'artists')
401 xbmcplugin.addSortMethod(self._handle, xbmcplugin.SORT_METHOD_ARTIST_IGNORE_THE)
31731635 402 xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg)
8817bb2e 403
6ae708d0 404 def _add_playlists_directory(self, playlists):
31731635 405 n = len(playlists)
406 xbmc.log("Found " + str(n) + " playlists...")
8817bb2e 407 i = 0
31731635 408 while i < n:
8817bb2e 409 playlist = playlists[i]
410 playlistName = playlist[0]
411 playlistID = playlist[1]
31731635 412 self._add_dir(playlistName, '', MODE_PLAYLIST, self.playlistImg, playlistID, n)
8817bb2e 413 i = i + 1
414 xbmcplugin.setContent(self._handle, 'files')
415 xbmcplugin.addSortMethod(self._handle, xbmcplugin.SORT_METHOD_PLAYLIST_ORDER)
31731635 416 xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg)
3fcef5ba 417
31731635 418 def _add_dir(self, name, url, mode, iconimage, id, items=1):
8817bb2e 419 u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&id="+str(id)
420 dir=xbmcgui.ListItem(name, iconImage=iconimage, thumbnailImage=iconimage)
b738088f 421 dir.setInfo( type="Music", infoLabels={ "title": name } )
8817bb2e 422 # Codes from http://xbmc-scripting.googlecode.com/svn/trunk/Script%20Templates/common/gui/codes.py
423 menuItems = []
424 menuItems.append(("Select", "XBMC.executebuiltin(Action(7))"))
36cc00d7 425 if mode == MODE_ALBUM:
426 mkplaylst=sys.argv[0]+"?mode="+str(MODE_MAKE_PLAYLIST)+"&name="+name+"&id="+str(id)
427 menuItems.append(("Make Grooveshark playlist", "XBMC.RunPlugin("+mkplaylst+")"))
428 if mode == MODE_PLAYLIST:
429 rmplaylst=sys.argv[0]+"?mode="+str(MODE_REMOVE_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id)
430 menuItems.append(("Delete playlist", "XBMC.RunPlugin("+rmplaylst+")"))
431 mvplaylst=sys.argv[0]+"?mode="+str(MODE_RENAME_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id)
432 menuItems.append(("Rename playlist", "XBMC.RunPlugin("+mvplaylst+")"))
8817bb2e 433 dir.addContextMenuItems(menuItems, replaceItems=True)
31731635 434 return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=dir,isFolder=True, totalItems=items)
6ae708d0 435
8817bb2e 436
437def get_params():
438 param=[]
439 paramstring=sys.argv[2]
440 if len(paramstring)>=2:
441 params=sys.argv[2]
442 cleanedparams=params.replace('?','')
443 if (params[len(params)-1]=='/'):
444 params=params[0:len(params)-2]
445 pairsofparams=cleanedparams.split('&')
446 param={}
447 for i in range(len(pairsofparams)):
448 splitparams={}
449 splitparams=pairsofparams[i].split('=')
450 if (len(splitparams))==2:
451 param[splitparams[0]]=splitparams[1]
452 print param
453 return param
454
455grooveshark = Groveshark();
456
457params=get_params()
458url=None
459name=None
460mode=None
461id=None
462
463try: url=urllib.unquote_plus(params["url"])
464except: pass
465try: name=urllib.unquote_plus(params["name"])
466except: pass
467try: mode=int(params["mode"])
468except: pass
469try: id=int(params["id"])
470except: pass
471
472if (id > 0):
473 lastID = id
474
475if mode==None:
476 grooveshark.categories()
477
478elif mode==MODE_SEARCH_SONGS:
479 grooveshark.searchSongs()
480
481elif mode==MODE_SEARCH_ALBUMS:
482 grooveshark.searchAlbums()
483
484elif mode==MODE_SEARCH_ARTISTS:
485 grooveshark.searchArtists()
486
36cc00d7 487elif mode==MODE_POPULAR_SONGS:
488 grooveshark.popularSongs()
8817bb2e 489
490elif mode==MODE_PLAYLISTS:
491 grooveshark.playlists()
492
493elif mode==MODE_FAVORITES:
494 grooveshark.favorites()
495
496elif mode==MODE_SONG:
497 try: name=urllib.unquote_plus(params["name"])
498 except: pass
499 try: album=urllib.unquote_plus(params["album"])
500 except: pass
501 try: artist=urllib.unquote_plus(params["artist"])
502 except: pass
503 try: duration=int(params["duration"])
504 except: pass
b738088f 505 try: thumb=urllib.unquote_plus(params["thumb"])
506 except: pass
507 try: image=urllib.unquote_plus(params["image"])
508 except: pass
6ae708d0 509 song = grooveshark.songItem(id, name, album, artist, duration, thumb, image)
3fcef5ba 510 grooveshark.playSong(song)
8817bb2e 511
512elif mode==MODE_ARTIST:
513 grooveshark.artist(lastID)
514
515elif mode==MODE_ALBUM:
516 grooveshark.album(lastID)
517
518elif mode==MODE_PLAYLIST:
519 grooveshark.playlist(lastID)
520
521elif mode==MODE_FAVORITE:
522 grooveshark.favorite(lastID)
523
524elif mode==MODE_UNFAVORITE:
525 grooveshark.unfavorite(lastID)
3fcef5ba 526
406ab447 527elif mode==MODE_SIMILAR_ARTISTS:
528 grooveshark.similarArtists(lastID)
3fcef5ba 529
36cc00d7 530elif mode==MODE_MAKE_PLAYLIST:
531 grooveshark.makePlaylist(lastID, name)
532
533elif mode==MODE_REMOVE_PLAYLIST:
534 grooveshark.removePlaylist(lastID, name)
535
536elif mode==MODE_RENAME_PLAYLIST:
537 grooveshark.renamePlaylist(lastID, name)
538
539
8817bb2e 540if (mode < MODE_SONG):
541 xbmcplugin.endOfDirectory(int(sys.argv[1]))