1 import urllib
, urllib2
, re
, xbmcplugin
, xbmcgui
, xbmc
, sys
, os
, time
, shutil
, xbmcaddon
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 gap
= int(self
.getHeight()/100)
56 w
= int(self
.getWidth()*0.5)
57 h
= self
.getHeight()-30*gap
63 self
.imgBg
= xbmcgui
.ControlImage(x
+gap
, 5*gap
+y
, w
-2*gap
, h
-5*gap
, listBackground
)
64 self
.addControl(self
.imgBg
)
66 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)
67 self
.addControl(self
.playlistControl
)
70 self
.isSelecting
= False
73 for playlist
in items
:
74 listitems
.append(xbmcgui
.ListItem(playlist
[0]))
75 listitems
.append(xbmcgui
.ListItem('New...'))
76 self
.playlistControl
.addItems(listitems
)
77 self
.setFocus(self
.playlistControl
)
78 self
.playlistControl
.selectItem(0)
79 item
= self
.playlistControl
.getListItem(self
.lastPos
)
82 # Highlight selected item
83 def setHighlight(self
):
87 self
.isSelecting
= True
89 pos
= self
.playlistControl
.getSelectedPosition()
91 item
= self
.playlistControl
.getListItem(self
.lastPos
)
93 item
= self
.playlistControl
.getListItem(pos
)
96 self
.isSelecting
= False
99 def onControl(self
, control
):
100 if control
== self
.playlistControl
:
101 self
.selected
= self
.playlistControl
.getSelectedPosition()
104 def onAction(self
, action
):
105 if action
== ACTION_PREVIOUS_MENU
:
108 elif action
== ACTION_MOVE_UP
or action
== ACTION_MOVE_DOWN
or action
== ACTION_PAGE_UP
or action
== ACTION_PAGE_DOWN
== 6:
109 self
.setFocus(self
.playlistControl
)
114 albumImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'album.png'))
115 artistImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'artist.png'))
116 favoritesImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'favorites.png'))
117 playlistImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'playlist.png'))
118 popularSongsImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'popularSongs.png'))
119 songImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'song.png'))
120 defImg
= xbmc
.translatePath(os
.path
.join(imgDir
, 'default.tbn'))
121 fanImg
= xbmc
.translatePath(os
.path
.join(baseDir
, 'fanart.png'))
123 settings
= xbmcaddon
.Addon(id='plugin.audio.groove')
124 songsearchlimit
= settings
.getSetting('songsearchlimit')
125 albumsearchlimit
= settings
.getSetting('albumsearchlimit')
126 artistsearchlimit
= settings
.getSetting('artistsearchlimit')
127 username
= settings
.getSetting('username')
128 password
= settings
.getSetting('password')
131 def __init__( self
):
132 self
._handle
= int(sys
.argv
[1])
134 def categories(self
):
136 xbmc
.log(self
.username
+ ", limits: " + str(self
.songsearchlimit
) + ", " + str(self
.albumsearchlimit
) + ", " + str(self
.artistsearchlimit
))
138 self
.userid
= self
._get
_login
()
141 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
142 if os
.path
.isdir(thumbDir
) == False:
143 os
.makedirs(thumbDir
)
145 self
._add
_dir
('Search songs', '', MODE_SEARCH_SONGS
, self
.songImg
, 0)
146 self
._add
_dir
('Search albums', '', MODE_SEARCH_ALBUMS
, self
.albumImg
, 0)
147 self
._add
_dir
('Search artists', '', MODE_SEARCH_ARTISTS
, self
.artistImg
, 0)
148 self
._add
_dir
('Popular songs', '', MODE_POPULAR_SONGS
, self
.popularSongsImg
, 0)
149 if (self
.userid
!= 0):
150 self
._add
_dir
('Favorites', '', MODE_FAVORITES
, self
.favoritesImg
, 0)
151 self
._add
_dir
('Playlists', '', MODE_PLAYLISTS
, self
.playlistImg
, 0)
153 def searchSongs(self
):
154 query
= self
._get
_keyboard
(default
="", heading
="Search songs")
156 groovesharkApi
.setRemoveDuplicates(True)
157 songs
= groovesharkApi
.searchSongs(query
, limit
= self
.songsearchlimit
)
159 self
._add
_songs
_directory
(songs
)
161 dialog
= xbmcgui
.Dialog()
162 dialog
.ok('Grooveshark XBMC', 'No matching songs.')
167 def searchAlbums(self
):
168 query
= self
._get
_keyboard
(default
="", heading
="Search albums")
170 albums
= groovesharkApi
.searchAlbums(query
, limit
= self
.albumsearchlimit
)
171 if (len(albums
) > 0):
172 self
._add
_albums
_directory
(albums
)
174 dialog
= xbmcgui
.Dialog()
175 dialog
.ok('Grooveshark XBMC', 'No matching albums.')
180 def searchArtists(self
):
181 query
= self
._get
_keyboard
(default
="", heading
="Search artists")
183 artists
= groovesharkApi
.searchArtists(query
, limit
= self
.artistsearchlimit
)
184 if (len(artists
) > 0):
185 self
._add
_artists
_directory
(artists
)
187 dialog
= xbmcgui
.Dialog()
188 dialog
.ok('Grooveshark XBMC', 'No matching artists.')
194 userid
= self
._get
_login
()
196 favorites
= groovesharkApi
.userGetFavoriteSongs(userid
)
197 if (len(favorites
) > 0):
198 self
._add
_songs
_directory
(favorites
, isFavorites
=True)
200 dialog
= xbmcgui
.Dialog()
201 dialog
.ok('Grooveshark XBMC', 'You have no favorites.')
204 def popularSongs(self
):
205 popular
= groovesharkApi
.popularGetSongs(limit
= self
.songsearchlimit
)
206 if (len(popular
) > 0):
207 self
._add
_songs
_directory
(popular
)
209 dialog
= xbmcgui
.Dialog()
210 dialog
.ok('Grooveshark XBMC', 'No popular songs.')
213 def popularAlbums(self
):
214 popular
= groovesharkApi
.popularGetAlbums(limit
= self
.albumsearchlimit
)
215 if (len(popular
) > 0):
216 self
._add
_albums
_directory
(popular
)
218 dialog
= xbmcgui
.Dialog()
219 dialog
.ok('Grooveshark XBMC', 'No popular albums.')
222 def popularArtists(self
):
223 popular
= groovesharkApi
.popularGetArtists(limit
= self
.artistsearchlimit
)
224 if (len(popular
) > 0):
225 self
._add
_artists
_directory
(popular
)
227 dialog
= xbmcgui
.Dialog()
228 dialog
.ok('Grooveshark XBMC', 'No popular artists.')
232 userid
= self
._get
_login
()
234 playlists
= groovesharkApi
.userGetPlaylists()
235 if (len(playlists
) > 0):
236 self
._add
_playlists
_directory
(playlists
)
238 dialog
= xbmcgui
.Dialog()
239 dialog
.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.')
242 dialog
= xbmcgui
.Dialog()
243 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to see your Grooveshark playlists.')
246 def favorite(self
, songid
):
247 userid
= self
._get
_login
()
249 xbmc
.log("Favorite song: " + str(songid
))
250 groovesharkApi
.favoriteSong(songID
= songid
)
251 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added to favorites, 1000, ' + thumbDef
+ ')')
253 dialog
= xbmcgui
.Dialog()
254 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to add favorites.')
256 def unfavorite(self
, songid
, prevMode
):
257 userid
= self
._get
_login
()
259 xbmc
.log("Unfavorite song: " + str(songid
) + ', previous mode was ' + str(prevMode
))
260 groovesharkApi
.unfavoriteSong(songID
= songid
)
261 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Removed from Grooveshark favorites, 1000, ' + thumbDef
+ ')')
262 if (int(prevMode
) == MODE_FAVORITES
):
263 xbmc
.executebuiltin("Container.Refresh(" + favoritesUrl
+ ")")
265 dialog
= xbmcgui
.Dialog()
266 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to remove Grooveshark favorites.')
268 def frown(self
, songid
):
269 userid
= self
._get
_login
()
271 xbmc
.log("Frown song: " + str(songid
))
272 if groovesharkApi
.radioFrown(songId
= songid
) != True:
273 xbmc
.log("Unable to frown song " + str(songid
))
275 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Frowned, 1000, ' + thumbDef
+ ')')
277 dialog
= xbmcgui
.Dialog()
278 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to frown a Grooveshark song.')
280 def similarArtists(self
, artistId
):
281 similar
= groovesharkApi
.artistGetSimilar(artistId
, limit
= self
.artistsearchlimit
)
282 if (len(similar
) > 0):
283 self
._add
_artists
_directory
(similar
)
285 dialog
= xbmcgui
.Dialog()
286 dialog
.ok('Grooveshark XBMC', 'No similar artists.')
289 def makePlaylist(self
, albumid
, name
):
290 userid
= self
._get
_login
()
292 re
.split(' - ',name
,1)
293 nameTokens
= re
.split(' - ',name
,1)
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.')
310 def removePlaylist(self
, playlistid
, name
):
311 dialog
= xbmcgui
.Dialog()
312 if dialog
.yesno('Grooveshark XBMC', name
, 'Delete this Grooveshark playlist?') == True:
313 userid
= self
._get
_login
()
315 groovesharkApi
.playlistDelete(playlistid
)
316 xbmc
.executebuiltin("Container.Refresh(" + playlistsUrl
+ ")")
318 dialog
= xbmcgui
.Dialog()
319 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a Grooveshark playlist.')
321 def removePlaylistSong(self
, playlistid
, playlistname
, songpos
):
322 dialog
= xbmcgui
.Dialog()
323 if dialog
.yesno('Grooveshark XBMC', 'Delete this song from the Grooveshark playlist?') == True:
324 userid
= self
._get
_login
()
326 if groovesharkApi
.playlistDeleteSong(playlistid
, songpos
) == 0:
327 dialog
= xbmcgui
.Dialog()
328 dialog
.ok('Grooveshark XBMC', 'Failed to remove ', ' song from Grooveshark playlist.')
330 xbmc
.executebuiltin("Container.Refresh(" + playlistUrl
+ "&id="+str(playlistid
) + "&name=" + playlistname
+ ",replace)")
332 dialog
= xbmcgui
.Dialog()
333 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a song from a Grooveshark playlist.')
335 def addPlaylistSong(self
, songid
):
336 userid
= self
._get
_login
()
338 playlists
= groovesharkApi
.userGetPlaylists()
339 if (len(playlists
) > 0):
341 playlistSelect
= GroovesharkPlaylistSelect(items
=playlists
)
342 playlistSelect
.setFocus(playlistSelect
.playlistControl
)
343 playlistSelect
.doModal()
344 i
= playlistSelect
.selected
348 if i
>= len(playlists
):
349 name
= self
._get
_keyboard
(default
='', heading
="Grooveshark playlist name")
352 songIds
.append(songid
)
353 if groovesharkApi
.playlistCreateUnique(name
, songIds
) == 0:
354 dialog
= xbmcgui
.Dialog()
355 dialog
.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name
)
357 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef
+ ')')
360 playlist
= playlists
[i
]
361 playlistid
= playlist
[1]
362 xbmc
.log("Add song " + str(songid
) + " to playlist " + str(playlistid
))
363 ret
= groovesharkApi
.playlistAddSong(playlistid
, songid
, 0)
365 dialog
= xbmcgui
.Dialog()
366 dialog
.ok('Grooveshark XBMC', 'Cannot add to playlist ')
368 xbmc
.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added song to Grooveshark playlist, 1000, ' + thumbDef
+ ')')
370 dialog
= xbmcgui
.Dialog()
371 dialog
.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.')
374 dialog
= xbmcgui
.Dialog()
375 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to add a song to a Grooveshark playlist.')
377 def renamePlaylist(self
, playlistid
, name
):
378 userid
= self
._get
_login
()
380 newname
= self
._get
_keyboard
(default
=name
, heading
="Grooveshark playlist name")
383 elif groovesharkApi
.playlistRename(playlistid
, newname
) == 0:
384 dialog
= xbmcgui
.Dialog()
385 dialog
.ok('Grooveshark XBMC', 'Cannot rename Grooveshark playlist ', name
)
387 xbmc
.executebuiltin("Container.Refresh")
389 dialog
= xbmcgui
.Dialog()
390 dialog
.ok('Grooveshark XBMC', 'You must be logged in ', ' to rename a Grooveshark playlist.')
392 def album(self
, albumid
):
393 groovesharkApi
.setRemoveDuplicates(True)
394 album
= groovesharkApi
.albumGetSongs(albumId
= albumid
, limit
= self
.songsearchlimit
)
395 self
._add
_songs
_directory
(album
)
397 def artist(self
, artistid
):
398 albums
= groovesharkApi
.artistGetAlbums(artistId
= artistid
, limit
= self
.albumsearchlimit
)
399 self
._add
_albums
_directory
(albums
, artistid
)
401 def playlist(self
, playlistid
, playlistname
):
402 userid
= self
._get
_login
()
404 songs
= groovesharkApi
.playlistGetSongs(playlistId
= playlistid
, limit
= self
.songsearchlimit
)
405 self
._add
_songs
_directory
(songs
, playlistid
, playlistname
)
407 dialog
= xbmcgui
.Dialog()
408 dialog
.ok('Grooveshark XBMC', 'You must be logged in', 'to get Grooveshark playlists.')
410 def playSong(self
, item
):
411 url
= item
.getProperty('url')
412 xbmc
.log("Playing: " + url
)
413 xbmcplugin
.setResolvedUrl(handle
=int(sys
.argv
[1]), succeeded
=True, listitem
=item
)
415 def songItem(self
, id, name
, album
, artist
, duration
, thumb
, image
):
416 url
= groovesharkApi
.getStreamURL(id)
417 # Only try to get the image
419 songImg
= self
._get
_icon
(image
, 'song-' + str(id) + "-image")
422 songThm
= self
._get
_icon
(thumb
, 'song-' + str(id) + "-thumb")
424 item
= xbmcgui
.ListItem(label
= artist
+ " - " + album
+ " - " + name
, path
=url
, thumbnailImage
=songThm
, iconImage
=songImg
)
425 item
.setInfo( type="music", infoLabels
={ "title": name
, "duration": duration
, "album": album
, "artist": artist
} )
426 item
.setProperty('mimetype', 'audio/mpeg')
427 item
.setProperty("IsPlayable", "true")
428 item
.setProperty('url', url
)
429 item
.setProperty('thumb', songThm
)
430 item
.setProperty('image', songImg
)
434 def _get_keyboard(self
, default
="", heading
="", hidden
=False):
435 kb
= xbmc
.Keyboard(default
, heading
, hidden
)
437 if (kb
.isConfirmed()):
438 return unicode(kb
.getText(), "utf-8")
441 def _get_login(self
):
442 if (self
.username
== "" or self
.password
== ""):
443 dialog
= xbmcgui
.Dialog()
444 dialog
.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.')
448 uid
= groovesharkApi
.loginExt(self
.username
, self
.password
)
450 xbmc
.log("Logged in")
453 dialog
= xbmcgui
.Dialog()
454 dialog
.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.')
457 def _get_song_item(self
, song
):
465 return self
.songItem(id, name
, album
, artist
, duration
, thumb
, image
)
468 def _get_icon(self
, url
, id):
469 localThumb
= os
.path
.join(xbmc
.translatePath(os
.path
.join(thumbDir
, str(id)))) + '.tbn'
471 if os
.path
.isfile(localThumb
) == False:
472 xbmc
.log('Downloading ' + url
+ ' to ' + localThumb
)
473 loc
= urllib
.URLopener()
474 loc
.retrieve(url
, localThumb
)
476 xbmc
.log('URL download failed of ' + url
+ ' to ' + localThumb
)
479 return os
.path
.join(os
.path
.join(thumbDir
, str(id))) + '.tbn'
481 def _add_songs_directory(self
, songs
, playlistid
=0, playlistname
='', isFavorites
=False):
483 xbmc
.log("Found " + str(n
) + " songs...")
484 progressDialog
= xbmcgui
.DialogProgress()
485 progressDialog
.create('Grooveshark XBMC', 'Fetching songs')
490 item
= self
._get
_song
_item
(song
)
491 songurl
= item
.getProperty('url')
492 songthumb
= item
.getProperty('thumb')
493 songimage
= item
.getProperty('image')
496 songduration
= song
[2]
499 u
=sys
.argv
[0]+"?url="+urllib
.quote_plus(songurl
) \
500 +"&mode="+str(MODE_SONG
)+"&name="+urllib
.quote_plus(songname
)+"&id=" \
502 +"&album="+urllib
.quote_plus(songalbum
) \
503 +"&artist="+urllib
.quote_plus(songartist
) \
504 +"&duration="+str(songduration
) \
505 +"&thumb="+urllib
.quote_plus(songthumb
) \
506 +"&image="+urllib
.quote_plus(songimage
)
507 fav
=sys
.argv
[0]+"?url="+urllib
.quote_plus(songurl
)+"&mode="+str(MODE_FAVORITE
)+"&name="+urllib
.quote_plus(songname
)+"&id="+str(songid
)
508 unfav
=sys
.argv
[0]+"?url="+urllib
.quote_plus(songurl
)+"&mode="+str(MODE_UNFAVORITE
)+"&name="+urllib
.quote_plus(songname
)+"&id="+str(songid
)+"&prevmode="
510 if isFavorites
== True:
511 unfav
= unfav
+str(MODE_FAVORITES
)
513 menuItems
.append(("Grooveshark favorite", "XBMC.RunPlugin("+fav
+")"))
514 menuItems
.append(("Not Grooveshark favorite", "XBMC.RunPlugin("+unfav
+")"))
516 rmplaylstsong
=sys
.argv
[0]+"?playlistid="+str(playlistid
)+"&id="+str(i
+1)+"&mode="+str(MODE_REMOVE_PLAYLIST_SONG
)+"&name="+playlistname
517 menuItems
.append(("Remove from Grooveshark playlist", "XBMC.RunPlugin("+rmplaylstsong
+")"))
519 addplaylstsong
=sys
.argv
[0]+"?id="+str(songid
)+"&mode="+str(MODE_ADD_PLAYLIST_SONG
)
520 menuItems
.append(("Add to Grooveshark playlist", "XBMC.RunPlugin("+addplaylstsong
+")"))
521 item
.addContextMenuItems(menuItems
, replaceItems
=False)
522 dirItem
= (u
, item
, False)
523 dirItems
.append(dirItem
)
525 progressDialog
.update(int((i
*100)/n
))
526 if progressDialog
.iscanceled():
529 progressDialog
.close()
530 xbmcplugin
.addDirectoryItems(int(sys
.argv
[1]), dirItems
,n
)
531 xbmcplugin
.setContent(self
._handle
, 'songs')
532 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
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 def _add_artists_directory(self
, artists
):
554 xbmc
.log("Found " + str(n
) + " artists...")
558 artistName
= artist
[0]
560 self
._add
_dir
(artistName
, '', MODE_ARTIST
, self
.artistImg
, artistID
, n
)
562 xbmcplugin
.setContent(self
._handle
, 'artists')
563 xbmcplugin
.addSortMethod(self
._handle
, xbmcplugin
.SORT_METHOD_ARTIST_IGNORE_THE
)
564 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
566 def _add_playlists_directory(self
, playlists
):
568 xbmc
.log("Found " + str(n
) + " playlists...")
571 playlist
= playlists
[i
]
572 playlistName
= playlist
[0]
573 playlistID
= playlist
[1]
574 self
._add
_dir
(playlistName
, '', MODE_PLAYLIST
, self
.playlistImg
, playlistID
, n
)
576 xbmcplugin
.setContent(self
._handle
, 'files')
577 xbmcplugin
.addSortMethod(self
._handle
, xbmcplugin
.SORT_METHOD_PLAYLIST_ORDER
)
578 xbmcplugin
.setPluginFanart(int(sys
.argv
[1]), self
.fanImg
)
580 def _add_dir(self
, name
, url
, mode
, iconimage
, id, items
=1):
581 u
=sys
.argv
[0]+"?url="+urllib
.quote_plus(url
)+"&mode="+str(mode
)+"&name="+urllib
.quote_plus(name
)+"&id="+str(id)
582 dir=xbmcgui
.ListItem(name
, iconImage
=iconimage
, thumbnailImage
=iconimage
)
583 dir.setInfo( type="Music", infoLabels
={ "title": name
} )
585 if mode
== MODE_ALBUM
:
586 mkplaylst
=sys
.argv
[0]+"?mode="+str(MODE_MAKE_PLAYLIST
)+"&name="+name
+"&id="+str(id)
587 menuItems
.append(("Make Grooveshark playlist", "XBMC.RunPlugin("+mkplaylst
+")"))
588 if mode
== MODE_PLAYLIST
:
589 rmplaylst
=sys
.argv
[0]+"?mode="+str(MODE_REMOVE_PLAYLIST
)+"&name="+urllib
.quote_plus(name
)+"&id="+str(id)
590 menuItems
.append(("Delete Grooveshark playlist", "XBMC.RunPlugin("+rmplaylst
+")"))
591 mvplaylst
=sys
.argv
[0]+"?mode="+str(MODE_RENAME_PLAYLIST
)+"&name="+urllib
.quote_plus(name
)+"&id="+str(id)
592 menuItems
.append(("Rename Grooveshark playlist", "XBMC.RunPlugin("+mvplaylst
+")"))
593 dir.addContextMenuItems(menuItems
, replaceItems
=False)
594 return xbmcplugin
.addDirectoryItem(handle
=int(sys
.argv
[1]),url
=u
,listitem
=dir,isFolder
=True, totalItems
=items
)
599 paramstring
=sys
.argv
[2]
600 if len(paramstring
)>=2:
602 cleanedparams
=params
.replace('?','')
603 if (params
[len(params
)-1]=='/'):
604 params
=params
[0:len(params
)-2]
605 pairsofparams
=cleanedparams
.split('&')
607 for i
in range(len(pairsofparams
)):
609 splitparams
=pairsofparams
[i
].split('=')
610 if (len(splitparams
))==2:
611 param
[splitparams
[0]]=splitparams
[1]
615 grooveshark
= Groveshark();
623 try: url
=urllib
.unquote_plus(params
["url"])
625 try: name
=urllib
.unquote_plus(params
["name"])
627 try: mode
=int(params
["mode"])
629 try: id=int(params
["id"])
633 grooveshark
.categories()
635 elif mode
==MODE_SEARCH_SONGS
:
636 grooveshark
.searchSongs()
638 elif mode
==MODE_SEARCH_ALBUMS
:
639 grooveshark
.searchAlbums()
641 elif mode
==MODE_SEARCH_ARTISTS
:
642 grooveshark
.searchArtists()
644 elif mode
==MODE_POPULAR_SONGS
:
645 grooveshark
.popularSongs()
647 elif mode
==MODE_PLAYLISTS
:
648 grooveshark
.playlists()
650 elif mode
==MODE_FAVORITES
:
651 grooveshark
.favorites()
653 elif mode
==MODE_SONG
:
654 try: album
=urllib
.unquote_plus(params
["album"])
656 try: artist
=urllib
.unquote_plus(params
["artist"])
658 try: duration
=int(params
["duration"])
660 try: thumb
=urllib
.unquote_plus(params
["thumb"])
662 try: image
=urllib
.unquote_plus(params
["image"])
664 song
= grooveshark
.songItem(id, name
, album
, artist
, duration
, thumb
, image
)
665 grooveshark
.playSong(song
)
667 elif mode
==MODE_ARTIST
:
668 grooveshark
.artist(id)
670 elif mode
==MODE_ALBUM
:
671 grooveshark
.album(id)
673 elif mode
==MODE_PLAYLIST
:
674 grooveshark
.playlist(id, name
)
676 elif mode
==MODE_FAVORITE
:
677 grooveshark
.favorite(id)
679 elif mode
==MODE_UNFAVORITE
:
680 try: prevMode
=urllib
.unquote_plus(params
["prevmode"])
682 grooveshark
.unfavorite(id, prevMode
)
684 elif mode
==MODE_SIMILAR_ARTISTS
:
685 grooveshark
.similarArtists(id)
687 elif mode
==MODE_MAKE_PLAYLIST
:
688 grooveshark
.makePlaylist(id, name
)
690 elif mode
==MODE_REMOVE_PLAYLIST
:
691 grooveshark
.removePlaylist(id, name
)
693 elif mode
==MODE_RENAME_PLAYLIST
:
694 grooveshark
.renamePlaylist(id, name
)
696 elif mode
==MODE_REMOVE_PLAYLIST_SONG
:
697 try: playlistID
=urllib
.unquote_plus(params
["playlistid"])
699 grooveshark
.removePlaylistSong(playlistID
, name
, id)
701 elif mode
==MODE_ADD_PLAYLIST_SONG
:
702 grooveshark
.addPlaylistSong(id)
704 if (mode
< MODE_SONG
):
705 xbmcplugin
.endOfDirectory(int(sys
.argv
[1]))