Showing
2 changed files
with
224 additions
and
13 deletions
| ... | ... | @@ -25,7 +25,7 @@ case "${scriptDir}" in /*);; *) scriptDir="${PWD}/${scriptDir}";; esac |
| 25 | 25 | # -------------------------------------------------------------- |
| 26 | 26 | # string definitions |
| 27 | 27 | enhUsage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h] |
| 28 | - [-I interface] [-D device] [-v[v|0]] [-q] | |
| 28 | + [-I interface] [-D device] [-v[v|0]] [-q] [-s] | |
| 29 | 29 | [--help] [--encoding=(m|f|o|w)] [--encoder=(lame|bladeenc)] |
| 30 | 30 | [--path=<string>] [--interface=(cooked_ioctl|generic_scsi)] |
| 31 | 31 | [--device=<string>] |
| ... | ... | @@ -59,11 +59,19 @@ enhUsage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h] |
| 59 | 59 | -D | --device: specifies device to use with cdda2wav. All values that |
| 60 | 60 | are valid for cdda2wav are valid here. |
| 61 | 61 | Defaults to /dev/cdrom |
| 62 | + -s: if set indicates that this disk contains various artists | |
| 63 | + (is a sampler). In this case the artist is written in the | |
| 64 | + title information of cddb most likely. Giving this option | |
| 65 | + the script will show a title list and give the oppotunity | |
| 66 | + to enter a delimiting string so that title and artist | |
| 67 | + information can be split properly and fill the mp3id | |
| 68 | + or whatever correctly. | |
| 62 | 69 | |
| 63 | -This script uses cdda2wav, cddb and various encoders to rip an audio CD." | |
| 70 | +This script uses cdda2wav, cddb and can use various encoders to rip | |
| 71 | +an audio CD." | |
| 64 | 72 | |
| 65 | 73 | usage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h] |
| 66 | - [-I interface] [-D device] [-v[v|0]] [-q] | |
| 74 | + [-I interface] [-D device] [-v[v|0]] [-q] [-s] | |
| 67 | 75 | options: |
| 68 | 76 | -h: this help |
| 69 | 77 | -v: set verbosity level. |
| ... | ... | @@ -94,8 +102,16 @@ usage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h] |
| 94 | 102 | -D: specifies device to use with cdda2wav. All values that |
| 95 | 103 | are valid for cdda2wav are valid here. |
| 96 | 104 | Defaults to /dev/cdrom |
| 105 | + -s: if set indicates that this disk contains various artists | |
| 106 | + (is a sampler). In this case the artist is written in the | |
| 107 | + title information of cddb most likely. Giving this option | |
| 108 | + the script will show a title list and give the oppotunity | |
| 109 | + to enter a delimiting string so that title and artist | |
| 110 | + information can be split properly and fill the mp3id | |
| 111 | + or whatever correctly. | |
| 97 | 112 | |
| 98 | -This script uses cdda2wav, cddb and various encoders to rip an audio CD." | |
| 113 | +This script uses cdda2wav, cddb and can use various encoders to rip | |
| 114 | +an audio CD." | |
| 99 | 115 | |
| 100 | 116 | ready=$"done" |
| 101 | 117 | |
| ... | ... | @@ -139,10 +155,10 @@ then |
| 139 | 155 | # enhanced getopt |
| 140 | 156 | usage="${enhUsage}" |
| 141 | 157 | |
| 142 | - TEMP="`$GETOPT -o "?hv::qt:p:e:c:I:D:" -l "help,encoding:,encoder:,path:,interface:,device:" -- "$@"`" | |
| 158 | + TEMP="`$GETOPT -o "?hsv::qt:p:e:c:I:D:" -l "help,encoding:,encoder:,path:,interface:,device:" -- "$@"`" | |
| 143 | 159 | else |
| 144 | 160 | # old getopt |
| 145 | - TEMP="`$GETOPT "?hv::qt:p:e:c:I:D:" "$@"`" | |
| 161 | + TEMP="`$GETOPT "?hsv::qt:p:e:c:I:D:" "$@"`" | |
| 146 | 162 | fi |
| 147 | 163 | test $? -ne 0 && { echo -e "${usage}"; exit 1; } # on error |
| 148 | 164 | |
| ... | ... | @@ -152,10 +168,11 @@ taOrder="t" |
| 152 | 168 | encodingDir=$HOME |
| 153 | 169 | encodingType="f" |
| 154 | 170 | encoder="lame" |
| 155 | -cddbEntry=1 | |
| 171 | +cddbEntry="" | |
| 156 | 172 | cddaIf="" |
| 157 | 173 | cddaDev="/dev/cdrom" |
| 158 | 174 | verbose=1 |
| 175 | +sampler="no" | |
| 159 | 176 | while true |
| 160 | 177 | do |
| 161 | 178 | case "$1" in |
| ... | ... | @@ -215,13 +232,15 @@ do |
| 215 | 232 | ;; |
| 216 | 233 | |
| 217 | 234 | -c) |
| 218 | - if [ $2 -lt 1 ] | |
| 235 | + if [ "$2" -ge 1 ] 2>/dev/null | |
| 219 | 236 | then |
| 237 | + cddbEntry="$2" | |
| 238 | + cddbEntry=$((cddbEntry-1)) | |
| 239 | + shift 2 | |
| 240 | + else | |
| 220 | 241 | echo -e "$usage" |
| 221 | 242 | exit 1 |
| 222 | 243 | fi |
| 223 | - cddbEntry=$2 | |
| 224 | - shift 2 | |
| 225 | 244 | ;; |
| 226 | 245 | |
| 227 | 246 | -I) |
| ... | ... | @@ -236,7 +255,7 @@ do |
| 236 | 255 | ;; |
| 237 | 256 | |
| 238 | 257 | -D) |
| 239 | - if [ $2 -lt 1 ] | |
| 258 | + if [ "x" == "x$2" ] | |
| 240 | 259 | then |
| 241 | 260 | echo -e "$usage" |
| 242 | 261 | exit 1 |
| ... | ... | @@ -245,6 +264,11 @@ do |
| 245 | 264 | shift 2 |
| 246 | 265 | ;; |
| 247 | 266 | |
| 267 | + -s) | |
| 268 | + sampler="yes" | |
| 269 | + shift | |
| 270 | + ;; | |
| 271 | + | |
| 248 | 272 | -h|--help|*) |
| 249 | 273 | echo "${usage}" |
| 250 | 274 | exit 1 |
| ... | ... | @@ -284,7 +308,8 @@ esac |
| 284 | 308 | # ---------------------------------------------------------------- |
| 285 | 309 | |
| 286 | 310 | test ${verbose} -ge 1 && echo -n ${getCDInfoMsg} |
| 287 | -getCDInfo # gets all info about the CD. Look in shellUtils for more info. | |
| 311 | +# gets all info about the CD. Look in shellUtils for more info. | |
| 312 | +getCDInfo "$sampler" "$cddbEntry" | |
| 288 | 313 | test ${verbose} -ge 1 && echo ${ready} |
| 289 | 314 | |
| 290 | 315 | if [ ${verbose} -ge 2 ] | ... | ... |
| ... | ... | @@ -307,8 +307,193 @@ then |
| 307 | 307 | |
| 308 | 308 | fi |
| 309 | 309 | |
| 310 | +function getDiscInfo | |
| 311 | +{ | |
| 312 | + local device | |
| 313 | + | |
| 314 | + test $# -ge 1 && device="$1" | |
| 315 | + | |
| 316 | + unset diskData cddbId dTracks dLength dIndex dText dExtra | |
| 317 | + | |
| 318 | + diskData="`cdda2wav -D ${device} -N -J -v toc,sectors 2>&1`" | |
| 319 | + | |
| 320 | + cddbId="`echo "$diskData" |\ | |
| 321 | + sed '/^CDDB/!d;s/^.*0x\(.*\)$/\1/'`" | |
| 322 | + dTracks="`echo "$diskData" |\ | |
| 323 | + sed '/tracks/!d;s/^.*tracks:\([0-9]*\).*$/\1/'`" | |
| 324 | + dLength="`echo "$diskData" |\ | |
| 325 | + sed '/tracks/!d;s/^.*time \([0-9:\.]*\).*$/\1/'`" | |
| 326 | + dIndex="`echo "$diskData" |\ | |
| 327 | + sed '/CDINDEX/!d;s/^.*: *\([a-zA-Z0-9_\.]*-\).*$/\1/'`" | |
| 328 | + dText="`echo "$diskData" | sed ' | |
| 329 | + /CD-Text/!d;s/^[^:]*: *\(.*[^ ]\).*$/\1/'`" | |
| 330 | + dExtra="`echo "$diskData" | sed ' | |
| 331 | + /CD-Extra/!d;s/^[^:]*: *\(.*[^ ]\).*$/\1/'`" | |
| 332 | +} | |
| 333 | + | |
| 334 | +function getCDDBInfo | |
| 335 | +{ | |
| 336 | + local uri i hello | |
| 337 | + | |
| 338 | + uri="freedb.freedb.org/~cddb/cddb.cgi" | |
| 339 | + | |
| 340 | + test $# -ge 1 && cddbId="$1" || return 1 | |
| 341 | + test $# -ge 2 && uri="$2" | |
| 342 | + | |
| 343 | + hello="hello=${USER}+${HOSTNAME}+test+0.0.1" | |
| 344 | + | |
| 345 | + # first get the genre list from server | |
| 346 | + eval "`curl -s "http://${uri}?cmd=cddb+lscat&${hello}&proto=6" |\ | |
| 347 | + sed '1d;$d' | tr -d '\r' | tr '\n' ',' |\ | |
| 348 | + sed 's/,$//;s/,/" "/g;s/^\(.*\)$/local -a genre=("\1")/'`" | |
| 349 | + | |
| 350 | + unset cddbInfo | |
| 351 | + | |
| 352 | + # search for info in all genres | |
| 353 | + for i in "${genre[@]}" | |
| 354 | + do | |
| 355 | + local cmd="cmd=cddb+read+${i}+${cddbId}" | |
| 356 | + local cddb="`curl -s "http://${uri}?${cmd}&${hello}&proto=6"`" | |
| 357 | + | |
| 358 | + local ret="`echo "$cddb" | head -c 3`" | |
| 359 | + | |
| 360 | + if [ "$ret" != "210" ] | |
| 361 | + then | |
| 362 | + if [ ${verbose:-0} -ge 3 ] | |
| 363 | + then | |
| 364 | + debug="`echo "$cddb" | head -n 1`" | |
| 365 | + echo $"[ERROR] cddb: ${debug}" | |
| 366 | + fi | |
| 367 | + else | |
| 368 | + cddb="`echo "$cddb" | tr -d '\r' | sed '1d;/^#/d;/^\.$/{d;q}'`" | |
| 369 | + cddbInfo[${#cddbInfo[@]}]="$cddb" | |
| 370 | + fi | |
| 371 | + done | |
| 372 | +} | |
| 373 | + | |
| 310 | 374 | function getCDInfo |
| 311 | 375 | { |
| 376 | + local uri device sampler cnt cddb | |
| 377 | + local delimiter | |
| 378 | + | |
| 379 | + sampler=0 | |
| 380 | + cddbEntry="" | |
| 381 | + device="/dev/cdrom" | |
| 382 | + uri="freedb.freedb.org/~cddb/cddb.cgi" | |
| 383 | + | |
| 384 | + test $# -ge 1 && sampler="$1" | |
| 385 | + test $# -ge 2 && cddbEntry="$2" | |
| 386 | + test $# -ge 3 && device="$3" | |
| 387 | + test $# -ge 4 && uri="$4" | |
| 388 | + | |
| 389 | + getDiscInfo "$device" | |
| 390 | + getCDDBInfo "$cddbId" | |
| 391 | + | |
| 392 | + cnt=${#cddbInfo[@]} | |
| 393 | + if [ ${cnt} -gt 1 ] | |
| 394 | + then | |
| 395 | + if [ "$cddbEntry" -lt $cnt ] 2>/dev/null | |
| 396 | + then | |
| 397 | + cddb="${cddbInfo[$cddbEntry]}" | |
| 398 | + echo "done" | |
| 399 | + else | |
| 400 | + echo | |
| 401 | + echo "found more than 1 CDDB Entry. Please select:" | |
| 402 | + | |
| 403 | + local i=0; | |
| 404 | + while [ $i -lt $cnt ] | |
| 405 | + do | |
| 406 | + local title="`echo "${cddbInfo[$i]}" | sed '/^DTITLE/!d;s/^.*=//'`" | |
| 407 | + echo " [$i] - $title" | |
| 408 | + i=$((i+1)) | |
| 409 | + done | |
| 410 | + | |
| 411 | + echo " [q] - quit script" | |
| 412 | + echo | |
| 413 | + | |
| 414 | + cddb="" | |
| 415 | + while [ -z "$cddb" ] | |
| 416 | + do | |
| 417 | + echo -n "==> " | |
| 418 | + read i | |
| 419 | + | |
| 420 | + test "x$i" == "xq" && exit 1 | |
| 421 | + i="`echo "$i" | sed '/[^0-9]/d'`" | |
| 422 | + test -z "$i" && continue | |
| 423 | + | |
| 424 | + cddb="${cddbInfo[$i]}" | |
| 425 | + test -z "$cddb" && echo "wrong input ($i)" | |
| 426 | + done | |
| 427 | + fi | |
| 428 | + else | |
| 429 | + cddb="${cddbInfo[0]}" | |
| 430 | + echo "done" | |
| 431 | + fi | |
| 432 | + | |
| 433 | + eval "`echo "$cddb" | tr -d '\r' | sed ' | |
| 434 | + /DTITLE/s/^.*=\(\(.*\) \/ \)*\(.*\)$/dArtist="\2";dTitle="\3"/p | |
| 435 | + /DYEAR/s/^.*=\(.*\)$/dYear="\1"/p | |
| 436 | + /DGENRE/s/^.*=\(.*\)$/dGenre="\1"/p | |
| 437 | + /TTITLE/s/^TTITLE\([0-9]*\)=\(.*\)$/tArtist[\1]="";tTitle[\1]="\2"/p | |
| 438 | + d'`" | |
| 439 | + | |
| 440 | + if [ "$sampler" == "yes" ] | |
| 441 | + then | |
| 442 | + echo | |
| 443 | + echo "some CDs contain content from various artist. If this is such a CD" | |
| 444 | + echo "one might want to declare a pattern that separates the artist from" | |
| 445 | + echo "the title information. Here are the titles as reported by CDDB:" | |
| 446 | + echo | |
| 447 | + | |
| 448 | + for i in "${tTitle[@]}" | |
| 449 | + do | |
| 450 | + echo " - $i" | |
| 451 | + done | |
| 452 | + | |
| 453 | + echo | |
| 454 | + echo "if you want to split those entries in artist and title please give" | |
| 455 | + echo "now the string pattern to split at." | |
| 456 | + echo "Otherwise simply press ENTER here" | |
| 457 | + echo -n "==> " | |
| 458 | + | |
| 459 | + __OLDIFS__="$IFS" | |
| 460 | + IFS="" | |
| 461 | + read delimiter | |
| 462 | + IFS="$__OLDIFS__" | |
| 463 | + | |
| 464 | + if [ "x$delimiter" != "x" ] | |
| 465 | + then | |
| 466 | + eval "`echo "$cddb" | tr -d '\r' | sed ' | |
| 467 | + /TTITLE/s/^TTITLE\([0-9]*\)=\(\(.*\)'"$delimiter"'\)*\(.*\)$/tArtist[\1]="\3";tTitle[\1]="\4"/p | |
| 468 | + d'`" | |
| 469 | + fi | |
| 470 | + fi | |
| 471 | + | |
| 472 | + # Nu pack ich in alle tArtist die leer sind den dArtist. | |
| 473 | + i=0 | |
| 474 | + while [ $i -lt ${#tArtist[@]} ] | |
| 475 | + do | |
| 476 | + tNum=$((i+1)) | |
| 477 | + tLength[$i]=`echo "$diskData" | sed ' | |
| 478 | + /[^0-9]'$tNum'\.(.*:.*)/ !d | |
| 479 | + s/.*[^0-9]'$tNum'\.( *\([^)]*\).*$/\1/'` | |
| 480 | + tStartSec[$i]=`echo "$diskData" | sed ' | |
| 481 | + /[^0-9]'$tNum'\.([^:]*)/ !d | |
| 482 | + s/.*[^0-9]'$tNum'\.( *\([^)]*\).*$/\1/'` | |
| 483 | + | |
| 484 | + test $tNum -eq ${#tArtist[@]} && tNum="lead-out" || tNum=$((tNum+1)) | |
| 485 | + | |
| 486 | + tEndSec[$i]=`echo "$diskData" | sed ' | |
| 487 | + /[^0-9]'$tNum'\.*([^:]*)/ !d | |
| 488 | + s/.*[^0-9]'$tNum'\.*( *\([^)]*\).*$/\1/'` | |
| 489 | + | |
| 490 | + test -z "${tArtist[$i]}" && tArtist[$i]="$dArtist" | |
| 491 | + i=$((i+1)) | |
| 492 | + done | |
| 493 | +} | |
| 494 | + | |
| 495 | +function getCDInfo_old | |
| 496 | +{ | |
| 312 | 497 | local uri device cmd i hello cddb ret diskData tNum |
| 313 | 498 | |
| 314 | 499 | uri="freedb.freedb.org/~cddb/cddb.cgi" |
| ... | ... | @@ -364,10 +549,11 @@ function getCDInfo |
| 364 | 549 | /DGENRE/s/^.*=\(.*\)$/dGenre="\1"/p |
| 365 | 550 | /TTITLE/s/^TTITLE\([0-9]*\)=\(\(.*\) \/ \)*\(.*\)$/tArtist[\1]="\3";tTitle[\1]="\4"/p |
| 366 | 551 | d'`" |
| 367 | - break | |
| 368 | 552 | fi |
| 369 | 553 | done |
| 370 | 554 | |
| 555 | + exit 1 | |
| 556 | + | |
| 371 | 557 | # Nu pack ich in alle tArtist die leer sind den dArtist. |
| 372 | 558 | i=0 |
| 373 | 559 | while [ $i -lt ${#tArtist[@]} ] | ... | ... |
Please
register
or
login
to post a comment