1 import urllib
, sys
, os
, shutil
, re
, xbmcaddon
, xbmcplugin
, xbmcgui
, xbmc
5 MODE_SEARCH_ARTISTS
= 3
12 MODE_SIMILAR_ARTISTS
= 10
16 MODE_MAKE_PLAYLIST
= 14
17 MODE_REMOVE_PLAYLIST
= 15
18 MODE_RENAME_PLAYLIST
= 16
19 MODE_REMOVE_PLAYLIST_SONG
= 17
20 MODE_ADD_PLAYLIST_SONG
= 18
27 ACTION_SELECT_ITEM
= 7
28 ACTION_PREVIOUS_MENU
= 10
31 resDir
= xbmc
.translatePath(os
.path
.join(baseDir
, 'resources'))
32 libDir
= xbmc
.translatePath(os
.path
.join(resDir
, 'lib'))
33 imgDir
= xbmc
.translatePath(os
.path
.join(resDir
, 'img'))
34 thumbDir
= os
.path
.join('special://masterprofile/addon_data/', os
.path
.join(os
.path
.basename(os
.getcwd()), 'thumb'))
36 baseModeUrl
= 'plugin://plugin.audio.groove/'
37 playlistUrl
= baseModeUrl
+ '?mode=' + str(MODE_PLAYLIST
)
38 playlistsUrl
= baseModeUrl
+ '?mode=' + str(MODE_PLAYLISTS
)
39 favoritesUrl
= baseModeUrl
+ '?mode=' + str(MODE_FAVORITES
)
41 thumbDef
= os
.path
.join(os
.path
.basename(os
.getcwd()), 'default.tbn')
42 listBackground
= os
.path
.join(imgDir
, 'listbackground.png')
44 sys
.path
.append (libDir
)
45 from GrooveAPI
import GrooveAPI
46 groovesharkApi
= GrooveAPI()
49 def __init__( self
, *args
, **kwargs
):
50 self
.__dict
__.update( kwargs
)
52 # Window dialog to select a grooveshark playlist
53 class GroovesharkPlaylistSelect(xbmcgui
.WindowDialog
):
55 def __init__(self
, items
=[]):
56 gap
= int(self
.getHeight()/100)
57 w
= int(self
.getWidth()*0.5)
58 h
= self
.getHeight()-30*gap
64 self
.imgBg
= xbmcgui
.ControlImage(x
+gap
, 5*gap
+y
, w
-2*gap
, h
-5*gap
, listBackground
)
65 self
.addControl(self
.imgBg
)
67 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)
68 self
.addControl(self
.playlistControl
)
71 self
.isSelecting
= False
74 for playlist
in items
:
75 listitems
.append(xbmcgui
.ListItem(playlist
[0]))
76 listitems
.append(xbmcgui
.ListItem('New...'))
77 self
.playlistControl
.addItems(listitems
)
78 self
.setFocus(self
.playlistControl
)
79 self
.playlistControl
.selectItem(0)
80 item
= self
.playlistControl
.getListItem(self
.lastPos
)
83 # Highlight selected item
84 def setHighlight(self
):
88 self
.isSelecting
= True
90 pos
= self
.playlistControl
.getSelectedPosition()
92 item
= self
.playlistControl
.getListItem(self
.lastPos
)
94 item
= self
.playlistControl
.getListItem(pos
)
97 self
.isSelecting
= False
100 def onControl(self
, control
):
101 if control
== self
.playlistControl
:
102 self
.selected
= self
.playlistControl
.getSelectedPosition()
105 # Action - close or up/down
106 def onAction(self
, action
):
107 if action
== ACTION_PREVIOUS_MENU
:
110 elif action
== ACTION_MOVE_UP
or action
== ACTION_MOVE_DOWN
or action
== ACTION_PAGE_UP
or action
== ACTION_PAGE_DOWN
== 6:
111 self
.setFocus(self
.playlistControl
)
116 albumImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'album.png'))
117 artistImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'artist.png'))
118 favoritesImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'favorites.png'))
119 playlistImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'playlist.png'))
120 popularSongsImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'popularSongs.png'))
121 songImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'song.png'))
122 defImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'default.tbn'))
123 fanImg
= xbmc
.translatePath(os
.path
.join(baseDir
, 'fanart.png'))
125 settings
= xbmcaddon
.Addon(id='plugin.audio.groove')
126 songsearchlimit
= settings
.getSetting('songsearchlimit')
127 albumsearchlimit
= settings
.getSetting('albumsearchlimit')
128 artistsearchlimit
= settings
.getSetting('artistsearchlimit')
129 username
= settings
.getSetting('username')
130 password
= settings
.getSetting('password')
133 def __init__( self
):
134 self
._handle
= int(sys
.argv
[1])
137 def categories(self
):
139 self
.userid
= self
._get
_login
()
142 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
143 if os
.path
.isdir(thumbDir
) == False:
144 os
.makedirs(thumbDir
)
146 self
._add
_dir
('Search songs...', '', MODE_SEARCH_SONGS
, self
.songImg
, 0)
147 self
._add
_dir
('Search albums...', '', MODE_SEARCH_ALBUMS
, self
.albumImg
, 0)
148 self
._add
_dir
('Search artists...', '', MODE_SEARCH_ARTISTS
, self
.artistImg
, 0)
149 self
._add
_dir
('Popular songs', '', MODE_POPULAR_SONGS
, self
.popularSongsImg
, 0)
150 if (self
.userid
!= 0):
151 self
._add
_dir
('Favorites', '', MODE_FAVORITES
, self
.favoritesImg
, 0)
152 self
._add
_dir
('Playlists', '', MODE_PLAYLISTS
, self
.playlistImg
, 0)
155 def searchSongs(self
):
156 query
= self
._get
_keyboard
(default
="", heading
="Search songs")
158 groovesharkApi
.setRemoveDuplicates(True)
159 songs
= groovesharkApi
.searchSongs(query
, limit
= self
.songsearchlimit
)
161 self
._add
_songs
_directory
(songs
)
163 dialog
= xbmcgui
.Dialog()
164 dialog
.ok('Grooveshark XBMC', 'No matching songs.')
170 def searchAlbums(self
):
171 query
= self
._get
_keyboard
(default
="", heading
="Search albums")
173 albums
= groovesharkApi
.searchAlbums(query
, limit
= self
.albumsearchlimit
)
174 if (len(albums
) > 0):
175 self
._add
_albums
_directory
(albums
)
177 dialog
= xbmcgui
.Dialog()
178 dialog
.ok('Grooveshark XBMC', 'No matching albums.')
184 def searchArtists(self
):
185 query
= self
._get
_keyboard
(default
="", heading
="Search artists")
187 artists
= groovesharkApi
.searchArtists(query
, limit
= self
.artistsearchlimit
)
188 if (len(artists
) > 0):
189 self
._add
_artists
_directory
(artists
)
191 dialog
= xbmcgui
.Dialog()
192 dialog
.ok('Grooveshark XBMC', 'No matching artists.')
199 userid
= self
._get
_login
()
201 favorites
= groovesharkApi
.userGetFavoriteSongs(userid
)
202 if (len(favorites
) > 0):
203 self
._add
_songs
_directory
(favorites
, isFavorites
=True)
205 dialog
= xbmcgui
.Dialog()
206 dialog
.ok('Grooveshark XBMC', 'You have no favorites.')
210 def popularSongs(self
):
211 popular
= groovesharkApi
.popularGetSongs(limit
= self
.songsearchlimit
)
212 if (len(popular
) > 0):
213 self
._add
_songs
_directory
(popular
)
215 dialog
= xbmcgui
.Dialog()
216 dialog
.ok('Grooveshark XBMC', 'No popular songs.')
221 userid
= self
._get
_login
()
223 playlists
= groovesharkApi
.userGetPlaylists()
224 if (len(playlists
) > 0):
225 self
._add
_playlists
_directory
(playlists
)
227 dialog
= xbmcgui
.Dialog()
228 dialog
.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.')
231 dialog
= xbmcgui
.Dialog()
232 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to see your Grooveshark playlists.')
234 # Make songs a favorite
235 def favorite(self
, songid
):
236 userid
= self
._get
_login
()
238 xbmc
.log("Favorite song: " + str(songid
))
239 groovesharkApi
.favoriteSong(songID
= songid
)
240 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added to favorites, 1000, ' + thumbDef
+ ')')
242 dialog
= xbmcgui
.Dialog()
243 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to add favorites.')
245 # Remove song from favorites
246 def unfavorite(self
, songid
, prevMode
=0):
247 userid
= self
._get
_login
()
249 xbmc
.log("Unfavorite song: " + str(songid
) + ', previous mode was ' + str(prevMode
))
250 groovesharkApi
.unfavoriteSong(songID
= songid
)
251 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Removed from Grooveshark favorites, 1000, ' + thumbDef
+ ')')
252 # Refresh to remove item from directory
253 if (int(prevMode
) == MODE_FAVORITES
):
254 xbmc
.executebuiltin("Container.Refresh(" + favoritesUrl
+ ")")
256 dialog
= xbmcgui
.Dialog()
257 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to remove Grooveshark favorites.')
260 def frown(self
, songid
):
261 userid
= self
._get
_login
()
263 xbmc
.log("Frown song: " + str(songid
))
264 if groovesharkApi
.radioFrown(songId
= songid
) != True:
265 xbmc
.log("Unable to frown song " + str(songid
))
267 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Frowned, 1000, ' + thumbDef
+ ')')
269 dialog
= xbmcgui
.Dialog()
270 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to frown a Grooveshark song.')
272 # Find similar artists to searched artist
273 def similarArtists(self
, artistId
):
274 similar
= groovesharkApi
.artistGetSimilar(artistId
, limit
= self
.artistsearchlimit
)
275 if (len(similar
) > 0):
276 self
._add
_artists
_directory
(similar
)
278 dialog
= xbmcgui
.Dialog()
279 dialog
.ok('Grooveshark XBMC', 'No similar artists.')
282 # Make a playlist from an album
283 def makePlaylist(self
, albumid
, name
):
284 userid
= self
._get
_login
()
286 re
.split(' - ',name
,1)
287 nameTokens
= re
.split(' - ',name
,1) # suggested name
288 name
= self
._get
_keyboard
(default
=nameTokens
[0], heading
="Grooveshark playlist name")
290 groovesharkApi
.setRemoveDuplicates(True)
291 album
= groovesharkApi
.albumGetSongs(albumid
, self
.songsearchlimit
)
294 songids
.append(song
[1])
295 if groovesharkApi
.playlistCreateUnique(name
, songids
) == 0:
296 dialog
= xbmcgui
.Dialog()
297 dialog
.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name
)
299 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef
+ ')')
301 dialog
= xbmcgui
.Dialog()
302 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to create a Grooveshark playlist.')
305 def renamePlaylist(self
, playlistid
, name
):
306 userid
= self
._get
_login
()
308 newname
= self
._get
_keyboard
(default
=name
, heading
="Grooveshark playlist name")
311 elif groovesharkApi
.playlistRename(playlistid
, newname
) == 0:
312 dialog
= xbmcgui
.Dialog()
313 dialog
.ok('Grooveshark XBMC', 'Cannot rename Grooveshark playlist ', name
)
315 # Refresh to show new item name
316 xbmc
.executebuiltin("Container.Refresh")
318 dialog
= xbmcgui
.Dialog()
319 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to rename a Grooveshark playlist.')
322 def removePlaylist(self
, playlistid
, name
):
323 dialog
= xbmcgui
.Dialog()
324 if dialog
.yesno('Grooveshark XBMC', name
, 'Delete this Grooveshark playlist?') == True:
325 userid
= self
._get
_login
()
327 if groovesharkApi
.playlistDelete(playlistid
) == 0:
328 dialog
= xbmcgui
.Dialog()
329 dialog
.ok('Grooveshark XBMC', 'Cannot remove Grooveshark playlist ', name
)
331 # Refresh to remove item from directory
332 xbmc
.executebuiltin("Container.Refresh(" + playlistsUrl
+ ")")
334 dialog
= xbmcgui
.Dialog()
335 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a Grooveshark playlist.')
337 # Add song to playlist
338 def addPlaylistSong(self
, songid
):
339 userid
= self
._get
_login
()
341 playlists
= groovesharkApi
.userGetPlaylists()
342 if (len(playlists
) > 0):
344 # Select the playlist
345 playlistSelect
= GroovesharkPlaylistSelect(items
=playlists
)
346 playlistSelect
.setFocus(playlistSelect
.playlistControl
)
347 playlistSelect
.doModal()
348 i
= playlistSelect
.selected
352 if i
>= len(playlists
):
353 name
= self
._get
_keyboard
(default
='', heading
="Grooveshark playlist name")
356 songIds
.append(songid
)
357 if groovesharkApi
.playlistCreateUnique(name
, songIds
) == 0:
358 dialog
= xbmcgui
.Dialog()
359 dialog
.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name
)
361 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef
+ ')')
364 playlist
= playlists
[i
]
365 playlistid
= playlist
[1]
366 xbmc
.log("Add song " + str(songid
) + " to playlist " + str(playlistid
))
367 ret
= groovesharkApi
.playlistAddSong(playlistid
, songid
, 0)
369 dialog
= xbmcgui
.Dialog()
370 dialog
.ok('Grooveshark XBMC', 'Cannot add to playlist ')
372 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added song to Grooveshark playlist, 1000, ' + thumbDef
+ ')')
374 dialog
= xbmcgui
.Dialog()
375 dialog
.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.')
378 dialog
= xbmcgui
.Dialog()
379 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to add a song to a Grooveshark playlist.')
381 # Remove song from playlist
382 def removePlaylistSong(self
, playlistid
, playlistname
, songpos
):
383 dialog
= xbmcgui
.Dialog()
384 if dialog
.yesno('Grooveshark XBMC', 'Delete this song from the Grooveshark playlist?') == True:
385 userid
= self
._get
_login
()
387 if groovesharkApi
.playlistDeleteSong(playlistid
, songpos
) == 0:
388 dialog
= xbmcgui
.Dialog()
389 dialog
.ok('Grooveshark XBMC', 'Failed to remove ', ' song from Grooveshark playlist.')
391 # Refresh to remove item from directory
392 xbmc
.executebuiltin("Container.Refresh(" + playlistUrl
+ "&id="+str(playlistid
) + "&name=" + playlistname
+ ")")
394 dialog
= xbmcgui
.Dialog()
395 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a song from a Grooveshark playlist.')
397 # Show selected album
398 def album(self
, albumid
):
399 groovesharkApi
.setRemoveDuplicates(True)
400 album
= groovesharkApi
.albumGetSongs(albumId
= albumid
, limit
= self
.songsearchlimit
)
401 self
._add
_songs
_directory
(album
)
403 # Show selected artist
404 def artist(self
, artistid
):
405 albums
= groovesharkApi
.artistGetAlbums(artistId
= artistid
, limit
= self
.albumsearchlimit
)
406 self
._add
_albums
_directory
(albums
, artistid
)
408 # Show selected playlist
409 def playlist(self
, playlistid
, playlistname
):
410 userid
= self
._get
_login
()
412 songs
= groovesharkApi
.playlistGetSongs(playlistId
= playlistid
, limit
= self
.songsearchlimit
)
413 self
._add
_songs
_directory
(songs
, playlistid
, playlistname
)
415 dialog
= xbmcgui
.Dialog()
416 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to get Grooveshark playlists.')
419 def playSong(self
, item
):
420 url
= groovesharkApi
.getStreamURL(item
.getProperty('id'))
422 xbmc
.log("Playing: " + url
)
423 xbmcplugin
.setResolvedUrl(handle
=int(sys
.argv
[1]), succeeded
=True, listitem
=item
)
425 # Make a song directory item
426 def songItem(self
, id, name
, album
, artist
, duration
, thumb
, image
):
427 # Only try to get the image
429 songImg
= self
._get
_icon
(image
, 'song-' + str(id) + "-image")
432 songThm
= self
._get
_icon
(thumb
, 'song-' + str(id) + "-thumb")
434 item
= xbmcgui
.ListItem(label
= artist
+ " - " + album
+ " - " + name
, thumbnailImage
=songThm
, iconImage
=songImg
)
435 item
.setInfo( type="music", infoLabels
={ "title": name
, "duration": duration
, "album": album
, "artist": artist
} )
436 item
.setProperty('mimetype', 'audio/mpeg')
437 item
.setProperty("IsPlayable", "true")
438 item
.setProperty('id', str(id))
439 item
.setProperty('thumb', songThm
)
440 item
.setProperty('image', songImg
)
444 def _get_keyboard(self
, default
="", heading
="", hidden
=False):
445 kb
= xbmc
.Keyboard(default
, heading
, hidden
)
447 if (kb
.isConfirmed()):
448 return unicode(kb
.getText(), "utf-8")
451 # Login to grooveshark
452 def _get_login(self
):
453 if (self
.username
== "" or self
.password
== ""):
454 dialog
= xbmcgui
.Dialog()
455 dialog
.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.')
459 uid
= groovesharkApi
.loginExt(self
.username
, self
.password
)
463 dialog
= xbmcgui
.Dialog()
464 dialog
.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.')
467 # Get a song directory item
468 def _get_song_item(self
, song
):
476 return self
.songItem(id, name
, album
, artist
, duration
, thumb
, image
)
479 def _get_icon(self
, url
, id):
480 localThumb
= os
.path
.join(xbmc
.translatePath(os
.path
.join(thumbDir
, str(id)))) + '.tbn'
482 if os
.path
.isfile(localThumb
) == False:
483 xbmc
.log('Downloading ' + url
+ ' to ' + localThumb
)
484 loc
= urllib
.URLopener()
485 loc
.retrieve(url
, localThumb
)
487 shutil
.copy2(self
.defImg
, localThumb
)
489 return os
.path
.join(os
.path
.join(thumbDir
, str(id))) + '.tbn'
491 # Add songs to directory
492 def _add_songs_directory(self
, songs
, playlistid
=0, playlistname
='', isFavorites
=False):
494 xbmc
.log("Found " + str(n
) + " songs...")
498 item
= self
._get
_song
_item
(song
)
499 songthumb
= item
.getProperty('thumb')
500 songimage
= item
.getProperty('image')
503 songduration
= song
[2]
506 u
=sys
.argv
[0]+"?mode="+str(MODE_SONG
)+"&name="+urllib
.quote_plus(songname
)+"&id="+str(songid
) \
507 +"&album="+urllib
.quote_plus(songalbum
) \
508 +"&artist="+urllib
.quote_plus(songartist
) \
509 +"&duration="+str(songduration
) \
510 +"&thumb="+urllib
.quote_plus(songthumb
) \
511 +"&image="+urllib
.quote_plus(songimage
)
512 fav
=sys
.argv
[0]+"?mode="+str(MODE_FAVORITE
)+"&name="+urllib
.quote_plus(songname
)+"&id="+str(songid
)
513 unfav
=sys
.argv
[0]+"?mode="+str(MODE_UNFAVORITE
)+"&name="+urllib
.quote_plus(songname
)+"&id="+str(songid
)+"&prevmode="
515 if isFavorites
== True:
516 unfav
= unfav
+str(MODE_FAVORITES
)
518 menuItems
.append(("Grooveshark favorite", "XBMC.RunPlugin("+fav
+")"))
519 menuItems
.append(("Not Grooveshark favorite", "XBMC.RunPlugin("+unfav
+")"))
521 rmplaylstsong
=sys
.argv
[0]+"?playlistid="+str(playlistid
)+"&id="+str(i
+1)+"&mode="+str(MODE_REMOVE_PLAYLIST_SONG
)+"&name="+playlistname
522 menuItems
.append(("Remove from Grooveshark playlist", "XBMC.RunPlugin("+rmplaylstsong
+")"))
524 addplaylstsong
=sys
.argv
[0]+"?id="+str(songid
)+"&mode="+str(MODE_ADD_PLAYLIST_SONG
)
525 menuItems
.append(("Add to Grooveshark playlist", "XBMC.RunPlugin("+addplaylstsong
+")"))
526 item
.addContextMenuItems(menuItems
, replaceItems
=False)
527 xbmcplugin
.addDirectoryItem(handle
=int(sys
.argv
[1]),url
=u
,listitem
=item
,isFolder
=False, totalItems
=n
)
530 xbmcplugin
.setContent(self
._handle
, 'songs')
531 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
533 # Add albums to directory
534 def _add_albums_directory(self
, albums
, artistid
=0):
536 xbmc
.log("Found " + str(n
) + " albums...")
540 albumArtistName
= album
[0]
543 albumImage
= self
._get
_icon
(album
[4], 'album-' + str(albumID
))
544 self
._add
_dir
(albumName
+ " - " + albumArtistName
, '', MODE_ALBUM
, albumImage
, albumID
, n
)
547 self
._add
_dir
('Similar artists...', '', MODE_SIMILAR_ARTISTS
, self
.artistImg
, artistid
)
548 xbmcplugin
.setContent(self
._handle
, 'albums')
549 xbmcplugin
.addSortMethod(self
._handle
, xbmcplugin
.SORT_METHOD_ALBUM_IGNORE_THE
)
550 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
552 # Add artists to directory
553 def _add_artists_directory(self
, artists
):
555 xbmc
.log("Found " + str(n
) + " artists...")
559 artistName
= artist
[0]
561 self
._add
_dir
(artistName
, '', MODE_ARTIST
, self
.artistImg
, artistID
, n
)
563 xbmcplugin
.setContent(self
._handle
, 'artists')
564 xbmcplugin
.addSortMethod(self
._handle
, xbmcplugin
.SORT_METHOD_ARTIST_IGNORE_THE
)
565 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
567 # Add playlists to directory
568 def _add_playlists_directory(self
, playlists
):
570 xbmc
.log("Found " + str(n
) + " playlists...")
573 playlist
= playlists
[i
]
574 playlistName
= playlist
[0]
575 playlistID
= playlist
[1]
576 self
._add
_dir
(playlistName
, '', MODE_PLAYLIST
, self
.playlistImg
, playlistID
, n
)
578 xbmcplugin
.setContent(self
._handle
, 'files')
579 xbmcplugin
.addSortMethod(self
._handle
, xbmcplugin
.SORT_METHOD_PLAYLIST_ORDER
)
580 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
582 # Add whatever directory
583 def _add_dir(self
, name
, url
, mode
, iconimage
, id, items
=1):
585 u
=sys
.argv
[0]+"?mode="+str(mode
)+"&name="+urllib
.quote_plus(name
)+"&id="+str(id)
586 dir=xbmcgui
.ListItem(name
, iconImage
=iconimage
, thumbnailImage
=iconimage
)
587 dir.setInfo( type="Music", infoLabels
={ "title": name
} )
591 if mode
== MODE_ALBUM
:
592 mkplaylst
=sys
.argv
[0]+"?mode="+str(MODE_MAKE_PLAYLIST
)+"&name="+name
+"&id="+str(id)
593 menuItems
.append(("Make Grooveshark playlist", "XBMC.RunPlugin("+mkplaylst
+")"))
594 if mode
== MODE_PLAYLIST
:
595 rmplaylst
=sys
.argv
[0]+"?mode="+str(MODE_REMOVE_PLAYLIST
)+"&name="+urllib
.quote_plus(name
)+"&id="+str(id)
596 menuItems
.append(("Delete Grooveshark playlist", "XBMC.RunPlugin("+rmplaylst
+")"))
597 mvplaylst
=sys
.argv
[0]+"?mode="+str(MODE_RENAME_PLAYLIST
)+"&name="+urllib
.quote_plus(name
)+"&id="+str(id)
598 menuItems
.append(("Rename Grooveshark playlist", "XBMC.RunPlugin("+mvplaylst
+")"))
600 dir.addContextMenuItems(menuItems
, replaceItems
=False)
601 return xbmcplugin
.addDirectoryItem(handle
=int(sys
.argv
[1]),url
=u
,listitem
=dir,isFolder
=True, totalItems
=items
)
604 # Parse URL parameters
607 paramstring
=sys
.argv
[2]
608 xbmc
.log(paramstring
)
609 if len(paramstring
)>=2:
611 cleanedparams
=params
.replace('?','')
612 if (params
[len(params
)-1]=='/'):
613 params
=params
[0:len(params
)-2]
614 pairsofparams
=cleanedparams
.split('&')
616 for i
in range(len(pairsofparams
)):
618 splitparams
=pairsofparams
[i
].split('=')
619 if (len(splitparams
))==2:
620 param
[splitparams
[0]]=splitparams
[1]
624 grooveshark
= Groveshark();
628 try: mode
=int(params
["mode"])
631 if mode
> MODE_FAVORITES
:
634 try: name
=urllib
.unquote_plus(params
["name"])
636 try: id=int(params
["id"])
639 # Call function for URL
641 grooveshark
.categories()
643 elif mode
==MODE_SEARCH_SONGS
:
644 grooveshark
.searchSongs()
646 elif mode
==MODE_SEARCH_ALBUMS
:
647 grooveshark
.searchAlbums()
649 elif mode
==MODE_SEARCH_ARTISTS
:
650 grooveshark
.searchArtists()
652 elif mode
==MODE_POPULAR_SONGS
:
653 grooveshark
.popularSongs()
655 elif mode
==MODE_FAVORITES
:
656 grooveshark
.favorites()
658 elif mode
==MODE_PLAYLISTS
:
659 grooveshark
.playlists()
661 elif mode
==MODE_SONG
:
662 try: album
=urllib
.unquote_plus(params
["album"])
664 try: artist
=urllib
.unquote_plus(params
["artist"])
666 try: duration
=int(params
["duration"])
668 try: thumb
=urllib
.unquote_plus(params
["thumb"])
670 try: image
=urllib
.unquote_plus(params
["image"])
672 song
= grooveshark
.songItem(id, name
, album
, artist
, duration
, thumb
, image
)
673 grooveshark
.playSong(song
)
675 elif mode
==MODE_ARTIST
:
676 grooveshark
.artist(id)
678 elif mode
==MODE_ALBUM
:
679 grooveshark
.album(id)
681 elif mode
==MODE_PLAYLIST
:
682 grooveshark
.playlist(id, name
)
684 elif mode
==MODE_FAVORITE
:
685 grooveshark
.favorite(id)
687 elif mode
==MODE_UNFAVORITE
:
688 try: prevMode
=int(urllib
.unquote_plus(params
["prevmode"]))
691 grooveshark
.unfavorite(id, prevMode
)
693 elif mode
==MODE_SIMILAR_ARTISTS
:
694 grooveshark
.similarArtists(id)
696 elif mode
==MODE_MAKE_PLAYLIST
:
697 grooveshark
.makePlaylist(id, name
)
699 elif mode
==MODE_REMOVE_PLAYLIST
:
700 grooveshark
.removePlaylist(id, name
)
702 elif mode
==MODE_RENAME_PLAYLIST
:
703 grooveshark
.renamePlaylist(id, name
)
705 elif mode
==MODE_REMOVE_PLAYLIST_SONG
:
706 try: playlistID
=urllib
.unquote_plus(params
["playlistid"])
708 grooveshark
.removePlaylistSong(playlistID
, name
, id)
710 elif mode
==MODE_ADD_PLAYLIST_SONG
:
711 grooveshark
.addPlaylistSong(id)
714 xbmcplugin
.endOfDirectory(int(sys
.argv
[1]))