]> diplodocus.org Git - flac-archive/blobdiff - fa-rip
Support a -t track-count option to fa-rip and mkcue, so we can skip
[flac-archive] / fa-rip
diff --git a/fa-rip b/fa-rip
index eabf52ea97878939f1418511c60f3aaaf190846d..47558220d9442d46d73a1ad60acf01fc1d5dcdf5 100755 (executable)
--- a/fa-rip
+++ b/fa-rip
@@ -3,12 +3,15 @@
 # $Id$
 
 set -e
-setopt NULL_GLOB
 
-get_cddev () {
-    local raw
+function get_cddev {
+    typeset raw
     raw=$(sysctl -n kern.rawpartition > /dev/null | awk '{printf "%c",97+$0}')
 
+    if [[ -n ${ZSH_VERSION} ]]; then
+        setopt NULL_GLOB
+    fi
+
     for CDDEV in /dev/{cdroms/cdrom*,cdrom*,rcd*${raw},{a,}cd*c}; do
         [[ -e ${CDDEV} ]] && return 0
     done
@@ -16,21 +19,42 @@ get_cddev () {
     return 1
 }
 
+trackcount=
+while getopts 'd:t:' ch; do
+    case ${ch} in
+        d)
+            CDDEV=${OPTARG}
+            export CDDEV
+            ;;
+        t)
+            trackcount=${OPTARG}
+            ;;
+        ?)
+            echo 'fa-rip [-t track-count]' >&2
+            exit 2
+            ;;
+    esac
+done
+shift $((${OPTIND} - 1))
+
 if [[ -z ${CDDEV} ]]; then
     if ! get_cddev; then
-        echo 'CDDEV environment variable not set, defaults did not work'
+        echo 'CDDEV environment variable not set, defaults did not work' >&2
         exit 2
     fi
+    export CDDEV
 fi
 
 dir=$(mktemp -d flac-archive.XXXXXXXXXX)
 cd ${dir}
 
-cdrdao read-toc --device ${CDDEV} --driver generic-mmc toc
-toc2cue toc cue
-
-trackcount=$(grep -c 'TRACK.*AUDIO' cue)
+if [[ -z ${trackcount} ]]; then
+    mkcue ${CDDEV} > cue
+    trackcount=$(grep -c 'TRACK.*AUDIO' cue)
+else
+    mkcue -t ${trackcount} ${CDDEV} > cue
+fi
 
 fa-tags ${trackcount}
 
-exec cdparanoia -d ${CDDEV} 1-$(grep -c 'TRACK.*AUDIO' cue) wav
+exec cdparanoia -d ${CDDEV} 1-${trackcount} wav