1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
|
# This file contains the functionality for audio CD burning
# This function lets you swap cds if you only have one device.
# (CDwriter and CDreader is same device.)
# Slightly rewritten for cdparanoia instead of cdda2wav
insert_new_CD()
{
typeset temp
while true
do
read -e -p "$bb_am_enter_2" temp
[[ -z "$temp" ]] && break
done
}
convert_if_exist()
{
typeset filetype="$1"
cd ${BBBURNDIR}
if check_for "$filetype"
then
echo -e "$filetype being used..."
convert_audio "$filetype"
else
echo -e "No $filetype audio files found"
fi
}
check_for_wavs()
{
check_for '*.wav'
}
check_for_mp3s()
{
check_for '*.mp3'
}
check_for_flacs()
{
check_for '*.flac'
}
# A function that adjusts the volume of wav
# audio files to a standard volume level.
normalization()
{
if [[ "$BBNORMALIZE" = yes ]]
then
cd ${BBBURNDIR}
for i in *.wav
do
echo -e \
"\n${BBTABLECOLOR}|>${BBSUBCOLOR}$bb_am_norm_1$i...${BBCOLOROFF}"
${BB_NORMCMD} -v -m "$i"
done
fi
}
# Function that validates the input of "y" or "n".
conf_yes_no()
{
typeset answer
while [[ "${answer}" != y && "${answer}" != n ]]
do
read -e -n 1 -p "$bb_am_conf_2" answer
done
[[ "$answer" == y ]]
}
# Function that controls errors.
conf_error()
{
typeset -i stderror=$1
# If there is any error return to main menu.
if (( stderror != 0 ))
then
message "${BBTABLECOLOR}$bb_am_err_1${BBCOLOROFF}"
return 1
fi
return 0
}
# Simple function that validates confirmation of song names.
confirmation()
{
typeset -i answer=0
echo
[[ -f "${BBBURNDIR}/song_name.txt" ]] || return 1
echo -e "${BBTABLECOLOR}|>${BBMAINCOLOR}$bb_am_conf_1${BBCOLOROFF}"
cat -n ${BBBURNDIR}/song_name.txt
echo -e "${BBSUBCOLOR}"
conf_yes_no || answer=1
echo -e "${BBCOLOROFF}"
(( answer == 1 )) && rm -f ${BBBURNDIR}/song_name.txt ${BBBURNDIR}/tracks.txt
return 0
}
# Function for interactive naming of files.
named()
{
typeset track
typeset song_name
typeset number_track
typeset -r funky_chars=$'[()?\277*\/&]'
typeset funky_gone
# Delete old lists of songs rip.
rm -f ${BBBURNDIR}/*.txt
# Show some info
message "${BBSUBCOLOR}$bb_am_named_1${BBCOLOROFF}"
${BB_CDAUDIORIP} -d ${BBCDROM} -vQ
# If there is any error return to main menu.
conf_error $? || return
track=1
cat <<'EOF'
You will now be asked for track numbers and track names.
Track names will default if not supplied.
EOF
echo -e "\n${BBMAINCOLOR}$bb_am_named_4\n${BBMAINCOLOR}$bb_am_named_5"
while [[ -n "${track}" ]]
do
printf "\n%b$bb_am_named_2 %b$bb_am_named_3%b|>%b " \
"${BBMAINCOLOR}" "${BBMAINCOLOR}" "${BBTABLECOLOR}" "${BBCOLOROFF}"
read -e track
[[ -z "$track" ]] && continue
# Only permit integer numbers standing the format
# in the numbers of back prompt.
# FIXME: This does not gurantee that track is an integer value
number_track=$(printf '%02d' ${track})
# This line puts track numbers of the input standard
# into tracks.txt.
echo "${number_track}" >> ${BBBURNDIR}/tracks.txt
printf "$bb_am_named_6${number_track} %b|>%b " \
${BBTABLECOLOR} ${BBCOLOROFF}
read -e song_name
# If the song_name variable = space blank then, change
# fill that with the number of the track to ripped.
if [[ -z "${song_name}" ]]
then
song_name="${number_track}.-Track"
else
# If the song_name variable contained some signs and
# characters specials,
# that difficulty the naming in bash shell, to be equal to nothing.
# Read sed man page to see how it work.
# Change by Casper
# Steveo here:
# This used to be 's/[()?*\/&]//g'
# When I analysed it, I saw that the funny upside down questionmark
# was an octal 277. So I changed it to native proper
# quoted bash notation, i.e., $'stuff' and switched in 277.
# They are equivalent, but the reason for switching is because
# what gets displayed to the person looking at the src code
# depends on the type of terminal emulator that is used.
funky_gone="${song_name//$funky_chars}"
song_name="$funky_gone"
fi
# Delete temporary file and add song name to a text file
echo ${song_name} >> ${BBBURNDIR}/song_name.txt
done
}
# Function rip the tracks or songs selects.
rip()
{
proc_file()
{
typeset var=$1
typeset fni=$2
typeset fno=$3
typeset -i first=1
while read line
do
if (( first ))
then
eval "$var=\"${line}.wav\""
first=0
else
echo "$line"
fi
done < $fni > $fno
}
typeset line
typeset track=0
typeset song_name
confirmation || return 1
cd ${BBBURNDIR}
while [[ -n "${track}" ]]
do
# Read the track to rip of the files in temp directory.
read track < ${BBBURNDIR}/tracks.txt
if [[ -n "${track}" ]]
then
echo -e \
"${BBTABLECOLOR}|>${BBSUBCOLOR}$bb_am_rip_1${track}...${BBCOLOROFF}"
# Begin Rip.
${BB_CDAUDIORIP} -d ${BBCDROM} ${track} ${track}.wav
proc_file track tracks.txt temp_tracks.txt
proc_file song_name song_name.txt temp_song.txt
# Rename the tracks that have been ripped, by the name
# get back by users in prompt.
mv "${track}" "${song_name}"
# Remove the song that has been ripped.
mv ${BBBURNDIR}/temp_song.txt ${BBBURNDIR}/song_name.txt
mv ${BBBURNDIR}/temp_tracks.txt ${BBBURNDIR}/tracks.txt
fi
done
# Remove temp files.
rm -f ${BBBURNDIR}/tracks.txt ${BBBURNDIR}/song_name.txt ${BBBURNDIR}/*.inf
eject ${BBCDROM}
message "${BBSUBCOLOR}$bb_am_rip_2${BBCOLOROFF}"
return 0
}
# Function Encode Filter Command.
encode_filter()
{
typeset format=$1
if [[ -n "$ENCODEFILTER" ]]
then
echo -e \
"${BBTABLECOLOR}|>${BBSUBCOLOR}$bb_am_encfilt(${ENCODEFILTER})${BBCOLOROFF}"
eval ${ENCODEFILTER} ${BBBURNDIR}/*.${format}
fi
}
# CD copying
copy_audio_cd()
{
# Copy an audio cd.
cd ${BBBURNDIR}
# if ${BB_CDAUDIORIP} -D ${BBCDROM} -v all -B -Owav; then
if ${BB_CDAUDIORIP} -d ${BBCDROM} -B
then
eject ${BBCDROM}
echo $bb_am_rip_2
# Normalize WAV's.
normalization
# Check number of devices
(( BBNUMDEV == 1 )) && insert_new_CD
# burnlist= should be set using caseglob and nullglob
if ${BB_CDBURNCMD} -v dev=${BBCDWRITER} \
speed=${BBSPEED} ${BBDRIVEROPT:+"driveropts=$BBDRIVEROPT"} \
${BBDTAO} ${BBPADDING} \
-useinfo ${BBBURNDIR}/*.[Ww][Aa][Vv]
then
message "$bb_am_ch3_1"
else
message "$bb_am_ch3_2"
fi
else
message "$bb_am_ch3_3${BBCDROM}"
fi
}
# Copy an audio cd to HD
copy_cd_to_hd()
{
cd ${BBBURNDIR}
# ${BB_CDAUDIORIP} -D ${BBCDROM} -v all -B -Owav
${BB_CDAUDIORIP} -d ${BBCDROM} -B
eject ${BBCDROM}
# Normalize WAV's.
normalization
message "$bb_am_ch4_1${BBBURNDIR}.$bb_am_ch4_2
$bb_am_ch4_3"
}
create_xxx_from_wavs()
{
# Very sneaky stuff going on here. cmd is passed in but it refers to file.
# file is a variable in the loop in here.
typeset cmd="$1"
typeset fmt=$2
typeset file
typeset cmd_was_executed=0
cd ${BBBURNDIR}
while read file
do
eval $cmd
cmd_was_executed=1
done < <(find . -iname "*.wav")
if (( cmd_was_executed ))
then
# Encode Filter Command.
encode_filter $fmt
else
message "\n$bb_am_ch6_3${BBBURNDIR}"
fi
}
# Create Mp3s from Wavs in BURNDIR (Is this comment _REALLY_ necessary?)
create_mp3s_from_wavs()
{
create_xxx_from_wavs \
'${BB_MP3ENC} --preset cd "${file}" "${file%%wav}mp3"' \
mp3
}
#Create Oggs from Wavs in BURNDIR
create_oggs_from_wavs()
{
create_xxx_from_wavs \
'${BB_OGGENC} -b ${BBBITRATE} "${file}"' \
ogg
}
# Create flacs from Wavs in BURNDIR
create_flacs_from_wavs()
{
create_xxx_from_wavs \
'${BB_FLACCMD} -b ${BBBITRATE} "${file}"' \
flac
}
create_xx_from_cd()
{
typeset cmd="$1"
typeset resultstr="$2"
typeset file
typeset cmd_was_executed=0
# First, name and rip the tracks
# Give name to the tracks.
named
# Rip the tracks in wav audio file.
rip || return
# Normalize WAV's.
normalization
# Now create the Mp3s
while read file
do
eval $cmd
cmd_was_executed=1
done < <(find . -iname "*.wav")
if (( cmd_was_executed ))
then
# Encode Filter Command.
encode_filter mp3
else
message "\n$bb_am_ch6_3${BBBURNDIR}"
fi
message "${resultstr}${BBURNDIR}"
shopt -s nocaseglob
rm ${BBBURNDIR}/*.wav
shopt -u nocaseglob
}
# Create Mp3s from an audio cd.
create_mp3s_from_cd()
{
create_xx_from_cd \
'${BB_MP3ENC} --preset cd "${file}" "${file%%.wav}.mp3"' \
"$bb_am_ch9_2${BBBURNDIR}"
}
# Create Oggs from an audio cd.
create_oggs_from_cd()
{
create_xx_from_cd \
'${BB_OGGENC} -b ${BBBITRATE} "${file}"' \
"$bb_am_ch10_2${BBBURNDIR}"
}
# Create flacs from cd
create_flacs_from_cd()
{
create_xx_from_cd \
'${BB_FLACCMD} "${file}"' \
"$bb_am_ch11_1${BBBURNDIR}"
}
|