Showing
1 changed file
with
162 additions
and
81 deletions
@@ -17,35 +17,78 @@ case "${scriptDir}" in /*);; *) scriptDir="${PWD}/${scriptDir}";; esac | @@ -17,35 +17,78 @@ case "${scriptDir}" in /*);; *) scriptDir="${PWD}/${scriptDir}";; esac | ||
17 | 17 | ||
18 | # -------------------------------------------------------------- | 18 | # -------------------------------------------------------------- |
19 | # string definitions | 19 | # string definitions |
20 | -usage=$"usage: $0 [-t {m|f|o}] [-p path] [-e encoder] [-c cddb-entry] [-h|-?] | ||
21 | - [-I interface] [-D device] [-v[v]] | ||
22 | -\t-t: you can specify either m for encoding to mp3 | ||
23 | -\t using lame, or f for making lossless encoding using flac, | ||
24 | -\t or o for making ogg/vorbis, or w for uncompressed wav. | ||
25 | -\t Omitting this results in encoding to flac. | ||
26 | -\t mp3s will be placed under a subfolder mp3 and flacs | ||
27 | -\t under a subfolder flac | ||
28 | -\t-p: specifies the path to save the encoded data. | ||
29 | -\t Defaults to the users home directory. | ||
30 | -\t-e: specifies the mp3 encoder to use. | ||
31 | -\t valid encoders are actually: lame,bladeenc | ||
32 | -\t Defaults to lame. | ||
33 | -\t-c: specifies the CDDB-Entry to use. | ||
34 | -\t sometimes there is more than 1 entry for a cd in cddb. | ||
35 | -\t Then you can specify wich one to use by this option. | ||
36 | -\t You can checkout all entries using cddb.pl. | ||
37 | -\t-I: specifies cdda2wav interface to use. | ||
38 | -\t Valid interfaces are generic_scsi and cooked_ioctl. | ||
39 | -\t Please note that cooked_ioctl is not available on all systems. | ||
40 | -\t Defaults to generic_scsi | ||
41 | -\t-D: specifies device to use with cdda2wav. | ||
42 | -\t Defaults to /dev/cdrom | ||
43 | -\t-v: make the script more verbose. The verbosity level defaults | ||
44 | -\t to 1. When -v is given the level is 2 and -vv increases the | ||
45 | -\t level to 3, what means give debug output. | ||
46 | -\t-q: make the script silent. Equivalent to -v0 | ||
47 | -\t-h| | ||
48 | -\t-?: Shows this help." | 20 | +enhUsage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h] |
21 | + [-I interface] [-D device] [-v[v|0]] [-q] | ||
22 | + [--help] [--encoding=(m|f|o|w)] [--encoder=(lame|bladeenc)] | ||
23 | + [--path=<string>] [--interface=(cooked_ioctl|generic_scsi)] | ||
24 | + [--device=<string>] | ||
25 | + options: | ||
26 | + -h | --help: gives this help | ||
27 | + -v: set verbosity level. | ||
28 | + -v0 disable all output | ||
29 | + -v be more verbose | ||
30 | + -vv enables debug | ||
31 | + -q: make the script silent. Equivalent to -v0 | ||
32 | + -t | --encoding: you can specify either m for encoding to mp3 | ||
33 | + using lame, or f for making lossless encoding using flac, | ||
34 | + or o for making ogg/vorbis, or w for uncompressed wav. | ||
35 | + Omitting this results in encoding to flac. | ||
36 | + mp3s will be placed under a subfolder mp3 and flacs | ||
37 | + under a subfolder flac | ||
38 | + -p | --path: specifies the path to save the encoded data. | ||
39 | + Defaults to the users home directory. | ||
40 | + -e | --encoder: specifies the mp3 encoder to use. | ||
41 | + valid encoders are actually: lame,bladeenc | ||
42 | + Defaults to lame. | ||
43 | + -c: specifies the CDDB-Entry to use. | ||
44 | + sometimes there is more than 1 entry for a cd in cddb. | ||
45 | + Then you can specify wich one to use by this option. | ||
46 | + You can checkout all entries using cddb.pl. | ||
47 | + -I | --interface: specifies cdda2wav interface to use. | ||
48 | + Valid interfaces are generic_scsi and cooked_ioctl. | ||
49 | + Please note that cooked_ioctl is not available on all | ||
50 | + systems. Defaults to cooked_ioctl if device begins with | ||
51 | + /dev else to generic_scsi | ||
52 | + -D | --device: specifies device to use with cdda2wav. All values that | ||
53 | + are valid for cdda2wav are valid here. | ||
54 | + Defaults to /dev/cdrom | ||
55 | + | ||
56 | +This script uses cdda2wav, cddb and various encoders to rip an audio CD." | ||
57 | + | ||
58 | +usage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h] | ||
59 | + [-I interface] [-D device] [-v[v|0]] [-q] | ||
60 | + options: | ||
61 | + -h: this help | ||
62 | + -v: set verbosity level. | ||
63 | + -v0 disable all output | ||
64 | + -v be more verbose | ||
65 | + -vv enables debug | ||
66 | + -q: make the script silent. Equivalent to -v0 | ||
67 | + -t: you can specify either m for encoding to mp3 | ||
68 | + using lame, or f for making lossless encoding using flac, | ||
69 | + or o for making ogg/vorbis, or w for uncompressed wav. | ||
70 | + Omitting this results in encoding to flac. | ||
71 | + mp3s will be placed under a subfolder mp3 and flacs | ||
72 | + under a subfolder flac | ||
73 | + -p: specifies the path to save the encoded data. | ||
74 | + Defaults to the users home directory. | ||
75 | + -e: specifies the mp3 encoder to use. | ||
76 | + valid encoders are actually: lame,bladeenc | ||
77 | + Defaults to lame. | ||
78 | + -c: specifies the CDDB-Entry to use. | ||
79 | + sometimes there is more than 1 entry for a cd in cddb. | ||
80 | + Then you can specify wich one to use by this option. | ||
81 | + You can checkout all entries using cddb.pl. | ||
82 | + -I: specifies cdda2wav interface to use. | ||
83 | + Valid interfaces are generic_scsi and cooked_ioctl. | ||
84 | + Please note that cooked_ioctl is not available on all | ||
85 | + systems. Defaults to cooked_ioctl if device begins with | ||
86 | + /dev else to generic_scsi | ||
87 | + -D: specifies device to use with cdda2wav. All values that | ||
88 | + are valid for cdda2wav are valid here. | ||
89 | + Defaults to /dev/cdrom | ||
90 | + | ||
91 | +This script uses cdda2wav, cddb and various encoders to rip an audio CD." | ||
49 | 92 | ||
50 | ready=$"done" | 93 | ready=$"done" |
51 | 94 | ||
@@ -79,92 +122,130 @@ TRACKS: | @@ -79,92 +122,130 @@ TRACKS: | ||
79 | =======" | 122 | =======" |
80 | # -------------------------------------------------------------- | 123 | # -------------------------------------------------------------- |
81 | 124 | ||
125 | +# -------------------------------------------------------------- | ||
126 | +# Optionen auswerten (im Moment nur angabe einer alternativen | ||
127 | +# Konfigurationsdatei, und vebose). Vorher default-werte setzen. | ||
128 | +# Irgendwie hab ich noch Probleme mit -? das scheint nicht zu funzen. | ||
129 | +$GETOPT -T >/dev/null 2>&1 | ||
130 | +if [ $? -eq 4 ] | ||
131 | +then | ||
132 | + # enhanced getopt | ||
133 | + usage="${enhUsage}" | ||
134 | + | ||
135 | + TEMP="`$GETOPT -o "?hv::qt:p:e:c:I:D:" -l "help,encoding:,encoder:,path:,interface:,device:" -- "$@"`" | ||
136 | +else | ||
137 | + # old getopt | ||
138 | + TEMP="`$GETOPT "?hv::qt:p:e:c:I:D:" "$@"`" | ||
139 | +fi | ||
140 | +test $? -ne 0 && { echo -e "${usage}"; exit 1; } # on error | ||
141 | + | ||
142 | +eval set -- "$TEMP" # set $1,$2,... | ||
143 | + | ||
82 | taOrder="t" | 144 | taOrder="t" |
83 | encodingDir=$HOME | 145 | encodingDir=$HOME |
84 | encodingType="f" | 146 | encodingType="f" |
85 | encoder="lame" | 147 | encoder="lame" |
86 | cddbEntry=1 | 148 | cddbEntry=1 |
87 | -cddaIf="generic_scsi" | 149 | +cddaIf="" |
88 | cddaDev="/dev/cdrom" | 150 | cddaDev="/dev/cdrom" |
89 | verbose=1 | 151 | verbose=1 |
90 | - | ||
91 | -# ---------------------------------------------------------------- | ||
92 | -# get commandline options | ||
93 | -while getopts qvt:p:he:c:I:D: option | 152 | +while true |
94 | do | 153 | do |
95 | - case $option in | ||
96 | - t) | ||
97 | - if [ "${OPTARG}" != "m" -a "${OPTARG}" != "f" -a \ | ||
98 | - "${OPTARG}" != "o" -a "${OPTARG}" != "w" ] | 154 | + case "$1" in |
155 | + --) | ||
156 | + shift; break;; | ||
157 | + | ||
158 | + -v) | ||
159 | + # v has an optional argument. As we are in quoted mode, | ||
160 | + # an empty parameter will be generated if its optional | ||
161 | + # argument is not found. | ||
162 | + if [ -z "$2" ] | ||
99 | then | 163 | then |
100 | - echo -e "$usage" | ||
101 | - exit 1 | 164 | + verbose=2 |
165 | + shift 2 | ||
166 | + else | ||
167 | + case "$2" in | ||
168 | + v) verbose=3; shift 2;; | ||
169 | + *) verbose="$2"; shift 2;; | ||
170 | + esac | ||
102 | fi | 171 | fi |
103 | - encodingType=$OPTARG | ||
104 | ;; | 172 | ;; |
105 | - p) | ||
106 | - if [ ! \( -d ${OPTARG} \) ] | 173 | + |
174 | + -q) | ||
175 | + verbose=0 | ||
176 | + ;; | ||
177 | + | ||
178 | + -t|--encoding) | ||
179 | + if [ "$2" != "m" -a "$2" != "f" -a \ | ||
180 | + "$2" != "o" -a "$2" != "w" ] | ||
107 | then | 181 | then |
108 | echo -e "$usage" | 182 | echo -e "$usage" |
109 | exit 1 | 183 | exit 1 |
110 | fi | 184 | fi |
111 | - encodingDir=$OPTARG | 185 | + encodingType=$2 |
112 | ;; | 186 | ;; |
113 | - e) | ||
114 | - if [ -z ${OPTARG} ] | 187 | + |
188 | + -p|--path) | ||
189 | + if [ ! \( -d $2 \) ] | ||
115 | then | 190 | then |
116 | echo -e "$usage" | 191 | echo -e "$usage" |
117 | exit 1 | 192 | exit 1 |
118 | fi | 193 | fi |
119 | - encoder=$OPTARG | 194 | + encodingDir=$2 |
120 | ;; | 195 | ;; |
121 | - c) | ||
122 | - if [ ${OPTARG} -lt 1 ] | 196 | + |
197 | + -e|--encoder) | ||
198 | + if [ -z $2 ] | ||
123 | then | 199 | then |
124 | echo -e "$usage" | 200 | echo -e "$usage" |
125 | exit 1 | 201 | exit 1 |
126 | fi | 202 | fi |
127 | - cddbEntry=$OPTARG | 203 | + encoder=$2 |
128 | ;; | 204 | ;; |
129 | - v) | ||
130 | - if [ "${OPTARG}" -a "${OPTARG}" != "0" -a "${OPTARG}" != "v" ] | 205 | + |
206 | + -c) | ||
207 | + if [ $2 -lt 1 ] | ||
131 | then | 208 | then |
132 | echo -e "$usage" | 209 | echo -e "$usage" |
133 | exit 1 | 210 | exit 1 |
134 | fi | 211 | fi |
135 | - test -z "${OPTARG}" && verbose=2 | ||
136 | - test "${OPTARG}" = "0" && verbose=0 | ||
137 | - test "${OPTARG}" = "v" && verbose=3 | ||
138 | - ;; | ||
139 | - q) | ||
140 | - verbose=0 | 212 | + cddbEntry=$2 |
141 | ;; | 213 | ;; |
142 | - I) | ||
143 | - if [ "${OPTARG}" != "generic_scsi" -a \ | ||
144 | - "${OPTARG}" != "cooked_ioctl" ] | 214 | + |
215 | + -I) | ||
216 | + if [ "$2" != "generic_scsi" -a \ | ||
217 | + "$2" != "cooked_ioctl" ] | ||
145 | then | 218 | then |
146 | echo -e "$usage" | 219 | echo -e "$usage" |
147 | exit 1 | 220 | exit 1 |
148 | fi | 221 | fi |
149 | - cddaIf=$OPTARG | 222 | + cddaIf=$2 |
150 | ;; | 223 | ;; |
151 | - D) | ||
152 | - if [ ${OPTARG} -lt 1 ] | 224 | + |
225 | + -D) | ||
226 | + if [ $2 -lt 1 ] | ||
153 | then | 227 | then |
154 | echo -e "$usage" | 228 | echo -e "$usage" |
155 | exit 1 | 229 | exit 1 |
156 | fi | 230 | fi |
157 | - cddaDev=$OPTARG | 231 | + cddaDev=$2 |
158 | ;; | 232 | ;; |
159 | - [h\?]) | ||
160 | - echo -e "$usage" | 233 | + |
234 | + -h|--help|*) | ||
235 | + echo "${usage}" | ||
161 | exit 1 | 236 | exit 1 |
162 | ;; | 237 | ;; |
163 | - esac | 238 | + esac |
164 | done | 239 | done |
165 | -# ---------------------------------------------------------------- | 240 | +# -------------------------------------------------------------- |
166 | 241 | ||
167 | -echo "verbose: $verbose" | 242 | +if [ -z "${cddaIf}" ] |
243 | +then | ||
244 | + test "${cddaDev%/*}" = "/dev" &&\ | ||
245 | + cddaIf="cooked_ioctl" ||\ | ||
246 | + cddaIf="generic_scsi" | ||
247 | +fi | ||
248 | +# ---------------------------------------------------------------- | ||
168 | 249 | ||
169 | # ---------------------------------------------------------------- | 250 | # ---------------------------------------------------------------- |
170 | # set encodingDir for used encodingType | 251 | # set encodingDir for used encodingType |
@@ -283,11 +364,9 @@ do | @@ -283,11 +364,9 @@ do | ||
283 | # processing at once, so the percentage is not shown correctly | 364 | # processing at once, so the percentage is not shown correctly |
284 | if [ ${verbose} -ge 2 ] | 365 | if [ ${verbose} -ge 2 ] |
285 | then | 366 | then |
286 | - outCmd="tr '\r' '\n' | | ||
287 | - sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'\"\${outStr}\"'\1/' | | ||
288 | - tr -d '\n'" | 367 | + outStream="/dev/stdout" |
289 | else | 368 | else |
290 | - outCmd="cat >/dev/null" | 369 | + outStream="/dev/null" |
291 | fi | 370 | fi |
292 | 371 | ||
293 | case ${encodingType} in | 372 | case ${encodingType} in |
@@ -303,8 +382,10 @@ do | @@ -303,8 +382,10 @@ do | ||
303 | -T genre="${dGenre}" -T title="${tTitle[$i]}" \ | 382 | -T genre="${dGenre}" -T title="${tTitle[$i]}" \ |
304 | -T tracknumber="${trackNr}" -T tracknum="${trackNr}" \ | 383 | -T tracknumber="${trackNr}" -T tracknum="${trackNr}" \ |
305 | -T date="${dYear}" -T comment="" \ | 384 | -T date="${dYear}" -T comment="" \ |
306 | - -o "${encodingDir}/${outFile}" - 2>/dev/null | ||
307 | - ) | $outCmd | 385 | + -o "${encodingDir}/${outFile}" - #2>/dev/null |
386 | + ) | tr '\r' '\n' |\ | ||
387 | + sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ | ||
388 | + tr -d '\n' >$outStream | ||
308 | ;; | 389 | ;; |
309 | m) | 390 | m) |
310 | outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.mp3" | 391 | outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.mp3" |
@@ -323,7 +404,7 @@ do | @@ -323,7 +404,7 @@ do | ||
323 | - "${encodingDir}/${outFile}" 2>/dev/null | 404 | - "${encodingDir}/${outFile}" 2>/dev/null |
324 | ) | tr '\r' '\n' |\ | 405 | ) | tr '\r' '\n' |\ |
325 | sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ | 406 | sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ |
326 | - tr -d '\n' | 407 | + tr -d '\n' >$outStream |
327 | ;; | 408 | ;; |
328 | bladeenc) | 409 | bladeenc) |
329 | ( | 410 | ( |
@@ -333,7 +414,7 @@ do | @@ -333,7 +414,7 @@ do | ||
333 | "${encodingDir}/${outFile}" 2>/dev/null | 414 | "${encodingDir}/${outFile}" 2>/dev/null |
334 | ) | tr '\r' '\n' |\ | 415 | ) | tr '\r' '\n' |\ |
335 | sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ | 416 | sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ |
336 | - tr -d '\n' | 417 | + tr -d '\n' >$outStream |
337 | ;; | 418 | ;; |
338 | esac | 419 | esac |
339 | ;; | 420 | ;; |
@@ -351,7 +432,7 @@ do | @@ -351,7 +432,7 @@ do | ||
351 | -o "${encodingDir}/${outFile}" - 2>/dev/null | 432 | -o "${encodingDir}/${outFile}" - 2>/dev/null |
352 | ) | tr '\r' '\n' |\ | 433 | ) | tr '\r' '\n' |\ |
353 | sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ | 434 | sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ |
354 | - tr -d '\n' | 435 | + tr -d '\n' >$outStream |
355 | ;; | 436 | ;; |
356 | w) | 437 | w) |
357 | outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.wav" | 438 | outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.wav" |
@@ -363,11 +444,11 @@ do | @@ -363,11 +444,11 @@ do | ||
363 | "${encodingDir}/${outFile}" | 444 | "${encodingDir}/${outFile}" |
364 | ) | tr '\r' '\n' |\ | 445 | ) | tr '\r' '\n' |\ |
365 | sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ | 446 | sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ |
366 | - tr -d '\n' | 447 | + tr -d '\n' >$outStream |
367 | ;; | 448 | ;; |
368 | esac | 449 | esac |
369 | 450 | ||
370 | - echo # do a newline after each file | 451 | + test ${verbose} -ge 2 && echo # do a newline after each file |
371 | i=$((i+1)) | 452 | i=$((i+1)) |
372 | done | 453 | done |
373 | 454 |
Please
register
or
login
to post a comment