1#! /bin/sh
2#############################################################################
3# dekagen - a frontend to rip, convert, and name MP3 / Ogg
4# Written by Martin Bayer <mbayer@zedat.fu-berlin.de>
5#                         http://userpage.fu-berlin.de/~mbayer/tools/
6# Portions based on ripenc-0.7 by Michael J. Parmeley
7#----------------------------------------------------------------------------
8# This is
9VERSION='dekagen 1.0.2'
10# created Di Jun 15 18:30:49 CEST 2004
11#============================================================================
12# This program is free software; you can redistribute it and/or modify it
13# under the terms of the GNU General Public License as published by the Free
14# Software Foundation; either version 2 of the License, or (at your option)
15# any later version.
16# This program is distributed in the hope that it will be useful, but
17# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19# more details.
20# You should have received a copy of the GNU General Public License along
21# with this program; if not, write to the Free Software Foundation, Inc.,
22# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23#============================================================================
24# Be sure you have already installed on your system:
25# 1. cdda2wav, cdparanoia, dagrab, or tosha,
26# 2. 8hz-mp3, bladeenc, l3enc, lame, mp3enc, or notlame,
27#    or oggenc.
28# You might also wish to install:
29# 3. xmcd,
30# 4. id3ed, id3tag, id3tool, or mp3info.
31# See the file README for details.
32#############################################################################
33#
34# Pre-set defaults:
35#
36RCDIR="${HOME}/.dekagen"	# per-user configuration directory
37TEMPDIR=${RCDIR}		# per-user temporary data directory
38SAVETO=${HOME}			# per-user file storage directory
39ENCODER='oggenc'		# MP3/Ogg converter tool (command name or 'none')
40RIPPER='cdparanoia'		# CDDA ripping tool (command name or 'none')
41ID3TOOL='built-in'		# ID3 tagging tool (command name or 'built-in' or 'none')
42BITRATE='128'			# MP3/Ogg nominal encoding bitrate (KBits)
43METHOD='manual'			# 'manual' or 'cddb'
44XMCDLIB=''			# $XMCD_LIBDIR
45# Adapted DEVICE to a reasonabe FreeBSD default. Martin Kraft.
46DEVICE='/dev/acd0c'		# device used for ripping
47NCONVENT='artist-name_of_song.mp3'
48SELEC='1'			# MP3/Ogg naming convention
49WHOLE='no'			# rip whole CD ('yes' or 'no')
50SMALL='no'			# small HD ('yes' or 'no')
51#
52#############################################################################
53
54if [ $# -ne 0 ] ;
55then
56	echo "This is ${VERSION}"
57	echo "Usage: $0"
58	echo
59	exit
60fi
61
62dialog 2>&1 | grep 'backtitle' >/dev/null && alias dialog="dialog --backtitle '${VERSION}'" ;
63
64trap forcequit INT
65trap forcequit TERM
66trap forcequit QUIT
67trap forcequit HUP
68
69forcequit ()
70{
71	# when aborting on ^c or "cancel", kill background encoding processes
72	test -f ${TEMPDIR}/lock.encode && killbgjob
73	cleantemp
74	saverc
75	echo 'Dekagen terminated on user request.' ;
76exit 1
77}
78
79killbgjob ()
80{
81	rm ${TEMPDIR}/convers
82	BCKGRNDP=$(cat ${TEMPDIR}/lock.encode 2>/dev/null) ;
83	ps -o ppid,pid | awk '$1 == '"${BCKGRNDP}"' { print $2 }' >>${TEMPDIR}/lock.encode 2>/dev/null ;
84	kill $(echo $(cat ${TEMPDIR}/lock.encode)) ;
85	echo 'Background encoding processes aborted.' ;
86	rm ${TEMPDIR}/lock.encode
87}
88
89cleantemp ()
90{
91	# remove temp data
92	rm ${TEMPDIR}/ripname 2>/dev/null
93	rm ${TEMPDIR}/cdnames 2>/dev/null
94	rm ${TEMPDIR}/toc1 2>/dev/null
95	rm ${TEMPDIR}/toc2 2>/dev/null
96	rm ${TEMPDIR}/tracks 2>/dev/null
97	rm ${TEMPDIR}/tmprip 2>/dev/null
98	rm ${TEMPDIR}/tracknrs1 2>/dev/null
99	rm ${TEMPDIR}/tracknrs2 2>/dev/null
100	rm ${TEMPDIR}/msgs 2>/dev/null
101}
102
103saverc ()
104{
105	# save settings on disk
106	echo SAVETO="'"${SAVETO}"'" > ${RCDIR}/dekagenrc
107	echo RIPPER="'"${RIPPER}"'" >> ${RCDIR}/dekagenrc
108	echo ENCODER="'"${ENCODER}"'" >> ${RCDIR}/dekagenrc
109	echo ID3TOOL="'"${ID3TOOL}"'" >> ${RCDIR}/dekagenrc
110	echo METHOD="'"${METHOD}"'" >> ${RCDIR}/dekagenrc
111	echo XMCDLIB="'"${XMCDLIB}"'" >> ${RCDIR}/dekagenrc
112	echo SELEC="'"${SELEC}"'" >> ${RCDIR}/dekagenrc
113	echo NCONVENT="'"${NCONVENT}"'" >> ${RCDIR}/dekagenrc
114	echo WHOLE="'"${WHOLE}"'" >> ${RCDIR}/dekagenrc
115	echo SMALL="'"${SMALL}"'" >> ${RCDIR}/dekagenrc
116	echo DEVICE="'"${DEVICE}"'" >> ${RCDIR}/dekagenrc
117	echo BITRATE="'"${BITRATE}"'" >> ${RCDIR}/dekagenrc
118}
119
120findripper ()
121{
122	# don't forget to update this array when extending features
123	for FNDRIP in ${RIPPER} cdparanoia cdda2wav dagrab tosha none
124	do
125		if [ "${FNDRIP}" = 'none' ] ;
126		then
127			RIPPER='none'
128		elif (which ${FNDRIP} >/dev/null && test -x $(which ${FNDRIP}))
129		then
130			RIPPER=${FNDRIP}
131			break
132		fi
133	done
134}
135
136findencoder ()
137{
138	# don't forget to update this array when extending features
139	for FNDENC in ${ENCODER} oggenc lame bladeenc notlame mp3enc 8hz-mp3 l3enc none
140	do
141		if [ "${FNDENC}" = 'none' ] ;
142		then
143			ENCODER='none'
144		elif (which ${FNDENC} >/dev/null && test -x $(which ${FNDENC}))
145		then
146			ENCODER=${FNDENC}
147			break
148		fi
149	done
150}
151
152findid3tool ()
153{
154	# don't forget to update this array when extending features
155	for FNDID3 in ${ID3TOOL} id3ed id3tag mp3info id3tool none
156	do
157		if [ "${FNDID3}" = 'none' ] ;
158		then
159			ID3TOOL='none'
160		elif (which ${FNDID3} >/dev/null && test -x $(which ${FNDID3}))
161		then
162			ID3TOOL=${FNDID3}
163			break
164		fi
165	done
166}
167
168checkoldrc ()
169{
170	# Make the .dekagen directory to store all the files used by dekagen
171	if [ ! -d ${RCDIR} ] && [ -d ${HOME}/.dekagen ] ;
172	then
173		cp -r ${HOME}/.dekagen ${RCDIR}
174		rm ${RCDIR}/dekagensed 2>/dev/null
175	elif [ ! -d ${RCDIR} ] ;
176	then
177		mkdir -p ${RCDIR}
178	fi
179}
180
181checkforsed ()
182{
183	# make file with sed rules
184	echo '/^$/d' > ${RCDIR}/dekagensed
185	echo "s/'//g" >> ${RCDIR}/dekagensed
186	echo 's/"//g' >> ${RCDIR}/dekagensed
187	echo 's/\*//g' >> ${RCDIR}/dekagensed
188	echo 's/,//g' >> ${RCDIR}/dekagensed
189	echo 's/)//g' >> ${RCDIR}/dekagensed
190	echo 's/(//g' >> ${RCDIR}/dekagensed
191	echo 's/\.//g' >> ${RCDIR}/dekagensed
192	echo 's/\$//g' >> ${RCDIR}/dekagensed
193	echo 's/&/and/g' >> ${RCDIR}/dekagensed
194	echo 's/://g' >> ${RCDIR}/dekagensed
195	echo 's/_*-_*/__/g' >> ${RCDIR}/dekagensed
196	echo 's/\?//g' >> ${RCDIR}/dekagensed
197	echo 's/^\ *//' >> ${RCDIR}/dekagensed
198	echo 's/ /_/g' >> ${RCDIR}/dekagensed
199	echo 's/^_*//' >> ${RCDIR}/dekagensed
200	echo 's/_*$//' >> ${RCDIR}/dekagensed
201}
202
203checksaveto ()
204{
205	# check whether working directory already exists and is writable, fallback: $HOME
206	if [ "${SAVETO}" != '' ] && [ ! -d ${SAVETO} ] ;
207	then
208		if dialog --title 'Question'\
209			--yesno "${SAVETO} does not exist.\nDo you wish to create it?" 19 70 ;
210		then
211			mkdir -p ${SAVETO} && return
212			dialog --title 'Error'\
213				--msgbox "Cannot create ${SAVETO}." 19 70 ;
214			SAVETO=''
215		else
216			SAVETO=''
217		fi
218	elif [ "${SAVETO}" != '' ] && [ ! -w ${SAVETO} ] ;
219	then
220		dialog --title 'Error'\
221			--msgbox "You have no write access to ${SAVETO}." 19 70 ;
222		SAVETO=''
223	fi
224	if [ "${SAVETO}" = '' ] && [ "${OLDSAVETO}" != '' ] ;
225	then
226		SAVETO=${OLDSAVETO}
227	fi
228	if [ "${SAVETO}" = '' ] || [ ! -d ${SAVETO} ] || [ ! -w ${SAVETO} ] ;
229	then
230		SAVETO=${HOME}
231	fi
232}
233
234checkdevice ()
235{
236	# check whether $DEVICE is pointing to a device, fallback: /dev/acd0
237	if [ ! -e ${DEVICE} ] ;
238	then
239		dialog --title 'Error' \
240			--msgbox "Device ${DEVICE} does not seem to exist." 19 70 ;
241		DEVICE=''
242	fi
243	if [ "${DEVICE}" = '' ] && [ "${TEMPDEVICE}" != '' ] ;
244	then
245		DEVICE=${TEMPDEVICE}
246	elif [ "${DEVICE}" = '' ] ;
247	then
248		DEVICE='/dev/acd0'
249	fi
250}
251
252checkripper ()
253{
254	# check whether $RIPPER is installed and executable
255	if [ "${RIPPER}" != 'none' ] && ! (which ${RIPPER} >/dev/null && test -x $(which ${RIPPER}))
256	then
257		dialog --title 'Error' --msgbox \
258			"${RIPPER} is not installed or not executable." 19 70 ;
259		CHR=''
260	fi
261	if [ "${CHR}" = '' ] && [ "${TEMPRIPPER}" != '' ] ;
262	then
263		RIPPER=${TEMPRIPPER}
264	elif [ "${CHR}" = '' ] && [ "${RIPPER}" != 'none' ] ;
265	then
266		# try to find a ripper automatically
267		findripper
268	fi
269}
270
271checkencoder ()
272{
273	# check whether $ENCODER is installed and executable
274	if [ "${ENCODER}" != 'none' ] && ! (which ${ENCODER} >/dev/null && test -x $(which ${ENCODER}))
275	then
276		dialog --title 'Error' --msgbox \
277			"${ENCODER} is not installed or not executable." 19 70 ;
278		OPT=''
279	fi
280	if [ "${OPT}" = '' ] && [ "${TEMPENCODER}" != '' ] ;
281	then
282		ENCODER=${TEMPENCODER}
283	elif [ "${OPT}" = '' ] && [ "${ENCODER}" != 'none' ] ;
284	then
285		# try to find an encoder automatically
286		findencoder
287	fi
288	if [ "${ENCODER}" != 'l3enc' ] && [ ${BITRATE} -gt 999 ] ;
289	then
290		BITRATE=$(expr ${BITRATE} / 1000)
291	elif [ "${ENCODER}" = 'l3enc' ] && [ ${BITRATE} -le 999 ] ;
292	then
293		BITRATE=$(expr ${BITRATE} \* 1000)
294	fi
295	# $ID3TOOL might need to be adjusted
296	TEMPID3TOOL=''
297	ID3UTIL='0'
298	checkid3tool
299}
300
301checkid3tool ()
302{
303	# check whether $ID3TOOL is installed and executable
304	if [ "${ENCODER}" = 'none' ] ;
305	then
306		ID3TOOL='none'
307	fi
308	if [ "${ID3TOOL}" != 'none' ] && [ "${ID3TOOL}" != 'built-in' ] && [ "${ENCODER}" = 'oggenc' ] ;
309	then
310		dialog --title 'Error' --msgbox \
311			'ID3 tags cannot be used with oggenc, only Built-In tagging.' 19 70 ;
312		ID3TOOL='built-in'
313	fi
314	if [ "${ID3TOOL}" = 'built-in' ] && ! ([ "${ENCODER}" = 'lame' ] || [ "${ENCODER}" = 'notlame' ] || [ "${ENCODER}" = 'oggenc' ]) ;
315	then
316		dialog --title 'Error' --msgbox \
317			'The Built-In tagging function can only be used with either lame, notlame, or oggenc.' 19 70 ;
318		ID3UTIL=''
319	fi
320	if [ "${ID3TOOL}" != 'built-in' ] && [ "${ID3TOOL}" != 'none' ] && ! (which ${ID3TOOL} >/dev/null && test -x $(which ${ID3TOOL}))
321	then
322		dialog --title 'Error' --msgbox \
323			"${ID3TOOL} is not installed or not executable." 19 70 ;
324		ID3UTIL=''
325	fi
326	if [ "${ID3UTIL}" = '' ] && [ "${TEMPID3TOOL}" != '' ] ;
327	then
328		ID3TOOL=${TEMPID3TOOL}
329	elif [ "${ID3UTIL}" = '' ] ;
330	then
331		if [ "${ENCODER}" = 'lame' ] || [ "${ENCODER}" = 'notlame' ] || [ "${ENCODER}" = 'oggenc' ] ;
332		then
333			ID3TOOL='built-in'
334		else
335			# try to find an ID3 tagging utility automatically
336			findid3tool
337		fi
338	fi
339}
340
341getcddb ()
342{
343	# try to access CDDB...
344	if [ "${XMCDLIB}" != '' ] ;
345	then
346		export XMCD_LIBDIR=${XMCDLIB}
347	fi
348	cda -batch -dev ${DEVICE} on
349	cda -dev ${DEVICE} toc > ${TEMPDIR}/toc1
350	grep '(unknown.*title)' ${TEMPDIR}/toc1 >/dev/null && cda -batch -offline -dev ${DEVICE} toc >${TEMPDIR}/toc1 2>/dev/null ;
351	cda -batch -dev ${DEVICE} off
352	if ! (grep '(unknown.*title)' ${TEMPDIR}/toc1 >/dev/null) && [ -s ${TEMPDIR}/toc1 ] ;
353	then
354		sed -e '/Total Time/d' -e '/Disc ID/d' -e '/Accessing CDDB/d' -e '/^Genre:.*$/d' -e '/^$/d' -e 's/\.//g' -e 's/\[//g' -e 's/\]//g' ${TEMPDIR}/toc1 > ${TEMPDIR}/toc2
355		CHECKVARIOUS=$(sed -ne '1p' ${TEMPDIR}/toc2 | cut -d "/" -f1 | tr A-Z a-z | sed -e 's/ //g')
356		if [ "${CHECKVARIOUS}" = 'variousartists' -o "${CHECKVARIOUS}" = 'soundtrack' -o "${CHECKVARIOUS}" = 'various' ] ;
357		then
358			ALBUM=$(sed -ne '1p' ${TEMPDIR}/toc2 | cut -d "/" -f2- | tr a-z A-Z)
359			sed -e '1d' ${TEMPDIR}/toc2 | cut -d ' ' -f5- | tr A-Z a-z | sed -e 's/\//-/g' -e 's/ - /-/g' -e 's/ -- /-/g' -f ${RCDIR}/dekagensed > ${TEMPDIR}/cdnames
360		else
361			ARTIST=$(sed -ne '1p' ${TEMPDIR}/toc2 | cut -d "/" -f1)
362			ALBUM=$(sed -ne '1p' ${TEMPDIR}/toc2 | cut -d "/" -f2-)
363			sed -e '1d' ${TEMPDIR}/toc2 | cut -d ' ' -f5- | sed -e 's/\///g' -f ${RCDIR}/dekagensed > ${TEMPDIR}/cdnames
364		fi
365		rm ${TEMPDIR}/toc[1-2]
366		test -s ${TEMPDIR}/cdnames || return ;
367		if [ "${WHOLE}" = 'yes' ] ;
368		then
369			if [ "${ID3TOOL}" != 'none' ] ;
370			then
371				YEAR=$(dialog --inputbox 'Please enter the publishing year:' \
372				19 70 3>&1 1>&2 2>&3) || return ;
373			fi
374			sed -e '=' ${TEMPDIR}/cdnames | sed -e 'N' -e 's/\n/ /g' >${TEMPDIR}/ripname
375			confirm
376		else
377			newmenu
378		fi
379	else
380		# ...or fall back to 'manual' method
381		METHOD='manual'
382		if [ "${WHOLE}" = 'yes' ] ;
383		then
384		WHOLE='no'
385		manual
386			WHOLE='yes'
387		else
388			manual
389		fi
390		METHOD='cddb'
391	fi
392}
393
394newmenu ()
395{
396	# select songs from CDDB list
397	test -f ${TEMPDIR}/ripname && rm ${TEMPDIR}/ripname
398	sed -e /^$/d ${TEMPDIR}/cdnames | sed -e '=' | sed -e 'N' -e 's/\n/ /g' -e 's/$/ off/g' >${TEMPDIR}/tracks
399	dialog --checklist 'Please select the song(s) you wish to rip/encode:' \
400		19 70 12 $(cat ${TEMPDIR}/tracks) 2>${TEMPDIR}/tracknrs1 || return ;
401	sed -e 's/\"//g' -e 's/$/\ /' ${TEMPDIR}/tracknrs1 | tr " " "\n" | sed -e '/^$/d' >${TEMPDIR}/tracknrs2
402	cat ${TEMPDIR}/tracknrs2 | while read SONGNRS
403		do
404			sed -ne "${SONGNRS}"'P' ${TEMPDIR}/tracks | sed -e 's/ off$//' >>${TEMPDIR}/ripname
405		done
406	rm ${TEMPDIR}/tracknrs[1-2]
407	test  -s ${TEMPDIR}/ripname || return ;
408	if [ "${ID3TOOL}" != 'none' ] ;
409	then
410		YEAR=$(dialog --inputbox 'Please enter the publishing year:' \
411			19 70 3>&1 1>&2 2>&3) || return ;
412	fi
413	confirm
414}
415
416manual ()
417{
418	# let user enter song title etc. manually
419	test -f ${TEMPDIR}/ripname && rm ${TEMPDIR}/ripname
420	ARTIST=$(dialog --inputbox 'Please enter the name of the artist or composer:' \
421		19 70 3>&1 1>&2 2>&3) || return ;
422	ALBUM=$(dialog --inputbox 'Please enter the title of the album:' \
423		19 70 3>&1 1>&2 2>&3) || return ;
424	if [ "${ID3TOOL}" != 'none' ] ;
425	then
426		YEAR=$(dialog --inputbox 'Please enter the publishing year:' \
427			19 70 3>&1 1>&2 2>&3) || return ;
428	fi
429	SNUM='0'
430	while [ "${SNUM}" != '' ] ;
431	do
432		SNUM=$(dialog --inputbox 'Please enter the track number of the song you wish to rip\n(leave it blank and hit return to continue):' \
433			19 70 3>&1 1>&2 2>&3) || return ;
434		if [ "${SNUM}" = '' ] ;
435		then
436			continue
437		fi
438		SNAME=$(dialog --inputbox "Please enter the name of the song number ${SNUM}:" \
439			19 70 3>&1 1>&2 2>&3) || return ;
440		SNAME=$(echo "${SNAME}" | sed -e 's/\//-/g' -f ${RCDIR}/dekagensed) ;
441		echo "${SNUM} ${SNAME}" >>${TEMPDIR}/ripname
442	done
443	confirm
444}
445
446confirm ()
447{
448	# let user check his selection
449	CONFMENU='' ;
450	while [ "${CONFMENU}" != 'd' ] && [ "${CONFMENU}" != 'b' ] ;
451	do
452		test -s ${TEMPDIR}/ripname || return ;
453		CONFMENU=$(dialog --menu 'You are going to start ripping/encoding NOW!' 19 70 5 \
454			'd' 'Do it!' \
455			'l' 'Show me what I have chosen' \
456			's' 'Change selection (discard current selection)' \
457			'b' 'Back to the main menu (nothing will be done)' 3>&1 1>&2 2>&3) || return ;
458		case ${CONFMENU} in
459			b)
460				return
461				;;
462			s)
463				if [ "${METHOD}" = 'manual' ] ;
464				then
465					manual
466				else
467					newmenu
468				fi
469			        ;;
470			l)
471				dialog --title 'These songs are going to be ripped/encoded:' \
472					--textbox ${TEMPDIR}/ripname 19 70 ;
473				;;
474			d)
475				rip
476				;;
477		esac
478	done
479}
480
481rip()
482{
483	# lets do it :-)
484	TEMPSAVETO=${SAVETO}
485	ARTIST=$(echo "${ARTIST}" | sed -e 's/\//-/g' -f ${RCDIR}/dekagensed) ;
486	ALBUM=$(echo "${ALBUM}" | sed -e 's/\//-/g' -f ${RCDIR}/dekagensed) ;
487	YEAR=$(printf '%04d' ${YEAR} 2>/dev/null) ;
488	cat ${TEMPDIR}/ripname | while read NUM TITLE
489		do
490			FORMATNUM=$(printf '%02d' ${NUM})
491			if [ "${CHECKVARIOUS}" = 'variousartists' -o "${CHECKVARIOUS}" = 'soundtrack' -o "${CHECKVARIOUS}" = 'various' ] ;
492			then
493				ARTIST='VARIOUS_ARTIST_CD'
494				case ${SELEC} in
495					1)
496						NAME=$(echo "${TITLE}" | tr A-Z a-z)
497						;;
498					2)
499						NAME=$(echo "${FORMATNUM}-${TITLE}" | tr A-Z a-z)
500						;;
501					3)
502						NAME="${TITLE}"
503						;;
504					4)
505						NAME="${FORMATNUM}-${TITLE}"
506						;;
507					*)
508						NAME=$(echo "${TITLE}" | tr A-Z a-z)
509						;;
510				esac
511			else
512				case ${SELEC} in
513					1)
514						NAME=$(echo "${ARTIST}-${TITLE}" | tr A-Z a-z)
515						;;
516					2)
517						NAME=$(echo "${FORMATNUM}-${ARTIST}-${TITLE}" | tr A-Z a-z)
518						;;
519					3)
520						NAME="${ARTIST}-${TITLE}"
521						;;
522					4)
523						NAME="${FORMATNUM}-${ARTIST}-${TITLE}"
524						;;
525					5)
526						NAME=$(echo "${FORMATNUM}-${TITLE}" | tr A-Z a-z)
527						mkdir -p "${SAVETO}/"$(echo "${ARTIST}--${ALBUM}" | tr A-Z a-z)
528						SAVETO="${SAVETO}/"$(echo "${ARTIST}--${ALBUM}" | tr A-Z a-z)
529						;;
530					6)
531						NAME=$(echo "${FORMATNUM}-${TITLE}" | tr A-Z a-z)
532						mkdir -p "${SAVETO}/"$(echo "${ARTIST}/${ALBUM}" | tr A-Z a-z)
533						SAVETO="${SAVETO}/"$(echo "${ARTIST}/${ALBUM}" | tr A-Z a-z)
534						;;
535					7)
536						NAME=$(echo "${ARTIST}-${ALBUM}-${FORMATNUM}-${TITLE}" | tr A-Z a-z)
537						;;
538					8)
539						NAME="${TITLE}"
540						mkdir -p "${SAVETO}/${ARTIST}--${ALBUM}"
541						SAVETO="${SAVETO}/${ARTIST}--${ALBUM}"
542						;;
543					*)
544						NAME=$(echo "${ARTIST}-${TITLE}" | tr A-Z a-z)
545				esac
546			fi
547			echo
548			echo "Now ripping the song ${TITLE} by ${ARTIST} from the album ${ALBUM}." ;
549			echo
550			case ${RIPPER} in
551				cdparanoia)
552					cdparanoia -d ${DEVICE} -w ${NUM} "${SAVETO}/${NAME}.wav"
553					;;
554				cdda2wav)
555					cdda2wav -H -Q -D ${DEVICE} -t ${NUM} "${SAVETO}/${NAME}.wav"
556					;;
557				dagrab)
558					dagrab -d ${DEVICE} -f "${SAVETO}/${NAME}.wav" ${NUM}
559					;;
560				tosha)
561					tosha -q -f wav -d ${DEVICE} -t ${NUM} -o "${SAVETO}/${NAME}.wav"
562					;;
563				none)
564					echo 'Not ripping.'
565					;;
566				*)
567					echo 'Cannot rip from CD.'
568					;;
569			esac
570			echo "${SAVETO}/${NAME}.wav*${ALBUM}*${ARTIST}*${TITLE}*${NUM}*${YEAR}" >> ${TEMPDIR}/convers ;
571			if [ "${ENCODER}" != 'none' ] && [ "${SMALL}" = 'yes' ] ;
572			then
573				echo "Currently converting the song ${TITLE} by ${ARTIST} from the album ${ALBUM}." ;
574				encodeit
575			elif [ "${ENCODER}" != 'none' ] && [ "${SMALL}" != 'yes' ] && [ ! -f ${TEMPDIR}/lock.encode ] ;
576			then
577				encodeit >> ${TEMPDIR}/encode.log 2>&1 &
578				echo $! > ${TEMPDIR}/lock.encode
579			fi
580			SAVETO=${TEMPSAVETO}
581		done
582}
583
584encodeit ()
585{
586	# generate mp3 / ogg and label it with name (id3) tag
587	AIO='0'
588	while [ "${AIO}" != '' ]  ;
589	do
590		AIO=$(head -n1 ${TEMPDIR}/convers) ;
591		EIN=$(echo "${AIO}" | cut -s -d '*' -f1) ;
592		ENEW=$(echo "${EIN}" | sed -e 's/\.wav$/\.mp3/') ;
593		if [ "${ID3TOOL}" != 'none' ] && [ "${ENCODER}" != 'none' ] ;
594		then
595			ID3ALBUM=$(echo "${AIO}" | cut -s -d '*' -f2 | sed -e 's/_/ /g' -e 's/-/ /g') ;
596			ID3ARTIST=$(echo "${AIO}" | cut -s -d '*' -f3 | sed -e 's/_/ /g' -e 's/-/ /g') ;
597			ID3TITLE=$(echo "${AIO}" | cut -s -d '*' -f4 | sed -e 's/_/ /g' -e 's/-/ /g') ;
598			ID3NUM=$(echo "${AIO}" | cut -s -d '*' -f5) ;
599			ID3YEAR=$(echo "${AIO}" | cut -s -d '*' -f6) ;
600			case ${ENCODER} in
601				bladeenc)
602					bladeenc -delete -quit -quiet -br "${BITRATE}" "${EIN}" </dev/null
603					;;
604				8hz-mp3)
605					8hz-mp3 -b ${BITRATE} "${EIN}" "${ENEW}"
606					rm "${EIN}"
607					;;
608				mp3enc)
609					mp3enc -br ${BITRATE} -if "${EIN}" -of "${ENEW}"
610					rm "${EIN}"
611					;;
612				l3enc)
613					l3enc -br ${BITRATE} "${EIN}" "${ENEW}"
614					rm "${EIN}"
615					;;
616				lame)
617					if [ "${ID3TOOL}" = 'built-in' ] ;
618					then
619						lame -S -h -b ${BITRATE} --tl "${ID3ALBUM}" --ta "${ID3ARTIST}" --tt "${ID3TITLE}" --tn "${ID3NUM}" --ty "${ID3YEAR}" "${EIN}" "${ENEW}" ;
620					else
621						lame -S -h -b ${BITRATE} "${EIN}" "${ENEW}" ;
622					fi
623					rm "${EIN}"
624					;;
625				notlame)
626					if [ "${ID3TOOL}" = 'built-in' ] ;
627					then
628						notlame -S -h -b ${BITRATE} --tl "${ID3ALBUM}" --ta "${ID3ARTIST}" --tt "${ID3TITLE}" --tn "${ID3NUM}" --ty "${ID3YEAR}" "${EIN}" "${ENEW}" ;
629					else
630						notlame -S -h -b ${BITRATE} "${EIN}" "${ENEW}" ;
631					fi
632					rm "${EIN}"
633					;;
634				oggenc)
635					EOGG=$(echo "${EIN}" | sed -e 's/\.wav$/\.ogg/') ;
636					oggenc --quiet -b ${BITRATE} -o "${EOGG}" -l "${ID3ALBUM}" -a "${ID3ARTIST}" -t "${ID3TITLE}" -N "${ID3NUM}" -d "${ID3YEAR}" "${EIN}"
637					rm "${EIN}"
638					;;
639			esac
640			case ${ID3TOOL} in
641				id3ed)
642					id3ed -a "${ID3ALBUM}" -n "${ID3ARTIST}" -s "${ID3TITLE}" -k "${ID3NUM}" -y "${ID3YEAR}" -q "${ENEW}" ;
643					;;
644				id3tool)
645					id3tool -c "${ID3NUM}" -a "${ID3ALBUM}" -r "${ID3ARTIST}" -t "${ID3TITLE}" -y "${ID3YEAR}" "${ENEW}" ;
646					;;
647				id3tag)
648					id3tag -A"${ID3ALBUM}" -a"${ID3ARTIST}" -s"${ID3TITLE}" -t"${ID3NUM}" -y"${ID3YEAR}" "${ENEW}" ;
649					;;
650				mp3info)
651					mp3info -l "${ID3ALBUM}" -a "${ID3ARTIST}" -t "${ID3TITLE}" -n "${ID3NUM}" -y "${ID3YEAR}" "${ENEW}" ;
652					;;
653				*)
654					# this should catch also the "built-in" option
655					;;
656			esac
657		else
658			case ${ENCODER} in
659				bladeenc)
660					bladeenc -delete -quit -quiet -br ${BITRATE} "${EIN}" </dev/null
661					;;
662				8hz-mp3)
663					8hz-mp3 -b ${BITRATE} "${EIN}" "${ENEW}"
664					rm "${EIN}"
665					;;
666				mp3enc)
667					mp3enc -br ${BITRATE} -if "${EIN}" -of "${ENEW}"
668					rm "${EIN}"
669					;;
670				l3enc)
671					l3enc -br ${BITRATE} "${EIN}" "${ENEW}"
672					rm "${EIN}"
673					;;
674				lame)
675					lame -S -h -b ${BITRATE} "${EIN}" "${ENEW}"
676					rm "${EIN}"
677					;;
678				notlame)
679					notlame -S -h -b ${BITRATE} "${EIN}" "${ENEW}"
680					rm "${EIN}"
681					;;
682				oggenc)
683					oggenc --quiet -b ${BITRATE} "${EIN}"
684					rm "${EIN}"
685					;;
686				none)
687					echo 'Not encoding.'
688					;;
689				*)
690					echo 'Cannot convert to MP3/Ogg.'
691					;;
692			esac
693		fi
694		sed -e '1d' ${TEMPDIR}/convers >>${TEMPDIR}/converstemp
695		mv ${TEMPDIR}/converstemp ${TEMPDIR}/convers
696		AIO=$(head -n1 ${TEMPDIR}/convers) ;
697	done
698	rm -f ${TEMPDIR}/lock.encode
699}
700
701main ()
702{
703	# main menu
704	MENU='' ;
705	while [ "${MENU}" != 'q' ] ;
706	do
707        	if [ -f ${TEMPDIR}/lock.encode ] ;
708        	then
709        	        echo 'There is currently an encoding process running in the background.' >${TEMPDIR}/msgs
710        	else
711        	        echo 'There is no encoding process running in the background.' >${TEMPDIR}/msgs
712        	fi
713        	if [ -s ${TEMPDIR}/encode.log ] ;
714        	then
715        	        SIZE=$(ls -sh ${TEMPDIR}/encode.log | awk '{ print $1 }')
716        	        echo "Your encode log file is ${SIZE} bytes long." >>${TEMPDIR}/msgs
717        	else
718        	        echo 'There is no encode log file.' >>${TEMPDIR}/msgs
719        	fi
720		MENU=$(dialog --menu "$(cat ${TEMPDIR}/msgs)" 19 70 10 \
721			's' 'Start' \
722			'e' 'Show details of encoding process' \
723			'v' 'Show the encode log' \
724			'd' 'Delete the encode log' \
725			'l' 'List the files in the working directory' \
726			'p' 'Preferences' \
727			'h' 'Help (show manual page)' \
728			'a' 'About dekagen' \
729			'q' 'Quit (safe exit)' 3>&1 1>&2 2>&3) || forcequit ;
730		rm ${TEMPDIR}/msgs
731
732		case ${MENU} in
733			v) # view encolde log
734				if [ -s ${TEMPDIR}/encode.log ] ;
735				then
736					dialog --title 'Content of your encode log:' \
737						--textbox ${TEMPDIR}/encode.log 19 70 ;
738				else
739					dialog --title 'Message' \
740						--msgbox 'There is no encode log file to view.' 19 70 ;
741				fi
742				;;
743			e) # show details of encoding process
744				if [ ! -f ${TEMPDIR}/lock.encode ] ;
745				then
746					dialog --title 'Message' \
747						--msgbox 'There is no encoding process running.' 19 70 ;
748				else
749					echo >${TEMPDIR}/tmprip
750					echo 'Encoder      PID     CPU Usage  CPU Time  Elapsed Time' >>${TEMPDIR}/tmprip
751					BCKGRNDP=$(cat ${TEMPDIR}/lock.encode 2>/dev/null) ;
752					ps -o comm,pid,pcpu,time,etime,ppid | awk '$6 == '"${BCKGRNDP}"' \
753						{ print $1"      "$2"          "$3"  "$4"         "$5 }' >>${TEMPDIR}/tmprip 2>/dev/null ;
754					STATUSINC=$(wc -l ${TEMPDIR}/convers | awk '{ print $1 }') ;
755					STATUS=$(expr ${STATUSINC} - 1) ;
756					CURRENT=$(sed -ne '1p' ${TEMPDIR}/convers | cut -s -d '*' -f1) ;
757					echo >>${TEMPDIR}/tmprip
758					echo 'File currently being encoded:' >>${TEMPDIR}/tmprip
759					echo "${CURRENT}" >>${TEMPDIR}/tmprip
760					echo >>${TEMPDIR}/tmprip
761					case ${STATUS} in
762						0)
763							echo 'There are no more songs in the queue.' >>${TEMPDIR}/tmprip
764							;;
765						1)
766							echo 'This song still needs to be encoded:' >>${TEMPDIR}/tmprip
767							;;
768						*)
769							echo "These ${STATUS} songs still need to be encoded:" >>${TEMPDIR}/tmprip
770							;;
771					esac
772					sed -ne '2,$p' ${TEMPDIR}/convers | cut -s -d '*' -f1 >>${TEMPDIR}/tmprip ;
773					dialog --title 'Currently running encoding processes:' \
774						--textbox ${TEMPDIR}/tmprip 19 70 ;
775					rm ${TEMPDIR}/tmprip
776				fi
777				;;
778			d) # delete encode log
779				if [ ! -f ${TEMPDIR}/encode.log ] ;
780				then
781					dialog --title 'Message' \
782						--msgbox 'There is no encode log file.' 19 70 ;
783				elif [ -f ${TEMPDIR}/lock.encode ] ;
784				then
785					dialog --title 'Question'\
786						--yesno 'Deleting the encode log while an encoding process is running
787will disable writing any more information to the log file until
788encoding processes for all files currently in the queue and for
789files that are added to the queue while the current encoding is
790running are completed.
791
792Are you sure you want to do this?' 19 70 \
793						&& rm -f ${TEMPDIR}/encode.log ;
794				else
795					rm ${TEMPDIR}/encode.log
796				fi
797				;;
798			p) # setup preferences
799				if [ -f ${TEMPDIR}/lock.encode ] ;
800				then
801					dialog --title 'Message' \
802						--msgbox 'Preferences cannot be changed while an encoding process is running.' 19 70 ;
803				else
804					setup
805					saverc
806				fi
807				;;
808			l) # list
809                        	ls -lF ${SAVETO}/ >${TEMPDIR}/tmprip
810				dialog --title "Content of ${SAVETO}:" --textbox ${TEMPDIR}/tmprip 19 70 ;
811                        	rm ${TEMPDIR}/tmprip
812                        	;;
813                	s) # start
814                        	if [ "${METHOD}" = 'cddb' ] ;
815                        	then
816                        	        getcddb
817                        	else
818                                	manual
819                        	fi
820                        	;;
821
822	                h) # show manual page
823                        	man dekagen 2>&1 | col -bx >${TEMPDIR}/tmprip
824				dialog --title 'dekagen manual page' --textbox ${TEMPDIR}/tmprip 19 70 ;
825                        	rm ${TEMPDIR}/tmprip
826                        	;;
827
828			a) # about
829				cat >${TEMPDIR}/tmprip <<- %%
830
831   Dekagen written by Martin Bayer <mbayer@zedat.fu-berlin.de>
832
833                 The latest version can be found at
834      http://userpage.fu-berlin.de/~mbayer/tools/dekagen.html
835
836  This program is free software; you can redistribute it and/or
837   modify it under the terms of the GNU General Public License
838   as published by the Free Software Foundation; either version
839     2 of the License, or (at your option) any later version.
840     This program is distributed in the hope that it will be
841   useful, but WITHOUT ANY WARRANTY; without even the implied
842     warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
843  PURPOSE. See the GNU General Public License for more details.
844%%
845				dialog --title "About ${VERSION}" --textbox ${TEMPDIR}/tmprip 19 70 ;
846				rm ${TEMPDIR}/tmprip
847				;;
848			q) # quit
849				if [ -f ${TEMPDIR}/lock.encode ] ;
850                	        then
851                	                dialog --title 'Question'\
852                	                        --yesno 'You are going to leave dekagen, but there are still encoding
853processes running in the background. Leave them as well?
854
855Answering Yes will cause these processes to be terminated and
856the encoding queue to be deleted. There is no way to resume
857these operations.
858Answering No will let these processes running in the
859background. It is safe to restart dekagen later to view the log
860file, or to add other songs to the queue.
861
862Do you wish these processes to be terminated?' 19 70 \
863                	                        && (killbgjob ; cleantemp ; saverc) ;
864                	        else
865                        		clear
866                        		cleantemp
867                        		saverc
868				fi
869				;;
870		esac
871	done
872}
873
874setup ()
875{
876	# setup options screen
877	SETMENU='' ;
878	while [ "${SETMENU}" != '1' ] ;
879	do
880		SETMENU=$(dialog --menu 'dekagen preferences' 19 70 12 \
881			'1' 'Save settings and return to main menu' \
882			'2' "Change working directory: ${SAVETO}" \
883			'3' "Choose ripper: ${RIPPER}" \
884			'4' "Choose encoder: ${ENCODER}" \
885			'5' "Choose ID3 tag tool: ${ID3TOOL}" \
886			'6' "Toggle between manual or CDDB naming: ${METHOD}" \
887			'7' "Set XMCD_LIBDIR variable for cda: ${XMCDLIB}" \
888			'8' "Set file naming convention: ${NCONVENT}" \
889			'9' "Rip whole CD? ${WHOLE}" \
890			'10' "Set small hard disk option? ${SMALL}" \
891			'11' "Select your CD-ROM device: ${DEVICE}" \
892			'12' "Set nominal bitrate for the encoded MP3/Ogg: ${BITRATE}" 3>&1 1>&2 2>&3) || return ;
893
894		case ${SETMENU} in
895			1) # leave preferences screen
896				saverc
897				;;
898			2) # setup working directory
899                	        OLDSAVETO=${SAVETO}
900				SAVETO=$(dialog --inputbox "Please enter the full path to the directory in which all ripping
901and encoding will be done
902(currently ${SAVETO}):" 19 70 3>&1 1>&2 2>&3 | sed -e 's/\/$//' -f ${RCDIR}/dekagensed) ;
903                	        checksaveto
904                	        ;;
905			3) # choose ripper
906				TEMPRIPPER=${RIPPER}
907				CHR=$(dialog --menu "Please choose your CD ripping tool\n(currently ${RIPPER}):" 19 70 6 \
908					'1' 'cdparanoia' \
909					'2' 'cdda2wav' \
910					'3' 'tosha' \
911					'4' 'dagrab' \
912					'5' 'none (in case wav file exists and needs only to be encoded)' \
913					3>&1 1>&2 2>&3) ;
914				case ${CHR} in
915					1)
916						RIPPER='cdparanoia'
917						;;
918					2)
919						RIPPER='cdda2wav'
920						;;
921					3)
922						RIPPER='tosha'
923						;;
924					4)
925						RIPPER='dagrab'
926						;;
927					5)
928						RIPPER='none'
929						;;
930					*)
931						CHR=''
932						;;
933				esac
934				checkripper
935                        	;;
936			4) # choose encoder
937				TEMPENCODER=${ENCODER}
938				OPT=$(dialog --menu "Please choose your MP3/Ogg encoder\n(currently ${ENCODER}):" 19 70 9 \
939					'1' 'bladeenc' \
940					'2' '8hz-mp3' \
941					'3' 'l3enc' \
942					'4' 'lame' \
943					'5' 'notlame' \
944					'6' 'mp3enc' \
945					'7' 'oggenc' \
946					'8' 'none (do not start encoding automatically)' \
947					 3>&1 1>&2 2>&3) ;
948				case ${OPT} in
949					1)
950						ENCODER='bladeenc'
951						;;
952					2)
953						ENCODER='8hz-mp3'
954						;;
955					3)
956						ENCODER='l3enc'
957						;;
958					4)
959						ENCODER='lame'
960						;;
961					5)
962						ENCODER='notlame'
963						;;
964					6)
965						ENCODER='mp3enc'
966						;;
967					7)
968						ENCODER='oggenc'
969						;;
970					8)
971						ENCODER='none'
972						;;
973					*)
974						OPT=''
975						;;
976				esac
977				checkencoder
978				;;
979			5) # choose id3 tag tool
980				if [ "${ENCODER}" = 'none' ] ;
981				then
982					dialog --title 'Message' --msgbox \
983						'An ID3 tagging tool can only be chosen after an encoder utility (option 4) was chosen.' 19 70 ;
984				else
985					TEMPID3TOOL=${ID3TOOL}
986					ID3UTIL=$(dialog --menu "Please choose your ID3 tag tool.
987The Built-In option will work only if you use an encoder
988with a built-in ID3 engine (lame, notlame).
989For Ogg-Vorbis, please use either None or Built-In.
990(Current value: ${ID3TOOL}.)" 19 70 7 \
991						'1' 'id3ed' \
992						'2' 'id3tool' \
993						'3' 'id3tag' \
994						'4' 'mp3info' \
995						'5' 'built-in (use tagging capability of your encoder)' \
996						'6' 'none (do not name MP3 file with ID3 tag)' \
997						3>&1 1>&2 2>&3) ;
998					case ${ID3UTIL} in
999						1)
1000							ID3TOOL='id3ed'
1001							;;
1002						2)
1003							ID3TOOL='id3tool'
1004							;;
1005						3)
1006							ID3TOOL='id3tag'
1007							;;
1008						4)
1009							ID3TOOL='mp3info'
1010							;;
1011						5)
1012							ID3TOOL='built-in'
1013							;;
1014						6)
1015							ID3TOOL='none'
1016							;;
1017						*)
1018							ID3UTIL=''
1019							;;
1020					esac
1021					checkid3tool
1022				fi
1023				;;
1024			6) # toggle cddb lookup
1025				if [ "${METHOD}" = 'cddb' ] ;
1026				then
1027					METHOD='manual'
1028					WHOLE='no'
1029				else
1030					METHOD='cddb'
1031					dialog --title 'Message' --msgbox \
1032'Setting this option will work only if xmcd/cda is installed and
1033configured on your system.
1034To use xmcd/cda, you will need either a permanent connection to
1035the internet for access to the remote CDDB, or an already existing
1036entry in your local CDDB for the CD you are going to rip.' 19 70 ;
1037				fi
1038				;;
1039			7) # set xmcd path
1040				XMCDTEMP=${XMCDLIB}
1041				XMCDLIB=$(dialog --inputbox "Please enter the complete path to your xmcd library directory\n(currently ${XMCDLIB}):" \
1042					19 70 3>&1 1>&2 2>&3) || XMCDLIB=${XMCDTEMP} ;
1043				if [ ! -d ${XMCDLIB} ] ;
1044				then
1045					dialog --title 'Error' --msgbox "Directory ${XMCDLIB} does not seem to exist." 19 70 ;
1046					XMCDLIB=${XMCDTEMP}
1047				fi
1048				;;
1049			8) # set file naming convention
1050				TEMPSELEC=${SELEC}
1051				SELEC=$(dialog --menu "Please choose your preferred file naming convention.
1052Options 5, 6, 7, and 8 cannot be used with various artist CDs.
1053(Current value: ${SELEC}, ${NCONVENT}.)" 19 70 9 \
1054					'1' 'artist-name_of_song.mp3' \
1055					'2' 'track-artist-name_of_song.mp3' \
1056					'3' 'Artist-Name_Of_Song.mp3 (Capitalized)' \
1057					'4' 'track-Artist-Name_Of_Song.mp3 (Capitalized)' \
1058					'5' 'artist--album/track-name_of_song.mp3 (creates a directory)' \
1059					'6' 'artist/album/track-name_of_song.mp3 (creates directories)' \
1060					'7' 'artist-album-track-name_of_song.mp3' \
1061					'8' 'Artist--Album/Name_Of_Song.mp3 (directory and Capitalized)' \
1062					3>&1 1>&2 2>&3) ;
1063				if [ "${SELEC}" = '' ] && [ "${TEMPSELEC}" != '' ] ;
1064				then
1065					SELEC=${TEMPSELEC}
1066				elif [ "${SELEC}" = '' ] ;
1067				then
1068					SELEC='1'
1069				fi
1070				case ${SELEC} in
1071					1)
1072						NCONVENT='artist-name_of_song.mp3'
1073						;;
1074					2)
1075						NCONVENT='track-artist-name_of_song.mp3'
1076						;;
1077					3)
1078						NCONVENT='Artist-Name_Of_Song.mp3'
1079						;;
1080					4)
1081						NCONVENT='track-Artist-Name_Of_Song.mp3'
1082						;;
1083					5)
1084						NCONVENT='artist--album/track-name_of_song.mp3'
1085						;;
1086					6)
1087						NCONVENT='artist/album/track-name_of_song.mp3'
1088						;;
1089					7)
1090						NCONVENT='artist-album-track-name_of_song.mp3'
1091						;;
1092					8)
1093						NCONVENT='Artist--Album/Name_Of_Song.mp3'
1094						;;
1095					*)
1096						NCONVENT='artist-name_of_song.mp3'
1097						SELEC='1'
1098						;;
1099				esac
1100				;;
1101			9) # toggle ripping whole CD
1102                        	if [ "${METHOD}" = 'manual' ] && [ "${WHOLE}" = 'no' ] ;
1103                        	then
1104					dialog --title 'Message' \
1105						--msgbox 'Setting this option has no effect because you are using manual naming.' 19 70 ;
1106                        	elif [ "${METHOD}" = 'manual' ] ;
1107                        	then
1108                        		WHOLE='no'
1109                        	else
1110                        		if [ "${WHOLE}" = 'no' ] ;
1111                                	then
1112                                	        WHOLE='yes'
1113                                	else
1114                                	        WHOLE='no'
1115                                	fi
1116                        	fi
1117                        	;;
1118			10) # toggle small HD option
1119				if [ "${SMALL}" = "no" ] ;
1120				then
1121					SMALL='yes'
1122					dialog --title 'Message' --msgbox \
1123'Setting this option makes dekagen rip one song and then encode that
1124song, before ripping another one.
1125This is useful if you have only a small hard disk with not the
1126space for a whole CD on it.
1127
1128This will also cause background encoding to be disabled.' 19 70 ;
1129				else
1130					SMALL='no'
1131				fi
1132				;;
1133			11) # set CD device
1134				TEMPDEVICE=${DEVICE}
1135				DEVICE=$(dialog --inputbox "Please enter the complete path of your CD device\n(currently ${DEVICE}):" \
1136					19 70 3>&1 1>&2 2>&3 | sed -e 's/\/$//' ) ;
1137				checkdevice
1138                        	;;
1139			12) # mp3 encoding bitrate
1140				TEMPBITRATE=${BITRATE}
1141				BITRATE=$(dialog --menu "Please choose your MP3/Ogg nominal encoding bitrate\n(currently ${BITRATE} KBits):" 19 70 11 \
1142					'64' '64 KBits' \
1143					'80' '80 KBits' \
1144					'96' '96 KBits' \
1145					'112' '112 KBits' \
1146					'128' '128 KBits' \
1147					'160' '160 KBits' \
1148					'192' '192 KBits' \
1149					'224' '224 KBits' \
1150					'256' '256 KBits' \
1151					'320' '320 KBits' \
1152					3>&1 1>&2 2>&3) ;
1153				if [ "${BITRATE}" = '' ] && [ "${TEMPBITRATE}" != '' ] ;
1154				then
1155					BITRATE=${TEMPBITRATE}
1156				elif [ "${BITRATE}" = '' ] ;
1157				then
1158					BITRATE='128'
1159				fi
1160				if [ "${ENCODER}" = 'l3enc' ] ;
1161				then
1162					BITRATE="${BITRATE}000"
1163				fi
1164				;;
1165		esac
1166	done
1167	return
1168}
1169
1170# finished defining functions, program follows
1171
1172checkoldrc
1173checkforsed
1174
1175test -f ${RCDIR}/dekagenrc && . ${RCDIR}/dekagenrc
1176
1177checksaveto
1178checkdevice
1179checkripper
1180checkencoder
1181
1182test -f ${RCDIR}/dekagenrc || saverc
1183
1184main
1185
1186
1187#EOF
1188