iTunes top 10 ... how to deal with boredom

… or basically a downtime of my 1st-tier ISP (bottom-up since I don’t know how many tiers my traffic goes through). Did you ever want to export to your Top10 of all times from your iTunes library to show off on your homepage (for example) or are you just bored like me?



#!/usr/bin/env ruby

LIBRARY_PATH = File.expand_path("~/Music/iTunes/iTunes Music Library.xml")

require 'rubygems'

require_gem 'plist'

class Plist

  class PDate < PTag

    def to_ruby

      text

    end

  end

  class PData < PTag

    def to_ruby

      text

    end

  end

end

d = Plist::parse_xml(LIBRARY_PATH)

top10=d['Tracks'].values.sort{|a,b| (a['Play Count'] ||= 0) <=> (b['Play Count'] ||= 0)}.reverse[0..10]

top10.each do |t|

  puts "#{t['Name']} by #{t['Artist']}"

end

Just to be on the safe side, better first backup your “iTunes Music Library.xml” or operate on a backup to begin with ;)

As always: Use this at your own risk.