- 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,104 +1,135 @@
#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
# Album MetaData Save
#
# 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
#-----------------------------------------------------------------------------------------------------------------------------------
AMS_NAME="album_metadata_save"
AMS_VERSION="$Name: album_metadata_save-1_0_0-1 $"
declare -g VERSION="1.0.0"
declare -g NAME="album_metadata_save"
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] [-f | --factoring] [-s | --standardising] <Source_Dir> <MetaData_File>"
declare -g FACTORING="FALSE"
declare -g STANDARDISING="FALSE"
declare -g SOURCE_DIR=""
declare -g METADATA_FILE=""
declare -g MODE="DEFAULT"
declare -g VERBOSE="FALSE"
declare -g DRY_RUN="FALSE"
# Print Version
#-----------------------------------------------------------------------------------------------------------------------------------
# Version Print
#-----------------------------------------------------------------------------------------------------------------------------------
function version_print()
ams_version_print()
{
echo ${AMS_VERSION} | sed -e 's/.*: //' -e 's/-/ /' -e 's/_/\./g' -e 's/\$$//'
version_print
}
# Prin Help
#-----------------------------------------------------------------------------------------------------------------------------------
# Help Print
#-----------------------------------------------------------------------------------------------------------------------------------
function help_print()
ams_help_print()
{
echo "${AMS_NAME} [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] [-f | --factoring] [-s | standardising] <source_dir> <metadata_file>"
ams_version_print
help_print
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Arg Parse
#-----------------------------------------------------------------------------------------------------------------------------------
function args_parse()
ams_args_parse()
{
mode="default"
verbose="false"
factoring="false"
standardising="false"
source_dir=""
metadata_file=""
tmp_args=$(getopt -o ThVvfs --long test,help,version,verbose,factoring,standardising -n "${NAME}" -- "$@")
tmp_args=$(getopt -o ThVvfs --long test,help,version,verbose,factoring,standardising -n "${AMS_NAME}" -- "$@")
if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi
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
# Options
while true
do
case "$1" in
# Mode switches
-T|--test) MODE="TEST"; shift;;
-h|--help) MODE="EXIT"; ams_help_print; shift;;
-V|--version) MODE="EXIT"; ams_version_print; 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;;
-f|--factoring) FACTORING="TRUE"; shift;;
-s|--standardising) STANDARDISING="TRUE"; shift;;
# Global options
-v|--verbose) verbose="true"; shift;;
-f|--factoring) factoring="true"; shift;;
-s|--standardising) standardising="true"; shift;;
#
--) shift; break;;
*) echo "args_parse internal error [$1] !"; exit 1;;
esac
--) shift; break;;
*) echo_error "args_parse internal error [$1]!"; exit 1;;
esac
done
if [[ "${mode}" != "exit" ]]
if [[ "${MODE}" != "EXIT" ]]
then
if [[ "${#}" != "2" ]]
then
if [[ "${#}" -lt "2" ]]
then
echo "Not enough args!"
else
echo "Too many args!"
fi
if [[ "${#}" != "2" ]]
then
if [[ "${#}" -lt "2" ]]
then
echo_error "Not enough args!"
else
echo_error "Too many args!"
fi
mode="exit"
help_print
else
source_dir="$1"
metadata_file="$2"
fi
MODE="EXIT"
ams_help_print
else
SOURCE_DIR="$1"
METADATA_FILE="$2"
fi
fi
}
@@ -106,88 +137,86 @@ function args_parse()
#-----------------------------------------------------------------------------------------------------------------------------------
# Main
#-----------------------------------------------------------------------------------------------------------------------------------
args_parse "$@"
ams_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_error "${NAME}: Mode: [${MODE}] Verbose: [${VERBOSE}] Factoring: [${FACTORING}] Standardising: [${STANDARDISING}] Source_Dir: [${SOURCE_DIR}] MetaData_File: [${METADATA_FILE}]"
echo "mode: [${mode}] verbose: [${verbose}] factoring: [${factoring}] standardising: [${standardising}] source_dir: [${source_dir}] metadata_file: [${metadata_file}]" 1>&2
find "${SOURCE_DIR}" -maxdepth 1 -name '*.flac' -o -name '*.mp3' | sort |
(
nb_track=0
declare -g nb_track
mt_tagtab_alloc
while read track_file
do
nb_track=$((nb_track + 1))
if [[ "${FACTORING}" == "TRUE" ]]
then
mt_tagtab_read "${nb_track}" "${track_file}" "FACTORING"
else
mt_tagtab_read "${nb_track}" "${track_file}" "NOFACTORING"
fi
done
track_id=0
find "${source_dir}" -maxdepth 1 -name '*.flac' -o -name '*.mp3' | sort | (
while [[ "${track_id}" -le "${nb_track}" ]]
do
if [[ "${track_id}" == 0 ]]
then
echo "DEF"
else
echo "SOT"
fi
tagtab_alloc
if [[ "${STANDARDISING}" == "TRUE" ]]
then
mt_tagtab_dump "${track_id}" "STANDARD"
else
mt_tagtab_dump "${track_id}" "PASSTHROUGH"
fi
while read track_file
do
nb_track=$((${nb_track} + 1))
echo "EOT"
if [[ "${factoring}" == "true" ]]
track_id=$((track_id + 1))
done
echo "EOA"
echo 1>&2 "NB Track dumped: [${nb_track}]"
) |
(
if [[ "${DRY_RUN}" == "TRUE" ]]
then
tagtab_read "${nb_track}" "${track_file}" "FACTORING"
else
tagtab_read "${nb_track}" "${track_file}" "NOFACTORING"
fi
done
track_id=0
while [[ "${track_id}" -le "${nb_track}" ]]
do
if [[ "${track_id}" == 0 ]]
then
echo "DEF"
else
echo "SOT"
fi
if [[ "${standardising}" == "true" ]]
cat
else
tee "${METADATA_FILE}"
fi
) |
(
if [[ "${VERBOSE}" == "TRUE" ]]
then
tagtab_dump "${track_id}" "STANDARD"
else
tagtab_dump "${track_id}" "PASSTHROUGH"
fi
echo "EOT"
track_id=$((${track_id} + 1))
done
echo "EOA"
echo 1>&2 "NB Track dumped: [${nb_track}]"
#)
#) >"${metadata_file}"
) | (
if [[ "${dry_run}" == "true" ]]
then
cat
else
tee "${metadata_file}"
fi
) | (
if [[ "${verbose}" == "true" ]]
then
cat
else
cat >/dev/null
fi
)
cat
else
cat >/dev/null
fi
)