The Most Annoying Dev Problem I Solved

I was going to write about the hardest tech problem I ever faced, but I figured let’s start off with something a bit easier. Writing code to solve something that seems very simple to a human, but was an utter pain in reality.

Many, many years ago I helped wrote the back-end for a local radio stations’ websites (plural because they had different stations for different areas). One little feature they wanted was to say what’s currently playing. Simple, right?

Nowadays the station would publish a JSON feed. Curl and done.

Back in those days though, we had to FTP into a server and download an XML blob. The server had an allowlist of allowed IPs. Fortunately this also predates cloud hosting, so we knew the IPs of our big iron boxes.

We had a cron job that would run every minute, FTP in, grab the file, store it locally, and close the connection. Except for when:

  • The radio stations software removed the old file to write the new one and we just happened to request the file in that window.
  • Or, the the station tried to write the file without removing the old one so you’d have date-stamped copies.

Eventually, we’d end up with an XML blob on our server. Now the real fun could begin.

You see, the XML file contained all of the currently playing tracks for the station. All of them. If, like me, you thought a radio station only played one track at a time, well you’d be very wrong. From memory here’s a rough recollection of what you’d get:

  <track runtime="00:30">Xmas_Jingle_02</track>
  <track runtime="03:30">Maria Carey - All I want for Christmas</track>
  <track runtime="00:05">Outro (2008) Final v2</track>
  <track runtime="+1:59:20">Drive-Show-Studio</track>

Yep. Anything playing at that time, be it the main song, a sound effect, or even the presents, was returned. Like I said at the beginning, it’s pretty easy for a human to read that and see what the current “track” is

Thus began the game of “trying to pick the right element”. We ended up with a bank of heuristics.

Runtime less than 2 minutes? Skip

Runtime over 10 minutes? Skip

Name matches one of a hundred different regex patterns? Skip

Got two tracks that look possible? Check if one of them was the previous now playing.

Every few weeks we’d have to add a new exception. Jingles that were exactly the same length as a song. Game segments where they’d make callers guess the song.

Despite our pleases to add a flag, any flag, to indicate a “primary” track, nothing ever changed. After a few months the system settled down and worked perfectly for the next five years or so. But now I see radioplayer’s data services and it’s all just so much easier.

At least we had snow mode to test the servers rather than the logic, but that’s a story for next time.