‮‮albert

albert

28 year old Male from Handen, Stockholms Lan, Sweden. 92 friends

CHOKLIT RAINZ!!!!!111111

Online Profile type: People
Trigs
1189

Blog post 'itunes anyone?'

itunes anyone?

  • Published: 479 days ago
  • Comments: 5
  • Reads: 96

From zenspider

require 'time' class Album < Array def age map { |track| track.age }.max end def score total / Math.log(age) end def total inject(0.0) do |total_score, track| total_score + track.score end end def self.parse(file) today = Time.now d = {} library = Hash.new { |h,k| h[k] = Album.new } IO.foreach(File.expand_path(file)) do |line| if line =~ /(Name|Artist|Album|Date Added|Play Count|Rating)<\/key><.*?>(.*)<\/.*?>/ then key = $1.downcase.split.first val = $2 d[key.intern] = val if d.size == 6 then date = d[:date].sub(/T.*/, '') key = "#{d[:album]} by #{d[:artist]}" age = ((today - Time.parse(date)) / 86400.0).to_i library[key] << Track.new(age, d[:play].to_i, d[:rating].to_i / 20) d.clear end end end library end end Track = Struct.new(:age, :count, :rating) class Track def score rating * count.to_f end end max = (ARGV.shift || 10).to_i file = ARGV.shift || "~/Music/iTunes/iTunes Music Library.xml" library = Album.parse(file) top = library.sort_by { |h,k| -k.score }[0...max] top.each_with_index do |(artist_album, album), c| puts "%-3d = (%4d tot, %5.2f adj): %s" % [c+1, album.total, album.score, artist_album,] album.each do |t| puts " #{t.age} days old, #{t.count} count, #{t.rating} rating = #{t.score}" end if $DEBUG end

Tagged as:

  • Trigs
    2

Comments

    • 1189 trigs,
    • People profile,
    • Currently idle,
    • 28 year old,
    • Male,
    • Handen,
    • Stockholms Lan,
    • Sweden
    oh this looks shite now
    • 1251 trigs,
    • People profile,
    • Currently idle,
    • 25 year old,
    • Male,
    • York,
    • York,
    • United Kingdom
    Oof. I hate the mangled XML that goes into plist files. I get why, but it's an arse to parse intelligibly.

    Anyway, shame the syntax highlighter was taken out temporarily
    • 5847 trigs,
    • People profile,
    • Currently idle,
    • 29 year old,
    • Male,
    • Sundbyberg,
    • Stockholms Lan,
    • Sweden
    ha ha.. that was NOT what i intended to do!
    • 5847 trigs,
    • People profile,
    • Currently idle,
    • 29 year old,
    • Male,
    • Sundbyberg,
    • Stockholms Lan,
    • Sweden
    "Hash.new"? I told you, don't get high on your own supply!



    • 2043 投趣,
    • Christian rock
    • 音乐简介,
    • Currently online,
    • Guelph,
    • Ontario,
    • Canada
    Okay... definitely have to add Ruby to my list of languages. Right now, it's like trying to listen to a Newfoundlander speak English in Ontario.

    Screech anyone?