1 import urllib
, urllib2
, re
, xbmcplugin
, xbmcgui
, xbmc
, sys
, os
, time
, pprint
, shutil
, xbmcaddon
, pprint
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
+ '?url=&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 *
46 groovesharkApi
= GrooveAPI()
49 def __init__( self
, *args
, **kwargs
):
50 self
.__dict
__.update( kwargs
)
52 class GroovesharkPlaylistSelect(xbmcgui
.WindowDialog
):
54 def __init__(self
, items
=[]):
55 w
= int(self
.getWidth()*0.5)
56 gap
= int(self
.getHeight()/100)
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
.title
= xbmcgui
.ControlLabel(x
, 5*gap
+y
, w
, titleH
, 'GROOVESHARK - PLAYLISTS', textColor
='0xFFFFFFFF', alignment
=2)
68 self
.addControl(self
.title
)
70 self
.playlistControl
= xbmcgui
.ControlList(2*gap
+x
, titleH
+y
+3*gap
, w
-4*gap
, h
-10*gap
, textColor
='0xFFFFFFFF', selectedColor
='0xFFFF4242')
71 self
.addControl(self
.playlistControl
)
74 self
.isSelecting
= False
77 for playlist
in items
:
78 listitems
.append(xbmcgui
.ListItem(playlist
[0]))
79 listitems
.append(xbmcgui
.ListItem('New...'))
80 self
.playlistControl
.addItems(listitems
)
81 self
.setFocus(self
.playlistControl
)
82 item
= self
.playlistControl
.getListItem(self
.lastPos
)
85 # Highlight selected item
86 def setHighlight(self
):
90 self
.isSelecting
= True
92 pos
= self
.playlistControl
.getSelectedPosition()
94 item
= self
.playlistControl
.getListItem(self
.lastPos
)
96 item
= self
.playlistControl
.getListItem(pos
)
99 self
.isSelecting
= False
101 def onAction(self
, action
):
103 if action
== ACTION_MOVE_LEFT
:
104 self
.selected
= self
.playlistControl
.getSelectedPosition()
106 elif action
== ACTION_PREVIOUS_MENU
:
109 elif action
== ACTION_MOVE_UP
or action
== ACTION_MOVE_DOWN
or action
== ACTION_PAGE_UP
or action
== ACTION_PAGE_DOWN
== 6:
110 self
.setFocus(self
.playlistControl
)
113 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Press left arrow to make selection, 1000, ' + thumbDef
+ ')')
118 albumImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'album.png'))
119 artistImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'artist.png'))
120 favoritesImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'favorites.png'))
121 playlistImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'playlist.png'))
122 popularSongsImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'popularSongs.png'))
123 songImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'song.png'))
124 defImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'default.tbn'))
125 fanImg
= xbmc
.translatePath(os
.path
.join(baseDir
, 'fanart.png'))
127 settings
= xbmcaddon
.Addon(id='plugin.audio.groove')
128 songsearchlimit
= settings
.getSetting('songsearchlimit')
129 albumsearchlimit
= settings
.getSetting('albumsearchlimit')
130 artistsearchlimit
= settings
.getSetting('artistsearchlimit')
131 username
= settings
.getSetting('username')
132 password
= settings
.getSetting('password')
135 def __init__( self
):
136 self
._handle
= int(sys
.argv
[1])
138 def categories(self
):
140 xbmc
.log(self
.username
+ ", limits: " + str(self
.songsearchlimit
) + ", " + str(self
.albumsearchlimit
) + ", " + str(self
.artistsearchlimit
))
142 self
.userid
= self
._get
_login
()
145 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
146 if os
.path
.isdir(thumbDir
) == False:
147 os
.makedirs(thumbDir
)
149 self
._add
_dir
('Search songs', '', MODE_SEARCH_SONGS
, self
.songImg
, 0)
150 self
._add
_dir
('Search albums', '', MODE_SEARCH_ALBUMS
, self
.albumImg
, 0)
151 self
._add
_dir
('Search artists', '', MODE_SEARCH_ARTISTS
, self
.artistImg
, 0)
152 self
._add
_dir
('Popular songs', '', MODE_POPULAR_SONGS
, self
.popularSongsImg
, 0)
153 if (self
.userid
!= 0):
154 self
._add
_dir
('Favorites', '', MODE_FAVORITES
, self
.favoritesImg
, 0)
155 self
._add
_dir
('Playlists', '', MODE_PLAYLISTS
, self
.playlistImg
, 0)
157 def searchSongs(self
):
158 query
= self
._get
_keyboard
(default
="", heading
="Search songs")
160 groovesharkApi
.setRemoveDuplicates(True)
161 songs
= groovesharkApi
.searchSongs(query
, limit
= self
.songsearchlimit
)
163 self
._add
_songs
_directory
(songs
)
165 dialog
= xbmcgui
.Dialog()
166 dialog
.ok('Grooveshark XBMC', 'No matching songs.')
171 def searchAlbums(self
):
172 query
= self
._get
_keyboard
(default
="", heading
="Search albums")
174 albums
= groovesharkApi
.searchAlbums(query
, limit
= self
.albumsearchlimit
)
175 if (len(albums
) > 0):
176 self
._add
_albums
_directory
(albums
)
178 dialog
= xbmcgui
.Dialog()
179 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.')
198 userid
= self
._get
_login
()
200 favorites
= groovesharkApi
.userGetFavoriteSongs(userid
)
201 if (len(favorites
) > 0):
202 self
._add
_songs
_directory
(favorites
, isFavorites
=True)
204 dialog
= xbmcgui
.Dialog()
205 dialog
.ok('Grooveshark XBMC', 'You have no favorites.')
208 def popularSongs(self
):
209 popular
= groovesharkApi
.popularGetSongs(limit
= self
.songsearchlimit
)
210 if (len(popular
) > 0):
211 self
._add
_songs
_directory
(popular
)
213 dialog
= xbmcgui
.Dialog()
214 dialog
.ok('Grooveshark XBMC', 'No popular songs.')
217 def popularAlbums(self
):
218 popular
= groovesharkApi
.popularGetAlbums(limit
= self
.albumsearchlimit
)
219 if (len(popular
) > 0):
220 self
._add
_albums
_directory
(popular
)
222 dialog
= xbmcgui
.Dialog()
223 dialog
.ok('Grooveshark XBMC', 'No popular albums.')
226 def popularArtists(self
):
227 popular
= groovesharkApi
.popularGetArtists(limit
= self
.artistsearchlimit
)
228 if (len(popular
) > 0):
229 self
._add
_artists
_directory
(popular
)
231 dialog
= xbmcgui
.Dialog()
232 dialog
.ok('Grooveshark XBMC', 'No popular artists.')
236 userid
= self
._get
_login
()
238 playlists
= groovesharkApi
.userGetPlaylists()
239 if (len(playlists
) > 0):
240 self
._add
_playlists
_directory
(playlists
)
242 dialog
= xbmcgui
.Dialog()
243 dialog
.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.')
246 dialog
= xbmcgui
.Dialog()
247 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to see your Grooveshark playlists.')
250 def favorite(self
, songid
):
251 userid
= self
._get
_login
()
253 xbmc
.log("Favorite song: " + str(songid
))
254 groovesharkApi
.favoriteSong(songID
= songid
)
255 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added to favorites, 1000, ' + thumbDef
+ ')')
257 dialog
= xbmcgui
.Dialog()
258 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to add favorites.')
260 def unfavorite(self
, songid
, prevMode
):
261 userid
= self
._get
_login
()
263 xbmc
.log("Unfavorite song: " + str(songid
) + ', previous mode was ' + str(prevMode
))
264 groovesharkApi
.unfavoriteSong(songID
= songid
)
265 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Removed from favorites, 1000, ' + thumbDef
+ ')')
266 if (int(prevMode
) == MODE_FAVORITES
):
267 xbmc
.executebuiltin("Container.Update(" + favoritesUrl
+ ")")
269 dialog
= xbmcgui
.Dialog()
270 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to remove favorites.')
272 def frown(self
, songid
):
273 userid
= self
._get
_login
()
275 xbmc
.log("Frown song: " + str(songid
))
276 if groovesharkApi
.radioFrown(songId
= songid
) != True:
277 xbmc
.log("Unable to frown song " + str(songid
))
279 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Frowned, 1000, ' + thumbDef
+ ')')
281 dialog
= xbmcgui
.Dialog()
282 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to frown a song.')
284 def similarArtists(self
, artistId
):
285 similar
= groovesharkApi
.artistGetSimilar(artistId
, limit
= self
.artistsearchlimit
)
286 if (len(similar
) > 0):
287 self
._add
_artists
_directory
(similar
)
289 dialog
= xbmcgui
.Dialog()
290 dialog
.ok('Grooveshark XBMC', 'No similar artists.')
293 def makePlaylist(self
, albumid
, name
):
294 userid
= self
._get
_login
()
296 re
.split(' - ',name
,1)
297 nameTokens
= re
.split(' - ',name
,1)
298 name
= self
._get
_keyboard
(default
=nameTokens
[0], heading
="Grooveshark playlist name")
300 groovesharkApi
.setRemoveDuplicates(True)
301 album
= groovesharkApi
.albumGetSongs(albumid
, self
.songsearchlimit
)
304 songids
.append(song
[1])
305 if groovesharkApi
.playlistCreateUnique(name
, songids
) == 0:
306 dialog
= xbmcgui
.Dialog()
307 dialog
.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name
)
309 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef
+ ')')
311 dialog
= xbmcgui
.Dialog()
312 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to create a Grooveshark playlist.')
314 def removePlaylist(self
, playlistid
, name
):
315 dialog
= xbmcgui
.Dialog()
316 if dialog
.yesno('Grooveshark XBMC', name
, 'Delete this Grooveshark playlist?') == True:
317 userid
= self
._get
_login
()
319 groovesharkApi
.playlistDelete(playlistid
)
320 xbmc
.executebuiltin("Container.Refresh(" + playlistsUrl
+ ")")
322 dialog
= xbmcgui
.Dialog()
323 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a Grooveshark playlist.')
325 def removePlaylistSong(self
, playlistid
, playlistname
, songpos
):
326 dialog
= xbmcgui
.Dialog()
327 if dialog
.yesno('Grooveshark XBMC', 'Delete this song from the Grooveshark playlist?') == True:
328 userid
= self
._get
_login
()
330 if groovesharkApi
.playlistDeleteSong(playlistid
, songpos
) == 0:
331 dialog
= xbmcgui
.Dialog()
332 dialog
.ok('Grooveshark XBMC', 'Failed to remove ', ' song from Grooveshark playlist.')
334 xbmc
.executebuiltin("Container.Refresh(" + playlistUrl
+ "&id="+str(playlistid
) + "&name=" + playlistname
+ ",replace)")
336 dialog
= xbmcgui
.Dialog()
337 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a song from a Grooveshark playlist.')
339 def addPlaylistSong(self
, songid
):
340 userid
= self
._get
_login
()
342 playlists
= groovesharkApi
.userGetPlaylists()
343 if (len(playlists
) > 0):
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 def renamePlaylist(self
, playlistid
, name
):
382 userid
= self
._get
_login
()
384 newname
= self
._get
_keyboard
(default
=name
, heading
="Playlist name")
387 elif groovesharkApi
.playlistRename(playlistid
, newname
) == 0:
388 dialog
= xbmcgui
.Dialog()
389 dialog
.ok('Grooveshark XBMC', 'Cannot rename Grooveshark playlist ', name
)
391 xbmc
.executebuiltin("Container.Refresh")
393 dialog
= xbmcgui
.Dialog()
394 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to rename a Grooveshark playlist.')
396 def album(self
, albumid
):
397 groovesharkApi
.setRemoveDuplicates(True)
398 album
= groovesharkApi
.albumGetSongs(albumId
= albumid
, limit
= self
.songsearchlimit
)
399 self
._add
_songs
_directory
(album
)
401 def artist(self
, artistid
):
402 albums
= groovesharkApi
.artistGetAlbums(artistId
= artistid
, limit
= self
.albumsearchlimit
)
403 self
._add
_albums
_directory
(albums
, artistid
)
405 def playlist(self
, playlistid
, playlistname
):
406 userid
= self
._get
_login
()
408 songs
= groovesharkApi
.playlistGetSongs(playlistId
= playlistid
, limit
= self
.songsearchlimit
)
409 self
._add
_songs
_directory
(songs
, playlistid
, playlistname
)
411 dialog
= xbmcgui
.Dialog()
412 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to get Grooveshark playlists.')
414 def playSong(self
, item
):
415 url
= item
.getProperty('url')
416 xbmc
.log("Playing: " + url
)
417 xbmcplugin
.setResolvedUrl(handle
=int(sys
.argv
[1]), succeeded
=True, listitem
=item
)
419 def songItem(self
, id, name
, album
, artist
, duration
, thumb
, image
):
420 url
= groovesharkApi
.getStreamURL(id)
421 # Only try to get the image
423 songImg
= self
._get
_icon
(image
, 'song-' + str(id) + "-image")
426 songThm
= self
._get
_icon
(thumb
, 'song-' + str(id) + "-thumb")
428 item
= xbmcgui
.ListItem(label
= artist
+ " - " + album
+ " - " + name
, path
=url
, thumbnailImage
=songThm
, iconImage
=songImg
)
429 item
.setInfo( type="music", infoLabels
={ "title": name
, "duration": duration
, "album": album
, "artist": artist
} )
430 item
.setProperty('mimetype', 'audio/mpeg')
431 item
.setProperty("IsPlayable", "true")
432 item
.setProperty('url', url
)
433 item
.setProperty('thumb', songThm
)
434 item
.setProperty('image', songImg
)
438 def _get_keyboard(self
, default
="", heading
="", hidden
=False):
439 kb
= xbmc
.Keyboard(default
, heading
, hidden
)
441 if (kb
.isConfirmed()):
442 return unicode(kb
.getText(), "utf-8")
445 def _get_login(self
):
446 if (self
.username
== "" or self
.password
== ""):
447 dialog
= xbmcgui
.Dialog()
448 dialog
.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.')
452 uid
= groovesharkApi
.loginExt(self
.username
, self
.password
)
454 xbmc
.log("Logged in")
457 dialog
= xbmcgui
.Dialog()
458 dialog
.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.')
461 def _get_song_item(self
, song
):
469 return self
.songItem(id, name
, album
, artist
, duration
, thumb
, image
)
472 def _get_icon(self
, url
, id):
473 localThumb
= os
.path
.join(xbmc
.translatePath(os
.path
.join(thumbDir
, str(id)))) + '.tbn'
475 if os
.path
.isfile(localThumb
) == False:
476 xbmc
.log('Downloading ' + url
+ ' to ' + localThumb
)
477 loc
= urllib
.URLopener()
478 loc
.retrieve(url
, localThumb
)
480 xbmc
.log('URL download failed of ' + url
+ ' to ' + localThumb
)
483 return os
.path
.join(os
.path
.join(thumbDir
, str(id))) + '.tbn'
485 def _add_songs_directory(self
, songs
, playlistid
=0, playlistname
='', isFavorites
=False):
487 xbmc
.log("Found " + str(n
) + " songs...")
491 item
= self
._get
_song
_item
(song
)
492 songurl
= item
.getProperty('url')
493 songthumb
= item
.getProperty('thumb')
494 songimage
= item
.getProperty('image')
497 songduration
= song
[2]
500 u
=sys
.argv
[0]+"?url="+urllib
.quote_plus(songurl
) \
501 +"&mode="+str(MODE_SONG
)+"&name="+urllib
.quote_plus(songname
)+"&id=" \
503 +"&album="+urllib
.quote_plus(songalbum
) \
504 +"&artist="+urllib
.quote_plus(songartist
) \
505 +"&duration="+str(songduration
) \
506 +"&thumb="+urllib
.quote_plus(songthumb
) \
507 +"&image="+urllib
.quote_plus(songimage
)
508 fav
=sys
.argv
[0]+"?url="+urllib
.quote_plus(songurl
)+"&mode="+str(MODE_FAVORITE
)+"&name="+urllib
.quote_plus(songname
)+"&id="+str(songid
)
509 unfav
=sys
.argv
[0]+"?url="+urllib
.quote_plus(songurl
)+"&mode="+str(MODE_UNFAVORITE
)+"&name="+urllib
.quote_plus(songname
)+"&id="+str(songid
)+"&prevmode="
511 if isFavorites
== True:
512 unfav
= unfav
+str(MODE_FAVORITES
)
514 menuItems
.append(("Grooveshark favorite", "XBMC.RunPlugin("+fav
+")"))
515 menuItems
.append(("Not Grooveshark favorite", "XBMC.RunPlugin("+unfav
+")"))
517 rmplaylstsong
=sys
.argv
[0]+"?playlistid="+str(playlistid
)+"&id="+str(i
+1)+"&mode="+str(MODE_REMOVE_PLAYLIST_SONG
)+"&name="+playlistname
518 menuItems
.append(("Remove from playlist", "XBMC.RunPlugin("+rmplaylstsong
+")"))
520 addplaylstsong
=sys
.argv
[0]+"?id="+str(songid
)+"&mode="+str(MODE_ADD_PLAYLIST_SONG
)
521 menuItems
.append(("Add to Grooveshark playlist", "XBMC.RunPlugin("+addplaylstsong
+")"))
522 item
.addContextMenuItems(menuItems
, replaceItems
=False)
523 xbmcplugin
.addDirectoryItem(handle
=int(sys
.argv
[1]),url
=u
,listitem
=item
,isFolder
=False,totalItems
=n
)
525 xbmcplugin
.setContent(self
._handle
, 'songs')
526 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
528 def _add_albums_directory(self
, albums
, artistid
=0):
530 xbmc
.log("Found " + str(n
) + " albums...")
534 albumArtistName
= album
[0]
537 albumImage
= self
._get
_icon
(album
[4], 'album-' + str(albumID
))
538 self
._add
_dir
(albumName
+ " - " + albumArtistName
, '', MODE_ALBUM
, albumImage
, albumID
, n
)
541 self
._add
_dir
('Similar artists...', '', MODE_SIMILAR_ARTISTS
, self
.artistImg
, artistid
)
542 xbmcplugin
.setContent(self
._handle
, 'albums')
543 xbmcplugin
.addSortMethod(self
._handle
, xbmcplugin
.SORT_METHOD_ALBUM_IGNORE_THE
)
544 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
546 def _add_artists_directory(self
, artists
):
548 xbmc
.log("Found " + str(n
) + " artists...")
552 artistName
= artist
[0]
554 self
._add
_dir
(artistName
, '', MODE_ARTIST
, self
.artistImg
, artistID
, n
)
556 xbmcplugin
.setContent(self
._handle
, 'artists')
557 xbmcplugin
.addSortMethod(self
._handle
, xbmcplugin
.SORT_METHOD_ARTIST_IGNORE_THE
)
558 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
560 def _add_playlists_directory(self
, playlists
):
562 xbmc
.log("Found " + str(n
) + " playlists...")
565 playlist
= playlists
[i
]
566 playlistName
= playlist
[0]
567 playlistID
= playlist
[1]
568 self
._add
_dir
(playlistName
, '', MODE_PLAYLIST
, self
.playlistImg
, playlistID
, n
)
570 xbmcplugin
.setContent(self
._handle
, 'files')
571 xbmcplugin
.addSortMethod(self
._handle
, xbmcplugin
.SORT_METHOD_PLAYLIST_ORDER
)
572 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
574 def _add_dir(self
, name
, url
, mode
, iconimage
, id, items
=1):
575 u
=sys
.argv
[0]+"?url="+urllib
.quote_plus(url
)+"&mode="+str(mode
)+"&name="+urllib
.quote_plus(name
)+"&id="+str(id)
576 dir=xbmcgui
.ListItem(name
, iconImage
=iconimage
, thumbnailImage
=iconimage
)
577 dir.setInfo( type="Music", infoLabels
={ "title": name
} )
579 if mode
== MODE_ALBUM
:
580 mkplaylst
=sys
.argv
[0]+"?mode="+str(MODE_MAKE_PLAYLIST
)+"&name="+name
+"&id="+str(id)
581 menuItems
.append(("Make Grooveshark playlist", "XBMC.RunPlugin("+mkplaylst
+")"))
582 if mode
== MODE_PLAYLIST
:
583 rmplaylst
=sys
.argv
[0]+"?mode="+str(MODE_REMOVE_PLAYLIST
)+"&name="+urllib
.quote_plus(name
)+"&id="+str(id)
584 menuItems
.append(("Delete playlist", "XBMC.RunPlugin("+rmplaylst
+")"))
585 mvplaylst
=sys
.argv
[0]+"?mode="+str(MODE_RENAME_PLAYLIST
)+"&name="+urllib
.quote_plus(name
)+"&id="+str(id)
586 menuItems
.append(("Rename playlist", "XBMC.RunPlugin("+mvplaylst
+")"))
587 dir.addContextMenuItems(menuItems
, replaceItems
=False)
588 return xbmcplugin
.addDirectoryItem(handle
=int(sys
.argv
[1]),url
=u
,listitem
=dir,isFolder
=True, totalItems
=items
)
593 paramstring
=sys
.argv
[2]
594 if len(paramstring
)>=2:
596 cleanedparams
=params
.replace('?','')
597 if (params
[len(params
)-1]=='/'):
598 params
=params
[0:len(params
)-2]
599 pairsofparams
=cleanedparams
.split('&')
601 for i
in range(len(pairsofparams
)):
603 splitparams
=pairsofparams
[i
].split('=')
604 if (len(splitparams
))==2:
605 param
[splitparams
[0]]=splitparams
[1]
609 grooveshark
= Groveshark();
617 try: url
=urllib
.unquote_plus(params
["url"])
619 try: name
=urllib
.unquote_plus(params
["name"])
621 try: mode
=int(params
["mode"])
623 try: id=int(params
["id"])
627 grooveshark
.categories()
629 elif mode
==MODE_SEARCH_SONGS
:
630 grooveshark
.searchSongs()
632 elif mode
==MODE_SEARCH_ALBUMS
:
633 grooveshark
.searchAlbums()
635 elif mode
==MODE_SEARCH_ARTISTS
:
636 grooveshark
.searchArtists()
638 elif mode
==MODE_POPULAR_SONGS
:
639 grooveshark
.popularSongs()
641 elif mode
==MODE_PLAYLISTS
:
642 grooveshark
.playlists()
644 elif mode
==MODE_FAVORITES
:
645 grooveshark
.favorites()
647 elif mode
==MODE_SONG
:
648 try: album
=urllib
.unquote_plus(params
["album"])
650 try: artist
=urllib
.unquote_plus(params
["artist"])
652 try: duration
=int(params
["duration"])
654 try: thumb
=urllib
.unquote_plus(params
["thumb"])
656 try: image
=urllib
.unquote_plus(params
["image"])
658 song
= grooveshark
.songItem(id, name
, album
, artist
, duration
, thumb
, image
)
659 grooveshark
.playSong(song
)
661 elif mode
==MODE_ARTIST
:
662 grooveshark
.artist(id)
664 elif mode
==MODE_ALBUM
:
665 grooveshark
.album(id)
667 elif mode
==MODE_PLAYLIST
:
668 grooveshark
.playlist(id, name
)
670 elif mode
==MODE_FAVORITE
:
671 grooveshark
.favorite(id)
673 elif mode
==MODE_UNFAVORITE
:
674 try: prevMode
=urllib
.unquote_plus(params
["prevmode"])
676 grooveshark
.unfavorite(id, prevMode
)
678 elif mode
==MODE_SIMILAR_ARTISTS
:
679 grooveshark
.similarArtists(id)
681 elif mode
==MODE_MAKE_PLAYLIST
:
682 grooveshark
.makePlaylist(id, name
)
684 elif mode
==MODE_REMOVE_PLAYLIST
:
685 grooveshark
.removePlaylist(id, name
)
687 elif mode
==MODE_RENAME_PLAYLIST
:
688 grooveshark
.renamePlaylist(id, name
)
690 elif mode
==MODE_REMOVE_PLAYLIST_SONG
:
691 try: playlistID
=urllib
.unquote_plus(params
["playlistid"])
693 grooveshark
.removePlaylistSong(playlistID
, name
, id)
695 elif mode
==MODE_ADD_PLAYLIST_SONG
:
696 grooveshark
.addPlaylistSong(id)
698 if (mode
< MODE_SONG
):
699 xbmcplugin
.endOfDirectory(int(sys
.argv
[1]))