- Migrate album_metadata_save, album_rename & album_renum,

- Add album_metadata_save, album_rename & album_renum completion scripts.
This commit is contained in:
2026-04-12 17:40:53 +02:00
parent 6f09c6c806
commit c314a9ec76
12 changed files with 780 additions and 232 deletions

View File

@@ -1,146 +1,183 @@
#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
# Album Renum
#
# 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
#-----------------------------------------------------------------------------------------------------------------------------------
AR_NAME="album_renum"
AR_VERSION="$Name: album_renum-1_0_0-1 $"
declare -g VERSION="1.0.0"
declare -g NAME="album_renum"
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] [-f | --first_number <first_number>] [-d | --number_of_digit <number_of_digit>] <source_dir> <target_dir>"
declare -g SOURCE_DIR=""
declare -g TARGET_DIR=""
declare -g FIRST_NUMBER="1"
declare -g NUMBER_OF_DIGIT="2"
declare -g MODE="DEFAULT"
declare -g VERBOSE="FALSE"
declare -g DRY_RUN="FALSE"
# Print Version
#-----------------------------------------------------------------------------------------------------------------------------------
# Version Print
#-----------------------------------------------------------------------------------------------------------------------------------
function version_print()
ar_version_print()
{
echo ${AR_VERSION} | sed -e 's/.*: //' -e 's/-/ /' -e 's/_/\./g' -e 's/\$$//'
version_print
}
# Prin Help
#-----------------------------------------------------------------------------------------------------------------------------------
# Help Print
#-----------------------------------------------------------------------------------------------------------------------------------
function help_print()
ar_help_print()
{
echo "${AR_NAME} [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] [ -f | --first_number <first_number>] [ -d | --number_of_digit <number_of_digit>] <source_dir> <target_dir>"
ar_version_print
help_print
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Arg Parse
#-----------------------------------------------------------------------------------------------------------------------------------
function args_parse()
ar_args_parse()
{
mode="default"
verbose="false"
source_dir=""
target_dir=""
first_number="1"
number_of_digit="2"
tmp_args=$(getopt -o f:d:ThVv --long first_number:,number_of_digit:,test,help,version,verbose -n "${AR_NAME}" -- "$@")
tmp_args=$(getopt -o f:d:ThVv --long first_number:,number_of_digit:,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
# Options
-f|--first_number) shift; first_number="$1"; shift;;
-d|--number_of_digit) shift; number_of_digit="$1"; shift;;
-f|--first_number) shift; FIRST_NUMBER="$1"; shift;;
-d|--number_of_digit) shift; NUMBER_OF_DIGIT="$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"; ar_help_print; shift;;
-V|--version) MODE="EXIT"; ar_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
if [[ "${#}" != "2" ]]
if [[ "${MODE}" != "EXIT" ]]
then
if [[ "${#}" -lt "2" ]]
if [[ "${#}" != "2" ]]
then
echo "Not enough args!"
else
echo "Too many args!"
fi
if [[ "${#}" -lt "2" ]]
then
echo_error "Not enough args!"
else
echo_error "Too many args!"
fi
mode="exit"
help_print
else
source_dir="$1"
target_dir="$2"
MODE="EXIT"
ar_help_print
else
SOURCE_DIR="$1"
TARGET_DIR="$2"
fi
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Main
#-----------------------------------------------------------------------------------------------------------------------------------
shopt -s extglob
ar_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=flase
DRY_RUN="TRUE"
fi
fi
echo "mode: [${mode}] verbose: [${verbose}] source_dir: [${source_dir}] target_dir: [${target_dir}] first_number: [${first_number}] number_of_digit: [${number_of_digit}]" 1>&2
echo_error "${NAME}: Mode: [${MODE}] Verbose: [${VERBOSE}] Source_Dir: [${SOURCE_DIR}] Target_Dir: [${TARGET_DIR}] First_Number: [${FIRST_NUMBER}] Number_Of_Digit: [${NUMBER_OF_DIGIT}]"
i="${first_number}"
if [[ ! -d "${TARGET_DIR}" ]]
then
echo_error "Target directory doesn't exist !"
exit -1
fi
for file in "${source_dir}"/*@(.flac|.mp3)
i="${FIRST_NUMBER}"
for file in "${SOURCE_DIR}"/*@(.flac|.mp3)
do
j=$(printf "%0${NUMBER_OF_DIGIT}d" "${i}")
target_file="${TARGET_DIR}/$(basename "${file}" | sed -e "s/^[0-9]*-/$j-/")"
j=$(printf "%0${number_of_digit}d" $i)
target_file="${target_dir}/$(echo $(basename ${file}) | sed -e "s/^[0-9]*-/$j-/")";
cmd_exec cp "${file}" "${target_file}"
cmd="cp \"${file}\" \"${target_file}\""
exec_cmd "${cmd}"
mt_tag_delete "${target_file}" "TRACKNUMBER"
mt_tag_delete "${target_file}" "DISCNUMBER"
mt_tag_delete "${target_file}" "DISCTOTAL"
mt_tag_write "${target_file}" "TRACKNUMBER" "${j}"
tag_delete "${target_file}" "TRACKNUMBER"
tag_delete "${target_file}" "DISCNUMBER"
tag_delete "${target_file}" "DISCTOTAL"
tag_write "${target_file}" "TRACKNUMBER" "$j"
i=$(($i+1))
i=$((i+1))
done