diff --git a/server/components.py b/server/components.py index 9c15d07..691ed9a 100644 --- a/server/components.py +++ b/server/components.py @@ -729,6 +729,7 @@ "name" : "EchoNestGenreRadio", "class": pbl.EchoNestGenreRadio, "type" : "source", + 'disabled': True, "display": "genre radio", "description": "generates a series of tracks in the given genre", @@ -807,6 +808,7 @@ "name" : "EchoNestArtist", "class": pbl.EchoNestArtistPlaylist, "type" : "source", + 'disabled': True, "display": "artist tracks", "description": "tracks by the given artist", diff --git a/server/plugs.py b/server/plugs.py index 6b6a5cc..81e15a5 100644 --- a/server/plugs.py +++ b/server/plugs.py @@ -1298,7 +1298,7 @@ def next_track(self): return None class SpotifyArtistRadio(object): - ''' returns tracks given a seed artist + ''' returns artist radio tracks given a seed artist :param seed_artist_name_or_uri the name or uri of the seed artist @@ -1336,6 +1336,47 @@ def next_track(self): else: return None +class SpotifyArtistTracks(object): + ''' returns top tracks given a seed artist + + :param seed_artist_name_or_uri the name or uri of the seed artist + + ''' + def __init__(self, seed_artist_name_or_uri): + self.name = 'Artist Top Tracks' + self.seed_artist_name_or_uri = seed_artist_name_or_uri + self.buffer = None + + # TODO: this just returns the top 10 tracks, need to add more + + def next_track(self): + if self.buffer == None: + self.buffer = [] + try: + sp = get_spotify() + + if is_uri(self.seed_artist_name_or_uri): + seed_uri = self.seed_artist_name_or_uri + else: + seed_uri = get_artist_uri(self.seed_artist_name_or_uri) + + if seed_uri: + results = sp.artist_top_tracks(seed_uri) + for track in results['tracks']: + if track and 'id' in track: + self.buffer.append(track['id']) + spotify_plugs._add_track(self.name, track) + else: + raise pbl.engine.PBLException(self, 'bad track') + except spotipy.SpotifyException as e: + raise pbl.engine.PBLException(self, e.msg) + + if len(self.buffer) > 0: + tid = self.buffer.pop(0) + return tid + else: + return None + def is_uri(s): fields = s.split(':')