+ stream = self._getSongStream(songid)
+ if stream != False:
+ duration = stream[1]
+ url = stream[2]
+ key = stream[3]
+ server = stream[4]
+ songImg = self._get_icon(coverart, 'song-' + str(songid) + "-image")
+ if int(trackLabelFormat) == NAME_ALBUM_ARTIST_LABEL:
+ trackLabel = name + " - " + album + " - " + artist
+ else:
+ trackLabel = artist + " - " + album + " - " + name
+ item = xbmcgui.ListItem(label = trackLabel, thumbnailImage=songImg, iconImage=songImg)
+ item.setPath(url)
+ item.setInfo( type="music", infoLabels={ "title": name, "album": album, "artist": artist, "duration": duration, "tracknumber" : tracknumber} )
+ item.setProperty('mimetype', 'audio/mpeg')
+ item.setProperty("IsPlayable", "true")
+ item.setProperty('songid', str(songid))
+ item.setProperty('coverart', songImg)
+ item.setProperty('title', name)
+ item.setProperty('album', album)
+ item.setProperty('artist', artist)
+ item.setProperty('duration', str(duration))
+ item.setProperty('key', str(key))
+ item.setProperty('server', str(server))
+ return item
+ else:
+ xbmc.log("No song URL")
+ return None
+
+ # Next page of songs
+ def songPage(self, offset, trackLabelFormat, playlistid = 0, playlistname = ''):
+ self._add_songs_directory([], trackLabelFormat, offset, playlistid = playlistid, playlistname = playlistname)
+
+ # Make a playlist from an album
+ def makePlaylist(self, albumid, name):
+ userid = self._get_login()
+ if (userid != 0):
+ re.split(' - ',name,1)
+ nameTokens = re.split(' - ',name,1) # suggested name
+ name = self._get_keyboard(default=nameTokens[0], heading=__language__(30045))
+ if name != '':
+ album = groovesharkApi.getAlbumSongs(albumid, limit = self.songsearchlimit)
+ songids = []
+ for song in album:
+ songids.append(song[1])
+ if groovesharkApi.createPlaylist(name, songids) == 0:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30046), name)
+ else:
+ xbmc.executebuiltin('XBMC.Notification(' + __language__(30008) + ',' + __language__(30047)+ ', 1000, ' + thumbDef + ')')
+ else:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30034), __language__(30048))
+
+ # Rename a playlist
+ def renamePlaylist(self, playlistid, name):
+ userid = self._get_login()
+ if (userid != 0):
+ newname = self._get_keyboard(default=name, heading=__language__(30049))
+ if newname == '':
+ return
+ elif groovesharkApi.playlistRename(playlistid, newname) == 0:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30050), name)
+ else:
+ # Refresh to show new item name
+ xbmc.executebuiltin("Container.Refresh")
+ else:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30034), __language__(30051))
+
+ # Remove a playlist
+ def removePlaylist(self, playlistid, name):
+ dialog = xbmcgui.Dialog()
+ if dialog.yesno(__language__(30008), name, __language__(30052)) == True:
+ userid = self._get_login()
+ if (userid != 0):
+ if groovesharkApi.playlistDelete(playlistid) == 0:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30053), name)
+ else:
+ # Refresh to remove item from directory
+ xbmc.executebuiltin("Container.Refresh(" + playlistsUrl + ")")
+ else:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30034), __language__(30054))
+
+ # Add song to playlist
+ def addPlaylistSong(self, songid):
+ userid = self._get_login()
+ if (userid != 0):
+ playlists = groovesharkApi.getUserPlaylists()
+ if (len(playlists) > 0):
+ ret = 0
+ # Select the playlist
+ playlistSelect = GroovesharkPlaylistSelect(items=playlists)
+ playlistSelect.setFocus(playlistSelect.playlistControl)
+ playlistSelect.doModal()
+ i = playlistSelect.selected
+ del playlistSelect
+ if i > -1:
+ # Add a new playlist
+ if i >= len(playlists):
+ name = self._get_keyboard(default='', heading=__language__(30055))
+ if name != '':
+ songIds = []
+ songIds.append(songid)
+ if groovesharkApi.createPlaylist(name, songIds) == 0:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30056), name)
+ else:
+ xbmc.executebuiltin('XBMC.Notification(' + __language__(30008) + ',' + __language__(30057) + ', 1000, ' + thumbDef + ')')
+ # Existing playlist
+ else:
+ playlist = playlists[i]
+ playlistid = playlist[1]
+ if __debugging__ :
+ xbmc.log("Add song " + str(songid) + " to playlist " + str(playlistid))
+ songIDs=[]
+ songs = groovesharkApi.getPlaylistSongs(playlistid)
+ for song in songs:
+ songIDs.append(song[1])
+ songIDs.append(songid)
+ ret = groovesharkApi.setPlaylistSongs(playlistid, songIDs)
+ if ret == False:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30058))
+ else:
+ xbmc.executebuiltin('XBMC.Notification(' + __language__(30008) + ',' + __language__(30059) + ', 1000, ' + thumbDef + ')')
+ else:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30060))
+ self.categories()
+ else:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30034), __language__(30061))
+
+ # Remove song from playlist
+ def removePlaylistSong(self, playlistid, playlistname, songid):
+ dialog = xbmcgui.Dialog()
+ if dialog.yesno(__language__(30008), __language__(30062), __language__(30063)) == True:
+ userid = self._get_login()
+ if (userid != 0):
+ songs = groovesharkApi.getPlaylistSongs(playlistID)
+ songIDs=[]
+ for song in songs:
+ if (song[1] != songid):
+ songIDs.append(song[1])
+ ret = groovesharkApi.setPlaylistSongs(playlistID, songIDs)
+ if ret == False:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30064), __language__(30065))
+ else:
+ # Refresh to remove item from directory
+ xbmc.executebuiltin('XBMC.Notification(' + __language__(30008) + ',' + __language__(30066)+ ', 1000, ' + thumbDef + ')')
+ xbmc.executebuiltin("Container.Update(" + playlistUrl + "&id="+str(playlistid) + "&name=" + playlistname + ")")
+ else:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30034), __language__(30067))
+
+ # Find similar artists to searched artist
+ def similarArtists(self, artistId):
+ similar = groovesharkApi.getSimilarArtists(artistId, limit = self.artistsearchlimit)
+ if (len(similar) > 0):
+ self._add_artists_directory(similar)
+ else:
+ dialog = xbmcgui.Dialog()
+ dialog.ok(__language__(30008), __language__(30068))
+ self.categories()