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
47 groovesharkApi
= GrooveAPI()
49 dialog
= xbmcgui
.Dialog()
50 dialog
.ok('Grooveshark XBMC', 'Unable to connect with Grooveshark.', 'Please try again later')
55 def __init__( self
, *args
, **kwargs
):
56 self
.__dict
__.update( kwargs
)
58 # Window dialog to select a grooveshark playlist
59 class GroovesharkPlaylistSelect(xbmcgui
.WindowDialog
):
61 def __init__(self
, items
=[]):
62 gap
= int(self
.getHeight()/100)
63 w
= int(self
.getWidth()*0.5)
64 h
= self
.getHeight()-30*gap
70 self
.imgBg
= xbmcgui
.ControlImage(x
+gap
, 5*gap
+y
, w
-2*gap
, h
-5*gap
, listBackground
)
71 self
.addControl(self
.imgBg
)
73 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)
74 self
.addControl(self
.playlistControl
)
77 self
.isSelecting
= False
80 for playlist
in items
:
81 listitems
.append(xbmcgui
.ListItem(playlist
[0]))
82 listitems
.append(xbmcgui
.ListItem('New...'))
83 self
.playlistControl
.addItems(listitems
)
84 self
.setFocus(self
.playlistControl
)
85 self
.playlistControl
.selectItem(0)
86 item
= self
.playlistControl
.getListItem(self
.lastPos
)
89 # Highlight selected item
90 def setHighlight(self
):
94 self
.isSelecting
= True
96 pos
= self
.playlistControl
.getSelectedPosition()
98 item
= self
.playlistControl
.getListItem(self
.lastPos
)
100 item
= self
.playlistControl
.getListItem(pos
)
103 self
.isSelecting
= False
106 def onControl(self
, control
):
107 if control
== self
.playlistControl
:
108 self
.selected
= self
.playlistControl
.getSelectedPosition()
111 # Action - close or up/down
112 def onAction(self
, action
):
113 if action
== ACTION_PREVIOUS_MENU
:
116 elif action
== ACTION_MOVE_UP
or action
== ACTION_MOVE_DOWN
or action
== ACTION_PAGE_UP
or action
== ACTION_PAGE_DOWN
== 6:
117 self
.setFocus(self
.playlistControl
)
122 albumImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'album.png'))
123 artistImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'artist.png'))
124 favoritesImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'favorites.png'))
125 playlistImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'playlist.png'))
126 popularSongsImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'popularSongs.png'))
127 songImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'song.png'))
128 defImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'default.tbn'))
129 fanImg
= xbmc
.translatePath(os
.path
.join(baseDir
, 'fanart.png'))
131 settings
= xbmcaddon
.Addon(id='plugin.audio.groove')
132 songsearchlimit
= settings
.getSetting('songsearchlimit')
133 albumsearchlimit
= settings
.getSetting('albumsearchlimit')
134 artistsearchlimit
= settings
.getSetting('artistsearchlimit')
135 username
= settings
.getSetting('username')
136 password
= settings
.getSetting('password')
139 def __init__( self
):
140 self
._handle
= int(sys
.argv
[1])
143 def categories(self
):
145 self
.userid
= self
._get
_login
()
148 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
149 if os
.path
.isdir(thumbDir
) == False:
150 os
.makedirs(thumbDir
)
152 self
._add
_dir
('Search songs...', '', MODE_SEARCH_SONGS
, self
.songImg
, 0)
153 self
._add
_dir
('Search albums...', '', MODE_SEARCH_ALBUMS
, self
.albumImg
, 0)
154 self
._add
_dir
('Search artists...', '', MODE_SEARCH_ARTISTS
, self
.artistImg
, 0)
155 self
._add
_dir
('Popular songs', '', MODE_POPULAR_SONGS
, self
.popularSongsImg
, 0)
156 if (self
.userid
!= 0):
157 self
._add
_dir
('Favorites', '', MODE_FAVORITES
, self
.favoritesImg
, 0)
158 self
._add
_dir
('Playlists', '', MODE_PLAYLISTS
, self
.playlistImg
, 0)
161 def searchSongs(self
):
162 query
= self
._get
_keyboard
(default
="", heading
="Search songs")
164 groovesharkApi
.setRemoveDuplicates(True)
165 songs
= groovesharkApi
.searchSongs(query
, limit
= self
.songsearchlimit
)
167 self
._add
_songs
_directory
(songs
)
169 dialog
= xbmcgui
.Dialog()
170 dialog
.ok('Grooveshark XBMC', 'No matching songs.')
176 def searchAlbums(self
):
177 query
= self
._get
_keyboard
(default
="", heading
="Search albums")
179 albums
= groovesharkApi
.searchAlbums(query
, limit
= self
.albumsearchlimit
)
180 if (len(albums
) > 0):
181 self
._add
_albums
_directory
(albums
)
183 dialog
= xbmcgui
.Dialog()
184 dialog
.ok('Grooveshark XBMC', 'No matching albums.')
190 def searchArtists(self
):
191 query
= self
._get
_keyboard
(default
="", heading
="Search artists")
193 artists
= groovesharkApi
.searchArtists(query
, limit
= self
.artistsearchlimit
)
194 if (len(artists
) > 0):
195 self
._add
_artists
_directory
(artists
)
197 dialog
= xbmcgui
.Dialog()
198 dialog
.ok('Grooveshark XBMC', 'No matching artists.')
205 userid
= self
._get
_login
()
207 favorites
= groovesharkApi
.userGetFavoriteSongs(userid
)
208 if (len(favorites
) > 0):
209 self
._add
_songs
_directory
(favorites
, isFavorites
=True)
211 dialog
= xbmcgui
.Dialog()
212 dialog
.ok('Grooveshark XBMC', 'You have no favorites.')
216 def popularSongs(self
):
217 popular
= groovesharkApi
.popularGetSongs(limit
= self
.songsearchlimit
)
218 if (len(popular
) > 0):
219 self
._add
_songs
_directory
(popular
)
221 dialog
= xbmcgui
.Dialog()
222 dialog
.ok('Grooveshark XBMC', 'No popular songs.')
227 userid
= self
._get
_login
()
229 playlists
= groovesharkApi
.userGetPlaylists()
230 if (len(playlists
) > 0):
231 self
._add
_playlists
_directory
(playlists
)
233 dialog
= xbmcgui
.Dialog()
234 dialog
.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.')
237 dialog
= xbmcgui
.Dialog()
238 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to see your Grooveshark playlists.')
240 # Make songs a favorite
241 def favorite(self
, songid
):
242 userid
= self
._get
_login
()
244 xbmc
.log("Favorite song: " + str(songid
))
245 groovesharkApi
.favoriteSong(songID
= songid
)
246 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added to favorites, 1000, ' + thumbDef
+ ')')
248 dialog
= xbmcgui
.Dialog()
249 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to add favorites.')
251 # Remove song from favorites
252 def unfavorite(self
, songid
, prevMode
=0):
253 userid
= self
._get
_login
()
255 xbmc
.log("Unfavorite song: " + str(songid
) + ', previous mode was ' + str(prevMode
))
256 groovesharkApi
.unfavoriteSong(songID
= songid
)
257 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Removed from Grooveshark favorites, 1000, ' + thumbDef
+ ')')
258 # Refresh to remove item from directory
259 if (int(prevMode
) == MODE_FAVORITES
):
260 xbmc
.executebuiltin("Container.Refresh(" + favoritesUrl
+ ")")
262 dialog
= xbmcgui
.Dialog()
263 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to remove Grooveshark favorites.')
266 def frown(self
, songid
):
267 userid
= self
._get
_login
()
269 xbmc
.log("Frown song: " + str(songid
))
270 if groovesharkApi
.radioFrown(songId
= songid
) != True:
271 xbmc
.log("Unable to frown song " + str(songid
))
273 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Frowned, 1000, ' + thumbDef
+ ')')
275 dialog
= xbmcgui
.Dialog()
276 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to frown a Grooveshark song.')
278 # Find similar artists to searched artist
279 def similarArtists(self
, artistId
):
280 similar
= groovesharkApi
.artistGetSimilar(artistId
, limit
= self
.artistsearchlimit
)
281 if (len(similar
) > 0):
282 self
._add
_artists
_directory
(similar
)
284 dialog
= xbmcgui
.Dialog()
285 dialog
.ok('Grooveshark XBMC', 'No similar artists.')
288 # Make a playlist from an album
289 def makePlaylist(self
, albumid
, name
):
290 userid
= self
._get
_login
()
292 re
.split(' - ',name
,1)
293 nameTokens
= re
.split(' - ',name
,1) # suggested name
294 name
= self
._get
_keyboard
(default
=nameTokens
[0], heading
="Grooveshark playlist name")
296 groovesharkApi
.setRemoveDuplicates(True)
297 album
= groovesharkApi
.albumGetSongs(albumid
, self
.songsearchlimit
)
300 songids
.append(song
[1])
301 if groovesharkApi
.playlistCreateUnique(name
, songids
) == 0:
302 dialog
= xbmcgui
.Dialog()
303 dialog
.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name
)
305 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef
+ ')')
307 dialog
= xbmcgui
.Dialog()
308 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to create a Grooveshark playlist.')
311 def renamePlaylist(self
, playlistid
, name
):
312 userid
= self
._get
_login
()
314 newname
= self
._get
_keyboard
(default
=name
, heading
="Grooveshark playlist name")
317 elif groovesharkApi
.playlistRename(playlistid
, newname
) == 0:
318 dialog
= xbmcgui
.Dialog()
319 dialog
.ok('Grooveshark XBMC', 'Cannot rename Grooveshark playlist ', name
)
321 # Refresh to show new item name
322 xbmc
.executebuiltin("Container.Refresh")
324 dialog
= xbmcgui
.Dialog()
325 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to rename a Grooveshark playlist.')
328 def removePlaylist(self
, playlistid
, name
):
329 dialog
= xbmcgui
.Dialog()
330 if dialog
.yesno('Grooveshark XBMC', name
, 'Delete this Grooveshark playlist?') == True:
331 userid
= self
._get
_login
()
333 if groovesharkApi
.playlistDelete(playlistid
) == 0:
334 dialog
= xbmcgui
.Dialog()
335 dialog
.ok('Grooveshark XBMC', 'Cannot remove Grooveshark playlist ', name
)
337 # Refresh to remove item from directory
338 xbmc
.executebuiltin("Container.Refresh(" + playlistsUrl
+ ")")
340 dialog
= xbmcgui
.Dialog()
341 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a Grooveshark playlist.')
343 # Add song to playlist
344 def addPlaylistSong(self
, songid
):
345 userid
= self
._get
_login
()
347 playlists
= groovesharkApi
.userGetPlaylists()
348 if (len(playlists
) > 0):
350 # Select the playlist
351 playlistSelect
= GroovesharkPlaylistSelect(items
=playlists
)
352 playlistSelect
.setFocus(playlistSelect
.playlistControl
)
353 playlistSelect
.doModal()
354 i
= playlistSelect
.selected
358 if i
>= len(playlists
):
359 name
= self
._get
_keyboard
(default
='', heading
="Grooveshark playlist name")
362 songIds
.append(songid
)
363 if groovesharkApi
.playlistCreateUnique(name
, songIds
) == 0:
364 dialog
= xbmcgui
.Dialog()
365 dialog
.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name
)
367 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef
+ ')')
370 playlist
= playlists
[i
]
371 playlistid
= playlist
[1]
372 xbmc
.log("Add song " + str(songid
) + " to playlist " + str(playlistid
))
373 ret
= groovesharkApi
.playlistAddSong(playlistid
, songid
, 0)
375 dialog
= xbmcgui
.Dialog()
376 dialog
.ok('Grooveshark XBMC', 'Cannot add to playlist ')
378 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added song to Grooveshark playlist, 1000, ' + thumbDef
+ ')')
380 dialog
= xbmcgui
.Dialog()
381 dialog
.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.')
384 dialog
= xbmcgui
.Dialog()
385 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to add a song to a Grooveshark playlist.')
387 # Remove song from playlist
388 def removePlaylistSong(self
, playlistid
, playlistname
, songpos
):
389 dialog
= xbmcgui
.Dialog()
390 if dialog
.yesno('Grooveshark XBMC', 'Delete this song from the Grooveshark playlist?') == True:
391 userid
= self
._get
_login
()
393 if groovesharkApi
.playlistDeleteSong(playlistid
, songpos
) == 0:
394 dialog
= xbmcgui
.Dialog()
395 dialog
.ok('Grooveshark XBMC', 'Failed to remove ', ' song from Grooveshark playlist.')
397 # Refresh to remove item from directory
398 xbmc
.executebuiltin("Container.Refresh(" + playlistUrl
+ "&id="+str(playlistid
) + "&name=" + playlistname
+ ")")
400 dialog
= xbmcgui
.Dialog()
401 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a song from a Grooveshark playlist.')
403 # Show selected album
404 def album(self
, albumid
):
405 groovesharkApi
.setRemoveDuplicates(True)
406 album
= groovesharkApi
.albumGetSongs(albumId
= albumid
, limit
= self
.songsearchlimit
)
407 self
._add
_songs
_directory
(album
)
409 # Show selected artist
410 def artist(self
, artistid
):
411 albums
= groovesharkApi
.artistGetAlbums(artistId
= artistid
, limit
= self
.albumsearchlimit
)
412 self
._add
_albums
_directory
(albums
, artistid
)
414 # Show selected playlist
415 def playlist(self
, playlistid
, playlistname
):
416 userid
= self
._get
_login
()
418 songs
= groovesharkApi
.playlistGetSongs(playlistId
= playlistid
, limit
= self
.songsearchlimit
)
419 self
._add
_songs
_directory
(songs
, playlistid
, playlistname
)
421 dialog
= xbmcgui
.Dialog()
422 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to get Grooveshark playlists.')
425 def playSong(self
, item
):
426 url
= groovesharkApi
.getStreamURL(item
.getProperty('id'))
428 xbmc
.log("Playing: " + url
)
429 xbmcplugin
.setResolvedUrl(handle
=int(sys
.argv
[1]), succeeded
=True, listitem
=item
)
431 # Make a song directory item
432 def songItem(self
, id, name
, album
, artist
, duration
, thumb
, image
):
433 # Only try to get the image
435 songImg
= self
._get
_icon
(image
, 'song-' + str(id) + "-image")
438 songThm
= self
._get
_icon
(thumb
, 'song-' + str(id) + "-thumb")
440 item
= xbmcgui
.ListItem(label
= artist
+ " - " + album
+ " - " + name
, thumbnailImage
=songThm
, iconImage
=songImg
)
441 item
.setInfo( type="music", infoLabels
={ "title": name
, "duration": duration
, "album": album
, "artist": artist
} )
442 item
.setProperty('mimetype', 'audio/mpeg')
443 item
.setProperty("IsPlayable", "true")
444 item
.setProperty('id', str(id))
445 item
.setProperty('thumb', songThm
)
446 item
.setProperty('image', songImg
)
450 def _get_keyboard(self
, default
="", heading
="", hidden
=False):
451 kb
= xbmc
.Keyboard(default
, heading
, hidden
)
453 if (kb
.isConfirmed()):
454 return unicode(kb
.getText(), "utf-8")
457 # Login to grooveshark
458 def _get_login(self
):
459 if (self
.username
== "" or self
.password
== ""):
460 dialog
= xbmcgui
.Dialog()
461 dialog
.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.')
465 uid
= groovesharkApi
.loginExt(self
.username
, self
.password
)
469 dialog
= xbmcgui
.Dialog()
470 dialog
.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.')
473 # Get a song directory item
474 def _get_song_item(self
, song
):
482 return self
.songItem(id, name
, album
, artist
, duration
, thumb
, image
)
485 def _get_icon(self
, url
, id):
486 localThumb
= os
.path
.join(xbmc
.translatePath(os
.path
.join(thumbDir
, str(id)))) + '.tbn'
488 if os
.path
.isfile(localThumb
) == False:
489 xbmc
.log('Downloading ' + url
+ ' to ' + localThumb
)
490 loc
= urllib
.URLopener()
491 loc
.retrieve(url
, localThumb
)
493 shutil
.copy2(self
.defImg
, localThumb
)
495 return os
.path
.join(os
.path
.join(thumbDir
, str(id))) + '.tbn'
497 # Add songs to directory
498 def _add_songs_directory(self
, songs
, playlistid
=0, playlistname
='', isFavorites
=False):
500 xbmc
.log("Found " + str(n
) + " songs...")
504 item
= self
._get
_song
_item
(song
)
505 songthumb
= item
.getProperty('thumb')
506 songimage
= item
.getProperty('image')
509 songduration
= song
[2]
512 u
=sys
.argv
[0]+"?mode="+str(MODE_SONG
)+"&name="+urllib
.quote_plus(songname
)+"&id="+str(songid
) \
513 +"&album="+urllib
.quote_plus(songalbum
) \
514 +"&artist="+urllib
.quote_plus(songartist
) \
515 +"&duration="+str(songduration
) \
516 +"&thumb="+urllib
.quote_plus(songthumb
) \
517 +"&image="+urllib
.quote_plus(songimage
)
518 fav
=sys
.argv
[0]+"?mode="+str(MODE_FAVORITE
)+"&name="+urllib
.quote_plus(songname
)+"&id="+str(songid
)
519 unfav
=sys
.argv
[0]+"?mode="+str(MODE_UNFAVORITE
)+"&name="+urllib
.quote_plus(songname
)+"&id="+str(songid
)+"&prevmode="
521 if isFavorites
== True:
522 unfav
= unfav
+str(MODE_FAVORITES
)
524 menuItems
.append(("Grooveshark favorite", "XBMC.RunPlugin("+fav
+")"))
525 menuItems
.append(("Not Grooveshark favorite", "XBMC.RunPlugin("+unfav
+")"))
527 rmplaylstsong
=sys
.argv
[0]+"?playlistid="+str(playlistid
)+"&id="+str(i
+1)+"&mode="+str(MODE_REMOVE_PLAYLIST_SONG
)+"&name="+playlistname
528 menuItems
.append(("Remove from Grooveshark playlist", "XBMC.RunPlugin("+rmplaylstsong
+")"))
530 addplaylstsong
=sys
.argv
[0]+"?id="+str(songid
)+"&mode="+str(MODE_ADD_PLAYLIST_SONG
)
531 menuItems
.append(("Add to Grooveshark playlist", "XBMC.RunPlugin("+addplaylstsong
+")"))
532 item
.addContextMenuItems(menuItems
, replaceItems
=False)
533 xbmcplugin
.addDirectoryItem(handle
=int(sys
.argv
[1]),url
=u
,listitem
=item
,isFolder
=False, totalItems
=n
)
536 xbmcplugin
.setContent(self
._handle
, 'songs')
537 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
539 # Add albums to directory
540 def _add_albums_directory(self
, albums
, artistid
=0):
542 xbmc
.log("Found " + str(n
) + " albums...")
546 albumArtistName
= album
[0]
549 albumImage
= self
._get
_icon
(album
[4], 'album-' + str(albumID
))
550 self
._add
_dir
(albumName
+ " - " + albumArtistName
, '', MODE_ALBUM
, albumImage
, albumID
, n
)
553 self
._add
_dir
('Similar artists...', '', MODE_SIMILAR_ARTISTS
, self
.artistImg
, artistid
)
554 xbmcplugin
.setContent(self
._handle
, 'albums')
555 xbmcplugin
.addSortMethod(self
._handle
, xbmcplugin
.SORT_METHOD_ALBUM_IGNORE_THE
)
556 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
558 # Add artists to directory
559 def _add_artists_directory(self
, artists
):
561 xbmc
.log("Found " + str(n
) + " artists...")
565 artistName
= artist
[0]
567 self
._add
_dir
(artistName
, '', MODE_ARTIST
, self
.artistImg
, artistID
, n
)
569 xbmcplugin
.setContent(self
._handle
, 'artists')
570 xbmcplugin
.addSortMethod(self
._handle
, xbmcplugin
.SORT_METHOD_ARTIST_IGNORE_THE
)
571 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
573 # Add playlists to directory
574 def _add_playlists_directory(self
, playlists
):
576 xbmc
.log("Found " + str(n
) + " playlists...")
579 playlist
= playlists
[i
]
580 playlistName
= playlist
[0]
581 playlistID
= playlist
[1]
582 self
._add
_dir
(playlistName
, '', MODE_PLAYLIST
, self
.playlistImg
, playlistID
, n
)
584 xbmcplugin
.setContent(self
._handle
, 'files')
585 xbmcplugin
.addSortMethod(self
._handle
, xbmcplugin
.SORT_METHOD_PLAYLIST_ORDER
)
586 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
588 # Add whatever directory
589 def _add_dir(self
, name
, url
, mode
, iconimage
, id, items
=1):
591 u
=sys
.argv
[0]+"?mode="+str(mode
)+"&name="+urllib
.quote_plus(name
)+"&id="+str(id)
592 dir=xbmcgui
.ListItem(name
, iconImage
=iconimage
, thumbnailImage
=iconimage
)
593 dir.setInfo( type="Music", infoLabels
={ "title": name
} )
597 if mode
== MODE_ALBUM
:
598 mkplaylst
=sys
.argv
[0]+"?mode="+str(MODE_MAKE_PLAYLIST
)+"&name="+name
+"&id="+str(id)
599 menuItems
.append(("Make Grooveshark playlist", "XBMC.RunPlugin("+mkplaylst
+")"))
600 if mode
== MODE_PLAYLIST
:
601 rmplaylst
=sys
.argv
[0]+"?mode="+str(MODE_REMOVE_PLAYLIST
)+"&name="+urllib
.quote_plus(name
)+"&id="+str(id)
602 menuItems
.append(("Delete Grooveshark playlist", "XBMC.RunPlugin("+rmplaylst
+")"))
603 mvplaylst
=sys
.argv
[0]+"?mode="+str(MODE_RENAME_PLAYLIST
)+"&name="+urllib
.quote_plus(name
)+"&id="+str(id)
604 menuItems
.append(("Rename Grooveshark playlist", "XBMC.RunPlugin("+mvplaylst
+")"))
606 dir.addContextMenuItems(menuItems
, replaceItems
=False)
607 return xbmcplugin
.addDirectoryItem(handle
=int(sys
.argv
[1]),url
=u
,listitem
=dir,isFolder
=True, totalItems
=items
)
610 # Parse URL parameters
613 paramstring
=sys
.argv
[2]
614 xbmc
.log(paramstring
)
615 if len(paramstring
)>=2:
617 cleanedparams
=params
.replace('?','')
618 if (params
[len(params
)-1]=='/'):
619 params
=params
[0:len(params
)-2]
620 pairsofparams
=cleanedparams
.split('&')
622 for i
in range(len(pairsofparams
)):
624 splitparams
=pairsofparams
[i
].split('=')
625 if (len(splitparams
))==2:
626 param
[splitparams
[0]]=splitparams
[1]
630 grooveshark
= Groveshark();
634 try: mode
=int(params
["mode"])
637 if mode
> MODE_FAVORITES
:
640 try: name
=urllib
.unquote_plus(params
["name"])
642 try: id=int(params
["id"])
645 # Call function for URL
647 grooveshark
.categories()
649 elif mode
==MODE_SEARCH_SONGS
:
650 grooveshark
.searchSongs()
652 elif mode
==MODE_SEARCH_ALBUMS
:
653 grooveshark
.searchAlbums()
655 elif mode
==MODE_SEARCH_ARTISTS
:
656 grooveshark
.searchArtists()
658 elif mode
==MODE_POPULAR_SONGS
:
659 grooveshark
.popularSongs()
661 elif mode
==MODE_FAVORITES
:
662 grooveshark
.favorites()
664 elif mode
==MODE_PLAYLISTS
:
665 grooveshark
.playlists()
667 elif mode
==MODE_SONG
:
668 try: album
=urllib
.unquote_plus(params
["album"])
670 try: artist
=urllib
.unquote_plus(params
["artist"])
672 try: duration
=int(params
["duration"])
674 try: thumb
=urllib
.unquote_plus(params
["thumb"])
676 try: image
=urllib
.unquote_plus(params
["image"])
678 song
= grooveshark
.songItem(id, name
, album
, artist
, duration
, thumb
, image
)
679 grooveshark
.playSong(song
)
681 elif mode
==MODE_ARTIST
:
682 grooveshark
.artist(id)
684 elif mode
==MODE_ALBUM
:
685 grooveshark
.album(id)
687 elif mode
==MODE_PLAYLIST
:
688 grooveshark
.playlist(id, name
)
690 elif mode
==MODE_FAVORITE
:
691 grooveshark
.favorite(id)
693 elif mode
==MODE_UNFAVORITE
:
694 try: prevMode
=int(urllib
.unquote_plus(params
["prevmode"]))
697 grooveshark
.unfavorite(id, prevMode
)
699 elif mode
==MODE_SIMILAR_ARTISTS
:
700 grooveshark
.similarArtists(id)
702 elif mode
==MODE_MAKE_PLAYLIST
:
703 grooveshark
.makePlaylist(id, name
)
705 elif mode
==MODE_REMOVE_PLAYLIST
:
706 grooveshark
.removePlaylist(id, name
)
708 elif mode
==MODE_RENAME_PLAYLIST
:
709 grooveshark
.renamePlaylist(id, name
)
711 elif mode
==MODE_REMOVE_PLAYLIST_SONG
:
712 try: playlistID
=urllib
.unquote_plus(params
["playlistid"])
714 grooveshark
.removePlaylistSong(playlistID
, name
, id)
716 elif mode
==MODE_ADD_PLAYLIST_SONG
:
717 grooveshark
.addPlaylistSong(id)
720 xbmcplugin
.endOfDirectory(int(sys
.argv
[1]))