Perl-Powered DJ

No, it’s not really my DJing that’s script-powered, but over the last couple of years that I’ve been doing regular net radio shows, I have written a number of Perl scripts to help with some of the more tedious aspects of the job, particularly related to the posting of the MP3 archives and tracklists of those shows (and my occasional promo mixes) on, but also for the broadcasting process itself.

In fact one of the first scripts I wrote was to assist with the fact that I broadcast (using darkice on my Linux box) on different stations, necessitating having multiple different configurations for darkice. What began as a one-liner to do the equivalent of darkice -c /path/to/darkice/configs/$1.cfg then expanded to do things like shut down certain daemons before broadcasting, and start them again afterwards, as my elderly PC would occasionally struggle to cope with the demands of running two MP3 encoders if it was also dealing with a large incoming mail or a disk-heavy cronjob.

I then tired of hitting reload on the server stats page to keep an eye on my listener count, so now I have a script which fetches that page every couple of minutes, parses the relevant number out of it, and shows it with a timestamp, so I have a full record of how many were tuned in at each point of the show, what the peak was etc.

Scripts followed to automate filling in the ID3 tag, and renaming darkice’s output spool name into a standard format prior to uploading it to the site. is a WordPress-based site with a heavily customised skin and a couple of extra plugins, nothing too fancy. After writing the first few posts by hand, I came up with a simple template-driven script which would simply wrap my plain-text tracklist of the show in some HTML to make it look a bit prettier for the site. This evolved so that it would read the metadata from the MP3 (eg filesize, bitrate, length in minutes and seconds) and put that info in there as well.

After a while I decided to have my online tracklists in table format rather than just reproducing what I write in plain text. So this meant adapting the script to split up each entry in the tracklist for the separate columns. I had the prescience to choose a roughly standardised format for my plain text tracklists anyway — at its simplest, it’s just “Artist – Title” or “Artist – Title – Label” — but over time it’s evolved a number of variations to deal with, for example, marking out who played which track when I have a guest in. I sensed it was time to create a separate library (Perl module) to parse tracklists into separate information, and a number of my scripts now use this.

Just this year I expanded the templating script into a more complex system which interfaces directly with the WordPress API. It determines which radio station the broadcast was on (which is in the filename), searches for some of my past mixes for that station on the site, and offers a selection of their post titles so I can choose one (eg with, or without, a guest DJ, as applicable) on which to base the default title for the new one, helping to keep the title format consistent. Both my current regular shows feature the number of the show in the title – the script will automatically increment this, be it in ordinary numerals or Roman numerals. Appropriate tags are chosen automatically, and any additional words for the article can be added before the script posts it directly to the site via the API.

Why stop there? Since my Tracklist library conveniently gives me information about the artists and labels played in each show, the script now also creates a Custom Field entry for each. I don’t really know why I’ve done that… just a vague sense that it might be useful at some point in the future. For now, a slight tweak at the WordPress end provides A-Z lists of artists and labels for each mix at the end of the article. At some point, if so desired, it should make it easier to search for all the mixes containing a specific artist or label…

Most recently, the thing I was finding particularly time-consuming was to fill in the label for each tune, which information I often don’t have handy during the show when I’m writing down the track. So now I have a couple of scripts to help with that. The first just looks for the “artist – title” string in all my previous tracklists and copies the label info from there if it finds it. The second, which is a work in progress, attempts to automate looking up the track details on the sites where I do most of my tune shopping, and screen-scraping the label from there.

Curiously, the net effect of all this automation has not really made it significantly quicker or easier to post a mix, compared to when I first started out and was doing it all by hand. What it has done is escalated the amount and quality of information I’m putting up, its consistency and reliability, while taking about the same amount of time and effort. Obviously that doesn’t include the effort required to write the scripts… but that’s not effort. That’s fun. It’s been a whole series of interesting little coding tasks… which of course is the main reason I did it.

OSX: Setting a global shortcut key to open a new Finder window

Given that the Finder is central to many tasks in Mac OS X, I’m surprised that there is no global keyboard shortcut to call up a new Finder window. Well, that’s not strictly true — there’s alt-cmd-space, which will bring up a new window to start a Spotlight search. But most of the time I want to open my home directory, so I’d rather have a shortcut which jumps straight there.

Googling for the answer to this problem turned up lots of out-of-date suggestions to use Clearsilver and the like, but it seemed to me that a solution could be found using only what OSX provides. And indeed it can. The following has only been tested in 10.6 Snow Leopard. Continue reading OSX: Setting a global shortcut key to open a new Finder window

Review: Edirol UA-25 24-bit 96kHz 2in 2out USB soundcard

I’ve become quite a fan of this sound device since I got it about a year ago.

For its price, the sound quality is excellent. It’s fairly packed with features, has a good range of options for input and output connectivity, plus MIDI. And it works flawlessly, out of the box, with Linux — no special setup or drivers required, ALSA knows what it is and how to deal with it in any mode.

The same is true of Mac OS, but only in the basic mode which restricts you to 16-bit 44.1kHz I/O – a driver is required for Advance mode to get up to 24-bit 96kHz support (either in, or out – we’ll come to this under Limitations). This driver can be downloaded free from the Edirol website, and seems to work fine on my new unibody Macbook Pro with OSX 10.6 Snow Leopard, though I haven’t used it extensively on there yet.

I guess it probably works in Windows too, but I wouldn’t know anything about that 🙂

The sound quality (for what I’ve used it for anyway) is very good. It’s stacked with features, and quite versatile… within certain limits.

First we’ll take a quick look at the features packed into this gadget, which is information you could probably find elsewhere but I include for ease of reference, and after that we’ll get to discussing those limitations in more detail.

Continue reading Review: Edirol UA-25 24-bit 96kHz 2in 2out USB soundcard

Using mutt on Linux to transfer your old mbox mail folders onto GMail

Unlike many webmail providers, Google don’t allow you to upload your folders from your old mail system in mbox format and import them. This is a pretty basic feature if you ask me, they really should.

There are a number of alternative ways. GMail does support fetching from other mail servers via POP3 (but not IMAP, another strange omission), so if your mail is all in your inbox at the old place that might work, but mine is organised into several folders, and I want to keep that organisation damnit!

Needless to say, someone has written a nice piece of software to do the job; in this case Mark Lyon’s GML. I was about to give this a whirl, but while I was waiting for the requisite Python lib to install, I found a much simpler way… click to read on…

Continue reading Using mutt on Linux to transfer your old mbox mail folders onto GMail

Terminal features wishlist: #1: Paste Intercept

A terminal program should have sufficient intelligence to recognise that, when (a) it is at a shell prompt, and (b) the user has just middle-clicked and sent hundreds of lines from the copy-paste buffer hurtling towards the shell prompt, the user may have made a mistake, the user’s mouse inadvertantly striking some object perhaps… and it should ask him whether he really wants to do that.

This was part of a much larger post which got killed by a bug in WordPress… “Are you sure you want to edit this post?” it asked. Yes, quoth I. And it was gone. 2 hours of scribbles, vanished, and even going back in the browser doesn’t recover it.

Related wishlist item: Anyone know of a little program that can sit on the desktop, probably always on top (so SMALL) and on all desks, which will show the current contents of the (Unix) copy-paste buffer, and provide a button to clear it? Even better if it can save a few of them too, even just 2 or 3. I like the Unix system. Left click and drag to select. Left click and right click to select by marking start and end points. Middle click to paste. It’s simple, it’s fast, it avoids faffing with menus. But there’s always a slight frisson of doubt which sets in as time passes between cut and paste. Currently the only way to find out is to paste somewhere. I’d like to just be able to look at the corner of the screen, see a tiny rendering of the contents, and know.

M-Audio Xponent + Linux + mixxx

Updated: 2007/07/27 – New section on LEDs. Update on mixxx SVN.

In case any of you who have read my review of the M-Audio Xponent are thinking of getting one and wondering “but will it work under Linux?”, the short answer is a resounding Yes!… except for the LEDs, so far. More on that later.

I use Debian unstable with a hand-rolled kernel. YMMV, of course, but the chances are that if you’re using any modern distro you’ll be fine. In fact you may not even have to manually insert the kernel modules if you have a working udev setup, you might just be able to plug’n’play.

Full details below the cut, as they say…

Continue reading M-Audio Xponent + Linux + mixxx