Scheduled Programming
The scheduler is the heart of the station. Every hour, a cron job reads schedule.json and switches what MPD is playing.
How It Works
radio_scheduler.sh runs at the top of every hour. It:
- Reads
schedule.jsonto find the programme for the current hour - Clears the MPD queue
- Loads the appropriate playlist or artist queue
- Starts playback
- Logs what it did to
/var/log/radio_schedule.log
If no entry matches the current hour, it falls back to a random shuffle of the full library.
Programming Types
| Type | What it does |
|---|---|
genre | Loads a genre playlist (e.g. Rock, Folk, Reggae) |
artist | Queues all tracks by a specific artist |
metal | Special metal mode — heavier rotation, specific playlists |
podcast | Switches to the podcast playlist |
random_playlist | Picks a random stored playlist |
random | Full library shuffle |
Playlists
Genre playlists are .m3u files stored in /var/lib/mpd/playlists/. They're generated by create_playlists.sh, which runs weekly (Sunday at 3 AM) and scans the music directory to build them.
/usr/local/bin/create_playlists.sh
This script runs mpc clear to reset the queue before rebuilding. If it runs while you're listening, playback will briefly stop. That's why it's scheduled for 3 AM Sunday.
You can trigger an on-demand rebuild from the web UI (Programming panel → Rebuild Playlists), or via the API:
curl -X POST http://your-pi/api/rebuild-playlists
Song Logging
song_logger.sh runs as a systemd service (song-logger.service) under the mpd user. It watches MPD for track changes and writes 4 lines to /var/log/radio_playlist.log for every song:
NOW PLAYING: Artist - Title
FILE PATH: /mnt/music/Artist/Album/track.mp3
GENRE: Rock
NEXT UP: Artist - Next Track
The Python API reads this log file (polling every 5 seconds in a background thread) to serve the current playlist. It never queries MPD directly — the log is the source of truth for what's playing.
Station IDs
At midnight, generate_stationid_hours.sh picks 6 random hours for the next day and writes them to a file. When the scheduler hits one of those hours, it plays a station ID announcement before the regular programming.
Station ID MP3s are stored on the NAS and pre-generated using text-to-speech.
The Watchdog
mpd_watchdog.sh runs every 5 minutes. It checks if MPD is running and playing. If MPD has stopped or stalled, it restarts it and resumes the queue.
This handles the occasional MPD crash or network hiccup without needing manual intervention.
Exclude List
Songs tagged Eject in the web UI are added to a plain text exclude file. The scheduler filters this list every hour — ejected songs never appear in the queue.
The exclude file is managed automatically: tagging a song Eject appends it; removing the tag removes it. You can also regenerate the file from scratch from the database:
curl http://your-pi/api/rebuild-excludes