Skip to content

Project: Early Work

Thirteen Languages

A Winamp lyrics plugin, its own scripting language, and the hole I left in it.

Part 6 of 11ofOpening Boxes
  1. 1The Forbidden Layer
  2. 2Sonya, Please Respond
  3. 3The Card That Never Ran Out
  4. 4The 640K Labyrinth
  5. 5How to Emulate a 6802
  6. 6Thirteen Languages
  7. 7Redraw Only What Changed
  8. 8CSS That Computes
  9. 9A Search Engine from Scratch
  10. 10The Large, Black Ball
  11. 11Twice to the Steering Council

The BestLyrics box from The Boy Who Opened Boxes.

It is 2001, Winamp is playing, and you want the words. So you open a browser, search for the song, find a lyrics site, read them, and close the window, and the next time the song comes around you do it all again. BestLyrics did that dirty work for you. Start Winamp, play a song, and the lyrics appeared in Winamp’s own built-in browser window, already saved for next time.

It began that year as my improved take on an existing plugin, pureLYRICS, and its last release, 2.8, shipped at the end of 2006. In between it was listed on Winamp’s official plugin page, grew its own scripting language, and was translated into thirteen languages by people I never met.

BestLyrics in Winamp, from my old website: the playlist on the left and the lyrics of The Cure's "Boys Don't Cry" in the browser window on the right.

The first versions did what pureLYRICS did, better. They searched its lyrics database with smarter patterns, stripped the banners and ads out of the page, and kept every lyric in a local cache as clean text, so the second time a song played they were instant. Then came the features nobody needs and everybody wants: fonts, sizes and colors, a little camera button to pick a color from anywhere on the screen so the lyrics matched your Winamp skin, and a choice between Capitalized, UPPERCASE and lowercase.

The readme had a sense of humor I still recognize. “Q. Is Winamp 3.x supported? A. No, BestLyrics only works with Winamp 2.x and Winamp 5.x. Winamp 3.x will never be supported.” And: “Q. When will the next release of BestLyrics be out? A. Who knows. Maybe tomorrow, maybe never.”

Version 2.1 added language modules, in English and Spanish, and the readme put up a sign: “HELP WANTED TO TRANSLATE BESTLYRICS”. Translate this one text file, it said, the part after each =, and send it.

People did. Version 2.11 shipped with French and Swedish. Version 2.3b added Icelandic, Polish, Dutch, Basque, Portuguese and Hebrew. Italian came in 2.4, and Russian and German in 2.5b. Thirteen languages, every one from a volunteer who wrote to me out of nowhere.

There was no counter on the website that meant anything, but this was better than one. Nobody translates a program they don’t use, and certainly not into Basque or Icelandic, so every new language file was proof that BestLyrics had reached somewhere I had never been, and that someone there cared enough to give it a few evenings.

The lyrics sites kept changing their pages, and every change broke the plugin. The changelog for 2.4 says it with a sigh: “Added support to those changes made by PureLYRICS so this plug-in wouldn’t work. Now it works again!!” After enough of those, I rewrote almost all of it for 2.6, around the part I am still proudest of.

Instead of hard-coding each site, BestLyrics learned them from scripts in its own small language, interpreted by a parser I built with flex++ and bison++. A script said how to query a site, how to pick the lyrics out of the HTML, and how to judge whether the result was the right song. Its best idea is how it reads a page: with templates that bind variables wherever they match.

while( #seek# = searchI(#result#, "<a href=\"index.php?lyrics=#key#\">#lyrics#</a>", #cnt#++?) ) {

That one line, from the pureLYRICS script, walks the search results and pulls each link’s key and title out of the page. Supporting a new site took a text file, and anyone could write one.

Judging the result took some care too. Titles were compared with parentheticals such as (live) or (unplugged) stripped out, by a fuzzy score that blends the Ratcliff-Obershelp match with the Levenshtein distance. And every search carried the number of the song it was started for. The workers checked that number before each statement and between network reads, so when you skipped to the next song, the stale search quietly died. I would still cancel work that way.

It shipped with three scripts: pureLYRICS, Lyrics-World.de (120,000 lyrics), and LocalNet, which asked other machines on your network. For that, every install ran a small web server that answered lyrics requests from its own cache.

The bigger plan was BLySP, a protocol for sharing lyrics between users, so a song missing from every lyrics site could still turn up in somebody else’s cache. It got as far as a working prototype in 2002 and I never finished it, and I’m not sure it could have worked anyway: it needed a service running in people’s homes, reachable from the outside, and home firewalls were already blocking that kind of thing, or soon would.

Version 2.8, at the end of 2006, was the last. I honestly don’t remember why. Maybe my interest drifted, maybe something came along that made it irrelevant, or maybe it already did everything I wanted from it, and I simply stopped.

The interpreter is less pretty than the language. The grammar file still opens with the header of bison’s example, “Parser for a simple calculator”, because that is where I started, and it shows: there is no syntax tree, the program runs inside the parser’s actions, and a while loop works by rewinding the lexer to the line and column where it began. && and || can’t short-circuit, and one of the bundled scripts carries a comment on how to get an if working inside a while. Today I’d parse once into a tree and walk it. My mistake was never stepping back to restructure it once the calculator had grown into a language.

Then the part I’m least proud of: that little web server. It was on by default and listened on every network interface, and one of its pages saved submitted lyrics to a file whose name came from the request, without checking who was asking. The settings even had a password, which the server never looked at. Anyone who could reach that port could make it write a file of their choosing anywhere the user could, including the places Windows runs programs from at startup, and its request parser could be made to overflow, too. The changelog for 2.6b3 reads, in full, “Corrected some minor security bugs”. I was naive: it never crossed my mind how tricky it is to get a server right. Today it would listen only on the machine itself, choose its own file names, and require a token.

The “certified” scripts weren’t safe either. They were XOR-ed with keys that shipped inside the plugin and checked with CRC-32, which detects accidents, so anyone with the plugin could have certified a script of their own. And the way it noticed a new song makes me smile: it eavesdropped on Winamp’s window title as it changed, when the SDK header I was compiling against already had a message for exactly that.

Set against its years, the good part was early. Keeping each site’s rules in a downloadable script, apart from the program, is how scrapers are still built, while in 2001 a plugin that read a website, pureLYRICS included, broke every time the site did. The bad part was late: that server shipped in the year of Code Red and Nimda, the worms that swept the Internet through exactly that kind of thing, a web server listening where it shouldn’t, and the year’s biggest security news. I didn’t connect it to my own little server. And when Windows XP turned its firewall on by default, in 2004, BLySP lost most of its peers before it had any.

The final 2.8 installer, for Winamp 2 and 5, is on its project page, and the full source, the language and its scripts are on GitHub at Kronuz/BestLyrics. If you install it for nostalgia, turn its server off first.