radio/radio-clean.sh
2017-02-20 17:04:09 +00:00

18 lines
400 B
Bash
Executable file

#!/bin/sh
track_id=1
track_removed=0
for track in $(mpc playlist);
do
expires_on=$(echo $track | grep -oE 'expire(=|/)[0-9]*(&|/)' | tr -s '=' '/' | tr -s '&' '/' | cut -d '/' -f 2)
if [[ $((expires_on - $(date '+%s'))) -le 3600 ]];
then
mpc del $track_id
track_removed=$((track_removed+1))
else
track_id=$((track_id+1))
fi
done
echo "Removed $track_removed tracks"
mpc play