Dynamic read of iTunes Library

texanpenguin

Registered Penguin
I have Apache serving a web-site at the moment, and I'd like to be able to have it show my iTunes Library as a nicely formatted HTML page.

Is there a nice way for the server to grab the XML on request and show it in plain HTML? Like on-the-fly conversion?
 
xml parsing in php4 is a bit of a pain in the butt, BUT it can be done. On request of the document... have the php file use get_file_contents() to the local path of the xml document on your machine, just to get the xml data to your webserver, then parse it in php. http://us2.php.net/manual/en/ref.xml.php

Also if you do flash....flash is a great tool to parse xml.
 
It might be easier to use a script (Apple Script) that handles everything at a set time. Say, every night at 3am the script grabs a copy of your playlist, formats it to an HTML document, then places it in a directory on your server (local or via FTP). Use CSS to control the look of the HTML file.

In fact...I think there's a few scripts like this already floating around out there.
 
http://www.dougscripts.com/itunes/scripts/scripts03.php?page=1 (Look through all 3 pages, as there's at least 4 scripts to export to HTML plus a few that export to TXT.)

Here's an PHP based XML parser for the iTunes XML file:
http://codetriangle.com/products/iTunesXmlParser/

----- EDIT -----

I retract the previous part about not using PHP with the XML...all you should have to do is run the PHP script above, then figure out a way to get a copy of your XML file to your server (if you want it to automatically update).

I played a bit with the script...I like it. :D

Here's a link to it in action after a bit of cleansing, CSS styling, and some other minor tweaks (links to iTMS, Zebra stripes on rows [really slow it down...darn JS], etc.).

http://mdnky.macosx.com/test/itunes/index.php
 
About a year ago, after much trial and error (1 month or so), I figured out the link structure for it. I was using it with an iTunes is Playing script I was working on. Of course 10 days later I found a site that had the information in an article...go figure.

Tried to find that site again, but I couldn't. Wound up forgetting most of how I did it the first time, but after a bit of searching and trail and error I figured it out again. Here's a quick and dirty HOWTO:

Code:
[b]Base Link:[/b]
[color=purple]itms://phobos.apple.com/WebObjects/MZSearch.woa/wa//advancedSearchResults?[/color]


[b]Search Modifiers:[/b]
[color=red]songTerm=[i]song name[/i][/color]
[color=blue]artistTerm=[i]artist name[/i][/color]
[color=green]albumTerm=[i]album name[/i][/color]

If you use more than 1 modifier, add an ampersand ( & ) before the additional ones.  Remember to use & !


[b]Example Links[/b]
To link to the song 'Cowboy' by artist 'Kid Rock', your link would look like this:
[color=purple]itms://phobos.apple.com/WebObjects/MZSearch.woa/wa//advancedSearchResults?[/color][color=red]songTerm=Cowboy[/color][color=black]&[/color][color=blue]artistTerm=Kid%20Rock[/color]

To link just to the artist 'Kid Rock', the link would look like this:
[color=purple]itms://phobos.apple.com/WebObjects/MZSearch.woa/wa//advancedSearchResults?[/color][color=blue]artistTerm=Kid%20Rock[/color]

To link to the album 'Devil Without a Cause' by the artist 'Kid Rock', the link would look like this:
[color=purple]itms://phobos.apple.com/WebObjects/MZSearch.woa/wa//advancedSearchResults?[/color][color=green]albumTerm=Devil%20Without%20A%20Cause[/color][color=black]&[/color][color=blue]artistTerm=Kid%20Rock[/color]

If you don't target the artist and song names together, say just song name...you'll get every song in the iTMS that has that name.  Same with album, if you only target the album name.  Sometimes this can be a really big issue.


For my music list, the index.php file (adaptation of the advanced example included in the XML Parser script) looks like this:

PHP:
$output .= "<tr>";
$output .= "<td>".(isset($song["Name"])?$song["Name"]:NULL)." <a href=\"itms://phobos.apple.com/WebObjects/MZSearch.woa/wa//advancedSearchResults?songTerm=".(isset($song["Name"])?$song["Name"]:NULL)."&amp;artistTerm=".(isset($song["Artist"])?$song["Artist"]:NULL)."\" title=\"Find the song ".(isset($song["Name"])?$song["Name"]:NULL)." by ".(isset($song["Artist"])?$song["Artist"]:NULL)." at the iTunes Music Store\"><img src=\"store.gif\" alt=\"iTMS\" /></a></td>";
$output .= "<td>".(isset($song["Artist"])?$song["Artist"]:NULL)." <a href=\"itms://phobos.apple.com/WebObjects/MZSearch.woa/wa//advancedSearchResults?artistTerm=".(isset($song["Artist"])?$song["Artist"]:NULL)."\" title=\"Find songs by ".(isset($song["Artist"])?$song["Artist"]:NULL)." at the iTunes Music Store\"><img src=\"store.gif\" alt=\"iTMS\" /></a></td>";
$output .= "<td>".(isset($song["Album"])?$song["Album"]:NULL)." <a href=\"itms://phobos.apple.com/WebObjects/MZSearch.woa/wa//advancedSearchResults?albumTerm=".(isset($song["Album"])?$song["Album"]:NULL)."&amp;artistTerm=".(isset($song["Artist"])?$song["Artist"]:NULL)."\" title=\"Find ".(isset($song["Album"])?$song["Album"]:NULL)." by ".(isset($song["Artist"])?$song["Artist"]:NULL)." from the iTunes Music Store\"><img src=\"store.gif\" alt=\"iTMS\" /></a></td>";
$output .= "<td>".(isset($song["Genre"])?$song["Genre"]:NULL)."</td>";
$output .= "</tr>";
The IMG tag for those links is floated right via CSS.
 
Back
Top