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:

123.123.123.123 workaround.phobos.apple.com

we can convinces iTunes that the server at 123.123.123.123 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/

IMAGE(http://www.applefritter.com/images/tuner-18147_640x480.jpg)
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.

Content Type: 
AttachmentSize
Image icon afTuner.jpg6.79 KB

Comments

Krest's picture

This looks really intersting!

Jon's picture

I'm awaiting the /.'ing.

1. Hack the iTMS interface to include custom free content.
2. Give away the code and method to the pubilc.
3. World beats indie artists bandwidth into pulp.
4. ???
5. No PROFIT!!!

Wink

Now to wait for the integrated BitTottrent that might appear in 10.5, and integrate THAT into Tuner. Biggrin

BDub's picture

I'm awaiting the /.'ing.

Just dropped my submission in their form. Hopefully an army of Slashdotters will decend upon our server and explain to me exactly why I'm not geeky enough, why I should have used a real language instead of bash, and with any luck address all of my personal shortcomings in great detail.

Now to wait for the integrated BitTottrent that might appear in 10.5, and integrate THAT into Tuner. :D

Excellent idea. I'd considered Bittorrent, but wanted to avoid bloating it at all (the download is fairly small), but if I can use something built into the OS it'd be worth taking a look at. Though honestly, now that it's out, I don't really even want to look at my source for a couple weeks.

So where do you find the xml for the iTMS?

BDub's picture

I found it by spoofing the iTunes user agent string and downloading them from the iTMS with cURL. There's a page describing it with wget: http://hcsoftware.sourceforge.net/jason-rohrer/itms4all/

Details are here - http://theducks.livejournal.com/405046.html

There is a host entry from localhost.apple.com 127.0.0.1 already. The hard part is generating and installing the fake SSL certificates/CSAs.

Bash is evil. I used Perl initially to make some test itms files from my iTunes Music Library.xml file, and then PHP when I started going further. However I lost interest, since the fastest I could get it to parse the XML file was about 10 seconds, and I couldn't be bothered setting up an SQL database on my powerbook.

It's a fun hack. I showed it to a friend who works for Apple in the iPod section.. he got a bit scared until I pointed out how difficult it was to get it happening.

Good luck Smile

BDub's picture

Nice job! The bash is just so that you can keep the XML at any URL without modifying your host file on a per-host basis. To generate actual playlists I've been using PHP/SQL.

(I should note, I'm fond of bash, and believe that Perl is evil Wink )

Oh, what did you need SSL certs for? I haven't needed to touch 'em.