<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ramblings of a Geek - Jeremy Johnstone &#187; iTunes</title>
	<atom:link href="http://www.jeremyjohnstone.com/tag/itunes/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jeremyjohnstone.com</link>
	<description>Ramblings of a Geek</description>
	<lastBuildDate>Tue, 20 Dec 2011 18:33:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP parser for OS X plist XML files</title>
		<link>http://www.jeremyjohnstone.com/blog/2008-10-26-php-parser-for-os-x-plist-xml-files.html</link>
		<comments>http://www.jeremyjohnstone.com/blog/2008-10-26-php-parser-for-os-x-plist-xml-files.html#comments</comments>
		<pubDate>Mon, 27 Oct 2008 03:42:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[iTunes]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php_class_lib]]></category>
		<category><![CDATA[plist]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.jeremyjohnstone.com/blog/?p=384</guid>
		<description><![CDATA[Digging around today for a PHP parser for OSX plist files, I was surprised to find no good pre-existing solutions. Even Apple&#8217;s own site gives a relatively poor solution to the problem (see here). Normally SimpleXML is enough to handle most XML parsing needs, but the plist XML format is just broken enough to make [...]]]></description>
			<content:encoded><![CDATA[<p>Digging around today for a PHP parser for OSX plist files, I was surprised to find no good pre-existing solutions. Even Apple&#8217;s own site gives a relatively poor solution to the problem (<a href="http://developer.apple.com/internet/opensource/php.html">see here</a>). Normally SimpleXML is enough to handle most XML parsing needs, but the plist XML format is just broken enough to make parsing it with SimpleXML virtually impossible. Since I hadn&#8217;t played with XMLReader much, I thought it would be a good chance to give it a spin. For the anxious types, the code is available on <a href="http://github.com/jsjohnst/php_class_lib/tree/master">github in my php_class_lib project</a>, so dig right in. Read on for a simple example (included in the repos).</p>
<p>The original intent of the parser for me was to parse my iTunes&#8217; library in PHP, so <a href="http://github.com/jsjohnst/php_class_lib/tree/master/classes/parsers/plist/example.php">this example</a> will show doing just that:</p>
<pre class="brush: php">&lt;?php

include("PlistParser.inc");

$parser = new plistParser();
$plist = $parser-&gt;parse(dirname(__FILE__) . "/iTunes.xml");
var_dump($plist);
</pre>
<p>And from that, the output is as follows:</p>
<pre class="brush: php">array(8) {
  ["Major Version"]=&gt;
  int(1)
  ["Minor Version"]=&gt;
  int(1)
  ["Application Version"]=&gt;
  string(5) "8.0.1"
  ["Features"]=&gt;
  int(5)
  ["Show Content Ratings"]=&gt;
  bool(true)
  ["Music Folder"]=&gt;
  string(60) "file://localhost/Users/testUser/Music/iTunes/iTunes%20Music/"
  ["Library Persistent ID"]=&gt;
  string(15) "C39203948AF3D3E"
  ["Tracks"]=&gt;
  array(1) {
    [1]=&gt;
    array(25) {
      ["Track ID"]=&gt;
      int(1)
      ["Name"]=&gt;
      string(8) "My Track"
      ["Artist"]=&gt;
      string(9) "My Artist"
      ["Album"]=&gt;
      string(8) "My Album"
      ["Genre"]=&gt;
      string(8) "My Genre"
      ["Kind"]=&gt;
      string(15) "MPEG audio file"
      ["Size"]=&gt;
      int(123456)
      ["Total Time"]=&gt;
      int(123456)
      ["Track Number"]=&gt;
      int(1)
      ["Year"]=&gt;
      int(2008)
      ["Date Modified"]=&gt;
      string(20) "2008-03-03T03:33:33Z"
      ["Date Added"]=&gt;
      string(20) "2008-03-03T03:33:33Z"
      ["Bit Rate"]=&gt;
      int(128)
      ["Sample Rate"]=&gt;
      int(44100)
      ["Comments"]=&gt;
      string(20) "All Rights Reserved."
      ["Release Date"]=&gt;
      string(20) "2007-03-12T04:01:37Z"
      ["Persistent ID"]=&gt;
      string(14) "C3E339393939E3"
      ["Track Type"]=&gt;
      string(4) "File"
      ["Podcast"]=&gt;
      bool(false)
      ["Unplayed"]=&gt;
      bool(true)
      ["File Type"]=&gt;
      int(123456)
      ["File Creator"]=&gt;
      int(123456)
      ["Location"]=&gt;
      string(66) "file://localhost/Users/testUser/Music/iTunes/iTunes%20Music/my.mp3"
      ["File Folder Count"]=&gt;
      int(4)
      ["Library Folder Count"]=&gt;
      int(1)
    }
  }
}</pre>
<p>As you can see, the PHP parser made short order of that task. From here you now have full access to all the metadata in your iTunes library. Feel free to use the class in your own projects and be sure to let me know what you build with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremyjohnstone.com/blog/2008-10-26-php-parser-for-os-x-plist-xml-files.html/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

