Is there a reason my Python code is not recognising a status() change when the current song changes on Web Radio, but does when I play a Flac from my network drive? My code is trying to get the current song title to display.
Thanks
Is there a reason my Python code is not recognising a status() change when the current song changes on Web Radio, but does when I play a Flac from my network drive? My code is trying to get the current song title to display.
Thanks
perhaps the status remains playing because it’s a webradio stream?
Can you check a title change?
just my 2 cents…
.Nico
Could be, certainly putting debug prints in my code shows nothing.
I wonder how Volumio manages to update the titles though?
Can you show us your code? Very hard to suggest otherwise…
Of course, thanks for taking an interest.
I think the key section is the While loop below.
I attempted to attach the complete file but .txt and .py are not permitted and was not sure what to try after that.
Sorry to be a bit of a noob!
[code] try:
#preamp = PreampClient()
#preamp.open()
volumio = VolumioClient()
volumio.connect()
# Retrieve the state first to be able to determine changes to it
last_state = volumio._client.status()
while True:
print('main loop')
result = volumio.idle()
new_state = volumio._client.status()
#logger.info("Volumio result: " + str(result))
#logger.info("Client status: " + str(new_state))
if 'player' in result:
if last_state['state'] != 'stop' and new_state['state'] == 'stop':
print("Player state changed to 'stop', remove the title")
#preamp.write("input set 9")
if last_state['state'] != 'pause' and new_state['state'] == 'pause':
print("Player state changed to 'pause', remove the title")
#preamp.write("input set 9")
if last_state['state'] == 'stop' or last_state['state'] == 'pause' and new_state['state'] == 'play':
print("Player state changed to 'play', power on preamp")
#preamp.write("power on")
time.sleep(2);
print("Set preamp input to Raspberry Pi")
#preamp.write("input set 9")
time.sleep(1);
if new_state['state'] == 'play':
update_title = False
# Update the title when the player status changes to 'play'
if last_state['state'] != 'play':
print("Player state changed to 'play', lets update the title")
update_title = True
else:
# Or update the title when the song id changed
if 'songid' in last_state:
last_songid = last_state['songid']
else:
last_songid = -1
if 'songid' in new_state:
new_songid = new_state['songid']
if last_songid != new_songid:
print("Songid changed, lets update the title")
update_title = True
if update_title:
currentsong = volumio._client.currentsong()
print("Current song result: " + str(currentsong))
if 'title' in currentsong:
title = str(currentsong['title'])
else:
title = 'No title'
# Limit title size to 70 characters
title = title[:70]
#logger.info("Set preamp title to: " + title)
print("Display would be this: " + title)
# Keep the last state to determine changes to it
last_state = new_state
except (KeyboardInterrupt, SystemExit):
print("Keyboard or system exit interrupt");
#logger.info("Script stopped, power of preamp")
#preamp.write("power off")
volumio.disconnect();
#preamp.close();
print('exited')
sys.exit();
# Catch all other non-exit errors
except Exception as e:
logger.error(e)
sys.exit(1)
except:
logger.info("unknown exception, exiting");
sys.exit(0)
[/code]
I have put the code up here:
https://forum.volumio.org/status-t14261.html
I hope someone will be able to help me with this.