Fetching 50 recommendations, and storing results to add 3x at a time to avoid locking server; Fixes #149
This commit is contained in:
@ -26,7 +26,8 @@ class IrisCore(object):
|
||||
"enabled": 0,
|
||||
"seed_artists": [],
|
||||
"seed_genres": [],
|
||||
"seed_tracks": []
|
||||
"seed_tracks": [],
|
||||
"results": []
|
||||
}
|
||||
|
||||
|
||||
@ -267,6 +268,7 @@ class IrisCore(object):
|
||||
# fetch more tracks from Mopidy-Spotify
|
||||
self.radio = data
|
||||
self.radio['enabled'] = 1;
|
||||
self.radio['results'] = [];
|
||||
uris = self.load_more_tracks()
|
||||
|
||||
# make sure we got recommendations
|
||||
@ -275,7 +277,12 @@ class IrisCore(object):
|
||||
self.core.tracklist.clear()
|
||||
|
||||
self.core.tracklist.set_consume(True)
|
||||
added = self.core.tracklist.add(uris = uris)
|
||||
|
||||
# We only want to play the first batch
|
||||
added = self.core.tracklist.add(uris = uris[0:3])
|
||||
|
||||
# Save results (minus first batch) for later use
|
||||
self.radio['results'] = uris[3:]
|
||||
|
||||
if added.get():
|
||||
if starting:
|
||||
@ -307,7 +314,8 @@ class IrisCore(object):
|
||||
"enabled": 0,
|
||||
"seed_artists": [],
|
||||
"seed_genres": [],
|
||||
"seed_tracks": []
|
||||
"seed_tracks": [],
|
||||
"results": []
|
||||
}
|
||||
|
||||
# restore initial consume state
|
||||
@ -343,13 +351,14 @@ class IrisCore(object):
|
||||
|
||||
try:
|
||||
spotify = Spotify( auth = token )
|
||||
response = spotify.recommendations(seed_artists = self.radio['seed_artists'], seed_genres = self.radio['seed_genres'], seed_tracks = self.radio['seed_tracks'], limit = 5)
|
||||
response = spotify.recommendations(seed_artists = self.radio['seed_artists'], seed_genres = self.radio['seed_genres'], seed_tracks = self.radio['seed_tracks'], limit = 50)
|
||||
|
||||
uris = []
|
||||
for track in response['tracks']:
|
||||
uris.append( track['uri'] )
|
||||
|
||||
|
||||
return uris
|
||||
|
||||
except:
|
||||
logger.error('IrisFrontend: Failed to fetch Spotify recommendations')
|
||||
self.broadcast({
|
||||
@ -357,25 +366,27 @@ class IrisCore(object):
|
||||
'message': 'Could not get radio tracks',
|
||||
'source': 'load_more_tracks'
|
||||
})
|
||||
return False
|
||||
return []
|
||||
|
||||
|
||||
def check_for_radio_update( self ):
|
||||
tracklistLength = self.core.tracklist.length.get()
|
||||
if( tracklistLength <= 5 and self.radio['enabled'] == 1 ):
|
||||
if( tracklistLength < 3 and self.radio['enabled'] == 1 ):
|
||||
|
||||
uris = self.load_more_tracks()
|
||||
# Grab our loaded tracks
|
||||
uris = self.radio['results']
|
||||
|
||||
if not uris:
|
||||
self.broadcast({
|
||||
'type': 'error',
|
||||
'message': 'Could not fetch tracklist length',
|
||||
'source': 'check_for_radio_update'
|
||||
})
|
||||
logger.warning('IrisFrontend: Could not fetch tracklist length')
|
||||
# We've run out of pre-fetched tracks, so we need to get more recommendations
|
||||
if (len(uris) < 3):
|
||||
uris = self.load_more_tracks()
|
||||
|
||||
else:
|
||||
self.core.tracklist.add(uris = uris)
|
||||
# Remove the next batch, and update our results
|
||||
self.radio['results'] = uris[3:]
|
||||
|
||||
# Only add the next set of uris
|
||||
uris = uris[0:3]
|
||||
|
||||
self.core.tracklist.add(uris = uris)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user