superrip: add an option to change cd device
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Sat, 3 Apr 2010 22:14:17 +0000 (15:14 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Sat, 3 Apr 2010 22:14:17 +0000 (15:14 -0700)
superrip.rb

index b6c5617..cc413db 100755 (executable)
@@ -16,7 +16,6 @@ require 'ostruct'
 #-----------------------------------------------------------------
 # constants
 #-----------------------------------------------------------------
-$cd_dev = "/dev/cdrom"
 $children = Hash.new
 
 #-----------------------------------------------------------------
@@ -36,7 +35,7 @@ end
 def get_number_of_tracks_on_cd
   look_for_tracks = false
   lines = Array.new
-  IO.popen("cdda2wav -v summary -J dev=#{$cd_dev} 2>&1", "r") do |io|
+  IO.popen("cdda2wav -v summary -J dev=#{$opts.cd_dev} 2>&1", "r") do |io|
     io.readlines.each do |line|
       line.chomp!
       lines << line
@@ -69,7 +68,7 @@ end
 
 def audiorip(tnum, track)
   begin
-    my_system("nice -1 cdparanoia -w -d #{$cd_dev} #{tnum}")
+    my_system("nice -1 cdparanoia -w -d #{$opts.cd_dev} #{tnum}")
   rescue
     raise "failed to rip track #{tnum} (#{track.name})"
   end
@@ -108,12 +107,17 @@ class MyOptions
     opts = OpenStruct.new
     opts.dry_run = false
     opts.max_children = 4
+    opts.cd_dev = "/dev/cdrom"
     $fu_args = { :verbose => true }
 
     # Fill in opts values
     parser = OptionParser.new do |myparser|
       myparser.banner = "Usage: #{ File.basename($0) } [opts]"
       myparser.separator("Specific options:")
+      myparser.on("--dev [DEV]", "-D",
+                  "choose the cdrom device file to use") do |dev|
+        opts.cd_dev = dev
+      end
       myparser.on("--dry-run", "-d",
             "Show what would be done, without doing it.") do |a|
         opts.dry_run = true
@@ -189,7 +193,13 @@ class Manifest
     if (@t.empty?) then
       raise "you must define some tracks"
     end
-    if (not $opts.partial) then
+    if ($opts.partial) then
+      highest_track = @t.keys.sort[-1]
+      if (num_tracks < highest_track) then
+        raise "can't rip track #{highest_track}, because there are \
+only #{num_tracks} tracks"
+      end
+    else
       (1..num_tracks).each do |tnum|
         if not @t.has_key?(tnum)
           raise "don't know what to do with track #{tnum}"