Projects: July 2005 Archives
You may recall I half-wrote a script to do this a couple years ago, but I was mostly cribbing from some guy at Apple and really had no idea what i was doing.
Anyway, I'm taking another shot at parsing the iTunes library XML using PHP5's new "SimpleXML" library, which is a terrific feature that I never get tired of working with.
I cooked up this little script in about 10 minutes. The format of Apple's XML files makes it sort of a pain to process in the usual ways, but you can still get reasonable output with just a few lines of code. And most of that code is concerned with formatting, not the actual XML processing.
To use this script:
- Make sure you are using PHP5 with SimpleXML support. At Dreamhost, you can turn this on by clicking the "edit" link on the main domain management page. If you're hosting a site on your Mac, you can get an easy-to-install version of PHP5.
- In iTunes, select a Playlist or Library, choose "File:Export..." and export it as XML. Name it itunes.xml. (If your site is hosted on your Mac, you can just create a symlink called "itunes.xml" that points to your "iTunes Music Library.xml" file or the playlist file you just exported. Place this link in your website directory.)
- Upload itunes.phps and itunes.xml to your webserver.
- Rename itunes.phps to itunes.php.
- Open your browser and navigate to itunes.php.
Obviously there are lots of ways to enhance the functionality of this script, but this will get you started.
