diff --git a/getcd.sh b/getcd.sh index a0f902a..030a937 100755 --- a/getcd.sh +++ b/getcd.sh @@ -17,35 +17,78 @@ case "${scriptDir}" in /*);; *) scriptDir="${PWD}/${scriptDir}";; esac # -------------------------------------------------------------- # string definitions -usage=$"usage: $0 [-t {m|f|o}] [-p path] [-e encoder] [-c cddb-entry] [-h|-?] - [-I interface] [-D device] [-v[v]] -\t-t: you can specify either m for encoding to mp3 -\t using lame, or f for making lossless encoding using flac, -\t or o for making ogg/vorbis, or w for uncompressed wav. -\t Omitting this results in encoding to flac. -\t mp3s will be placed under a subfolder mp3 and flacs -\t under a subfolder flac -\t-p: specifies the path to save the encoded data. -\t Defaults to the users home directory. -\t-e: specifies the mp3 encoder to use. -\t valid encoders are actually: lame,bladeenc -\t Defaults to lame. -\t-c: specifies the CDDB-Entry to use. -\t sometimes there is more than 1 entry for a cd in cddb. -\t Then you can specify wich one to use by this option. -\t You can checkout all entries using cddb.pl. -\t-I: specifies cdda2wav interface to use. -\t Valid interfaces are generic_scsi and cooked_ioctl. -\t Please note that cooked_ioctl is not available on all systems. -\t Defaults to generic_scsi -\t-D: specifies device to use with cdda2wav. -\t Defaults to /dev/cdrom -\t-v: make the script more verbose. The verbosity level defaults -\t to 1. When -v is given the level is 2 and -vv increases the -\t level to 3, what means give debug output. -\t-q: make the script silent. Equivalent to -v0 -\t-h| -\t-?: Shows this help." +enhUsage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h] + [-I interface] [-D device] [-v[v|0]] [-q] + [--help] [--encoding=(m|f|o|w)] [--encoder=(lame|bladeenc)] + [--path=] [--interface=(cooked_ioctl|generic_scsi)] + [--device=] + options: + -h | --help: gives this help + -v: set verbosity level. + -v0 disable all output + -v be more verbose + -vv enables debug + -q: make the script silent. Equivalent to -v0 + -t | --encoding: you can specify either m for encoding to mp3 + using lame, or f for making lossless encoding using flac, + or o for making ogg/vorbis, or w for uncompressed wav. + Omitting this results in encoding to flac. + mp3s will be placed under a subfolder mp3 and flacs + under a subfolder flac + -p | --path: specifies the path to save the encoded data. + Defaults to the users home directory. + -e | --encoder: specifies the mp3 encoder to use. + valid encoders are actually: lame,bladeenc + Defaults to lame. + -c: specifies the CDDB-Entry to use. + sometimes there is more than 1 entry for a cd in cddb. + Then you can specify wich one to use by this option. + You can checkout all entries using cddb.pl. + -I | --interface: specifies cdda2wav interface to use. + Valid interfaces are generic_scsi and cooked_ioctl. + Please note that cooked_ioctl is not available on all + systems. Defaults to cooked_ioctl if device begins with + /dev else to generic_scsi + -D | --device: specifies device to use with cdda2wav. All values that + are valid for cdda2wav are valid here. + Defaults to /dev/cdrom + +This script uses cdda2wav, cddb and various encoders to rip an audio CD." + +usage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h] + [-I interface] [-D device] [-v[v|0]] [-q] + options: + -h: this help + -v: set verbosity level. + -v0 disable all output + -v be more verbose + -vv enables debug + -q: make the script silent. Equivalent to -v0 + -t: you can specify either m for encoding to mp3 + using lame, or f for making lossless encoding using flac, + or o for making ogg/vorbis, or w for uncompressed wav. + Omitting this results in encoding to flac. + mp3s will be placed under a subfolder mp3 and flacs + under a subfolder flac + -p: specifies the path to save the encoded data. + Defaults to the users home directory. + -e: specifies the mp3 encoder to use. + valid encoders are actually: lame,bladeenc + Defaults to lame. + -c: specifies the CDDB-Entry to use. + sometimes there is more than 1 entry for a cd in cddb. + Then you can specify wich one to use by this option. + You can checkout all entries using cddb.pl. + -I: specifies cdda2wav interface to use. + Valid interfaces are generic_scsi and cooked_ioctl. + Please note that cooked_ioctl is not available on all + systems. Defaults to cooked_ioctl if device begins with + /dev else to generic_scsi + -D: specifies device to use with cdda2wav. All values that + are valid for cdda2wav are valid here. + Defaults to /dev/cdrom + +This script uses cdda2wav, cddb and various encoders to rip an audio CD." ready=$"done" @@ -79,92 +122,130 @@ TRACKS: =======" # -------------------------------------------------------------- +# -------------------------------------------------------------- +# Optionen auswerten (im Moment nur angabe einer alternativen +# Konfigurationsdatei, und vebose). Vorher default-werte setzen. +# Irgendwie hab ich noch Probleme mit -? das scheint nicht zu funzen. +$GETOPT -T >/dev/null 2>&1 +if [ $? -eq 4 ] +then + # enhanced getopt + usage="${enhUsage}" + + TEMP="`$GETOPT -o "?hv::qt:p:e:c:I:D:" -l "help,encoding:,encoder:,path:,interface:,device:" -- "$@"`" +else + # old getopt + TEMP="`$GETOPT "?hv::qt:p:e:c:I:D:" "$@"`" +fi +test $? -ne 0 && { echo -e "${usage}"; exit 1; } # on error + +eval set -- "$TEMP" # set $1,$2,... + taOrder="t" encodingDir=$HOME encodingType="f" encoder="lame" cddbEntry=1 -cddaIf="generic_scsi" +cddaIf="" cddaDev="/dev/cdrom" verbose=1 - -# ---------------------------------------------------------------- -# get commandline options -while getopts qvt:p:he:c:I:D: option +while true do - case $option in - t) - if [ "${OPTARG}" != "m" -a "${OPTARG}" != "f" -a \ - "${OPTARG}" != "o" -a "${OPTARG}" != "w" ] + case "$1" in + --) + shift; break;; + + -v) + # v has an optional argument. As we are in quoted mode, + # an empty parameter will be generated if its optional + # argument is not found. + if [ -z "$2" ] then - echo -e "$usage" - exit 1 + verbose=2 + shift 2 + else + case "$2" in + v) verbose=3; shift 2;; + *) verbose="$2"; shift 2;; + esac fi - encodingType=$OPTARG ;; - p) - if [ ! \( -d ${OPTARG} \) ] + + -q) + verbose=0 + ;; + + -t|--encoding) + if [ "$2" != "m" -a "$2" != "f" -a \ + "$2" != "o" -a "$2" != "w" ] then echo -e "$usage" exit 1 fi - encodingDir=$OPTARG + encodingType=$2 ;; - e) - if [ -z ${OPTARG} ] + + -p|--path) + if [ ! \( -d $2 \) ] then echo -e "$usage" exit 1 fi - encoder=$OPTARG + encodingDir=$2 ;; - c) - if [ ${OPTARG} -lt 1 ] + + -e|--encoder) + if [ -z $2 ] then echo -e "$usage" exit 1 fi - cddbEntry=$OPTARG + encoder=$2 ;; - v) - if [ "${OPTARG}" -a "${OPTARG}" != "0" -a "${OPTARG}" != "v" ] + + -c) + if [ $2 -lt 1 ] then echo -e "$usage" exit 1 fi - test -z "${OPTARG}" && verbose=2 - test "${OPTARG}" = "0" && verbose=0 - test "${OPTARG}" = "v" && verbose=3 - ;; - q) - verbose=0 + cddbEntry=$2 ;; - I) - if [ "${OPTARG}" != "generic_scsi" -a \ - "${OPTARG}" != "cooked_ioctl" ] + + -I) + if [ "$2" != "generic_scsi" -a \ + "$2" != "cooked_ioctl" ] then echo -e "$usage" exit 1 fi - cddaIf=$OPTARG + cddaIf=$2 ;; - D) - if [ ${OPTARG} -lt 1 ] + + -D) + if [ $2 -lt 1 ] then echo -e "$usage" exit 1 fi - cddaDev=$OPTARG + cddaDev=$2 ;; - [h\?]) - echo -e "$usage" + + -h|--help|*) + echo "${usage}" exit 1 ;; - esac + esac done -# ---------------------------------------------------------------- +# -------------------------------------------------------------- -echo "verbose: $verbose" +if [ -z "${cddaIf}" ] +then + test "${cddaDev%/*}" = "/dev" &&\ + cddaIf="cooked_ioctl" ||\ + cddaIf="generic_scsi" +fi +# ---------------------------------------------------------------- # ---------------------------------------------------------------- # set encodingDir for used encodingType @@ -283,11 +364,9 @@ do # processing at once, so the percentage is not shown correctly if [ ${verbose} -ge 2 ] then - outCmd="tr '\r' '\n' | - sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'\"\${outStr}\"'\1/' | - tr -d '\n'" + outStream="/dev/stdout" else - outCmd="cat >/dev/null" + outStream="/dev/null" fi case ${encodingType} in @@ -303,8 +382,10 @@ do -T genre="${dGenre}" -T title="${tTitle[$i]}" \ -T tracknumber="${trackNr}" -T tracknum="${trackNr}" \ -T date="${dYear}" -T comment="" \ - -o "${encodingDir}/${outFile}" - 2>/dev/null - ) | $outCmd + -o "${encodingDir}/${outFile}" - #2>/dev/null + ) | tr '\r' '\n' |\ + sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ + tr -d '\n' >$outStream ;; m) outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.mp3" @@ -323,7 +404,7 @@ do - "${encodingDir}/${outFile}" 2>/dev/null ) | tr '\r' '\n' |\ sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ - tr -d '\n' + tr -d '\n' >$outStream ;; bladeenc) ( @@ -333,7 +414,7 @@ do "${encodingDir}/${outFile}" 2>/dev/null ) | tr '\r' '\n' |\ sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ - tr -d '\n' + tr -d '\n' >$outStream ;; esac ;; @@ -351,7 +432,7 @@ do -o "${encodingDir}/${outFile}" - 2>/dev/null ) | tr '\r' '\n' |\ sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ - tr -d '\n' + tr -d '\n' >$outStream ;; w) outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.wav" @@ -363,11 +444,11 @@ do "${encodingDir}/${outFile}" ) | tr '\r' '\n' |\ sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ - tr -d '\n' + tr -d '\n' >$outStream ;; esac - echo # do a newline after each file + test ${verbose} -ge 2 && echo # do a newline after each file i=$((i+1)) done