X-Git-Url: https://git.hcoop.net/clinton/xbmc-groove.git/blobdiff_plain/c64c644c8947d11a07c2424f034fe0756b4211b8..df35aa069a65b5a8a64b686041c606a99d4b4ffe:/default.py diff --git a/default.py b/default.py index 2eba189..a750f09 100644 --- a/default.py +++ b/default.py @@ -26,6 +26,7 @@ __version__ = __addon__.getAddonInfo('version') __language__ = __addon__.getLocalizedString __debugging__ = __addon__.getSetting('debug') +# Directory listings must be < MODE_SONG MODE_SEARCH_SONGS = 1 MODE_SEARCH_ALBUMS = 2 MODE_SEARCH_ARTISTS = 3 @@ -40,14 +41,16 @@ MODE_ARTIST = 11 MODE_PLAYLIST = 12 MODE_SONG_PAGE = 13 MODE_SIMILAR_ARTISTS = 14 -MODE_SONG = 15 -MODE_FAVORITE = 16 -MODE_UNFAVORITE = 17 -MODE_MAKE_PLAYLIST = 18 -MODE_REMOVE_PLAYLIST = 19 -MODE_RENAME_PLAYLIST = 20 -MODE_REMOVE_PLAYLIST_SONG = 21 -MODE_ADD_PLAYLIST_SONG = 22 +MODE_ARTIST_POPULAR_FROM_ALBUMS = 15 +MODE_SONG = 150 + +MODE_FAVORITE = 160 +MODE_UNFAVORITE = 170 +MODE_MAKE_PLAYLIST = 180 +MODE_REMOVE_PLAYLIST = 190 +MODE_RENAME_PLAYLIST = 200 +MODE_REMOVE_PLAYLIST_SONG = 210 +MODE_ADD_PLAYLIST_SONG = 220 ACTION_MOVE_LEFT = 1 ACTION_MOVE_UP = 3 @@ -355,12 +358,14 @@ class Grooveshark: if (query != ''): artists = groovesharkApi.getArtistSearchResults(query, limit = self.artistsearchlimit) if (len(artists) > 0): - artist = artists[0] + # check for artist name match, first result is sometimes not the closest lexical match + artist = next ((a for a in artists if a[0].lower() == query.lower()), artists[0]) artistID = artist[1] if __debugging__ : xbmc.log("Found " + artist[0] + "...") albums = groovesharkApi.getArtistAlbums(artistID, self.albumsearchlimit) if (len(albums) > 0): + self._add_dir(__language__(30016), '', MODE_ARTIST_POPULAR_FROM_ALBUMS, self.popularSongsArtistImg, artistID) self._add_albums_directory(albums, artistID) else: dialog = xbmcgui.Dialog() @@ -446,7 +451,12 @@ class Grooveshark: # Show selected artist def artist(self, artistid): albums = groovesharkApi.getArtistAlbums(artistid, limit = self.albumsearchlimit) - self._add_albums_directory(albums, artistid, True) + if (len(albums) > 0): + self._add_dir(__language__(30016), '', MODE_ARTIST_POPULAR_FROM_ALBUMS, self.popularSongsArtistImg, artistid) + self._add_albums_directory(albums, artistid, True) + else: + # There are likely songs for the artist even when no verified albums are found + self.artistPopularSongs(artistid) # Show selected playlist def playlist(self, playlistid, playlistname): @@ -458,30 +468,38 @@ class Grooveshark: dialog = xbmcgui.Dialog() dialog.ok(__language__(30008), __language__(30034), __language__(30040)) - # Show popular songs of the artist - def artistPopularSongs(self): + # Search for artist show popular songs of the artist + def searchArtistPopularSongs(self): query = self._get_keyboard(default="", heading=__language__(30041)) - if (query != ''): + if (query != ''): artists = groovesharkApi.getArtistSearchResults(query, limit = self.artistsearchlimit) if (len(artists) > 0): - artist = artists[0] + # check for exact artist name match, sometimes a more + # popular artist is returned first (e.g. 'Angel Dust' + # gets you 'Faith No More' because of their popular + # album 'Angel Dust') + artist = next ((a for a in artists if a[0].lower() == query.lower()), artists[0]) artistID = artist[1] if __debugging__ : xbmc.log("Found " + artist[0] + "...") - songs = groovesharkApi.getArtistPopularSongs(artistID, limit = self.songsearchlimit) - if (len(songs) > 0): - self._add_songs_directory(songs, trackLabelFormat=NAME_ALBUM_ARTIST_LABEL) - else: - dialog = xbmcgui.Dialog() - dialog.ok(__language__(30008), __language__(30042)) - self.categories() + self.artistPopularSongs (artistID) else: dialog = xbmcgui.Dialog() dialog.ok(__language__(30008), __language__(30043)) self.categories() else: self.categories() - + + # Show popular songs of the artist + def artistPopularSongs(self, artistID): + songs = groovesharkApi.getArtistPopularSongs(artistID, limit = self.songsearchlimit) + if (len(songs) > 0): + self._add_songs_directory(songs, trackLabelFormat=NAME_ALBUM_ARTIST_LABEL) + else: + dialog = xbmcgui.Dialog() + dialog.ok(__language__(30008), __language__(30042)) + self.categories() + # Play a song def playSong(self, item): global playTimer @@ -823,13 +841,11 @@ class Grooveshark: while i < n: album = albums[i] albumID = album[3] - if isverified: - albumArtistName = album[0] - albumName = album[2] - albumImage = self._get_icon(album[4], 'album-' + str(albumID)) - self._add_dir(albumName + " - " + albumArtistName, '', MODE_ALBUM, albumImage, albumID, itemsExisting) - else: - itemsExisting = itemsExisting - 1 + + albumArtistName = album[0] + albumName = album[2] + albumImage = self._get_icon(album[4], 'album-' + str(albumID)) + self._add_dir(albumName + " - " + albumArtistName, '', MODE_ALBUM, albumImage, albumID, itemsExisting) i = i + 1 # Not supported by key #if artistid > 0: @@ -1062,7 +1078,7 @@ elif mode==MODE_POPULAR_SONGS: grooveshark.popularSongs() elif mode==MODE_ARTIST_POPULAR: - grooveshark.artistPopularSongs() + grooveshark.searchArtistPopularSongs() elif mode==MODE_FAVORITES: grooveshark.favorites() @@ -1124,6 +1140,9 @@ elif mode==MODE_REMOVE_PLAYLIST_SONG: elif mode==MODE_ADD_PLAYLIST_SONG: grooveshark.addPlaylistSong(itemId) + +elif mode==MODE_ARTIST_POPULAR_FROM_ALBUMS: + grooveshark.artistPopularSongs(itemId) if mode < MODE_SONG: xbmcplugin.endOfDirectory(int(sys.argv[1]))