- Migrate album_retitle, music_folder_make, music_info & music_tag_cleaner,
- Add album_retitle, music_folder_make, music_info & music_tag_cleaner completion script.
This commit is contained in:
@@ -1,84 +1,117 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Music Folder Make
|
||||
#
|
||||
# Copyright (C) 2016-2026 Arnaud G. GIBERT
|
||||
# mailto:arnaud@rx3.net
|
||||
#
|
||||
# This is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Includes
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
. /usr/global/lib/music.bash
|
||||
: "${RX3_LIB_DIR:=/usr/lib/rx3}"
|
||||
. "${RX3_LIB_DIR}/music_tools.bash"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# System Constants
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Global Variables
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
MFM_NAME="music_folder_make"
|
||||
MFM_VERSION="$Name: music_mk_folder-1_0_0-1 $"
|
||||
declare -g VERSION="1.0.0"
|
||||
declare -g NAME="music_folder_make"
|
||||
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] [-p | --music_pattern <music_pattern>] [-r | --root_dir <music_root_dir>]"
|
||||
|
||||
declare -g ROOT_DIR="/opt/music/src"
|
||||
declare -g MUSIC_PATTERN="/"
|
||||
|
||||
declare -g MODE="DEFAULT"
|
||||
declare -g VERBOSE="FALSE"
|
||||
declare -g DRY_RUN="FALSE"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Print Version
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Version Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function version_print()
|
||||
mfm_version_print()
|
||||
{
|
||||
echo ${MFM_VERSION} | sed -e 's/.*: //' -e 's/-/ /' -e 's/_/\./g' -e 's/\$$//'
|
||||
version_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Prin Help
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Help Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function help_print()
|
||||
mfm_help_print()
|
||||
{
|
||||
echo "${MFM_NAME} [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] [-p | --music_pattern <music_pattern>] [-r | --root_dir <music_root_dir>]"
|
||||
mfm_version_print
|
||||
help_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Arg Parse
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function args_parse()
|
||||
mfm_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}" -- "$@")
|
||||
tmp_args=$(getopt -o r:p:ThVv --long root_dir:,music_pattern:,test,help,version,verbose -n "${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
|
||||
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;;
|
||||
-r|--root_dir) shift; ROOT_DIR="$1"; shift;;
|
||||
-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;;
|
||||
-T|--test) MODE="TEST"; shift;;
|
||||
-h|--help) MODE="EXIT"; mfm_help_print; shift;;
|
||||
-V|--version) MODE="EXIT"; mfm_version_print; shift;;
|
||||
|
||||
# Global options
|
||||
-v|--verbose) verbose="true"; shift;;
|
||||
-v|--verbose) VERBOSE="TRUE"; shift;;
|
||||
|
||||
#
|
||||
--) shift; break;;
|
||||
*) echo "args_parse internal error [$1] !"; exit 1;;
|
||||
# End of options
|
||||
--) shift; break;;
|
||||
*) echo "args_parse internal error [$1] !"; exit 1;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
@@ -87,72 +120,75 @@ function args_parse()
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
shopt -s extglob
|
||||
mfm_args_parse "$@"
|
||||
|
||||
args_parse "$@"
|
||||
|
||||
if [[ ${mode} == "exit" ]]
|
||||
|
||||
if [[ "${MODE}" == "EXIT" ]]
|
||||
then
|
||||
exit 0
|
||||
else
|
||||
if [[ ${mode} == "test" ]]
|
||||
if [[ "${MODE}" == "TEST" ]]
|
||||
then
|
||||
dry_run=true
|
||||
else
|
||||
dry_run=false
|
||||
DRY_RUN="TRUE"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
|
||||
echo "mode: [${mode}] verbose: [${verbose}] root_dir: [${root_dir}] music_pattern: [${music_pattern}]" 1>&2
|
||||
echo_error "${NAME}: Mode: [${MODE}] Verbose: [${VERBOSE}] Root_Dir: [${ROOT_DIR}] Music_Pattern: [${MUSIC_PATTERN}]"
|
||||
|
||||
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"
|
||||
if [[ ! -d "${ROOT_DIR}" ]]
|
||||
then
|
||||
echo_error "Root directory doesn't exist !"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
for file in ${dir}/cover-front ${dir}/slipcase-front ${dir}/box-front
|
||||
do
|
||||
i=1
|
||||
|
||||
while read -r dir
|
||||
do
|
||||
if [[ "$(basename "${dir}")" == "misc" ]]
|
||||
then
|
||||
echo_line "${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
|
||||
if [[ "${src}" == "" ]]
|
||||
then
|
||||
if [[ -f "${file}.${suffix}" ]]
|
||||
then
|
||||
src="${file}.${suffix}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
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}"
|
||||
if [[ "${src}" == "" ]]
|
||||
then
|
||||
echo_line "${dir}: BAD!\n" "${i}"
|
||||
else
|
||||
if [[ -f "${dst}" ]] && [[ -s "${dst}" ]] && [[ "${dst}" -nt "${src}" ]]
|
||||
then
|
||||
echo_line "${dir}: Skipping\r" "${i}"
|
||||
else
|
||||
echo_line "${dir}: Processing...\n" "${i}"
|
||||
sh_exec "anytopnm \"${src}\" | pamscale -xyfit 1024 1024 | pnmtojpeg -quality=95 -optimize >\"${dst}\""
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
cmd="anytopnm \"${src}\" | pamscale -xyfit 1024 1024 | pnmtojpeg -quality=95 -optimize >\"${dst}\""
|
||||
exec_cmd "${cmd}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
i=$(( i + 1 ))
|
||||
|
||||
i=$(($i + 1))
|
||||
done
|
||||
done < <(find "${ROOT_DIR}" -type d -links 2 | grep -e "${MUSIC_PATTERN}" | grep -v -e "/video" -e "/photo" | sort)
|
||||
|
||||
line_echo ""
|
||||
)
|
||||
echo_line ""
|
||||
|
||||
Reference in New Issue
Block a user