Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Created May 20, 2011 15:22
Show Gist options
  • Save leejarvis/983143 to your computer and use it in GitHub Desktop.
Save leejarvis/983143 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'nokogiri'
path = ARGV.shift || File.join(ENV['HOME'], "Music/iTunes/iTunes Music Library.xml")
doc = Nokogiri.XML File.open(path)
tracks = []
doc.xpath('/plist/dict/dict/dict').each do |node|
children = node.children.map(&:text).reject { |x| x.strip.empty? }
tracks << Hash[children.each_cons(2).to_a]
end
p tracks.first['Name'] #=> some awesome track name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment