159 lines
3.9 KiB
Bash
Executable File
159 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Includes
|
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
. /usr/global/lib/music.bash
|
|
|
|
|
|
|
|
|
|
|
|
# System Constants
|
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
MFM_NAME="music_folder_make"
|
|
MFM_VERSION="$Name: music_mk_folder-1_0_0-1 $"
|
|
|
|
|
|
|
|
|
|
|
|
# Print Version
|
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
function version_print()
|
|
{
|
|
echo ${MFM_VERSION} | sed -e 's/.*: //' -e 's/-/ /' -e 's/_/\./g' -e 's/\$$//'
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Prin Help
|
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
function help_print()
|
|
{
|
|
echo "${MFM_NAME} [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] [-p | --music_pattern <music_pattern>] [-r | --root_dir <music_root_dir>]"
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Arg Parse
|
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
function args_parse()
|
|
{
|
|
mode="default"
|
|
verbose="false"
|
|
root_dir="/opt/music/src"
|
|
music_pattern="/"
|
|
|
|
tmp_args=$(getopt -o r:p:ThVv --long root_dir:,music_pattern:,test,help,version,verbose -n "${MFM_NAME}" -- "$@")
|
|
|
|
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
|
|
|
|
# Note the quotes around `$TEMP': they are essential!
|
|
eval set -- "${tmp_args}"
|
|
|
|
while true ; do
|
|
case "$1" in
|
|
# Path options
|
|
-r|--root_dir) shift; root_dir="$1"; shift;;
|
|
|
|
# Options
|
|
-p|--music_pattern) shift; music_pattern="$1"; shift;;
|
|
|
|
# Mode switches
|
|
-T|--test) mode="test"; shift;;
|
|
-h|--help) mode="exit"; help_print; shift;;
|
|
-V|--version) mode="exit"; version_print; shift;;
|
|
|
|
# Global options
|
|
-v|--verbose) verbose="true"; shift;;
|
|
|
|
#
|
|
--) shift; break;;
|
|
*) echo "args_parse internal error [$1] !"; exit 1;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Main
|
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
shopt -s extglob
|
|
|
|
args_parse "$@"
|
|
|
|
if [[ ${mode} == "exit" ]]
|
|
then
|
|
exit 0
|
|
else
|
|
if [[ ${mode} == "test" ]]
|
|
then
|
|
dry_run=true
|
|
else
|
|
dry_run=false
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
echo "mode: [${mode}] verbose: [${verbose}] root_dir: [${root_dir}] music_pattern: [${music_pattern}]" 1>&2
|
|
|
|
find ${root_dir} -type d -links 2 | grep -e "${music_pattern}" | grep -v -e "/video" -e "/photo" | sort | (
|
|
while read dir
|
|
do
|
|
if [[ $(basename ${dir}) == "misc" ]]
|
|
then
|
|
line_echo "${dir}: Misc\r" "${i}"
|
|
else
|
|
|
|
src=""
|
|
dst="${dir}/folder.jpg"
|
|
|
|
for file in ${dir}/cover-front ${dir}/slipcase-front ${dir}/box-front
|
|
do
|
|
for suffix in png jpg
|
|
do
|
|
if [[ "${src}" == "" ]]
|
|
then
|
|
if [[ -f "${file}.${suffix}" ]]
|
|
then
|
|
src="${file}.${suffix}"
|
|
fi
|
|
fi
|
|
done
|
|
done
|
|
|
|
if [[ "${src}" == "" ]]
|
|
then
|
|
line_echo "${dir}: BAD!\n" "${i}"
|
|
else
|
|
if [[ ( -f "${dst}") && ( -s "${dst}") && ( "${dst}" -nt "${src}") ]]
|
|
then
|
|
line_echo "${dir}: Skipping\r" "${i}"
|
|
else
|
|
line_echo "${dir}: Processing...\n" "${i}"
|
|
|
|
cmd="anytopnm \"${src}\" | pamscale -xyfit 1024 1024 | pnmtojpeg -quality=95 -optimize >\"${dst}\""
|
|
exec_cmd "${cmd}"
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
i=$(($i + 1))
|
|
done
|
|
|
|
line_echo ""
|
|
)
|