| 1 | import urllib, sys, os, shutil, re, pickle, time, tempfile, xbmcaddon, xbmcplugin, xbmcgui, xbmc |
| 2 | MODE_SEARCH_SONGS = 1 |
| 3 | MODE_SEARCH_ALBUMS = 2 |
| 4 | MODE_SEARCH_ARTISTS = 3 |
| 5 | MODE_SEARCH_ARTISTS_ALBUMS = 4 |
| 6 | MODE_SEARCH_PLAYLISTS = 5 |
| 7 | MODE_ARTIST_POPULAR = 6 |
| 8 | MODE_POPULAR_SONGS = 7 |
| 9 | MODE_FAVORITES = 8 |
| 10 | MODE_PLAYLISTS = 9 |
| 11 | MODE_ALBUM = 10 |
| 12 | MODE_ARTIST = 11 |
| 13 | MODE_PLAYLIST = 12 |
| 14 | MODE_SONG_PAGE = 13 |
| 15 | MODE_SIMILAR_ARTISTS = 14 |
| 16 | MODE_SONG = 15 |
| 17 | MODE_FAVORITE = 16 |
| 18 | MODE_UNFAVORITE = 17 |
| 19 | MODE_MAKE_PLAYLIST = 18 |
| 20 | MODE_REMOVE_PLAYLIST = 19 |
| 21 | MODE_RENAME_PLAYLIST = 20 |
| 22 | MODE_REMOVE_PLAYLIST_SONG = 21 |
| 23 | MODE_ADD_PLAYLIST_SONG = 22 |
| 24 | |
| 25 | ACTION_MOVE_LEFT = 1 |
| 26 | ACTION_MOVE_UP = 3 |
| 27 | ACTION_MOVE_DOWN = 4 |
| 28 | ACTION_PAGE_UP = 5 |
| 29 | ACTION_PAGE_DOWN = 6 |
| 30 | ACTION_SELECT_ITEM = 7 |
| 31 | ACTION_PREVIOUS_MENU = 10 |
| 32 | |
| 33 | # Formats for track labels |
| 34 | ARTIST_ALBUM_NAME_LABEL = 0 |
| 35 | NAME_ALBUM_ARTIST_LABEL = 1 |
| 36 | |
| 37 | # Stream marking time (seconds) |
| 38 | STREAM_MARKING_TIME = 30 |
| 39 | |
| 40 | songMarkTime = 0 |
| 41 | player = xbmc.Player() |
| 42 | playTimer = None |
| 43 | |
| 44 | baseDir = os.getcwd() |
| 45 | resDir = xbmc.translatePath(os.path.join(baseDir, 'resources')) |
| 46 | libDir = xbmc.translatePath(os.path.join(resDir, 'lib')) |
| 47 | imgDir = xbmc.translatePath(os.path.join(resDir, 'img')) |
| 48 | cacheDir = os.path.join(xbmc.translatePath('special://masterprofile/addon_data/'), os.path.basename(os.getcwd())) |
| 49 | thumbDirName = 'thumb' |
| 50 | thumbDir = os.path.join('special://masterprofile/addon_data/', os.path.basename(os.getcwd()), thumbDirName) |
| 51 | |
| 52 | baseModeUrl = 'plugin://plugin.audio.groove/' |
| 53 | playlistUrl = baseModeUrl + '?mode=' + str(MODE_PLAYLIST) |
| 54 | playlistsUrl = baseModeUrl + '?mode=' + str(MODE_PLAYLISTS) |
| 55 | favoritesUrl = baseModeUrl + '?mode=' + str(MODE_FAVORITES) |
| 56 | |
| 57 | searchArtistsAlbumsName = "Search for artist's albums..." |
| 58 | |
| 59 | thumbDef = os.path.join(imgDir, 'default.tbn') |
| 60 | listBackground = os.path.join(imgDir, 'listbackground.png') |
| 61 | |
| 62 | sys.path.append (libDir) |
| 63 | from GroovesharkAPI import GrooveAPI |
| 64 | from threading import Event, Thread |
| 65 | |
| 66 | try: |
| 67 | groovesharkApi = GrooveAPI() |
| 68 | if groovesharkApi.pingService() != True: |
| 69 | raise StandardError('No Grooveshark service') |
| 70 | except: |
| 71 | dialog = xbmcgui.Dialog() |
| 72 | dialog.ok('Grooveshark XBMC', 'Unable to connect with Grooveshark.', 'Please try again later') |
| 73 | sys.exit(-1) |
| 74 | |
| 75 | # Mark song as playing or played |
| 76 | def markSong(songid, duration): |
| 77 | global songMarkTime |
| 78 | global playTimer |
| 79 | global player |
| 80 | if player.isPlayingAudio(): |
| 81 | tNow = player.getTime() |
| 82 | if tNow >= STREAM_MARKING_TIME and songMarkTime == 0: |
| 83 | groovesharkApi.markStreamKeyOver30Secs() |
| 84 | songMarkTime = tNow |
| 85 | elif duration > tNow and duration - tNow < 2 and songMarkTime >= STREAM_MARKING_TIME: |
| 86 | playTimer.cancel() |
| 87 | songMarkTime = 0 |
| 88 | groovesharkApi.markSongComplete(songid) |
| 89 | else: |
| 90 | playTimer.cancel() |
| 91 | songMarkTime = 0 |
| 92 | |
| 93 | class _Info: |
| 94 | def __init__( self, *args, **kwargs ): |
| 95 | self.__dict__.update( kwargs ) |
| 96 | |
| 97 | # Window dialog to select a grooveshark playlist |
| 98 | class GroovesharkPlaylistSelect(xbmcgui.WindowDialog): |
| 99 | |
| 100 | def __init__(self, items=[]): |
| 101 | gap = int(self.getHeight()/100) |
| 102 | w = int(self.getWidth()*0.5) |
| 103 | h = self.getHeight()-30*gap |
| 104 | rw = self.getWidth() |
| 105 | rh = self.getHeight() |
| 106 | x = rw/2 - w/2 |
| 107 | y = rh/2 -h/2 |
| 108 | |
| 109 | self.imgBg = xbmcgui.ControlImage(x+gap, 5*gap+y, w-2*gap, h-5*gap, listBackground) |
| 110 | self.addControl(self.imgBg) |
| 111 | |
| 112 | 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) |
| 113 | self.addControl(self.playlistControl) |
| 114 | |
| 115 | self.lastPos = 0 |
| 116 | self.isSelecting = False |
| 117 | self.selected = -1 |
| 118 | listitems = [] |
| 119 | for playlist in items: |
| 120 | listitems.append(xbmcgui.ListItem(playlist[0])) |
| 121 | listitems.append(xbmcgui.ListItem('New...')) |
| 122 | self.playlistControl.addItems(listitems) |
| 123 | self.setFocus(self.playlistControl) |
| 124 | self.playlistControl.selectItem(0) |
| 125 | item = self.playlistControl.getListItem(self.lastPos) |
| 126 | item.select(True) |
| 127 | |
| 128 | # Highlight selected item |
| 129 | def setHighlight(self): |
| 130 | if self.isSelecting: |
| 131 | return |
| 132 | else: |
| 133 | self.isSelecting = True |
| 134 | |
| 135 | pos = self.playlistControl.getSelectedPosition() |
| 136 | if pos >= 0: |
| 137 | item = self.playlistControl.getListItem(self.lastPos) |
| 138 | item.select(False) |
| 139 | item = self.playlistControl.getListItem(pos) |
| 140 | item.select(True) |
| 141 | self.lastPos = pos |
| 142 | self.isSelecting = False |
| 143 | |
| 144 | # Control - select |
| 145 | def onControl(self, control): |
| 146 | if control == self.playlistControl: |
| 147 | self.selected = self.playlistControl.getSelectedPosition() |
| 148 | self.close() |
| 149 | |
| 150 | # Action - close or up/down |
| 151 | def onAction(self, action): |
| 152 | if action == ACTION_PREVIOUS_MENU: |
| 153 | self.selected = -1 |
| 154 | self.close() |
| 155 | elif action == ACTION_MOVE_UP or action == ACTION_MOVE_DOWN or action == ACTION_PAGE_UP or action == ACTION_PAGE_DOWN == 6: |
| 156 | self.setFocus(self.playlistControl) |
| 157 | self.setHighlight() |
| 158 | |
| 159 | |
| 160 | class PlayTimer(Thread): |
| 161 | # interval -- floating point number specifying the number of seconds to wait before executing function |
| 162 | # function -- the function (or callable object) to be executed |
| 163 | |
| 164 | # iterations -- integer specifying the number of iterations to perform |
| 165 | # args -- list of positional arguments passed to function |
| 166 | # kwargs -- dictionary of keyword arguments passed to function |
| 167 | |
| 168 | def __init__(self, interval, function, iterations=0, args=[], kwargs={}): |
| 169 | Thread.__init__(self) |
| 170 | self.interval = interval |
| 171 | self.function = function |
| 172 | self.iterations = iterations |
| 173 | self.args = args |
| 174 | self.kwargs = kwargs |
| 175 | self.finished = Event() |
| 176 | |
| 177 | def run(self): |
| 178 | count = 0 |
| 179 | while not self.finished.isSet() and (self.iterations <= 0 or count < self.iterations): |
| 180 | self.finished.wait(self.interval) |
| 181 | if not self.finished.isSet(): |
| 182 | self.function(*self.args, **self.kwargs) |
| 183 | count += 1 |
| 184 | |
| 185 | def cancel(self): |
| 186 | self.finished.set() |
| 187 | |
| 188 | def setIterations(self, iterations): |
| 189 | self.iterations = iterations |
| 190 | |
| 191 | |
| 192 | def getTime(self): |
| 193 | return self.iterations * self.interval |
| 194 | |
| 195 | |
| 196 | class Groveshark: |
| 197 | |
| 198 | albumImg = xbmc.translatePath(os.path.join(imgDir, 'album.png')) |
| 199 | artistImg = xbmc.translatePath(os.path.join(imgDir, 'artist.png')) |
| 200 | artistsAlbumsImg = xbmc.translatePath(os.path.join(imgDir, 'artistsalbums.png')) |
| 201 | favoritesImg = xbmc.translatePath(os.path.join(imgDir, 'favorites.png')) |
| 202 | playlistImg = xbmc.translatePath(os.path.join(imgDir, 'playlist.png')) |
| 203 | usersplaylistsImg = xbmc.translatePath(os.path.join(imgDir, 'usersplaylists.png')) |
| 204 | popularSongsImg = xbmc.translatePath(os.path.join(imgDir, 'popularSongs.png')) |
| 205 | popularSongsArtistImg = xbmc.translatePath(os.path.join(imgDir, 'popularSongsArtist.png')) |
| 206 | songImg = xbmc.translatePath(os.path.join(imgDir, 'song.png')) |
| 207 | defImg = xbmc.translatePath(os.path.join(imgDir, 'default.tbn')) |
| 208 | fanImg = xbmc.translatePath(os.path.join(baseDir, 'fanart.png')) |
| 209 | |
| 210 | settings = xbmcaddon.Addon(id='plugin.audio.groove') |
| 211 | songsearchlimit = int(settings.getSetting('songsearchlimit')) |
| 212 | albumsearchlimit = int(settings.getSetting('albumsearchlimit')) |
| 213 | artistsearchlimit = int(settings.getSetting('artistsearchlimit')) |
| 214 | songspagelimit = int(settings.getSetting('songspagelimit')) |
| 215 | username = settings.getSetting('username') |
| 216 | password = settings.getSetting('password') |
| 217 | userid = 0 |
| 218 | |
| 219 | def __init__( self ): |
| 220 | self._handle = int(sys.argv[1]) |
| 221 | if os.path.isdir(cacheDir) == False: |
| 222 | os.makedirs(cacheDir) |
| 223 | xbmc.log("Made " + cacheDir) |
| 224 | artDir = xbmc.translatePath(thumbDir) |
| 225 | if os.path.isdir(artDir) == False: |
| 226 | os.makedirs(artDir) |
| 227 | xbmc.log("Made " + artDir) |
| 228 | |
| 229 | # Top-level menu |
| 230 | def categories(self): |
| 231 | |
| 232 | self.userid = self._get_login() |
| 233 | |
| 234 | # Setup |
| 235 | xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg) |
| 236 | |
| 237 | self._add_dir('Search for songs...', '', MODE_SEARCH_SONGS, self.songImg, 0) |
| 238 | self._add_dir('Search for albums...', '', MODE_SEARCH_ALBUMS, self.albumImg, 0) |
| 239 | self._add_dir('Search for artists...', '', MODE_SEARCH_ARTISTS, self.artistImg, 0) |
| 240 | self._add_dir(searchArtistsAlbumsName, '', MODE_SEARCH_ARTISTS_ALBUMS, self.artistsAlbumsImg, 0) |
| 241 | # Not supported by key |
| 242 | #self._add_dir("Search for user's playlists...", '', MODE_SEARCH_PLAYLISTS, self.usersplaylistsImg, 0) |
| 243 | self._add_dir('Popular Grooveshark songs for artist...', '', MODE_ARTIST_POPULAR, self.popularSongsArtistImg, 0) |
| 244 | self._add_dir('Popular Grooveshark songs', '', MODE_POPULAR_SONGS, self.popularSongsImg, 0) |
| 245 | if (self.userid != 0): |
| 246 | self._add_dir('My Grooveshark favorites', '', MODE_FAVORITES, self.favoritesImg, 0) |
| 247 | self._add_dir('My Grooveshark playlists', '', MODE_PLAYLISTS, self.playlistImg, 0) |
| 248 | |
| 249 | # Search for songs |
| 250 | def searchSongs(self): |
| 251 | query = self._get_keyboard(default="", heading='Search for songs powered by Grooveshark') |
| 252 | if (query != ''): |
| 253 | songs = groovesharkApi.getSongSearchResults(query, limit = self.songsearchlimit) |
| 254 | if (len(songs) > 0): |
| 255 | self._add_songs_directory(songs) |
| 256 | else: |
| 257 | dialog = xbmcgui.Dialog() |
| 258 | dialog.ok('Grooveshark XBMC', 'No matching songs.') |
| 259 | self.categories() |
| 260 | else: |
| 261 | self.categories() |
| 262 | |
| 263 | # Search for albums |
| 264 | def searchAlbums(self): |
| 265 | query = self._get_keyboard(default="", heading='Search for albums powered by Grooveshark') |
| 266 | if (query != ''): |
| 267 | albums = groovesharkApi.getAlbumSearchResults(query, limit = self.albumsearchlimit) |
| 268 | if (len(albums) > 0): |
| 269 | self._add_albums_directory(albums) |
| 270 | else: |
| 271 | dialog = xbmcgui.Dialog() |
| 272 | dialog.ok('Grooveshark XBMC', 'No matching albums.') |
| 273 | self.categories() |
| 274 | else: |
| 275 | self.categories() |
| 276 | |
| 277 | # Search for artists |
| 278 | def searchArtists(self): |
| 279 | query = self._get_keyboard(default="", heading='Search for artists powered by Grooveshark') |
| 280 | if (query != ''): |
| 281 | artists = groovesharkApi.getArtistSearchResults(query, limit = self.artistsearchlimit) |
| 282 | if (len(artists) > 0): |
| 283 | self._add_artists_directory(artists) |
| 284 | else: |
| 285 | dialog = xbmcgui.Dialog() |
| 286 | dialog.ok('Grooveshark XBMC', 'No matching artists.') |
| 287 | self.categories() |
| 288 | else: |
| 289 | self.categories() |
| 290 | |
| 291 | # Search for playlists |
| 292 | def searchPlaylists(self): |
| 293 | query = self._get_keyboard(default="", heading="Username") |
| 294 | if (query != ''): |
| 295 | playlists = groovesharkApi.getUserPlaylistsByUsername(query) |
| 296 | if (len(playlists) > 0): |
| 297 | self._add_playlists_directory(playlists) |
| 298 | else: |
| 299 | dialog = xbmcgui.Dialog() |
| 300 | dialog.ok('Grooveshark XBMC', 'No Grooveshark playlists found.') |
| 301 | self.categories() |
| 302 | else: |
| 303 | self.categories() |
| 304 | |
| 305 | # Search for artists albums |
| 306 | def searchArtistsAlbums(self, artistName = None): |
| 307 | if artistName == None or artistName == searchArtistsAlbumsName: |
| 308 | query = self._get_keyboard(default="", heading="Search for artist's albums powered by Grooveshark") |
| 309 | else: |
| 310 | query = artistName |
| 311 | if (query != ''): |
| 312 | artists = groovesharkApi.getArtistSearchResults(query, limit = self.artistsearchlimit) |
| 313 | if (len(artists) > 0): |
| 314 | artist = artists[0] |
| 315 | artistID = artist[1] |
| 316 | xbmc.log("Found " + artist[0] + "...") |
| 317 | albums = groovesharkApi.getArtistAlbums(artistID, limit = self.albumsearchlimit) |
| 318 | if (len(albums) > 0): |
| 319 | self._add_albums_directory(albums, artistID) |
| 320 | else: |
| 321 | dialog = xbmcgui.Dialog() |
| 322 | dialog.ok('Grooveshark XBMC', 'No matching albums.') |
| 323 | self.categories() |
| 324 | else: |
| 325 | dialog = xbmcgui.Dialog() |
| 326 | dialog.ok('Grooveshark XBMC', 'No matching artists.') |
| 327 | self.categories() |
| 328 | else: |
| 329 | self.categories() |
| 330 | |
| 331 | # Get my favorites |
| 332 | def favorites(self): |
| 333 | userid = self._get_login() |
| 334 | if (userid != 0): |
| 335 | favorites = groovesharkApi.getUserFavoriteSongs() |
| 336 | if (len(favorites) > 0): |
| 337 | self._add_songs_directory(favorites, isFavorites=True) |
| 338 | else: |
| 339 | dialog = xbmcgui.Dialog() |
| 340 | dialog.ok('Grooveshark XBMC', 'You have no favorites.') |
| 341 | self.categories() |
| 342 | |
| 343 | # Get popular songs |
| 344 | def popularSongs(self): |
| 345 | popular = groovesharkApi.getPopularSongsToday(limit = self.songsearchlimit) |
| 346 | if (len(popular) > 0): |
| 347 | self._add_songs_directory(popular) |
| 348 | else: |
| 349 | dialog = xbmcgui.Dialog() |
| 350 | dialog.ok('Grooveshark XBMC', 'No popular songs.') |
| 351 | self.categories() |
| 352 | |
| 353 | # Get my playlists |
| 354 | def playlists(self): |
| 355 | userid = self._get_login() |
| 356 | if (userid != 0): |
| 357 | playlists = groovesharkApi.getUserPlaylists() |
| 358 | if (len(playlists) > 0): |
| 359 | self._add_playlists_directory(playlists) |
| 360 | else: |
| 361 | dialog = xbmcgui.Dialog() |
| 362 | dialog.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.') |
| 363 | self.categories() |
| 364 | else: |
| 365 | dialog = xbmcgui.Dialog() |
| 366 | dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to see your Grooveshark playlists.') |
| 367 | |
| 368 | # Make songs a favorite |
| 369 | def favorite(self, songid): |
| 370 | userid = self._get_login() |
| 371 | if (userid != 0): |
| 372 | xbmc.log("Favorite song: " + str(songid)) |
| 373 | groovesharkApi.addUserFavoriteSong(songID = songid) |
| 374 | xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added to favorites, 1000, ' + thumbDef + ')') |
| 375 | else: |
| 376 | dialog = xbmcgui.Dialog() |
| 377 | dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to add favorites.') |
| 378 | |
| 379 | # Remove song from favorites |
| 380 | def unfavorite(self, songid, prevMode=0): |
| 381 | userid = self._get_login() |
| 382 | if (userid != 0): |
| 383 | xbmc.log("Unfavorite song: " + str(songid) + ', previous mode was ' + str(prevMode)) |
| 384 | groovesharkApi.removeUserFavoriteSongs(songIDs = songid) |
| 385 | xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Removed from Grooveshark favorites, 1000, ' + thumbDef + ')') |
| 386 | # Refresh to remove item from directory |
| 387 | if (int(prevMode) == MODE_FAVORITES): |
| 388 | xbmc.executebuiltin("Container.Refresh(" + favoritesUrl + ")") |
| 389 | else: |
| 390 | dialog = xbmcgui.Dialog() |
| 391 | dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to remove Grooveshark favorites.') |
| 392 | |
| 393 | |
| 394 | # Show selected album |
| 395 | def album(self, albumid): |
| 396 | album = groovesharkApi.getAlbumSongs(albumid, limit = self.songsearchlimit) |
| 397 | self._add_songs_directory(album, trackLabelFormat=NAME_ALBUM_ARTIST_LABEL) |
| 398 | |
| 399 | # Show selected artist |
| 400 | def artist(self, artistid): |
| 401 | albums = groovesharkApi.getArtistAlbums(artistid, limit = self.albumsearchlimit) |
| 402 | self._add_albums_directory(albums, artistid) |
| 403 | |
| 404 | # Show selected playlist |
| 405 | def playlist(self, playlistid, playlistname): |
| 406 | userid = self._get_login() |
| 407 | if (userid != 0): |
| 408 | songs = groovesharkApi.getPlaylistSongs(playlistid) |
| 409 | self._add_songs_directory(songs, trackLabelFormat=NAME_ALBUM_ARTIST_LABEL, playlistid=playlistid, playlistname=playlistname) |
| 410 | else: |
| 411 | dialog = xbmcgui.Dialog() |
| 412 | dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to get Grooveshark playlists.') |
| 413 | |
| 414 | # Show popular songs of the artist |
| 415 | def artistPopularSongs(self): |
| 416 | query = self._get_keyboard(default="", heading="Artist") |
| 417 | if (query != ''): |
| 418 | artists = groovesharkApi.getArtistSearchResults(query, limit = self.artistsearchlimit) |
| 419 | if (len(artists) > 0): |
| 420 | artist = artists[0] |
| 421 | artistID = artist[1] |
| 422 | xbmc.log("Found " + artist[0] + "...") |
| 423 | songs = groovesharkApi.getArtistPopularSongs(artistID, limit = self.songsearchlimit) |
| 424 | if (len(songs) > 0): |
| 425 | self._add_songs_directory(songs, trackLabelFormat=NAME_ALBUM_ARTIST_LABEL) |
| 426 | else: |
| 427 | dialog = xbmcgui.Dialog() |
| 428 | dialog.ok('Grooveshark XBMC', 'No popular songs.') |
| 429 | self.categories() |
| 430 | else: |
| 431 | dialog = xbmcgui.Dialog() |
| 432 | dialog.ok('Grooveshark XBMC', 'No matching artists.') |
| 433 | self.categories() |
| 434 | else: |
| 435 | self.categories() |
| 436 | |
| 437 | # Play a song |
| 438 | def playSong(self, item): |
| 439 | global playTimer |
| 440 | global player |
| 441 | if item != None: |
| 442 | songid = item.getProperty('songid') |
| 443 | stream = groovesharkApi.getSubscriberStreamKey(songid) |
| 444 | url = stream['url'] |
| 445 | item.setPath(url) |
| 446 | xbmc.log("Grooveshark playing: " + url) |
| 447 | xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=item) |
| 448 | # Wait for play then start time |
| 449 | seconds = 0 |
| 450 | while seconds < STREAM_MARKING_TIME: |
| 451 | try: |
| 452 | if player.isPlayingAudio() == True: |
| 453 | if playTimer != None: |
| 454 | playTimer.cancel() |
| 455 | songMarkTime = 0 |
| 456 | duration = int(item.getProperty('duration')) |
| 457 | playTimer = PlayTimer(1, markSong, duration, [songid, duration]) |
| 458 | playTimer.start() |
| 459 | break |
| 460 | except: pass |
| 461 | time.sleep(1) |
| 462 | seconds = seconds + 1 |
| 463 | else: |
| 464 | xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Unable to play song, 1000, ' + thumbDef + ')') |
| 465 | |
| 466 | # Make a song directory item |
| 467 | def songItem(self, songid, name, album, artist, coverart, trackLabelFormat=ARTIST_ALBUM_NAME_LABEL): |
| 468 | songImg = self._get_icon(coverart, 'song-' + str(songid) + "-image") |
| 469 | if int(trackLabelFormat) == NAME_ALBUM_ARTIST_LABEL: |
| 470 | trackLabel = name + " - " + album + " - " + artist |
| 471 | else: |
| 472 | trackLabel = artist + " - " + album + " - " + name |
| 473 | duration = self._getSongDuration(songid) |
| 474 | item = xbmcgui.ListItem(label = trackLabel, thumbnailImage=songImg, iconImage=songImg) |
| 475 | item.setInfo( type="music", infoLabels={ "title": name, "album": album, "artist": artist, "duration": duration} ) |
| 476 | item.setProperty('mimetype', 'audio/mpeg') |
| 477 | item.setProperty("IsPlayable", "true") |
| 478 | item.setProperty('songid', str(songid)) |
| 479 | item.setProperty('coverart', songImg) |
| 480 | item.setProperty('title', name) |
| 481 | item.setProperty('album', album) |
| 482 | item.setProperty('artist', artist) |
| 483 | item.setProperty('duration', str(duration)) |
| 484 | |
| 485 | return item |
| 486 | |
| 487 | # Next page of songs |
| 488 | def songPage(self, page, trackLabelFormat, playlistid = 0, playlistname = ''): |
| 489 | self._add_songs_directory([], trackLabelFormat, page, playlistid = playlistid, playlistname = playlistname) |
| 490 | |
| 491 | # Make a playlist from an album |
| 492 | def makePlaylist(self, albumid, name): |
| 493 | userid = self._get_login() |
| 494 | if (userid != 0): |
| 495 | re.split(' - ',name,1) |
| 496 | nameTokens = re.split(' - ',name,1) # suggested name |
| 497 | name = self._get_keyboard(default=nameTokens[0], heading="Grooveshark playlist name") |
| 498 | if name != '': |
| 499 | album = groovesharkApi.getAlbumSongs(albumid, limit = self.songsearchlimit) |
| 500 | songids = [] |
| 501 | for song in album: |
| 502 | songids.append(song[1]) |
| 503 | if groovesharkApi.createPlaylist(name, songids) == 0: |
| 504 | dialog = xbmcgui.Dialog() |
| 505 | dialog.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name) |
| 506 | else: |
| 507 | xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef + ')') |
| 508 | else: |
| 509 | dialog = xbmcgui.Dialog() |
| 510 | dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to create a Grooveshark playlist.') |
| 511 | |
| 512 | # Rename a playlist |
| 513 | def renamePlaylist(self, playlistid, name): |
| 514 | userid = self._get_login() |
| 515 | if (userid != 0): |
| 516 | newname = self._get_keyboard(default=name, heading="Grooveshark playlist name") |
| 517 | if newname == '': |
| 518 | return |
| 519 | elif groovesharkApi.playlistRename(playlistid, newname) == 0: |
| 520 | dialog = xbmcgui.Dialog() |
| 521 | dialog.ok('Grooveshark XBMC', 'Cannot rename Grooveshark playlist ', name) |
| 522 | else: |
| 523 | # Refresh to show new item name |
| 524 | xbmc.executebuiltin("Container.Refresh") |
| 525 | else: |
| 526 | dialog = xbmcgui.Dialog() |
| 527 | dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to rename a Grooveshark playlist.') |
| 528 | |
| 529 | # Remove a playlist |
| 530 | def removePlaylist(self, playlistid, name): |
| 531 | dialog = xbmcgui.Dialog() |
| 532 | if dialog.yesno('Grooveshark XBMC', name, 'Delete this Grooveshark playlist?') == True: |
| 533 | userid = self._get_login() |
| 534 | if (userid != 0): |
| 535 | if groovesharkApi.playlistDelete(playlistid) == 0: |
| 536 | dialog = xbmcgui.Dialog() |
| 537 | dialog.ok('Grooveshark XBMC', 'Cannot remove Grooveshark playlist ', name) |
| 538 | else: |
| 539 | # Refresh to remove item from directory |
| 540 | xbmc.executebuiltin("Container.Refresh(" + playlistsUrl + ")") |
| 541 | else: |
| 542 | dialog = xbmcgui.Dialog() |
| 543 | dialog.ok('Grooveshark XBMC', 'You must be logged in ', ' to delete a Grooveshark playlist.') |
| 544 | |
| 545 | # Add song to playlist |
| 546 | def addPlaylistSong(self, songid): |
| 547 | userid = self._get_login() |
| 548 | if (userid != 0): |
| 549 | playlists = groovesharkApi.getUserPlaylists() |
| 550 | if (len(playlists) > 0): |
| 551 | ret = 0 |
| 552 | # Select the playlist |
| 553 | playlistSelect = GroovesharkPlaylistSelect(items=playlists) |
| 554 | playlistSelect.setFocus(playlistSelect.playlistControl) |
| 555 | playlistSelect.doModal() |
| 556 | i = playlistSelect.selected |
| 557 | del playlistSelect |
| 558 | if i > -1: |
| 559 | # Add a new playlist |
| 560 | if i >= len(playlists): |
| 561 | name = self._get_keyboard(default='', heading="Grooveshark playlist name") |
| 562 | if name != '': |
| 563 | songIds = [] |
| 564 | songIds.append(songid) |
| 565 | if groovesharkApi.createPlaylist(name, songIds) == 0: |
| 566 | dialog = xbmcgui.Dialog() |
| 567 | dialog.ok('Grooveshark XBMC', 'Cannot create Grooveshark playlist ', name) |
| 568 | else: |
| 569 | xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Grooveshark playlist created, 1000, ' + thumbDef + ')') |
| 570 | # Existing playlist |
| 571 | else: |
| 572 | playlist = playlists[i] |
| 573 | playlistid = playlist[1] |
| 574 | xbmc.log("Add song " + str(songid) + " to playlist " + str(playlistid)) |
| 575 | songIDs=[] |
| 576 | songs = groovesharkApi.getPlaylistSongs(playlistid) |
| 577 | for song in songs: |
| 578 | songIDs.append(song[1]) |
| 579 | songIDs.append(songid) |
| 580 | ret = groovesharkApi.setPlaylistSongs(playlistid, songIDs) |
| 581 | if ret == False: |
| 582 | dialog = xbmcgui.Dialog() |
| 583 | dialog.ok('Grooveshark XBMC', 'Cannot add to playlist ') |
| 584 | else: |
| 585 | xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Added song to Grooveshark playlist, 1000, ' + thumbDef + ')') |
| 586 | else: |
| 587 | dialog = xbmcgui.Dialog() |
| 588 | dialog.ok('Grooveshark XBMC', 'You have no Grooveshark playlists.') |
| 589 | self.categories() |
| 590 | else: |
| 591 | dialog = xbmcgui.Dialog() |
| 592 | dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to add a song to a Grooveshark playlist.') |
| 593 | |
| 594 | # Remove song from playlist |
| 595 | def removePlaylistSong(self, playlistid, playlistname, songid): |
| 596 | dialog = xbmcgui.Dialog() |
| 597 | if dialog.yesno('Grooveshark XBMC', 'Delete this song from', 'the Grooveshark playlist?') == True: |
| 598 | userid = self._get_login() |
| 599 | if (userid != 0): |
| 600 | songs = groovesharkApi.getPlaylistSongs(playlistID) |
| 601 | songIDs=[] |
| 602 | for song in songs: |
| 603 | if (song[1] != songid): |
| 604 | songIDs.append(song[1]) |
| 605 | ret = groovesharkApi.setPlaylistSongs(playlistID, songIDs) |
| 606 | if ret == False: |
| 607 | dialog = xbmcgui.Dialog() |
| 608 | dialog.ok('Grooveshark XBMC', 'Failed to remove', 'song from Grooveshark playlist.') |
| 609 | else: |
| 610 | # Refresh to remove item from directory |
| 611 | xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Removed song from Grooveshark playlist, 1000, ' + thumbDef + ')') |
| 612 | xbmc.executebuiltin("Container.Update(" + playlistUrl + "&id="+str(playlistid) + "&name=" + playlistname + ")") |
| 613 | else: |
| 614 | dialog = xbmcgui.Dialog() |
| 615 | dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to delete a song from a Grooveshark playlist.') |
| 616 | |
| 617 | # Find similar artists to searched artist |
| 618 | def similarArtists(self, artistId): |
| 619 | similar = groovesharkApi.getSimilarArtists(artistId, limit = self.artistsearchlimit) |
| 620 | if (len(similar) > 0): |
| 621 | self._add_artists_directory(similar) |
| 622 | else: |
| 623 | dialog = xbmcgui.Dialog() |
| 624 | dialog.ok('Grooveshark XBMC', 'No similar artists.') |
| 625 | self.categories() |
| 626 | |
| 627 | # Get keyboard input |
| 628 | def _get_keyboard(self, default="", heading="", hidden=False): |
| 629 | kb = xbmc.Keyboard(default, heading, hidden) |
| 630 | kb.doModal() |
| 631 | if (kb.isConfirmed()): |
| 632 | return unicode(kb.getText(), "utf-8") |
| 633 | return '' |
| 634 | |
| 635 | # Login to grooveshark |
| 636 | def _get_login(self): |
| 637 | if (self.username == "" or self.password == ""): |
| 638 | dialog = xbmcgui.Dialog() |
| 639 | dialog.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.') |
| 640 | return 0 |
| 641 | else: |
| 642 | if self.userid == 0: |
| 643 | uid = groovesharkApi.login(self.username, self.password) |
| 644 | if (uid != 0): |
| 645 | return uid |
| 646 | else: |
| 647 | dialog = xbmcgui.Dialog() |
| 648 | dialog.ok('Grooveshark XBMC', 'Unable to login.', 'Check username and password in settings.') |
| 649 | return 0 |
| 650 | |
| 651 | # Get a song directory item |
| 652 | def _get_song_item(self, song, trackLabelFormat): |
| 653 | name = song[0] |
| 654 | songid = song[1] |
| 655 | album = song[2] |
| 656 | artist = song[4] |
| 657 | coverart = song[6] |
| 658 | return self.songItem(songid, name, album, artist, coverart, trackLabelFormat) |
| 659 | |
| 660 | # File download |
| 661 | def _get_icon(self, url, songid): |
| 662 | if url != 'None': |
| 663 | localThumb = os.path.join(xbmc.translatePath(os.path.join(thumbDir, str(songid)))) + '.tbn' |
| 664 | try: |
| 665 | if os.path.isfile(localThumb) == False: |
| 666 | loc = urllib.URLopener() |
| 667 | loc.retrieve(url, localThumb) |
| 668 | except: |
| 669 | shutil.copy2(thumbDef, localThumb) |
| 670 | return os.path.join(os.path.join(thumbDir, str(songid))) + '.tbn' |
| 671 | else: |
| 672 | return thumbDef |
| 673 | |
| 674 | # Add songs to directory |
| 675 | def _add_songs_directory(self, songs, trackLabelFormat=ARTIST_ALBUM_NAME_LABEL, page=0, playlistid=0, playlistname='', isFavorites=False): |
| 676 | |
| 677 | totalSongs = len(songs) |
| 678 | page = int(page) |
| 679 | |
| 680 | # No pages needed |
| 681 | if page == 0 and totalSongs <= self.songspagelimit: |
| 682 | xbmc.log("Found " + str(totalSongs) + " songs...") |
| 683 | # Pages |
| 684 | else: |
| 685 | # Cache all songs |
| 686 | if page == 0: |
| 687 | self._setSavedSongs(songs) |
| 688 | else: |
| 689 | songs = self._getSavedSongs() |
| 690 | totalSongs = len(songs) |
| 691 | |
| 692 | if totalSongs > 0: |
| 693 | start = page * self.songspagelimit |
| 694 | end = start + self.songspagelimit |
| 695 | songs = songs[start:end] |
| 696 | |
| 697 | id = 0 |
| 698 | for song in songs: |
| 699 | item = self._get_song_item(song, trackLabelFormat) |
| 700 | coverart = item.getProperty('coverart') |
| 701 | songname = song[0] |
| 702 | songid = song[1] |
| 703 | songalbum = song[2] |
| 704 | songartist = song[4] |
| 705 | |
| 706 | |
| 707 | u=sys.argv[0]+"?mode="+str(MODE_SONG)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid) \ |
| 708 | +"&album="+urllib.quote_plus(songalbum) \ |
| 709 | +"&artist="+urllib.quote_plus(songartist) \ |
| 710 | +"&coverart="+urllib.quote_plus(coverart) |
| 711 | fav=sys.argv[0]+"?mode="+str(MODE_FAVORITE)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid) |
| 712 | unfav=sys.argv[0]+"?mode="+str(MODE_UNFAVORITE)+"&name="+urllib.quote_plus(songname)+"&id="+str(songid)+"&prevmode=" |
| 713 | menuItems = [] |
| 714 | if isFavorites == True: |
| 715 | unfav = unfav +str(MODE_FAVORITES) |
| 716 | else: |
| 717 | menuItems.append(("Grooveshark favorite", "XBMC.RunPlugin("+fav+")")) |
| 718 | menuItems.append(("Not Grooveshark favorite", "XBMC.RunPlugin("+unfav+")")) |
| 719 | if playlistid > 0: |
| 720 | rmplaylstsong=sys.argv[0]+"?playlistid="+str(playlistid)+"&id="+str(songid)+"&mode="+str(MODE_REMOVE_PLAYLIST_SONG)+"&name="+playlistname |
| 721 | menuItems.append(("Remove from Grooveshark playlist", "XBMC.RunPlugin("+rmplaylstsong+")")) |
| 722 | else: |
| 723 | addplaylstsong=sys.argv[0]+"?id="+str(songid)+"&mode="+str(MODE_ADD_PLAYLIST_SONG) |
| 724 | menuItems.append(("Add to Grooveshark playlist", "XBMC.RunPlugin("+addplaylstsong+")")) |
| 725 | item.addContextMenuItems(menuItems, replaceItems=False) |
| 726 | xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=item,isFolder=False, totalItems=len(songs)) |
| 727 | id = id + 1 |
| 728 | |
| 729 | page = page + 1 |
| 730 | if totalSongs > page * self.songspagelimit: |
| 731 | u=sys.argv[0]+"?mode="+str(MODE_SONG_PAGE)+"&id=playlistid"+"&page="+str(page)+"&label="+str(trackLabelFormat)+"&name="+playlistname |
| 732 | self._add_dir('More songs...', u, MODE_SONG_PAGE, self.songImg, 0, totalSongs - (page * self.songspagelimit)) |
| 733 | |
| 734 | xbmcplugin.setContent(self._handle, 'songs') |
| 735 | xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg) |
| 736 | |
| 737 | # Add albums to directory |
| 738 | def _add_albums_directory(self, albums, artistid=0): |
| 739 | n = len(albums) |
| 740 | xbmc.log("Found " + str(n) + " albums...") |
| 741 | i = 0 |
| 742 | while i < n: |
| 743 | album = albums[i] |
| 744 | albumArtistName = album[0] |
| 745 | albumName = album[2] |
| 746 | albumID = album[3] |
| 747 | albumImage = self._get_icon(album[4], 'album-' + str(albumID)) |
| 748 | self._add_dir(albumName + " - " + albumArtistName, '', MODE_ALBUM, albumImage, albumID, n) |
| 749 | i = i + 1 |
| 750 | # Not supported by key |
| 751 | #if artistid > 0: |
| 752 | # self._add_dir('Similar artists...', '', MODE_SIMILAR_ARTISTS, self.artistImg, artistid) |
| 753 | xbmcplugin.setContent(self._handle, 'albums') |
| 754 | xbmcplugin.addSortMethod(self._handle, xbmcplugin.SORT_METHOD_ALBUM_IGNORE_THE) |
| 755 | xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg) |
| 756 | |
| 757 | # Add artists to directory |
| 758 | def _add_artists_directory(self, artists): |
| 759 | n = len(artists) |
| 760 | xbmc.log("Found " + str(n) + " artists...") |
| 761 | i = 0 |
| 762 | while i < n: |
| 763 | artist = artists[i] |
| 764 | artistName = artist[0] |
| 765 | artistID = artist[1] |
| 766 | self._add_dir(artistName, '', MODE_ARTIST, self.artistImg, artistID, n) |
| 767 | i = i + 1 |
| 768 | xbmcplugin.setContent(self._handle, 'artists') |
| 769 | xbmcplugin.addSortMethod(self._handle, xbmcplugin.SORT_METHOD_ARTIST_IGNORE_THE) |
| 770 | xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg) |
| 771 | |
| 772 | # Add playlists to directory |
| 773 | def _add_playlists_directory(self, playlists): |
| 774 | n = len(playlists) |
| 775 | xbmc.log("Found " + str(n) + " playlists...") |
| 776 | i = 0 |
| 777 | while i < n: |
| 778 | playlist = playlists[i] |
| 779 | playlistName = playlist[0] |
| 780 | playlistID = playlist[1] |
| 781 | dir = self._add_dir(playlistName, '', MODE_PLAYLIST, self.playlistImg, playlistID, n) |
| 782 | i = i + 1 |
| 783 | xbmcplugin.setContent(self._handle, 'files') |
| 784 | xbmcplugin.addSortMethod(self._handle, xbmcplugin.SORT_METHOD_LABEL) |
| 785 | xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg) |
| 786 | |
| 787 | # Add whatever directory |
| 788 | def _add_dir(self, name, url, mode, iconimage, id, items=1): |
| 789 | |
| 790 | if url == '': |
| 791 | u=sys.argv[0]+"?mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&id="+str(id) |
| 792 | else: |
| 793 | u = url |
| 794 | dir=xbmcgui.ListItem(name, iconImage=iconimage, thumbnailImage=iconimage) |
| 795 | dir.setInfo( type="Music", infoLabels={ "title": name } ) |
| 796 | |
| 797 | # Custom menu items |
| 798 | menuItems = [] |
| 799 | if mode == MODE_ALBUM: |
| 800 | mkplaylst=sys.argv[0]+"?mode="+str(MODE_MAKE_PLAYLIST)+"&name="+name+"&id="+str(id) |
| 801 | menuItems.append(("Make Grooveshark playlist", "XBMC.RunPlugin("+mkplaylst+")")) |
| 802 | # Broken rename/delete are broken in API |
| 803 | if mode == MODE_PLAYLIST: |
| 804 | rmplaylst=sys.argv[0]+"?mode="+str(MODE_REMOVE_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id) |
| 805 | menuItems.append(("Delete Grooveshark playlist", "XBMC.RunPlugin("+rmplaylst+")")) |
| 806 | mvplaylst=sys.argv[0]+"?mode="+str(MODE_RENAME_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id) |
| 807 | menuItems.append(("Rename Grooveshark playlist", "XBMC.RunPlugin("+mvplaylst+")")) |
| 808 | dir.addContextMenuItems(menuItems, replaceItems=False) |
| 809 | |
| 810 | return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=dir,isFolder=True, totalItems=items) |
| 811 | |
| 812 | def _getSavedSongs(self): |
| 813 | path = os.path.join(cacheDir, 'songs.dmp') |
| 814 | try: |
| 815 | f = open(path, 'rb') |
| 816 | songs = pickle.load(f) |
| 817 | f.close() |
| 818 | except: |
| 819 | songs = [] |
| 820 | pass |
| 821 | return songs |
| 822 | |
| 823 | def _setSavedSongs(self, songs): |
| 824 | try: |
| 825 | # Create the 'data' directory if it doesn't exist. |
| 826 | if not os.path.exists(cacheDir): |
| 827 | os.makedirs(cacheDir) |
| 828 | path = os.path.join(cacheDir, 'songs.dmp') |
| 829 | f = open(path, 'wb') |
| 830 | pickle.dump(songs, f, protocol=pickle.HIGHEST_PROTOCOL) |
| 831 | f.close() |
| 832 | except: |
| 833 | xbmc.log("An error occurred saving songs") |
| 834 | pass |
| 835 | |
| 836 | def _getSongDuration(self, songid): |
| 837 | path = os.path.join(cacheDir, 'duration.dmp') |
| 838 | id = int(songid) |
| 839 | durations = [] |
| 840 | duration = -1 |
| 841 | |
| 842 | # Try cache first |
| 843 | try: |
| 844 | f = open(path, 'rb') |
| 845 | durations = pickle.load(f) |
| 846 | for song in durations: |
| 847 | if song[0] == id: |
| 848 | duration = song[1] |
| 849 | f.close() |
| 850 | except: |
| 851 | pass |
| 852 | |
| 853 | if duration < 0: |
| 854 | stream = groovesharkApi.getSubscriberStreamKey(songid) |
| 855 | usecs = stream['uSecs'] |
| 856 | if usecs < 60000000: |
| 857 | usecs = usecs * 10 # Some durations are 10x to small |
| 858 | duration = usecs / 1000000 |
| 859 | song = [id, duration] |
| 860 | durations.append(song) |
| 861 | self._setSongDuration(durations) |
| 862 | |
| 863 | return duration |
| 864 | |
| 865 | def _setSongDuration(self, durations): |
| 866 | try: |
| 867 | # Create the 'data' directory if it doesn't exist. |
| 868 | if not os.path.exists(cacheDir): |
| 869 | os.makedirs(cacheDir) |
| 870 | path = os.path.join(cacheDir, 'duration.dmp') |
| 871 | f = open(path, 'wb') |
| 872 | pickle.dump(durations, f, protocol=pickle.HIGHEST_PROTOCOL) |
| 873 | f.close() |
| 874 | except: |
| 875 | xbmc.log("An error occurred saving durations") |
| 876 | pass |
| 877 | |
| 878 | |
| 879 | # Parse URL parameters |
| 880 | def get_params(): |
| 881 | param=[] |
| 882 | paramstring=sys.argv[2] |
| 883 | xbmc.log(paramstring) |
| 884 | if len(paramstring)>=2: |
| 885 | params=sys.argv[2] |
| 886 | cleanedparams=params.replace('?','') |
| 887 | if (params[len(params)-1]=='/'): |
| 888 | params=params[0:len(params)-2] |
| 889 | pairsofparams=cleanedparams.split('&') |
| 890 | param={} |
| 891 | for i in range(len(pairsofparams)): |
| 892 | splitparams={} |
| 893 | splitparams=pairsofparams[i].split('=') |
| 894 | if (len(splitparams))==2: |
| 895 | param[splitparams[0]]=splitparams[1] |
| 896 | return param |
| 897 | |
| 898 | # Main |
| 899 | grooveshark = Groveshark(); |
| 900 | |
| 901 | params=get_params() |
| 902 | mode=None |
| 903 | try: mode=int(params["mode"]) |
| 904 | except: pass |
| 905 | id=0 |
| 906 | try: id=int(params["id"]) |
| 907 | except: pass |
| 908 | name = None |
| 909 | try: name=urllib.unquote_plus(params["name"]) |
| 910 | except: pass |
| 911 | |
| 912 | # Call function for URL |
| 913 | if mode==None: |
| 914 | grooveshark.categories() |
| 915 | |
| 916 | elif mode==MODE_SEARCH_SONGS: |
| 917 | grooveshark.searchSongs() |
| 918 | |
| 919 | elif mode==MODE_SEARCH_ALBUMS: |
| 920 | grooveshark.searchAlbums() |
| 921 | |
| 922 | elif mode==MODE_SEARCH_ARTISTS: |
| 923 | grooveshark.searchArtists() |
| 924 | |
| 925 | elif mode==MODE_SEARCH_ARTISTS_ALBUMS: |
| 926 | grooveshark.searchArtistsAlbums(name) |
| 927 | |
| 928 | elif mode==MODE_SEARCH_PLAYLISTS: |
| 929 | grooveshark.searchPlaylists() |
| 930 | |
| 931 | elif mode==MODE_POPULAR_SONGS: |
| 932 | grooveshark.popularSongs() |
| 933 | |
| 934 | elif mode==MODE_ARTIST_POPULAR: |
| 935 | grooveshark.artistPopularSongs() |
| 936 | |
| 937 | elif mode==MODE_FAVORITES: |
| 938 | grooveshark.favorites() |
| 939 | |
| 940 | elif mode==MODE_PLAYLISTS: |
| 941 | grooveshark.playlists() |
| 942 | |
| 943 | elif mode==MODE_SONG_PAGE: |
| 944 | try: page=urllib.unquote_plus(params["page"]) |
| 945 | except: pass |
| 946 | try: label=urllib.unquote_plus(params["label"]) |
| 947 | except: pass |
| 948 | grooveshark.songPage(page, label, id, name) |
| 949 | |
| 950 | elif mode==MODE_SONG: |
| 951 | try: album=urllib.unquote_plus(params["album"]) |
| 952 | except: pass |
| 953 | try: artist=urllib.unquote_plus(params["artist"]) |
| 954 | except: pass |
| 955 | try: coverart=urllib.unquote_plus(params["coverart"]) |
| 956 | except: pass |
| 957 | song = grooveshark.songItem(id, name, album, artist, coverart) |
| 958 | grooveshark.playSong(song) |
| 959 | |
| 960 | elif mode==MODE_ARTIST: |
| 961 | grooveshark.artist(id) |
| 962 | |
| 963 | elif mode==MODE_ALBUM: |
| 964 | grooveshark.album(id) |
| 965 | |
| 966 | elif mode==MODE_PLAYLIST: |
| 967 | grooveshark.playlist(id, name) |
| 968 | |
| 969 | elif mode==MODE_FAVORITE: |
| 970 | grooveshark.favorite(id) |
| 971 | |
| 972 | elif mode==MODE_UNFAVORITE: |
| 973 | try: prevMode=int(urllib.unquote_plus(params["prevmode"])) |
| 974 | except: |
| 975 | prevMode = 0 |
| 976 | grooveshark.unfavorite(id, prevMode) |
| 977 | |
| 978 | elif mode==MODE_SIMILAR_ARTISTS: |
| 979 | grooveshark.similarArtists(id) |
| 980 | |
| 981 | elif mode==MODE_MAKE_PLAYLIST: |
| 982 | grooveshark.makePlaylist(id, name) |
| 983 | |
| 984 | elif mode==MODE_REMOVE_PLAYLIST: |
| 985 | grooveshark.removePlaylist(id, name) |
| 986 | |
| 987 | elif mode==MODE_RENAME_PLAYLIST: |
| 988 | grooveshark.renamePlaylist(id, name) |
| 989 | |
| 990 | elif mode==MODE_REMOVE_PLAYLIST_SONG: |
| 991 | try: playlistID=urllib.unquote_plus(params["playlistid"]) |
| 992 | except: pass |
| 993 | grooveshark.removePlaylistSong(playlistID, name, id) |
| 994 | |
| 995 | elif mode==MODE_ADD_PLAYLIST_SONG: |
| 996 | grooveshark.addPlaylistSong(id) |
| 997 | |
| 998 | if mode < MODE_SONG: |
| 999 | xbmcplugin.endOfDirectory(int(sys.argv[1])) |