Git Repos / dotfiles / bin / flac_reencode.sh
Last update to this file was on 2024-01-02 at 05:12.
Show flac_reencode.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.
#
#- flac_reencode.sh 2015/03/26 cev
#- flac_reencode.sh 2021/07/23 cev
## Usage: flac_reencode.sh [-hV] <file or directory>
##
## -h Show help
## -V Print version info
# Useful for sniffing out broken flac files.
# References:
# http://unix.aspcode.net/view/63539508700411522976682/copy-all-tags-from-one-flac-file-to-another
[ -x $HOME/.local/bin/cev_print.sh ] && . $HOME/.local/bin/cev_print.sh
self="${0##*'/'}"
tdir=""
cwd=""
cleanup() {
if [ -n "$tdir" -a -d "$tdir" ]; then
rm -f $tdir/*.backup $tdir/*.wav $tdir/*.tags $tdir/picture
rmdir $tdir
fi
if [ -n "$cwd" ]; then cd "$cwd"; fi
}
die_filenotfound() {
print_filenotfound "$*"
exit 1
}
die_nofile() {
print_nofile
exit 1
}
flac_recover() {
printf " %berror.%b\n" "$_error" "$_clear"
mv "$1" "$2"
exit 1
}
flac_reencode() {
print_self
printf "%b%s%b" "$_high" "$@" "$_norm"
base="$(basename "$@" ".flac")"
printf "."
flac --totally-silent -o "$tdir/$base.wav" -d "$@" || \
flac_recover "$tdir/$base.backup" "$@"
mv "$@" "$tdir/$base.backup"
printf "."
flac --totally-silent -o "$@" "$tdir/$base.wav" || \
flac_recover "$tdir/$base.backup" "$@"
printf "."
printf " copying tags"
metaflac --no-utf8-convert \
--export-tags-to="$tdir/$base.tags" "$tdir/$base.backup" && \
metaflac \
--remove-all-tags --import-tags-from="$tdir/$base.tags" "$@" || \
flac_recover "$tdir/$base.backup" "$@"
printf "."
pic="$(metaflac --list --block-type=PICTURE "$tdir/$base.backup")"
if [ -n "$pic" ]; then
metaflac --export-picture-to="$tdir/picture" "$tdir/$base.backup" || \
flac_recover "$tdir/$base.backup" "$@"
printf "."
metaflac --import-picture-from="3||||$tdir/picture" "$@" || \
flac_recover "$tdir/$base.backup" "$@"
printf "."
rm "$tdir/picture"
else
printf ".."
fi
rm "$tdir/$base.backup" "$tdir/$base.wav"
printf "%b\n" "$_clear"
}
while getopts "hV?" option; do
case $option in
h) print_help && exit ;;
V) print_version && exit ;;
"?") print_help && exit ;;
esac
shift $((OPTIND - 1))
done
[ $# -lt 1 ] && die_nofile
trap cleanup EXIT
tdir=$(mktemp -d ${TMPDIR:-/tmp}/${self}.XXXXXXXX)
if [ -d "$@" ]; then
cwd="$PWD"
cd "$@"
for i in *.flac; do
flac_reencode "$i"
done
cd "$cwd"
elif [ -e "$@" ]; then
flac_reencode "$@"
else
die_filenotfound "$*"
fi
Return to the top of this page or return to the overview of this repo.
Log flac_reencode.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 | +109 |
Return to the top of this page or return to the overview of this repo.