# Parsing iTunes Libary

**URL:** <https://www.ruby-forum.com/t/parsing-itunes-libary/109940>\
**Category:** Ruby\
**Created:** [July 20, 2007, 2:41pm UTC](https://www.ruby-forum.com/t/parsing-itunes-libary/109940 "2007-07-20T14:41:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 20, 2007, 2:41pm UTC](https://www.ruby-forum.com/t/parsing-itunes-libary/109940/1 "2007-07-20T14:41:11Z")

</div>

Hello everybody !

I thought about writing something like that:  
[http://code.google.com/p/itunes-to-rhythmbox-ratings/](http://code.google.com/p/itunes-to-rhythmbox-ratings/)

I wanted to parse the library with REXML but the file is quite big.

Is there a possibility to parse only a part of the file ?  
Or parses only a certain depth of the tree ?  
Does anybody know an existing tool for the iTunes library ?

Thanks

Dominik

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 20, 2007, 10:58pm UTC](https://www.ruby-forum.com/t/parsing-itunes-libary/109940/2 "2007-07-20T22:58:17Z")

</div>

On Jul 20, 2007, at 05:40 , removed\_email\_address@domain.invalid wrote:

> I thought about writing something like that:  
> [Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/itunes-to-rhythmbox-ratings/)
> 
> I wanted to parse the library with REXML but the file is quite big.
> 
> Is there a possibility to parse only a part of the file ?

I just use regular expressions:

[http://blog.zenspider.com/archives/2007/03/](http://blog.zenspider.com/archives/2007/03/)  
that\_stupid\_thing\_i\_wrote\_the\_other\_day\_part\_2.html

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 20, 2007, 11:53pm UTC](https://www.ruby-forum.com/t/parsing-itunes-libary/109940/3 "2007-07-20T23:53:23Z")

</div>

Thanks a lot Ryan !

You safed me from some nasty work.

Dominik

2007/7/20, Ryan D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 21, 2007, 3:44am UTC](https://www.ruby-forum.com/t/parsing-itunes-libary/109940/4 "2007-07-21T03:44:37Z")

</div>

I also recently needed to parse the AlbumData.xml. Started into it with  
REXML and realized that it was becoming something of a pain do to the  
rather inane XML that Apple uses. So I searched around and found the  
plist gem. It parses it (and other files that use the same strucure\_  
and gives you hashmaps that you can navigate rather easily.

It is probably slower than the regex code here and it loads everything  
into memory. But I found it pretty helpful.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 21, 2007, 10:32am UTC](https://www.ruby-forum.com/t/parsing-itunes-libary/109940/5 "2007-07-21T10:32:35Z")

</div>

Dominik wrote:

> I thought about writing something like that:  
> [Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/itunes-to-rhythmbox-ratings/)
> 
> I wanted to parse the library with REXML but the file is quite big.

You could look into using libxml:

[http://libxml.rubyforge.org/](http://libxml.rubyforge.org/)  
[http://raa.ruby-lang.org/search.rhtml?search=libxml](http://raa.ruby-lang.org/search.rhtml?search=libxml)

Another option would be to access iTunes via its COM (Windows) or Apple  
event (OS X) API. e.g. Using rb-appscript  
[http://rb-appscript.rubyforge.org](http://rb-appscript.rubyforge.org) on OS X:

#!/usr/bin/env ruby

require ‘appscript’  
include Appscript

t = app(‘iTunes’).library\_playlists[1].tracks

t.name.get.zip(t.artist.get, t.rating.get).each do |name, artist,  
rating|  
p name, artist, rating  
end

There’s also a project to provide a common cross-platform API, although  
I don’t know how far on it is yet:

[http://rubyforge.org/projects/rb-itunes/](http://rubyforge.org/projects/rb-itunes/)

HTH

## has

[http://appscript.sourceforge.net](http://appscript.sourceforge.net)  
[http://rb-appscript.rubyforge.org](http://rb-appscript.rubyforge.org)

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 21, 2007, 1:06pm UTC](https://www.ruby-forum.com/t/parsing-itunes-libary/109940/6 "2007-07-21T13:06:19Z")

</div>

Thanks a lot everybody !

I tried plist but it didn’t work. Don’t ask me why.  
Know I’m using regexp similar to Ryan.  
Maybe I’ll also have another look at libxml and so on.

Dominik

2007/7/21, hengist podd [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
