Georg Hopp 18 years ago
parent
commit
1ef3d1bfa7
  1. 49
      getcd.sh
  2. 188
      shellUtils.sh

49
getcd.sh

@ -25,7 +25,7 @@ case "${scriptDir}" in /*);; *) scriptDir="${PWD}/${scriptDir}";; esac
# -------------------------------------------------------------- # --------------------------------------------------------------
# string definitions # string definitions
enhUsage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h] enhUsage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h]
[-I interface] [-D device] [-v[v|0]] [-q]
[-I interface] [-D device] [-v[v|0]] [-q] [-s]
[--help] [--encoding=(m|f|o|w)] [--encoder=(lame|bladeenc)] [--help] [--encoding=(m|f|o|w)] [--encoder=(lame|bladeenc)]
[--path=<string>] [--interface=(cooked_ioctl|generic_scsi)] [--path=<string>] [--interface=(cooked_ioctl|generic_scsi)]
[--device=<string>] [--device=<string>]
@ -59,11 +59,19 @@ enhUsage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h]
-D | --device: specifies device to use with cdda2wav. All values that -D | --device: specifies device to use with cdda2wav. All values that
are valid for cdda2wav are valid here. are valid for cdda2wav are valid here.
Defaults to /dev/cdrom Defaults to /dev/cdrom
-s: if set indicates that this disk contains various artists
(is a sampler). In this case the artist is written in the
title information of cddb most likely. Giving this option
the script will show a title list and give the oppotunity
to enter a delimiting string so that title and artist
information can be split properly and fill the mp3id
or whatever correctly.
This script uses cdda2wav, cddb and various encoders to rip an audio CD."
This script uses cdda2wav, cddb and can use various encoders to rip
an audio CD."
usage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h] usage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h]
[-I interface] [-D device] [-v[v|0]] [-q]
[-I interface] [-D device] [-v[v|0]] [-q] [-s]
options: options:
-h: this help -h: this help
-v: set verbosity level. -v: set verbosity level.
@ -94,8 +102,16 @@ usage=$"usage: $0 [-t(m|f|o|w)] [-p path] [-e encoder] [-c cddbitem] [-h]
-D: specifies device to use with cdda2wav. All values that -D: specifies device to use with cdda2wav. All values that
are valid for cdda2wav are valid here. are valid for cdda2wav are valid here.
Defaults to /dev/cdrom Defaults to /dev/cdrom
-s: if set indicates that this disk contains various artists
(is a sampler). In this case the artist is written in the
title information of cddb most likely. Giving this option
the script will show a title list and give the oppotunity
to enter a delimiting string so that title and artist
information can be split properly and fill the mp3id
or whatever correctly.
This script uses cdda2wav, cddb and various encoders to rip an audio CD."
This script uses cdda2wav, cddb and can use various encoders to rip
an audio CD."
ready=$"done" ready=$"done"
@ -139,10 +155,10 @@ then
# enhanced getopt # enhanced getopt
usage="${enhUsage}" usage="${enhUsage}"
TEMP="`$GETOPT -o "?hv::qt:p:e:c:I:D:" -l "help,encoding:,encoder:,path:,interface:,device:" -- "$@"`"
TEMP="`$GETOPT -o "?hsv::qt:p:e:c:I:D:" -l "help,encoding:,encoder:,path:,interface:,device:" -- "$@"`"
else else
# old getopt # old getopt
TEMP="`$GETOPT "?hv::qt:p:e:c:I:D:" "$@"`"
TEMP="`$GETOPT "?hsv::qt:p:e:c:I:D:" "$@"`"
fi fi
test $? -ne 0 && { echo -e "${usage}"; exit 1; } # on error test $? -ne 0 && { echo -e "${usage}"; exit 1; } # on error
@ -152,10 +168,11 @@ taOrder="t"
encodingDir=$HOME encodingDir=$HOME
encodingType="f" encodingType="f"
encoder="lame" encoder="lame"
cddbEntry=1
cddbEntry=""
cddaIf="" cddaIf=""
cddaDev="/dev/cdrom" cddaDev="/dev/cdrom"
verbose=1 verbose=1
sampler="no"
while true while true
do do
case "$1" in case "$1" in
@ -215,13 +232,15 @@ do
;; ;;
-c) -c)
if [ $2 -lt 1 ]
if [ "$2" -ge 1 ] 2>/dev/null
then then
cddbEntry="$2"
cddbEntry=$((cddbEntry-1))
shift 2
else
echo -e "$usage" echo -e "$usage"
exit 1 exit 1
fi fi
cddbEntry=$2
shift 2
;; ;;
-I) -I)
@ -236,7 +255,7 @@ do
;; ;;
-D) -D)
if [ $2 -lt 1 ]
if [ "x" == "x$2" ]
then then
echo -e "$usage" echo -e "$usage"
exit 1 exit 1
@ -245,6 +264,11 @@ do
shift 2 shift 2
;; ;;
-s)
sampler="yes"
shift
;;
-h|--help|*) -h|--help|*)
echo "${usage}" echo "${usage}"
exit 1 exit 1
@ -284,7 +308,8 @@ esac
# ---------------------------------------------------------------- # ----------------------------------------------------------------
test ${verbose} -ge 1 && echo -n ${getCDInfoMsg} test ${verbose} -ge 1 && echo -n ${getCDInfoMsg}
getCDInfo # gets all info about the CD. Look in shellUtils for more info.
# gets all info about the CD. Look in shellUtils for more info.
getCDInfo "$sampler" "$cddbEntry"
test ${verbose} -ge 1 && echo ${ready} test ${verbose} -ge 1 && echo ${ready}
if [ ${verbose} -ge 2 ] if [ ${verbose} -ge 2 ]

188
shellUtils.sh

@ -307,7 +307,192 @@ then
fi fi
function getDiscInfo
{
local device
test $# -ge 1 && device="$1"
unset diskData cddbId dTracks dLength dIndex dText dExtra
diskData="`cdda2wav -D ${device} -N -J -v toc,sectors 2>&1`"
cddbId="`echo "$diskData" |\
sed '/^CDDB/!d;s/^.*0x\(.*\)$/\1/'`"
dTracks="`echo "$diskData" |\
sed '/tracks/!d;s/^.*tracks:\([0-9]*\).*$/\1/'`"
dLength="`echo "$diskData" |\
sed '/tracks/!d;s/^.*time \([0-9:\.]*\).*$/\1/'`"
dIndex="`echo "$diskData" |\
sed '/CDINDEX/!d;s/^.*: *\([a-zA-Z0-9_\.]*-\).*$/\1/'`"
dText="`echo "$diskData" | sed '
/CD-Text/!d;s/^[^:]*: *\(.*[^ ]\).*$/\1/'`"
dExtra="`echo "$diskData" | sed '
/CD-Extra/!d;s/^[^:]*: *\(.*[^ ]\).*$/\1/'`"
}
function getCDDBInfo
{
local uri i hello
uri="freedb.freedb.org/~cddb/cddb.cgi"
test $# -ge 1 && cddbId="$1" || return 1
test $# -ge 2 && uri="$2"
hello="hello=${USER}+${HOSTNAME}+test+0.0.1"
# first get the genre list from server
eval "`curl -s "http://${uri}?cmd=cddb+lscat&${hello}&proto=6" |\
sed '1d;$d' | tr -d '\r' | tr '\n' ',' |\
sed 's/,$//;s/,/" "/g;s/^\(.*\)$/local -a genre=("\1")/'`"
unset cddbInfo
# search for info in all genres
for i in "${genre[@]}"
do
local cmd="cmd=cddb+read+${i}+${cddbId}"
local cddb="`curl -s "http://${uri}?${cmd}&${hello}&proto=6"`"
local ret="`echo "$cddb" | head -c 3`"
if [ "$ret" != "210" ]
then
if [ ${verbose:-0} -ge 3 ]
then
debug="`echo "$cddb" | head -n 1`"
echo $"[ERROR] cddb: ${debug}"
fi
else
cddb="`echo "$cddb" | tr -d '\r' | sed '1d;/^#/d;/^\.$/{d;q}'`"
cddbInfo[${#cddbInfo[@]}]="$cddb"
fi
done
}
function getCDInfo function getCDInfo
{
local uri device sampler cnt cddb
local delimiter
sampler=0
cddbEntry=""
device="/dev/cdrom"
uri="freedb.freedb.org/~cddb/cddb.cgi"
test $# -ge 1 && sampler="$1"
test $# -ge 2 && cddbEntry="$2"
test $# -ge 3 && device="$3"
test $# -ge 4 && uri="$4"
getDiscInfo "$device"
getCDDBInfo "$cddbId"
cnt=${#cddbInfo[@]}
if [ ${cnt} -gt 1 ]
then
if [ "$cddbEntry" -lt $cnt ] 2>/dev/null
then
cddb="${cddbInfo[$cddbEntry]}"
echo "done"
else
echo
echo "found more than 1 CDDB Entry. Please select:"
local i=0;
while [ $i -lt $cnt ]
do
local title="`echo "${cddbInfo[$i]}" | sed '/^DTITLE/!d;s/^.*=//'`"
echo " [$i] - $title"
i=$((i+1))
done
echo " [q] - quit script"
echo
cddb=""
while [ -z "$cddb" ]
do
echo -n "==> "
read i
test "x$i" == "xq" && exit 1
i="`echo "$i" | sed '/[^0-9]/d'`"
test -z "$i" && continue
cddb="${cddbInfo[$i]}"
test -z "$cddb" && echo "wrong input ($i)"
done
fi
else
cddb="${cddbInfo[0]}"
echo "done"
fi
eval "`echo "$cddb" | tr -d '\r' | sed '
/DTITLE/s/^.*=\(\(.*\) \/ \)*\(.*\)$/dArtist="\2";dTitle="\3"/p
/DYEAR/s/^.*=\(.*\)$/dYear="\1"/p
/DGENRE/s/^.*=\(.*\)$/dGenre="\1"/p
/TTITLE/s/^TTITLE\([0-9]*\)=\(.*\)$/tArtist[\1]="";tTitle[\1]="\2"/p
d'`"
if [ "$sampler" == "yes" ]
then
echo
echo "some CDs contain content from various artist. If this is such a CD"
echo "one might want to declare a pattern that separates the artist from"
echo "the title information. Here are the titles as reported by CDDB:"
echo
for i in "${tTitle[@]}"
do
echo " - $i"
done
echo
echo "if you want to split those entries in artist and title please give"
echo "now the string pattern to split at."
echo "Otherwise simply press ENTER here"
echo -n "==> "
__OLDIFS__="$IFS"
IFS=""
read delimiter
IFS="$__OLDIFS__"
if [ "x$delimiter" != "x" ]
then
eval "`echo "$cddb" | tr -d '\r' | sed '
/TTITLE/s/^TTITLE\([0-9]*\)=\(\(.*\)'"$delimiter"'\)*\(.*\)$/tArtist[\1]="\3";tTitle[\1]="\4"/p
d'`"
fi
fi
# Nu pack ich in alle tArtist die leer sind den dArtist.
i=0
while [ $i -lt ${#tArtist[@]} ]
do
tNum=$((i+1))
tLength[$i]=`echo "$diskData" | sed '
/[^0-9]'$tNum'\.(.*:.*)/ !d
s/.*[^0-9]'$tNum'\.( *\([^)]*\).*$/\1/'`
tStartSec[$i]=`echo "$diskData" | sed '
/[^0-9]'$tNum'\.([^:]*)/ !d
s/.*[^0-9]'$tNum'\.( *\([^)]*\).*$/\1/'`
test $tNum -eq ${#tArtist[@]} && tNum="lead-out" || tNum=$((tNum+1))
tEndSec[$i]=`echo "$diskData" | sed '
/[^0-9]'$tNum'\.*([^:]*)/ !d
s/.*[^0-9]'$tNum'\.*( *\([^)]*\).*$/\1/'`
test -z "${tArtist[$i]}" && tArtist[$i]="$dArtist"
i=$((i+1))
done
}
function getCDInfo_old
{ {
local uri device cmd i hello cddb ret diskData tNum local uri device cmd i hello cddb ret diskData tNum
@ -364,10 +549,11 @@ function getCDInfo
/DGENRE/s/^.*=\(.*\)$/dGenre="\1"/p /DGENRE/s/^.*=\(.*\)$/dGenre="\1"/p
/TTITLE/s/^TTITLE\([0-9]*\)=\(\(.*\) \/ \)*\(.*\)$/tArtist[\1]="\3";tTitle[\1]="\4"/p /TTITLE/s/^TTITLE\([0-9]*\)=\(\(.*\) \/ \)*\(.*\)$/tArtist[\1]="\3";tTitle[\1]="\4"/p
d'`" d'`"
break
fi fi
done done
exit 1
# Nu pack ich in alle tArtist die leer sind den dArtist. # Nu pack ich in alle tArtist die leer sind den dArtist.
i=0 i=0
while [ $i -lt ${#tArtist[@]} ] while [ $i -lt ${#tArtist[@]} ]

Loading…
Cancel
Save