Archive for the 'Technology' Category

Perl-Powered DJ

Friday 20th August 2010

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 quextal.com, 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.

quextal.com 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.

Me v Wordle: Redux

Wednesday 10th March 2010

After all those hours of effort trying to control Wordle’s opinion of me in the end the Dev8D organisers didn’t use the single-post URL I’d provided to create my Wordle badge – they used the whole blog feed. I didn’t mind though. The badges, which I’d expected to be of the lapel variety and therefore easily readable, were actually in a kind of laminate pass holder which hung from our necks almost down to waist level, rather too low to read comfortably. The colour scheme was very muted too – someone would really have peer at it quite close to in order to make out most of the words. And, had anyone done so, I wouldn’t have been unhappy with the words there anyway.

While this exercise was ultimately futile for its original purpose, I still found it interesting (otherwise I wouldn’t have spent so long on it!) to consider how I might represent myself in a few words, and then sculpting an article specifically to get that result out of Wordle, but making the article a real piece of prose about the very process of its own construction. As I said, I’m a fan of self-reference. But I wonder if this can also be considered, perhaps loosely, a kind of steganography. While it contains no encryption, the article has a deeper purpose which — had I not explicitly made it the subject of the article, but instead concealed it — could be entirely hidden from view. I suppose it’s a fairly basic cipher to encode hidden messages inside a larger article according to the word frequency… but Wordle does a bit more than that. I think that, in controlled circumstances, Wordle’s output can be made reproducible for a given input and set of parameters. In which case, it would be feasible to conceal messages in a way that could not be calculated from the text alone, that could not be reliably decoded without the additional knowledge of which website it needs to be pumped through, the precise configuration parameters to use, and what further processing is required on the result — say, the message could be in just the words that Wordle makes a particular colour in one of its fixed palettes, or that are given a certain orientation.

Indeed, as Wordle’s precise algorithm is secret due to patent issues, the precise layout for a given set of parameters might be rather unpredictable without actually trying it. That makes Wordle a kind of public-private key pair, the public key being the set of parameters fed into the engine, and the private key being the secret method by which Wordle transforms those parameters into a layout. This transformation is probably relatively feasible to work out by trial-and-error, and in any case the number of configuration permutations is sufficiently low that if necessary the results of all of them could be tested and mapped fairly easily, so it only offers a fairly low security cipher. But you gain added security from the fact that very existence of a hidden message is steganographically concealed within the larger article, and, perhaps even more so, from the surprising and obscure means chosen to conceal it!

Ok, so I’ve given the game away now. If you’ve been quietly hiding secret messages in Wordle tag clouds for ages… sorry. If not, don’t start now, they’ll be onto you. But, more generally, using innocent third-party web applications as a kind of cipher function might have potential. You’d have to ensure that the output from the website isn’t just the pure decoded message, otherwise the third party has it as well. Some sort of post-processing which requires pre-shared secret knowledge is key. This could include things like piping your message through multiple web applications, either serially or in parallel, with each contributing some small part of the overall message, which can only be merged into the whole by someone with an additional piece of knowledge of how that needs to be done.

These are just idle thought experiments… I don’t advise anyone to actually use this technique for anything really secret! There are several obvious weaknesses, although they can probably be ameliorated. However, I believe it’s worth considering novel means of passing around secrets. If quantum computers actually happen as the physicists predict, all current encryption technology may be rendered useless at a stroke, as it all relies on a computationally-unfeasible mathematical problem that, theoretically, quantum computers could make feasible to solve quickly. Quantum computers also themselves have the potential to offer novel encryption techniques, but at the moment, no-one really knows how these things are going to behave… and, for a while anyway, quantum computers will be the preserve of rich governments, corporations, and other organised well-funded criminal gangs… so us ordinary folk will be at a disadvantage. The survival of our networks might depend on us being a little bit cunning…

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

Tuesday 9th March 2010

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. (more…)

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

Friday 15th January 2010

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.

(more…)

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

Saturday 4th July 2009

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…

(more…)

Terminal features wishlist: #1: Paste Intercept

Thursday 10th July 2008
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.