Git Repos / dotfiles / bin / tag_cover.sh
Last update to this file was on 2024-01-02 at 05:12.
Show tag_cover.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.
#
#- tag_cover.sh 2016/07/05 cev, updated 2021/07/23 & 2022/01/29.
## Usage: tag_cover.sh [-3fdhvV] [-c coverfile] <file>
##
## Add a cover image to an audio file (mp3 or flac) or display the
## cover image embedded in an existing file.
##
## -3 Operate on mp3 files
## -f Operate on flac files
## -c Use [coverfile] instead of "00 cover.jpg"
## -d Display cover embedded in file <file> to the screen
## -h Show help
## -v Verbose
## -V Print version info
#
# TODO: better error checking.
# TODO: implement option to choose image viewer instead of xdg-open
[ -x $HOME/.local/bin/cev_print.sh ] && . $HOME/.local/bin/cev_print.sh
self="${0##*'/'}"
filetype=""
fileext=""
cover="00 cover.jpg"
display=""
verbose=""
tdir=""
if [ "$self" = "flac_cover.sh" -o "$self" = "flac_cover" ]; then
filetype="flac"
fileext="flac"
elif [ "$self" = "mp3_cover.sh" -o "$self" = "mp3_cover" ]; then
filetype="mp3"
fileext="mp3"
fi
cleanup() {
if [ -n "$tdir" -a -d "$tdir" ]; then
rm -f $tdir/*.*
rmdir $tdir
fi
}
die_filenotfound() {
print_filenotfound "$*"
exit 1
}
die_nofile() {
print_nofile
exit 1
}
die_unknownfiletype() {
shortname="$(basename "$*")"
print_unknownfiletype "$shortname"
exit 1
}
is_flac() { test_mimetype.sh -t "audio/x-flac" "$@" ; }
is_mp3() {
if test_mimetype.sh -t "audio/mpeg" "$@"; then
return 0
else
# test file extension
tmpname="$(basename "$@" ".mp3")"
tmpname2="${@##$tmpname}"
if [ "$tmpname2" = ".mp3" ]; then
return 0
fi
fi
return 1
}
flac_getcover() {
metaflac --export-picture-to="$tdir/$cover" "$*" 2>/dev/null
}
flac_setcover() {
metaflac --import-picture-from="3||||$cover" "$1"
}
mp3_getcover() {
eyeD3 --write-images "$tdir" "$*" 1>/dev/null 2>&1
}
mp3_setcover() {
eyeD3 --add-image="${cover}:FRONT_COVER:" "$1"
}
while getopts "3fc:dhvV?" option; do
case $option in
3) filetype="mp3" && fileext="mp3" ;;
f) filetype="flac" && fileext="flac" ;;
c) cover="$OPTARG" ;;
d) display="y" ;;
h) print_help && exit 0 ;;
v) verbose="y" ;;
V) print_version && exit 0 ;;
"?") print_help && exit 0 ;;
esac
shift $((OPTIND - 1))
done
[ $# -lt 1 ] && die_nofile
[ ! -f "$*" ] && die_filenotfound "$*"
if [ "$filetype" ]; then
eval get_cover=\${filetype}_getcover
eval set_cover=\${filetype}_setcover
elif is_flac "$@"; then
filetype="flac" && fileext="flac"
get_cover="flac_getcover"
set_cover="flac_setcover"
elif is_mp3 "$@"; then
filetype="mp3" && fileext="mp3"
get_cover="mp3_getcover"
set_cover="mp3_setcover"
else
die_unknownfiletype "$*"
fi
if [ "$display" ]; then
trap cleanup EXIT
tdir=$(mktemp -d ${TMPDIR:-/tmp}/${self}.XXXXXXXX)
$get_cover "$*"
xdg-open "$tdir"/* &
sleep 1
exit 0
else
if [ "$verbose" ]; then
print_self
printf "%badding cover '%b%s%b' to file '%b%s%b'%b\n" "$_norm" \
"$coverfile" "$_high" "$_norm" "$_high" "$*" "$_norm" "$_clear"
fi
$set_cover "$*"
exit 0
fi
Return to the top of this page or return to the overview of this repo.
Log tag_cover.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 | +144 |
Return to the top of this page or return to the overview of this repo.