It’s been a while since I’ve posted an xQuery. So I dusted off the old saxon processor and thought I’d have a bit of fun with the iTunes library.
I got me some well formed xml by selecting the Podcasts node in iTunes’ left column and exported it to Podcasts.xml (File/Library/Export Playlist). That gives you this xml file. So what now? Run some xQuery against it, is what!
You have to examine the xml a bit to get a feel for how it is laid out. The xQuery which I ran searches for all podcasts by the artist Jupiter Broadcasting and sets out several pieces of meta-data for those podcast episodes (Name, Kind, Bit Rate, Sample Rate). The xQuery is:
declare namespace dave = "http://www.localhost:8090/xquery"; declare function dave:getJupiterBroadcastingShows($allShows as element()+) as element()+ { let $JBShows := $allShows[contains(child::string[preceding-sibling::key[1]/child::text() = 'Artist'], 'Jupiter Broadcasting')] return $JBShows }; let $list := doc("Podcasts.xml")/plist/dict/key[.="Tracks"]/following-sibling::dict[1] let $key := $list/child::key let $pods := $key/following-sibling::dict[1] let $podCastJupiter := dave:getJupiterBroadcastingShows($pods) return <podcasts> { for $keyVal in $podCastJupiter return <podcast> <name> {$keyVal/child::key[child::text() = 'Name']/following-sibling::string[1]/child::text()} </name> <filetype> {$keyVal/child::key[child::text() = 'Kind']/following-sibling::string[1]/child::text()} </filetype> <bitrate> {$keyVal/child::key[child::text() = 'Bit Rate']/following-sibling::integer[1]/child::text()} </bitrate> <samplerate> {$keyVal/child::key[child::text() = 'Sample Rate']/following-sibling::integer[1]/child::text()} </samplerate> </podcast> } </podcasts>
and the result of this query was:
<?xml version="1.0" encoding="UTF-8"?> <podcasts> <podcast> <name>The Computer Action Show! Season 2 Episode 1</name> <filetype>MPEG audio file</filetype> <bitrate>96</bitrate> <samplerate>44100</samplerate> </podcast> <podcast> <name>The Computer Action Show! Season 2 Episode 2</name> <filetype>MPEG audio file</filetype> <bitrate>96</bitrate> <samplerate>44100</samplerate> </podcast> <podcast> <name>The Computer Action Show! Season 2 Episode 3</name> <filetype>MPEG audio file</filetype> <bitrate>80</bitrate> <samplerate>44100</samplerate> </podcast> <podcast> <name>The Computer Action Show! Season 1 Episode 4</name> <filetype>MPEG audio file</filetype> <bitrate>96</bitrate> <samplerate>44100</samplerate> </podcast> <podcast> <name>The Computer Action Show! Season 1 Episode 5</name> <filetype>MPEG audio file</filetype> <bitrate>96</bitrate> <samplerate>44100</samplerate> </podcast> <podcast> <name>The Computer Action Show! Season 1 Episode 6</name> <filetype>MPEG audio file</filetype> <bitrate>96</bitrate> <samplerate>44100</samplerate> </podcast> <podcast> <name>The Computer Action Show! Season 1 Episode 7</name> <filetype>MPEG audio file</filetype> <bitrate>96</bitrate> <samplerate>44100</samplerate> </podcast> <podcast> <name>The Computer Action Show! Season 1 Episode 9</name> <filetype>MPEG audio file</filetype> <bitrate>96</bitrate> <samplerate>44100</samplerate> </podcast> <podcast> <name>The Computer Action Show! Season 1 Episode 10</name> <filetype>MPEG audio file</filetype> <bitrate>96</bitrate> <samplerate>44100</samplerate> </podcast> <podcast> <name>The Computer Action Show! Season 2 Episode 4</name> <filetype>MPEG audio file</filetype> <bitrate>96</bitrate> <samplerate>48000</samplerate> </podcast> </podcasts>
I know I know. It’s awesome.