From: Colin Patrick McCabe Date: Sat, 3 Apr 2010 08:34:51 +0000 (-0700) Subject: superrip.rb: Get basic track ripping working X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=663b146e8b8506caa7605bb8330b4f31b5912b94;p=cmccabe-bin superrip.rb: Get basic track ripping working --- diff --git a/superrip.rb b/superrip.rb index 3826483..a2071e5 100755 --- a/superrip.rb +++ b/superrip.rb @@ -23,7 +23,7 @@ $cd_dev = "/dev/cdrom" #----------------------------------------------------------------- def my_system(cmd) puts cmd - system(cmd) unless $opts.dry_run + system(cmd) unless $opts.dry_run == true ($?.exitstatus == 0) or raise "#{cmd} failed" end @@ -50,20 +50,26 @@ def get_number_of_tracks_on_cd raise "couldn't find what we were looking for in cdda2wav output!" end -def audiorip(track, number) +def audiorip(tnum, track) begin - my_system("nice -1 cdparanoia -w -d #{$cd_dev} #{number}") + my_system("nice -1 cdparanoia -w -d #{$cd_dev} #{tnum}") rescue - raise "failed to rip track #{number} (#{track.name})" + raise "failed to rip track #{tnum} (#{track.name})" end # cdparanoia always outputs to cdda.wav FileUtils.mv("cdda.wav", track.wav_file_name, $fu_args) # TODO: spawn a thread to do this stuff in the background FileUtils.mkdir_p(track.flac_dir, $fu_args) - my_system("flac -c #{track.wav_file_name} > #{track.flac_file_name}") - my_system("lame -q 1 -b 192 #{track.wav_file_name} > #{track.mp3_file_name}") - FileUtils.rm_f(track.wav_file, $fu_args) + my_system("flac -f '#{track.wav_file_name}' --output-name='#{track.flac_file_name}'") + begin + my_system("flac --test '#{track.flac_file_name}'") + rescue + raise "failed to encode #{track.flac_file_name}" + end + FileUtils.mkdir_p(track.mp3_dir, $fu_args) + my_system("lame -q 1 -b 192 '#{track.wav_file_name}' '#{track.mp3_file_name}'") + FileUtils.rm_f(track.wav_file_name, $fu_args) end #----------------------------------------------------------------- @@ -103,7 +109,8 @@ class MyOptions end class Track - attr_accessor :name, :flac_dir, :flac_file_name, :mp3_dir, :mp3_file_name + attr_accessor :name, :flac_dir, :flac_file_name, :mp3_dir, :mp3_file_name, + :wav_file_name def initialize(name) if name =~ /\[LL\]/ then raise "you can't include [LL] in a track name" @@ -117,15 +124,15 @@ class Track (name =~ /([^\/][^\/]*)\/([^\/]*[^\/])/) or \ raise "track name must be of the form 'foo/bar'" @name = name - @flac_dir = "#{1} [LL]" - @flac_file_name = "#{@flac_dir}/#{2}.flac" - @mp3_dir = "#{1}" - @mp3_file_name = "#{@mp3_dir}/#{2}.mp3" - @wav_file_name = "#{1}__#{2}.wav" + @flac_dir = "#{$1} [LL]" + @flac_file_name = "#{@flac_dir}/#{$2}.flac" + @mp3_dir = "#{$1}" + @mp3_file_name = "#{@mp3_dir}/#{$2}.mp3" + @wav_file_name = "#{$1}__#{$2}.wav" end def inspect - "#{@name}" + "track(\"#{@name}\")" end end @@ -158,9 +165,9 @@ class Manifest end def rip(num_tracks) - (1..num_tracks).each do |t| - next unless @t.defined?(t) - audiorip(t) + (1..num_tracks).each do |tnum| + next unless @t.has_key?(tnum) + audiorip(tnum, @t[tnum]) end end @@ -192,8 +199,8 @@ die_unless_installed("cdparanoia") die_unless_installed("cdda2wav") manifest = Manifest.new($opts.manifest_file) -#puts manifest.inspect +puts manifest.inspect num_tracks = get_number_of_tracks_on_cd() puts "found #{num_tracks} tracks" -#manifest.rip(num_tracks) +manifest.rip(num_tracks) exit 0