#!/usr/bin/env ruby require 'freedb' # The default output for each track is NN - title.flac=NN - title. # To simplify this to just the title, uncomment the following line simple_format = true def readable_length(l) s = l h = 0 if l >= 3600 h, s = l.divmod(3600) end m, s = s.divmod(60) sprintf("%dh %02dm %02ds", h, m, s) end f = Freedb.new("/dev/cdrom") case ARGV[0] when "cgi" #puts "using cgi method" f.fetch_cgi when /^disk=(.+)/ #puts "using disk method" f.fetch_disk($1) when /^disk_win=(.+)/ #puts "using disk (windows format) method" f.fetch_disk($1, true) else #puts "using socket method" f.fetch_net end #p f.results if f.results.size > 1 # if more than 1 result f.results.each_with_index { |title,i| STDERR.printf("%02d %s\n", i, title) } STDERR.print "Enter selection: " STDERR.flush f.get_result(STDIN.gets.to_i) elsif f.results.size == 1 f.get_result(0) else puts "No match found." exit(1) end puts "Artist=#{f.artist}" puts "Album=#{f.title}" if f.genre puts "Genre=#{f.genre}" elsif f.category puts "Genre=#{f.category}" else puts "Genre=unknown" end if f.year != 0 puts "Date=#{f.year}" else if f.ext_infos =~ /YEAR:\s*(\d+)/ puts "Date=#{$1}" else puts "Date=0000" end end f.tracks.each_with_index do |tr,i| if (simple_format) puts(tr['title']) else printf("%02d - %s.flac=%02d - %s\n", i+1, tr['title'], i+1, tr['title']) end end f.close