paranoia
This commit is contained in:
parent
eccc30ea85
commit
5138132c46
36
flacconv
36
flacconv
|
@ -11,7 +11,7 @@ NL='
|
|||
'
|
||||
export POSIXLY_CORRECT=1
|
||||
|
||||
if [ "${NO_COLOR:-}" ]; then
|
||||
if [ -n "${NO_COLOR:-}" ]; then
|
||||
RED="" GREEN="" YELLOW="" RESET=""
|
||||
fi
|
||||
|
||||
|
@ -35,9 +35,9 @@ warn() {
|
|||
|
||||
_tempdir() {
|
||||
set +u
|
||||
[ "$TMPDIR" ] || \
|
||||
{ [ "$TEMP" ] && TMPDIR="$TEMP"; } || \
|
||||
{ [ "$TMP" ] && TMPDIR="$TMP"; } || \
|
||||
[ -n "$TMPDIR" ] || \
|
||||
{ [ -n "$TEMP" ] && TMPDIR="$TEMP"; } || \
|
||||
{ [ -n "$TMP" ] && TMPDIR="$TMP"; } || \
|
||||
{ [ -d "/tmp" ] && TMPDIR="/tmp"; } || \
|
||||
{ [ -d "/var/tmp" ] && TMPDIR="/var/tmp"; } || \
|
||||
{ [ -d "/usr/tmp" ] && TMPDIR="/usr/tmp"; } || \
|
||||
|
@ -111,10 +111,10 @@ process_file() {
|
|||
fi
|
||||
|
||||
# now test if keepkeys or removekeys was used, set exported tags
|
||||
if [ "$KEEPKEYS" ]; then
|
||||
if [ -n "$KEEPKEYS" ]; then
|
||||
tagnames="$(printf '%s' "$tagnames" | grep -i -E "^$KEEPKEYS")"
|
||||
fi
|
||||
if [ "$REMOVEKEYS" ]; then
|
||||
if [ -n "$REMOVEKEYS" ]; then
|
||||
[ "$REMOVEKEYS" = "ALL" ] && REMOVEKEYS=''
|
||||
tagnames="$(printf '%s' "$tagnames" | grep -v -i -E "^$REMOVEKEYS")"
|
||||
fi
|
||||
|
@ -130,7 +130,7 @@ process_file() {
|
|||
VLVL=
|
||||
# build opus comment chain, can't "import" tags like with flac
|
||||
set --
|
||||
[ "$tagnames" ] && while read -r name; do
|
||||
[ -n "$tagnames" ] && while read -r name; do
|
||||
tag="$(metaflac --show-tag="$name" "$infile")"
|
||||
# need a while loop here to handle tags with multiple values
|
||||
while [ "$tag" != "${tag#*$name=}" ]; do # check if we're on last one
|
||||
|
@ -140,14 +140,14 @@ process_file() {
|
|||
done <<-EOF
|
||||
$tagnames
|
||||
EOF
|
||||
if [ "$VERBOSE" ]; then
|
||||
if [ -n "$VERBOSE" ]; then
|
||||
_opusenc "$@" || convwarn
|
||||
else
|
||||
_opusenc "$@" 1>/dev/null 2>&1 || convwarn
|
||||
fi
|
||||
|
||||
# remove encoding metadata
|
||||
[ "$RMENCTAG" ] && opustags -d ENCODER -d ENCODER_OPTIONS -i "${infile%.*}.opus"
|
||||
[ -n "$RMENCTAG" ] && opustags -d ENCODER -d ENCODER_OPTIONS -i "${infile%.*}.opus"
|
||||
else
|
||||
album="$(metaflac --show-tag=album "$infile")"
|
||||
artist="$(metaflac --show-tag=artist "$infile")"
|
||||
|
@ -158,17 +158,17 @@ process_file() {
|
|||
tracknumber="$(metaflac --show-tag=tracknumber "$infile")"
|
||||
comment="$(metaflac --show-tag=comment "$infile")"
|
||||
|
||||
[ ! "$VLVL" ] && cbr="-b $BITRATE --cbr"
|
||||
if [ "$VERBOSE" ]; then
|
||||
[ -z "$VLVL" ] && cbr="-b $BITRATE --cbr"
|
||||
if [ -n "$VERBOSE" ]; then
|
||||
_mp3enc || convwarn
|
||||
else
|
||||
_mp3enc 1>/dev/null 2>&1 || convwarn
|
||||
fi
|
||||
fi
|
||||
|
||||
[ "${pic:-}" ] && rm -f "$pic"
|
||||
[ "$DELETE" ] && rm -f "$infile"
|
||||
[ "${err:-}" ] || errecho "$infile ${GREEN}successfully converted to ${RESET}$TYPE${GREEN} with bitrate/quality ${RESET}${VLVL:+V}${VLVL:-${BITRATE}k}"
|
||||
[ -n "${pic:-}" ] && rm -f "$pic"
|
||||
[ -n "$DELETE" ] && rm -f "$infile"
|
||||
[ -n "${err:-}" ] || errecho "$infile ${GREEN}successfully converted to ${RESET}$TYPE${GREEN} with bitrate/quality ${RESET}${VLVL:+V}${VLVL:-${BITRATE}k}"
|
||||
}
|
||||
|
||||
usage() {
|
||||
|
@ -222,7 +222,7 @@ IGNOREWARNINGS=
|
|||
TYPE=opus
|
||||
BITRATE=128
|
||||
THREADS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)" # hopefully portable enough to not be an issue
|
||||
[ ! $? ] && warn 'unable to find number of cores! defaulting to 1 thread unless otherwise specified...' && THREADS=1
|
||||
[ $? -ne 0 ] && warn 'unable to find number of cores! defaulting to 1 thread unless otherwise specified...' && THREADS=1
|
||||
_tempdir # set temp dir
|
||||
|
||||
while getopts :huvVid3peb:l:k:r:j: OPT; do
|
||||
|
@ -246,19 +246,19 @@ while getopts :huvVid3peb:l:k:r:j: OPT; do
|
|||
done
|
||||
shift "$((OPTIND - 1))"
|
||||
|
||||
[ "$REALLYVERBOSE" ] && set -x
|
||||
[ -n "$REALLYVERBOSE" ] && set -x
|
||||
command -v metaflac 1>/dev/null 2>&1 || fail 'flac tools are not installed! (metaflac)'
|
||||
if [ "$TYPE" = "opus" ]; then command -v opusenc 1>/dev/null 2>&1 || fail 'opus-tools is not installed! (opusenc)'
|
||||
else command -v lame 1>/dev/null 2>&1 || fail 'lame is not installed! (lame)'
|
||||
fi
|
||||
[ "$RMENCTAG" ] && { command -v opustags 1>/dev/null 2>&1 || fail 'opustags is not installed! this is required for -e (opustags)' ; }
|
||||
[ -n "$RMENCTAG" ] && { command -v opustags 1>/dev/null 2>&1 || fail 'opustags is not installed! this is required for -e (opustags)' ; }
|
||||
|
||||
# this script assumes you aren't using newlines in path names
|
||||
# I do not want to change it to account for this
|
||||
# you should never put newlines in paths
|
||||
# it is a very bad idea for many programs
|
||||
FLACFILES="$(find "$@" -type f -name "*.[fF][lL][aA][cC]")"
|
||||
[ "$FLACFILES" ] || fail 'no flac files found!'
|
||||
[ -n "$FLACFILES" ] || fail 'no flac files found!'
|
||||
|
||||
# make a fifo/fd for parallel stuff
|
||||
mk_parallel_fd() {
|
||||
|
|
Loading…
Reference in New Issue