Airplay Pirate Radio safe pwr off button

I’ve made the Pirate Radio with the Airplay scripts following the guide (https://learn.pimoroni.com/tutorial/sandyj/streaming-airplay-to-your-pi), but am wondering if there is a safe® way to shutdown the Pirate Radio then just cutting the power?
Preferably something like assigning su -c poweroff to one of the buttons?