dvd-sector-copy.c (report_progress): Fiddle with the averaging parameter.
[dvdrip] / dvdrip
diff --git a/dvdrip b/dvdrip
index b09abe8..ad7a280 100755 (executable)
--- a/dvdrip
+++ b/dvdrip
@@ -4,9 +4,8 @@ prog=${0##*/}
 dev=${DVDRIP_DEVICE-/dev/dvd}
 tmp=${DVDRIP_TMPDIR-${HOME?}/tmp/dvdrip}
 archive=${DVDRIP_ARCHIVE-jem.distorted.org.uk:/mnt/dvd/archive}
-here=$(realpath "$0"); here=${here%/*}
-: ${DVD_SECTOR_COPY=$here/dvd-sector-copy.$(uname -m)}
-: ${DVDRIP_UPLOAD=$here/dvdrip-upload}
+: ${DVD_SECTOR_COPY=dvd-sector-copy}
+: ${DVDRIP_UPLOAD=dvdrip-upload}
 backup=nil eject=nil force=nil verbose=nil bogus=nil; unset dir sub n label
 usage () {
   cat <<EOF
@@ -118,7 +117,24 @@ case $rc,$force in
   0,t) warn "output file already exists; will overwrite" ;;
 esac
 
+accumulate_badblocks () {
+  if [ -f "$tmp/$tag/badblocks.new" ]; then
+    if [ ! -f "$tmp/$tag/badblocks" ]; then
+      { echo "## bad-blocks region map"; echo; } >"$tmp/$tag/badblocks"
+    fi
+    sed -n "/^[^#]/p" "$tmp/$tag/badblocks.new" >>"$tmp/$tag/badblocks"
+    rm "$tmp/$tag/badblocks.new"
+  fi
+}
+
 mkdir -p "$tmp/$tag"
+any=nil
+for i in "$tmp/$tag/dest.new" "$tmp/$tag/dest" "$tmp/$tag/dest.seen"; do
+  if [ -f "$tmp/$tag/dest.new" ]; then any=t; fi
+done
+case $any in
+  nil) printf "%s\n" "${sub+$sub/}$out.iso" >"$tmp/$tag/dest.new" ;;
+esac
 case $backup in
   t)
     if [ ! -d "$tmp/$tag/rip" ]; then
@@ -134,23 +150,17 @@ case $backup in
     ;;
   nil)
     if [ ! -f "$tmp/$tag/iso" ]; then
-      run_setrc "$DVD_SECTOR_COPY" -D"$dev" -c -b"$tmp/$tag/badblocks" -o"$tmp/$tag/iso.new"
-      case $rc in
-       0)
-         run mv "$tmp/$tag/iso.new" "$tmp/$tag/iso"
-         ;;
-       1)
-         run mv "$tmp/$tag/iso.new" "$tmp/$tag/iso"
-         fail "bad sectors found: check \`$tmp/$tag/iso', run again if ok"
-         ;;
-       *)
-         fail "$DVD_SECTOR_COPY: exit $rc"
-         ;;
-      esac
+      accumulate_badblocks
+      run "$DVD_SECTOR_COPY" -c -b"$tmp/$tag/badblocks.new" \
+         "$dev" "$tmp/$tag/iso.new"
+      run mv "$tmp/$tag/iso.new" "$tmp/$tag/iso"
+      accumulate_badblocks
+      if [ -f "$tmp/$tag/badblocks" ]; then
+       fail "bad sectors found: check \`$tmp/$tag/iso', run again if ok"
+      fi
     fi
     ;;
 esac
-printf "%s\n" "${sub+$sub/}$out.iso" >"$tmp/$tag/dest.new"
 mv "$tmp/$tag/dest.new" "$tmp/$tag/dest"
 run "$DVDRIP_UPLOAD"
 case $eject in t) run eject "$dev" ;; esac