Skip to content

Instantly share code, notes, and snippets.

@rngtng
Created December 12, 2010 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rngtng/738401 to your computer and use it in GitHub Desktop.
Save rngtng/738401 to your computer and use it in GitHub Desktop.
simple script to parse the iTunes XML file
require 'rubygems'
require 'xml'
class Inode
attr_reader :at
def initialize(node)
@at = {}
key = nil
node.each_element do |p1|
if p1.name == 'key'
key = p1.content
else
@at[key] = p1.content
end
end
end
def has_rating?
at['Rating'] || at['Grouping'] =~ /Star/
end
end
doc = XML::Parser.file('lib.xml').parse
a = []
doc.find('/plist/dict/dict/dict').each do |p|
n = Inode.new(p)
a << n if n.has_rating?
end
a.sort! { |n,m| n.at['Rating'].to_i <=> m.at['Rating'].to_i }
a.each do |v|
puts v.at['Rating'].to_s + " - " + v.at['Name']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment