djcev.com

//

Git Repos / dotfiles / bin / cd_audio.sh

Last update to this file was on 2024-01-02 at 05:12.

Show cd_audio.sh

#!/bin/sh
#
# Copyright (c) 2015-2022, Cameron Vanderzanden. Available under the
# terms of the 2-clause BSD license. Please see the file "LICENSE" in
# the root dir of this repository for more information.
#
#- cd_audio.sh 2015/02/17 cev
#- cd_audio.sh 2021/07/23 cev
#- cd_audio.sh 2022/01/29 cev
## Usage: cd_audio.sh [-3fhV] [-o outdir] <directory>
##
## Convert mp3 or flac files in <directory> to wav files in an
## autogenerated dir (or outdir). Then print a suitable command
## for writing the wav files to a redbook audio CD.
##
## -3 Convert mp3 files
## -f Convert flac files
## -h Show help
## -o Write wav files to outdir instead of creating a dir in /tmp
## -V Print version info
# Todo: switch from specifying filetype to detecting filetype? Would allow
# generation of audio CDs from mixed format sources.

[ -x $HOME/.local/bin/cev_print.sh ] && . $HOME/.local/bin/cev_print.sh

self="${0##*'/'}"
mode="mp3"
cd_command=${cd_command:-"cdrecord"}
cd_opts=${cd_opts:-"-v -dao -pad -audio speed=1 dev=5,0,0"}

die_directorynotfound() {
print_directorynotfound "$@"
exit 1
}

while getopts "3fho:V?" option; do
case $option in
3) mode="mp3" ;;
f) mode="flac" ;;
h) print_help && exit ;;
o) tdir="$OPTARG" ;;
V) print_version && exit ;;
"?") print_help && exit ;;
esac
shift $((OPTIND - 1))
done

if [ -n "$tdir" ]; then
if [ ! -d "$tdir" ]; then
print_self error
printf "%boutput dir %b%s %bdoes not exist or is not a directory!%b\n" \
"$_norm" "$_error" "$tdir" "$_norm" "$_clear" >&2
fi
else
tdir=$(mktemp -d ${TMPDIR:-/tmp}/${self}.XXXXXXXX)
fi

[ ! -d "$@" ] && die_directorynotfound "$@"

if [ $mode = "flac" ]; then
extension="flac"
command="flac -d -o"
command_expr="\${outfile}"
elif [ $mode = "mp3" ]; then
extension="mp3"
command="mpv --msg-level=all=warn --no-audio-display --no-video"
command="$command --audio-samplerate=44100 --ao=pcm"
command_expr="--ao-pcm-file=\${outfile}"
fi

for f in "$@"/*."$extension"; do
file="$(basename "$f")"
outfile="$tdir/${file}.wav"
print_self
printf "%bprocessing '%b%s%b'...%b\n" \
"$_norm" "$_high" "$file" "$_norm" "$_clear"
eval e="\$$command_expr"
$command "$e" "$f"
unset e
done

# echo the command; don't run it. let the user copy/paste it when ready.
print_self
printf "%bwaves written. copy & paste the next line to burn.%b\n" \
"$_norm" "$_clear"
printf "%s %s %s && rm %s && rmdir %s\n" \
"$cd_command" "$cd_opts" "$tdir/*.wav" "$tdir/*.wav" "$tdir"

Return to the top of this page or return to the overview of this repo.

Log cd_audio.sh

Date Commit Message Author + -
2024-01-02 Change from FreeBSD to Linux, other minor changes cev +1 -1
2022-01-29 Adding first batch of audio file handling scripts. cev +87  

Return to the top of this page or return to the overview of this repo.