Start/update radio as change_radio
This commit is contained in:
@ -21,6 +21,7 @@ class IrisCore(object):
|
||||
spotify_token = False
|
||||
queue_metadata = {}
|
||||
connections = {}
|
||||
initial_consume = False
|
||||
radio = {
|
||||
"enabled": 0,
|
||||
"seed_artists": [],
|
||||
@ -252,62 +253,54 @@ class IrisCore(object):
|
||||
'radio': self.radio
|
||||
}
|
||||
|
||||
def start_radio(self, data):
|
||||
def change_radio(self, data):
|
||||
|
||||
# figure out if we're starting or updating radio mode
|
||||
if self.radio['enabled']:
|
||||
starting = False
|
||||
self.initial_consume = self.core.tracklist.get_consume()
|
||||
else:
|
||||
starting = True
|
||||
|
||||
# fetch more tracks from Mopidy-Spotify
|
||||
self.radio = data
|
||||
self.radio['enabled'] = 1;
|
||||
|
||||
uris = self.load_more_tracks()
|
||||
|
||||
# no uris means we can't play radio
|
||||
if not uris:
|
||||
self.radio['enabled'] = 0
|
||||
return {
|
||||
'status': 0,
|
||||
'message': 'No recommendations found',
|
||||
'radio': self.radio
|
||||
}
|
||||
|
||||
# if we got recommendations
|
||||
else:
|
||||
# make sure we got recommendations
|
||||
if uris:
|
||||
if starting:
|
||||
self.core.tracklist.clear()
|
||||
self.core.tracklist.set_consume( True )
|
||||
self.core.tracklist.add( uris = uris )
|
||||
self.core.playback.play()
|
||||
|
||||
self.core.tracklist.set_consume(True)
|
||||
added = self.core.tracklist.add(uris = uris)
|
||||
|
||||
if added.get():
|
||||
if starting:
|
||||
self.core.playback.play()
|
||||
self.broadcast({
|
||||
'type': 'radio_started',
|
||||
'radio': self.radio
|
||||
})
|
||||
|
||||
return self.get_radio({})
|
||||
|
||||
def update_radio(self, data):
|
||||
self.radio = data
|
||||
self.radio['enabled'] = 1;
|
||||
|
||||
uris = self.load_more_tracks()
|
||||
|
||||
# no uris means we can't play radio
|
||||
if not uris:
|
||||
self.radio['enabled'] = 0
|
||||
return {
|
||||
'status': 0,
|
||||
'message': 'No recommendations found',
|
||||
'radio': self.radio
|
||||
}
|
||||
|
||||
# if we got recommendations
|
||||
else:
|
||||
self.core.tracklist.add( uris = uris )
|
||||
self.broadcast({
|
||||
'type': 'radio_updated',
|
||||
'type': 'radio_changed',
|
||||
'radio': self.radio
|
||||
})
|
||||
|
||||
return self.get_radio({})
|
||||
|
||||
# failed fetching/adding tracks, so no-go
|
||||
self.radio['enabled'] = 0;
|
||||
return {
|
||||
'status': 0,
|
||||
'message': 'Could not start radio',
|
||||
'radio': self.radio
|
||||
}
|
||||
|
||||
|
||||
def stop_radio(self, data):
|
||||
|
||||
self.radio = {
|
||||
"enabled": 0,
|
||||
"seed_artists": [],
|
||||
@ -315,6 +308,8 @@ class IrisCore(object):
|
||||
"seed_tracks": []
|
||||
}
|
||||
|
||||
# restore initial consume state
|
||||
self.core.tracklist.set_consume(self.initial_consume)
|
||||
self.core.playback.stop()
|
||||
|
||||
self.broadcast({
|
||||
|
||||
@ -244,15 +244,13 @@ const PusherMiddleware = (function(){
|
||||
|
||||
case 'PUSHER_START_RADIO':
|
||||
case 'PUSHER_UPDATE_RADIO':
|
||||
if (action.type == 'PUSHER_UPDATE_RADIO'){
|
||||
var method = 'update_radio'
|
||||
var process_text = 'Updating radio'
|
||||
} else {
|
||||
var method = 'start_radio'
|
||||
var process_text = 'Starting radio'
|
||||
}
|
||||
|
||||
store.dispatch(uiActions.startProcess('PUSHER_RADIO', process_text))
|
||||
// start our UI process notification
|
||||
if (action.type == 'PUSHER_UPDATE_RADIO'){
|
||||
store.dispatch(uiActions.startProcess('PUSHER_RADIO', 'Updating radio'))
|
||||
} else {
|
||||
store.dispatch(uiActions.startProcess('PUSHER_RADIO', 'Starting radio'))
|
||||
}
|
||||
|
||||
var data = {
|
||||
seed_artists: [],
|
||||
@ -274,8 +272,11 @@ const PusherMiddleware = (function(){
|
||||
}
|
||||
}
|
||||
|
||||
request(store, method, data)
|
||||
request(store, 'change_radio', data)
|
||||
.then(response => {
|
||||
if (response.status == 0){
|
||||
store.dispatch(uiActions.createNotification(response.message, 'bad'))
|
||||
}
|
||||
store.dispatch(uiActions.stopProcess('PUSHER_RADIO'))
|
||||
})
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user