Parsing iTunes Libary

Hello everybody !

I thought about writing something like that:
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

On Jul 20, 2007, at 05:40 , [email protected] wrote:

I thought about writing something like that:
Google Code Archive - Long-term storage for Google Code Project Hosting.

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/
that_stupid_thing_i_wrote_the_other_day_part_2.html

Thanks a lot Ryan !

You safed me from some nasty work.

Dominik

2007/7/20, Ryan D. [email protected]:

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.

Dominik wrote:

I thought about writing something like that:
Google Code Archive - Long-term storage for Google Code Project Hosting.

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://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 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/

HTH

has

http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org

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 [email protected]: