[LUAU] not using SED to extract song, artist, and album from my iTunes Music List Export

Vince Hoang vince at litrium.com
Tue Oct 3 02:30:31 PDT 2006


On Sun, Oct 01, 2006 at 06:58:00AM -1000, Tim Newsham wrote:
> XML is a problem in search of a problem....

It was a sad day when I discovered OS X and Solaris startup
scripts depending on XML files. I certainly would not mind more
compact and easily parsable alternatives like JSON and YAML.

Here is a solution in ruby/rexml that runs natively on OS X 10.4
without requiring any library exports. Podcast subscriptions
are not contained within the XML file, so an OPML export is
unfortunately required to get to those bits.

  #! /usr/bin/env ruby

  require 'rexml/document'

  itunes_index = "#{ENV['HOME']}/Music/iTunes/iTunes Music Library.xml"
  doc = REXML::Document.new IO.read(itunes_index)
  doc.elements.each 'plist/dict/dict/dict' do |entry|
    headers = {
      'Name'   => '',
      'Artist' => '',
      'Album'  => '',
    }
    entry.elements.each do |track|
      if track.name == 'key'
        if headers.key? track.text
          headers[track.text] = track.next_sibling.text
        end
      end
    end
    puts "\"#{headers['Name']}\" #{headers['Artist']} ~ #{headers['Album']}"
  end

-Vince



More information about the LUAU mailing list