silly edits
This commit is contained in:
parent
18ceb3c756
commit
eba9ccc504
60
flacconv
60
flacconv
|
@ -1,18 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
# flacconv 1.4.2 // use https://github.com/yoshiyoshyosh/flacconv for issues
|
||||
|
||||
GREEN="$(tput setf 2)" || GREEN="$(tput setaf 2)"
|
||||
RED="$(tput setf 4)" || RED="$(tput setaf 1)"
|
||||
YELLOW="$(tput setf 6)" || YELLOW="$(tput setaf 3)"
|
||||
VERSION=1.4.3
|
||||
RED="$(tput setaf 9)" || RED="$(tput setf 4)"
|
||||
GREEN="$(tput setaf 10)" || GREEN="$(tput setf 2)"
|
||||
YELLOW="$(tput setaf 11)" || YELLOW="$(tput setf 6)"
|
||||
RESET="$(tput sgr0)"
|
||||
set -euf
|
||||
BN="${0##*/}"
|
||||
POSIXLY_CORRECT=1
|
||||
export POSIXLY_CORRECT=1
|
||||
|
||||
if [ "${NO_COLOR:-}" ]; then
|
||||
GREEN=
|
||||
RED=
|
||||
GREEN=
|
||||
YELLOW=
|
||||
RESET=
|
||||
fi
|
||||
|
@ -48,11 +47,12 @@ _tempdir() {
|
|||
}
|
||||
|
||||
checkupdate() {
|
||||
errecho 'checking for updates...'
|
||||
errecho "you are running version ${GREEN}${VERSION}"
|
||||
errecho "${YELLOW}checking for updates..."
|
||||
if curl -s https://github.com/yoshiyoshyosh/flacconv/releases/latest/download/flacconv | cmp -s "$0" -; then
|
||||
errecho 'your script is updated to the latest version!'
|
||||
errecho "${GREEN}your script is updated to the latest version!"
|
||||
else
|
||||
errecho 'your script differs from remote!'
|
||||
errecho "${RED}your script differs from remote!"
|
||||
errecho 'if this is unintentional, download the newest version from'
|
||||
errecho 'https://github.com/yoshiyoshyosh/flacconv/releases/latest'
|
||||
fi
|
||||
|
@ -135,9 +135,9 @@ process_file() {
|
|||
tmptag="$(metaflac --show-tag="$name" "$infile")"
|
||||
if [ "${tmptag#*=}" ]; then
|
||||
tagcount="$(printf '%s' "$tmptag"| grep -c "^$name=")" # multi-value tags funsies
|
||||
i=2
|
||||
i=2 # must be 2 because there's a blank 1st record
|
||||
while [ $i -le $((tagcount + 1)) ]; do
|
||||
# this awk is kinda cursed, I like it
|
||||
# this awk is kinda cool, I like it
|
||||
set -- "$@" "--comment" "$(printf '%s' "$tmptag" | awk -v RS="^$name=|\n$name=" "FNR==$i{print \"$name=\" \$0 }")"
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
@ -163,7 +163,7 @@ process_file() {
|
|||
tracknumber="$(metaflac --show-tag=tracknumber "$infile")"
|
||||
comment="$(metaflac --show-tag=comment "$infile")"
|
||||
|
||||
[ "$VLVL" ] || cbr="-b $BITRATE --cbr"
|
||||
[ ! "$VLVL" ] && cbr="-b $BITRATE --cbr"
|
||||
if [ "$VERBOSE" ]; then
|
||||
_mp3enc || convwarn
|
||||
else
|
||||
|
@ -173,39 +173,40 @@ process_file() {
|
|||
|
||||
[ "${pic:-}" ] && rm -f "$pic"
|
||||
[ "$DELETE" ] && rm -f "$infile"
|
||||
[ "${err:-}" ] || errecho "$infile ${GREEN}successfully converted to ${RESET}$TYPE${GREEN} with bitrate/quality ${RESET}${VLVL:-${BITRATE}k}"
|
||||
[ "${err:-}" ] || errecho "$infile ${GREEN}successfully converted to ${RESET}$TYPE${GREEN} with bitrate/quality ${RESET}${VLVL:+V}${VLVL:-${BITRATE}k}"
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat >&2 <<-EOF
|
||||
flacconv $VERSION
|
||||
usage: $BN [-huvVipe3] [-b BITRATE] [-l LEVEL] [-k KEYS] [-r KEYS] [-j THREADS] [--] [DIRECTORY...]
|
||||
|
||||
$BN recursively converts directories of flac files to opus/mp3
|
||||
DIRECTORY can be specified multiple times. if omitted, the current directory is used
|
||||
by default, this script outputs opus with variable bitrate 128k
|
||||
IF ENCODING TO MP3, -k AND -r WILL NOT WORK. the only metadata that will be kept is the following:
|
||||
TITLE, ARTIST, ALBUM, ALBUMARTIST, DATE, GENRE, TRACKNUMBER, COMMENT, and the cover picture
|
||||
${RED}IF ENCODING TO MP3, -k AND -r WILL NOT WORK.${RESET} the only metadata that will be kept is the following:
|
||||
${YELLOW}TITLE, ARTIST, ALBUM, ALBUMARTIST, DATE, GENRE, TRACKNUMBER, COMMENT, and the cover picture${RESET}
|
||||
(blame id3. just use opus)
|
||||
|
||||
-h show script help
|
||||
-u check for updates
|
||||
-v verbose output (messy with multithreading)
|
||||
-V very verbose output (VERY messy, use only for debugging and with like, -j 1)
|
||||
-v verbose output ${YELLOW}(messy with multithreading)${RESET}
|
||||
-V very verbose output ${RED}(VERY messy, use only for debugging and with like, -j 1)${RESET}
|
||||
-i ignore script-stopping warnings
|
||||
-d delete original flac files after transcoding
|
||||
-3 switch output filetype to mp3
|
||||
-b <BITRATE> output bitrate in kbits (default 128)
|
||||
this value is variable for opus & CBR for mp3
|
||||
-l <LEVEL> mp3 only: use specified mp3 variable quality (0-9). integer only
|
||||
OVERRIDES -b
|
||||
${YELLOW}OVERRIDES -b${RESET}
|
||||
-k <KEYS> keep specified flac metadata KEYS in output file
|
||||
keys can be checked with metaflac --export-tags-to=- FILE
|
||||
option argument is a PIPE-separated list of keys to keep, case-insensitive
|
||||
option argument is a ${YELLOW}PIPE-separated${RESET} list of keys to keep, case-insensitive
|
||||
(i.e. -k "artist|title|albumartist|album|date")
|
||||
if both -k and -r are not present, all keys are kept.
|
||||
${YELLOW}if both -k and -r are not present, all keys are kept.${RESET}
|
||||
-r <KEYS> remove specified flac metadata KEYS in output file
|
||||
option argument is of the same format as -k
|
||||
if set to "ALL" (with capitalization), all keys are removed
|
||||
${YELLOW}if set to "ALL" (with capitalization), all keys are removed${RESET}
|
||||
-p remove embedded picture in output files
|
||||
-e remove the "encoder" tag that automatically gets applied with opusenc
|
||||
(requires opustags)
|
||||
|
@ -217,16 +218,16 @@ usage() {
|
|||
VERBOSE=
|
||||
REALLYVERBOSE=
|
||||
DELETE=
|
||||
TYPE=opus
|
||||
BITRATE=128
|
||||
VLVL=
|
||||
RMPIC=
|
||||
RMENCTAG=
|
||||
KEEPKEYS=
|
||||
REMOVEKEYS=
|
||||
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
|
||||
[ ! $? ] && 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
|
||||
|
@ -252,15 +253,16 @@ shift "$((OPTIND - 1))"
|
|||
|
||||
[ "$REALLYVERBOSE" ] && set -x
|
||||
command -v metaflac 1>/dev/null 2>&1 || fail 'flac tools are not installed! (metaflac)'
|
||||
[ $TYPE = "mp3" ] && { command -v lame 1>/dev/null 2>&1 || fail 'lame is not installed! (lame)' ; }
|
||||
[ $TYPE = "opus" ] && { command -v opusenc 1>/dev/null 2>&1 || fail 'opus-tools is not installed! (opusenc)' ; }
|
||||
[ $RMENCTAG ] && { command -v opustags 1>/dev/null 2>&1 || fail 'opustags is not installed! this is required for -e (opustags)' ; }
|
||||
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)' ; }
|
||||
|
||||
# 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 -iname "*.[fF][lL][aA][cC]")"
|
||||
FLACFILES="$(find "$@" -type f -name "*.[fF][lL][aA][cC]")"
|
||||
[ "$FLACFILES" ] || fail 'no flac files found!'
|
||||
|
||||
# make a fifo/fd for parallel stuff
|
||||
|
|
Loading…
Reference in New Issue