public
Description: A ruby client for freebase
Clone URL: git://github.com/dustin/ruby-freebase.git
chriseppstein (author)
Sun Feb 03 12:15:22 -0800 2008
commit  a631c2035df055d70560a7a7a248a146cc1ee69f
tree    1dba0c62d357e1b0a8e15588fc2f3dd531c055f3
parent  70ce157b1061accaa86c21b5694dd592dec21ac5
ruby-freebase / examples / albums.rb
100755 52 lines (44 sloc) 1.202 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env ruby
# (c) Copyright 2007 Chris Eppstein. All Rights Reserved.
# Usage:
# ruby albums.rb "The Police"
 
 
require "freebase"
 
 
# add these methods to the Track class
module Freebase::Mixins::Music
  module Track
    def formatted_length
      "#{self.length.to_i / 60}:#{sprintf("%02i", self.length.to_i % 60)}"
    end
  end
end
 
def usage
%Q{Usage:
ruby albums.rb artist_name_in_english
}
end
 
unless ARGV[0]
  puts usage
  exit 1
end
 
artist = Freebase::Types::Music::Artist.find(:first,
  :conditions => {
    :name => {:value => ARGV[0], :lang => {:name => "English"}},
    :album => [{
      :fb_object => true,
      :name => {:value => nil, :lang => {:name => "English"}},
      :release_date => nil,
      :track => [{
        :fb_object => true,
        :length => nil,
        :name => {:value => nil, :lang => {:name => "English"}}
      }]
    }]
  }
)
 
artist.albums.each_with_index do |album, i|
  next unless album # XXX I don't know why I'm getting random nils here.
  puts "#{i+1}) #{album.name} (#{album.release_date || '?'})"
  album.tracks.compact.each_with_index do |track, j|
      puts "\tT#{j+1}. #{track.name || '???'} (#{track.formatted_length})"
  end
end