Skip to content

Commit

Permalink
disable echo nest components
Browse files Browse the repository at this point in the history
  • Loading branch information
plamere committed Sep 17, 2017
1 parent b8abcda commit 310264d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions server/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down Expand Up @@ -807,6 +808,7 @@
"name" : "EchoNestArtist",
"class": pbl.EchoNestArtistPlaylist,
"type" : "source",
'disabled': True,
"display": "artist tracks",
"description": "tracks by the given artist",

Expand Down
43 changes: 42 additions & 1 deletion server/plugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(':')
Expand Down

0 comments on commit 310264d

Please sign in to comment.