July 30, 2005
Parse iTunes XML with a couple lines of PHP
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.
categories:
How To, Projects, Software
posted by adm at July 30, 2005 05:38 PM
Trackback Pings
TrackBack URL for this entry:
http://www.thousandrobots.com/mt/mt-tb.cgi/1061
Comments
Hi,
same problem here. But the difficulty is: how do you check for certain keys and print the following sibling. Guess I'll have to look somewhere else.
cheers
Posted by: Axl at September 1, 2006 01:05 PM
Post a comment
Thanks for signing in, . Now you can comment. (sign out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)
Hi,
same problem here. But the difficulty is: how do you check for certain keys and print the following sibling. Guess I'll have to look somewhere else.
Posted by: Axl at September 1, 2006 01:05 PM