From b046723cf8f054d29927c9fe421d0cbaaaed44c8 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Sat, 3 Apr 2010 01:08:24 -0700 Subject: [PATCH] superrip: incremental improvements Get count_number_of_tracks working. Add some future TODOs. Get inspect methods working for Track and Manifest --- superrip.rb | 60 +++++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 40 insertions(+), 20 deletions(-) diff --git a/superrip.rb b/superrip.rb index 0b1ef6f..3826483 100755 --- a/superrip.rb +++ b/superrip.rb @@ -34,15 +34,17 @@ end def get_number_of_tracks_on_cd look_for_tracks = false - IO.popen("cdda2wav -v summary -J dev=#{$cd_dev}", "r") do |io| - line = io.read.chomp - if (line =~ /^AUDIOtrack/) then - look_for_tracks = true - elsif (look_for_tracks == true) then - look_for_tracks = false - line =~ /[ \t]*1-([1234567890][1234567890]*)[^1234567890]/ \ - or raise "couldn't understand cdda2wav output!" - return $1.to_i + IO.popen("cdda2wav -v summary -J dev=#{$cd_dev} 2>&1", "r") do |io| + io.readlines.each do |line| + line.chomp! + if (line =~ /^AUDIOtrack/) then + look_for_tracks = true + elsif (look_for_tracks == true) then + look_for_tracks = false + line =~ /[ \t]*1-([1234567890][1234567890]*)[^1234567890]/ \ + or raise "couldn't understand cdda2wav output!" + return $1.to_i + end end end raise "couldn't find what we were looking for in cdda2wav output!" @@ -82,12 +84,12 @@ class MyOptions opts.dry_run = true $fu_args = { :verbose => true, :noop => true } end - myparser.on("--tracklist", "-t", + myparser.on("--tracklist [FILE]", "-t", "Provide a list of tracks to use.") do |file| opts.manifest_file = file opts.partial = false end - myparser.on("--partial-tracklist", "-T", + myparser.on("--partial-tracklist [FILE]", "-T", "Provide a partial list of tracks to use.") do |file| opts.manifest_file = file opts.partial = true @@ -121,37 +123,54 @@ class Track @mp3_file_name = "#{@mp3_dir}/#{2}.mp3" @wav_file_name = "#{1}__#{2}.wav" end + + def inspect + "#{@name}" + end end class Manifest def initialize(filename) - @tracks = Hash.new - eval(filename) - @tracks.each do |key, val| - @tracks[key] = Track.new(val) + @t = Hash.new + eval(File.new(filename).read) + @t.each do |key, val| + @t[key] = Track.new(val) end + # TODO: implement some shortcuts that make manifests easier to type. + # Probably avoiding the necessity to continue typing the album name if it is the same as the + # previous track's name would make things a lot easier without complicating everything too much. end def validate(num_tracks) - if (@tracks.empty?) then + if (@t.empty?) then raise "you must define some tracks" end - @tracks.each { |t| t.validate } + @t.each { |t| t.validate } if (not $opts.partial) then (1..num_tracks).each do |t| - if not @tracks[t].defined? + if not @t[t].defined? raise "don't know what to do with track #{t}" end end end + # TODO: make sure that tracks inside albums are in order + # i.e. we don't map track 2 to a name that sorts to before track 1 end def rip(num_tracks) (1..num_tracks).each do |t| - next unless @tracks.defined?(t) + next unless @t.defined?(t) audiorip(t) end end + + def inspect + ret = "" + @t.keys.sort.each do |key| + ret = "#{ret}#{key}:'#{@t[key].inspect()}'\n" + end + return ret + end end #----------------------------------------------------------------- @@ -173,7 +192,8 @@ die_unless_installed("cdparanoia") die_unless_installed("cdda2wav") manifest = Manifest.new($opts.manifest_file) +#puts manifest.inspect num_tracks = get_number_of_tracks_on_cd() -puts "num_tracks = #{num_tracks}" +puts "found #{num_tracks} tracks" #manifest.rip(num_tracks) exit 0 -- 1.6.6.rc1.39.g9a42