Tuner: iTMS For The Rest Of Us
A little over three years ago, Apple Computer introduced a new area in iTunes so interesting that they used the word groundbreaking twice in the press release. Since then, the iTunes Music Store has sold over one billion songs at 99 cents a piece. But until now, the iTunes Music Store interface has stayed locked in Apple's hands.
Four months ago, I decides that I wanted to put his own audio in the iTunes Music Store. Except that I wanted to give it away for free. And I wanted to have total control over what's put up. And I wanted to be able to change it however I want.
iTunes is locked down to a couple different URL's. If you're not a subdomain of phobos.apple.com or demios.apple.com, iTunes just refuses to load your content. So the first step is to trick iTunes into thinking that your server with all your content on it is part of phobos.apple.com.
To do this, we can use an /etc/hosts entry. For those of you not familiar with networks, a hosts file is the first spot your computer looks when it's trying to convert a domain name (like phobos.apple.com) into an IP address. By placing an entry into his hosts file that looks like this:
we can convinces iTunes that the server at 126.96.36.199 is really a part of the phobos.apple.com domain. In other words, now iTunes thinks that my server is alright to load data from.
Using data that I picked up from http://hcsoftware.sourceforge.net/jason-rohrer/itms4all/, I grabbed some XML pages from the real iTMS and put them on my server. They loaded up properly when I typed in itms://workaround.phobos.apple.com/itms.xml.
With the angle of attack clear, I eventually decided that the only good way to do this would be to allow anyone to serve up content, not just me. Very few people would be willing to alter their host files if the only result was being able to see my playlist.
I put together a small group of shell scripts that, when run as an OS X startup item, would sit in the background on my system and listen for requests to my fake iTMS store. Then they'd take a URL out of that request, get data from the real server that I wanted to find data from, and pass it back. To iTunes, it looks like the data is coming from a perfectly legitimate iTMS server, when in reality it means that using these scripts you can now download an iTMS compatible playlist from any website.
As an example, let's say that Applefritter has a number of recordings that we want to make available through the iTunes interface. Assuming that you'd installed this group of scripts on your computer, you could send a request to the fake server with the Applefritter address included in it, the scripts would catch it, retrieve the actual data from Applefritter, and then return it to iTunes.
To make these scripts easier to use, I've bundled it up, given it an installer, and called it "Tuner". It's available as an OS X package at http://www.tunedial.org/download/
iTunes displays a playlist showing several recordings from VCF
To help create iTunes compatible playlists, I've also put together tunedial.org. Tunedial is built to create the correct XML files for iTunes, while keeping you away from the code itself. Using a few interactive forms, you can create an iTMS compatible playlist.
Those of you who love the Mac for it's simplicity may want to stop reading here.
Tuner is installed in /Library/StartupItems/. After installing Tuner, on reboot a StartupItem located at /Library/StartupItems/Tuner is activated. It starts a script (/Library/StartupItems/Tuner/check.sh) whose purpose in life is to execute the command:
/Library/StartupItems/Tuner/retrieveURL.sh | sudo /usr/bin/nc -l -p 42139 127.0.0.1 > /Library/StartupItems/Tuner/output.txt
This command starts retrieveURL.sh, which cycles, waiting for nc (netcat) to dump data received on localhost:42139 into a buffer file. Once something has been received, it parses out the requested URL, and uses cURL to retrieve the XML content from any URL. retrieveURL.sh then sends it's data back through the netcat connection which leads to iTunes.
Netcat is a small utility which allows you to talk directly to a network pipe from a shell script. You can find out more about it on its Sourceforge page.
As soon as the connection is complete, netcat exits, and the retrieveURL.sh script is finished. check.sh, which has been cycling quietly in the background, sees this and restarts it with the same command.
The Tuner directory is available for download so you can examine the source for a clearer idea.