- Add SPEC file,

- Add bash_completion,
- Migrate album_convert, album_merge & album_name_fix commands.
This commit is contained in:
2026-04-11 17:15:06 +02:00
parent 5b141b45cf
commit 7abfcab917
8 changed files with 553 additions and 763 deletions

View File

@@ -1,79 +1,113 @@
#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
# Album Convert
#
# 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
#-----------------------------------------------------------------------------------------------------------------------------------
AM_NAME="album_merge"
AM_VERSION="$Name: album_merge-1_0_0-1 $"
declare -g VERSION="1.0.0"
declare -g NAME="album_merge"
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] <source_dir> <target_dir> <album_name> <prefix>"
declare -g SOURCE_DIR=""
declare -g TARGET_DIR=""
declare -g ALBUM_NAME=""
declare -g PREFIX=""
declare -g MODE="DEFAULT"
declare -g VERBOSE="FALSE"
declare -g DRY_RUN="FALSE"
# Print Version
#-----------------------------------------------------------------------------------------------------------------------------------
# Version Print
#-----------------------------------------------------------------------------------------------------------------------------------
function version_print()
am_version_print()
{
echo ${AM_VERSION} | sed -e 's/.*: //' -e 's/-/ /' -e 's/_/\./g' -e 's/\$$//'
version_print
}
# Prin Help
#-----------------------------------------------------------------------------------------------------------------------------------
# Help Print
#-----------------------------------------------------------------------------------------------------------------------------------
function help_print()
am_help_print()
{
echo "${AM_NAME} [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] <source_dir> <target_dir> <album_name> <prefix>"
am_version_print
help_print
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Arg Parse
#-----------------------------------------------------------------------------------------------------------------------------------
function args_parse()
am_args_parse()
{
mode="default"
verbose="false"
source_dir=""
target_dir=""
album_name=""
prefix=""
tmp_args=$(getopt -o ThVv --long test,help,version,verbose -n "${AM_NAME}" -- "$@")
tmp_args=$(getopt -o ThVv --long 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
# 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"; am_help_print; shift;;
-V|--version) MODE="EXIT"; am_version_print; shift;;
# Global options
-v|--verbose) verbose="true"; shift;;
-v|--verbose) VERBOSE="TRUE"; shift;;
#
--) shift; break;;
@@ -81,24 +115,24 @@ function args_parse()
esac
done
if [[ "${mode}" != "exit" ]]
if [[ "${MODE}" != "EXIT" ]]
then
if [[ "${#}" != "4" ]]
then
if [[ "${#}" -lt "4" ]]
then
echo "Not enough args!"
echo_error "Not enough args!"
else
echo "Too many args!"
echo_error "Too many args!"
fi
mode="exit"
help_print
MODE="EXIT"
am_help_print
else
source_dir="$1"
target_dir="$2"
album_name="$3"
prefix="$4"
SOURCE_DIR="$1"
TARGET_DIR="$2"
ALBUM_NAME="$3"
PREFIX="$4"
fi
fi
}
@@ -107,39 +141,37 @@ function args_parse()
#-----------------------------------------------------------------------------------------------------------------------------------
# Main
#-----------------------------------------------------------------------------------------------------------------------------------
shopt -s extglob
am_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}] source_dir: [${source_dir}] target_dir: [${target_dir}] album_name: [${album_name}] prefix: [${prefix}]" 1>&2
echo_error "${NAME}: Mode: [${MODE}] Verbose: [${VERBOSE}] Source_Dir: [${SOURCE_DIR}] Target_Dir: [${TARGET_DIR}] Album_Name: [${ALBUM_NAME}] Prefix: [${PREFIX}]"
for file in "${source_dir}"/*@(.flac|.mp3)
for file in "${SOURCE_DIR}"/*@(.flac|.mp3)
do
id="$(basename $file | sed -e "s/-.*//")"
target_file="${target_dir}/${prefix}$(basename $file)"
target_file="${TARGET_DIR}/${PREFIX}$(basename $file)"
cmd="cp \"${file}\" \"${target_file}\""
exec_cmd "${cmd}"
cmd_exec cp "${file}" "${target_file}"
tag_delete "${target_file}" "ALBUM"
tag_write "${target_file}" "ALBUM" "${album_name}"
tag_delete "${target_file}" "TRACKNUMBER"
tag_write "${target_file}" "TRACKNUMBER" "${prefix}${id}"
mt_tag_delete "${target_file}" "ALBUM"
mt_tag_write "${target_file}" "ALBUM" "${ALBUM_NAME}"
mt_tag_delete "${target_file}" "TRACKNUMBER"
mt_tag_write "${target_file}" "TRACKNUMBER" "${PREFIX}${id}"
done