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