- 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

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*~
*.old

View File

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

View File

@@ -1,21 +1,177 @@
#!/bin/bash #!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
# Album Rename
#
# 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/>.
#
#-----------------------------------------------------------------------------------------------------------------------------------
if [[ "$1" == "-h" ]]
#-----------------------------------------------------------------------------------------------------------------------------------
# Includes
#-----------------------------------------------------------------------------------------------------------------------------------
: "${RX3_LIB_DIR:=/usr/lib/rx3}"
. "${RX3_LIB_DIR}/music_tools.bash"
#-----------------------------------------------------------------------------------------------------------------------------------
# Global Variables
#-----------------------------------------------------------------------------------------------------------------------------------
declare -g VERSION="1.0.0"
declare -g NAME="album_rename"
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] <source_dir> <target_dir> <album_name>"
declare -g SOURCE_DIR=""
declare -g TARGET_DIR=""
declare -g ALBUM_NAME=""
declare -g MODE="DEFAULT"
declare -g VERBOSE="FALSE"
declare -g DRY_RUN="FALSE"
#-----------------------------------------------------------------------------------------------------------------------------------
# Version Print
#-----------------------------------------------------------------------------------------------------------------------------------
ar_version_print()
{
version_print
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Help Print
#-----------------------------------------------------------------------------------------------------------------------------------
ar_help_print()
{
ar_version_print
help_print
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Arg Parse
#-----------------------------------------------------------------------------------------------------------------------------------
ar_args_parse()
{
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
case "$1" in
# Options
# Mode switches
-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;;
# End of options
--) shift; break;;
*) echo "args_parse internal error [$1] !"; exit 1;;
esac
done
if [[ "${MODE}" != "EXIT" ]]
then
if [[ "${#}" != "3" ]]
then
if [[ "${#}" -lt "3" ]]
then
echo_error "Not enough args!"
else
echo_error "Too many args!"
fi
MODE="EXIT"
ar_help_print
else
SOURCE_DIR="$1"
TARGET_DIR="$2"
ALBUM_NAME="$3"
fi
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Main
#-----------------------------------------------------------------------------------------------------------------------------------
ar_args_parse "$@"
if [[ "${MODE}" == "EXIT" ]]
then then
echo "album_rename [-h] | <source_dir> <target_dir> <album_name>" exit 0
exit else
if [[ "${MODE}" == "TEST" ]]
then
DRY_RUN="TRUE"
fi
fi fi
source_dir="$1"
target_dir="$2"
album_name="$3"
for file in ${source_dir}/*.flac
echo_error "${NAME}: Mode: [${MODE}] Verbose: [${VERBOSE}] Source_Dir: [${SOURCE_DIR}] Target_Dir: [${TARGET_DIR}] Album_Name: [${ALBUM_NAME}]"
if [[ ! -d "${TARGET_DIR}" ]]
then
echo_error "Target directory doesn't exist!"
exit -1
fi
for file in "${SOURCE_DIR}"/*@(.flac|.mp3)
do do
target_file="${target_dir}/$(basename $file)" target_file="${TARGET_DIR}/$(basename "${file}")"
cp "${file}" "${target_file}" cmd_exec cp "${file}" "${target_file}"
metaflac --remove-tag=ALBUM --set-tag="ALBUM=${album_name}" "${target_file}" mt_tag_delete "${target_file}" "ALBUM"
mt_tag_write "${target_file}" "ALBUM" "${ALBUM_NAME}"
i=$(($i+1))
done done

View File

@@ -1,146 +1,183 @@
#!/bin/bash #!/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 # 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" declare -g VERSION="1.0.0"
AR_VERSION="$Name: album_renum-1_0_0-1 $" 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 # Arg Parse
#----------------------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------------------
function args_parse() ar_args_parse()
{ {
mode="default" tmp_args=$(getopt -o f:d:ThVv --long first_number:,number_of_digit:,test,help,version,verbose -n "${NAME}" -- "$@")
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}" -- "$@")
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! # Note the quotes around `$TEMP': they are essential!
eval set -- "${tmp_args}" eval set -- "${tmp_args}"
while true ; do while true
do
case "$1" in case "$1" in
# Options # Options
-f|--first_number) shift; first_number="$1"; shift;; -f|--first_number) shift; FIRST_NUMBER="$1"; shift;;
-d|--number_of_digit) shift; number_of_digit="$1"; shift;; -d|--number_of_digit) shift; NUMBER_OF_DIGIT="$1"; shift;;
# Mode switches # Mode switches
-T|--test) mode="test"; shift;; -T|--test) MODE="TEST"; shift;;
-h|--help) mode="exit"; help_print; shift;; -h|--help) MODE="EXIT"; ar_help_print; shift;;
-V|--version) mode="exit"; version_print; shift;; -V|--version) MODE="EXIT"; ar_version_print; shift;;
# Global options # Global options
-v|--verbose) verbose="true"; shift;; -v|--verbose) VERBOSE="TRUE"; shift;;
# # End of options
--) shift; break;; --) shift; break;;
*) echo "args_parse internal error [$1] !"; exit 1;; *) echo "args_parse internal error [$1] !"; exit 1;;
esac esac
done done
if [[ "${#}" != "2" ]] if [[ "${MODE}" != "EXIT" ]]
then then
if [[ "${#}" -lt "2" ]] if [[ "${#}" != "2" ]]
then then
echo "Not enough args!" if [[ "${#}" -lt "2" ]]
else then
echo "Too many args!" echo_error "Not enough args!"
fi else
echo_error "Too many args!"
fi
mode="exit" MODE="EXIT"
help_print ar_help_print
else else
source_dir="$1" SOURCE_DIR="$1"
target_dir="$2" TARGET_DIR="$2"
fi
fi fi
} }
#-----------------------------------------------------------------------------------------------------------------------------------
# Main # Main
#----------------------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------------------
shopt -s extglob ar_args_parse "$@"
args_parse "$@"
if [[ ${mode} == "exit" ]]
if [[ "${MODE}" == "EXIT" ]]
then then
exit 0 exit 0
else else
if [[ ${mode} == "test" ]] if [[ "${MODE}" == "TEST" ]]
then then
dry_run=true DRY_RUN="TRUE"
else
dry_run=flase
fi fi
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 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) cmd_exec cp "${file}" "${target_file}"
target_file="${target_dir}/$(echo $(basename ${file}) | sed -e "s/^[0-9]*-/$j-/")";
cmd="cp \"${file}\" \"${target_file}\"" mt_tag_delete "${target_file}" "TRACKNUMBER"
exec_cmd "${cmd}" mt_tag_delete "${target_file}" "DISCNUMBER"
mt_tag_delete "${target_file}" "DISCTOTAL"
mt_tag_write "${target_file}" "TRACKNUMBER" "${j}"
tag_delete "${target_file}" "TRACKNUMBER" i=$((i+1))
tag_delete "${target_file}" "DISCNUMBER"
tag_delete "${target_file}" "DISCTOTAL"
tag_write "${target_file}" "TRACKNUMBER" "$j"
i=$(($i+1))
done done

View File

@@ -25,25 +25,67 @@
#-----------------------------------------------------------------------------------------------------------------------------------
# Album Convert Completion
#-----------------------------------------------------------------------------------------------------------------------------------
_album_convert_completion() _album_convert_completion()
{ {
local cur prev opts local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=() local prev="${COMP_WORDS[COMP_CWORD-1]}"
cur="${COMP_WORDS[COMP_CWORD]}" local opts="-h --help -V --version -T --test -v --verbose -r --resample -d --downsampled_tag"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-h --help -V --version -T --test -v --verbose -r --resample -d --downsampled_tag"
if [[ ${cur} == -* ]] ; then local pos=0
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) local i
COMPREPLY=()
# Complete options if current word starts with '-'
if [[ "${cur}" == -* ]]
then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0 return 0
fi fi
# Handle directory completion for source_dir and target_dir # Count non-option positional arguments already provided
if [[ ${COMP_CWORD} -eq 1 ]] || [[ ${prev} != -* && ${COMP_CWORD} -eq 2 ]]; then for (( i=1; i<COMP_CWORD; i++ ))
COMPREPLY=( $(compgen -d -- "${cur}") ) do
fi case "${COMP_WORDS[i]}" in
-T|--test|-h|--help|-V|--version|-v|--verbose|-r|--resample|-d|--downsampled_tag)
;;
--)
;;
-*)
;;
*)
pos=$(( pos + 1 ))
;;
esac
done
# Complete positional arguments
case "${pos}" in
0)
# source_dir: directory completion
COMPREPLY=( $(compgen -d -- "${cur}") )
;;
1)
# target_dir: directory completion
COMPREPLY=( $(compgen -d -- "${cur}") )
;;
*)
COMPREPLY=()
;;
esac
return 0
} }
complete -F _album_convert_completion album_convert complete -o filenames -F _album_convert_completion album_convert

View File

@@ -25,6 +25,10 @@
#-----------------------------------------------------------------------------------------------------------------------------------
# Album Merge Completion
#-----------------------------------------------------------------------------------------------------------------------------------
_album_merge_completion() _album_merge_completion()
{ {
local cur prev opts local cur prev opts

View File

@@ -25,7 +25,11 @@
_album_metadata_load() #-----------------------------------------------------------------------------------------------------------------------------------
# Album MetaData Load Completion
#-----------------------------------------------------------------------------------------------------------------------------------
_album_metadata_load_completion()
{ {
local cur prev words cword local cur prev words cword
_init_completion || return _init_completion || return
@@ -73,4 +77,4 @@ _album_metadata_load()
complete -F _album_metadata_load album_metadata_load complete -F _album_metadata_load_completion album_metadata_load

View File

@@ -0,0 +1,48 @@
#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
# Album MetaData Save Bash Completion
#
# 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/>.
#
#-----------------------------------------------------------------------------------------------------------------------------------
# -*- mode: shell; sh-basic-offset: 4; indent-tabs-mode: nil; -*-
#-----------------------------------------------------------------------------------------------------------------------------------
# Album MetaData Save Completion
#-----------------------------------------------------------------------------------------------------------------------------------
_album_metadata_save_completion()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-h --help -V --version -T --test -v --verbose -f --factoring -s --standardising"
if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -F _album_metadata_save_completion album_metadata_save

View File

@@ -25,6 +25,10 @@
#-----------------------------------------------------------------------------------------------------------------------------------
# Album Name Fix Completion
#-----------------------------------------------------------------------------------------------------------------------------------
_album_name_fix_completion() { _album_name_fix_completion() {
local cur prev opts local cur prev opts
COMPREPLY=() COMPREPLY=()

View File

@@ -0,0 +1,96 @@
#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
# Album Rename Bash Completion
#
# 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/>.
#
#-----------------------------------------------------------------------------------------------------------------------------------
# -*- mode: shell; sh-basic-offset: 4; indent-tabs-mode: nil; -*-
#-----------------------------------------------------------------------------------------------------------------------------------
# Album Rename Completion
#-----------------------------------------------------------------------------------------------------------------------------------
_album_renam_completion()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
local opts="-T --test -h --help -V --version -v --verbose"
local pos=0
local i
COMPREPLY=()
# Count non-option positional arguments already provided
for (( i=1; i<COMP_CWORD; i++ ))
do
case "${COMP_WORDS[i]}" in
-T|--test|-h|--help|-V|--version|-v|--verbose)
;;
--)
;;
-*)
;;
*)
pos=$(( pos + 1 ))
;;
esac
done
# Complete options if current word starts with '-'
if [[ "${cur}" == -* ]]
then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
# Complete positional arguments
case "${pos}" in
0)
# source_dir: directory completion
COMPREPLY=( $(compgen -d -- "${cur}") )
;;
1)
# target_dir: directory completion
COMPREPLY=( $(compgen -d -- "${cur}") )
;;
2)
# album_name: free text, no completion
COMPREPLY=()
;;
*)
COMPREPLY=()
;;
esac
return 0
}
complete -o filenames -F _album_rename_completion album_rename

View File

@@ -0,0 +1,107 @@
#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
# Album Renum Bash Completion
#
# 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/>.
#
#-----------------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------
# Album Renum Completion
#-----------------------------------------------------------------------------------------------------------------------------------
_album_renum_completion()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
local opts="-h --help -V --version -T --test -v --verbose -f --first_number -d --number_of_digit"
local pos=0
local i
COMPREPLY=()
# Handle argument of options that take a value
case "${prev}" in
-f|--first_number)
COMPREPLY=()
return 0
;;
-d|--number_of_digit)
COMPREPLY=()
return 0
;;
esac
# Complete options if current word starts with '-'
if [[ "${cur}" == -* ]]
then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
# Count non-option positional arguments already provided
for (( i=1; i<COMP_CWORD; i++ ))
do
case "${COMP_WORDS[i]}" in
-f|--first_number|-d|--number_of_digit)
i=$(( i + 1 ))
;;
-T|--test|-h|--help|-V|--version|-v|--verbose)
;;
--)
;;
-*)
;;
*)
pos=$(( pos + 1 ))
;;
esac
done
# Complete positional arguments
case "${pos}" in
0)
# source_dir: directory completion
COMPREPLY=( $(compgen -d -- "${cur}") )
;;
1)
# target_dir: directory completion
COMPREPLY=( $(compgen -d -- "${cur}") )
;;
*)
COMPREPLY=()
;;
esac
return 0
}
complete -o filenames -F _album_renum_completion album_renum

View File

@@ -192,11 +192,11 @@ mt_fix_file_name()
mt_tagtab_alloc() mt_tagtab_alloc()
{ {
unset tagtab unset TAGTAB
declare -Ag tagtab declare -Ag TAGTAB
declare -g taglist declare -g TAGLIST
taglist=":" TAGLIST=":"
} }
@@ -212,7 +212,7 @@ mt_tag_exist()
local tag="$1" local tag="$1"
echo ${taglist} | grep -e ":${tag}:" echo ${TAGLIST} | grep -e ":${tag}:"
} }
@@ -247,17 +247,17 @@ mt_tagtab_read()
if [[ "$(mt_tag_exist ${tag})" == "" ]] if [[ "$(mt_tag_exist ${tag})" == "" ]]
then then
taglist="${taglist}${tag}:" TAGLIST="${TAGLIST}${tag}:"
fi fi
if [[ ( "${mode}" != "FACTORING" ) || ( "${tag}" =~ ^${MT_NODEF_TAG_COND}$ ) || ( "${tagtab["0,${tag}"]}" != "" ) ]] if [[ ( "${mode}" != "FACTORING" ) || ( "${tag}" =~ ^${MT_NODEF_TAG_COND}$ ) || ( -v "TAGTAB[\"0,${tag}\"]}" ) ]]
then then
if [[ "${tagtab["0,${tag}"]}" != "${value}" ]] if [[ ( ! -v "TAGTAB[\"0,${tag}\"]}" ) || ( "${TAGTAB["0,${tag}"]}" != "${value}") ]]
then then
tagtab["${track_id},${tag}"]="$value" TAGTAB["${track_id},${tag}"]="$value"
fi fi
else else
tagtab["0,${tag}"]="${value}" TAGTAB["0,${tag}"]="${value}"
fi fi
fi fi
done < ${tmp_file} done < ${tmp_file}
@@ -278,17 +278,17 @@ mt_tagtab_read()
if [[ "$(mt_tag_exist ${tag})" == "" ]] if [[ "$(mt_tag_exist ${tag})" == "" ]]
then then
taglist="${taglist}${tag}:" TAGLIST="${TAGLIST}${tag}:"
fi fi
if [[ ( "${mode}" != "FACTORING" ) || ( "${tag}" =~ ^${MT_NODEF_TAG_COND}$ ) || ( "${tagtab["0,${tag}"]}" != "" ) ]] if [[ ( "${mode}" != "FACTORING" ) || ( "${tag}" =~ ^${MT_NODEF_TAG_COND}$ ) || ( "${TAGTAB["0,${tag}"]}" != "" ) ]]
then then
if [[ "${tagtab["0,${tag}"]}" != "${value}" ]] if [[ "${TAGTAB["0,${tag}"]}" != "${value}" ]]
then then
tagtab["${track_id},${tag}"]="$value" TAGTAB["${track_id},${tag}"]="$value"
fi fi
else else
tagtab["0,${tag}"]="${value}" TAGTAB["0,${tag}"]="${value}"
fi fi
fi fi
done < ${tmp_file} done < ${tmp_file}
@@ -299,9 +299,9 @@ mt_tagtab_read()
;; ;;
esac esac
if [[ ${taglist} == ":" ]] if [[ ${TAGLIST} == ":" ]]
then then
taglist="" TAGLIST=""
fi fi
\rm -f ${tmp_file} \rm -f ${tmp_file}
@@ -332,7 +332,7 @@ mt_tagtab_load()
case "${tag}" case "${tag}"
in in
@${MT_FLAC_TAG_COND}) @${MT_FLAC_TAG_COND})
tagtab["${track_id},${tag}"]="$value" TAGTAB["${track_id},${tag}"]="$value"
;; ;;
DEF) DEF)
@@ -360,6 +360,26 @@ mt_tagtab_load()
#-----------------------------------------------------------------------------------------------------------------------------------
# TagTab Full Dump
#-----------------------------------------------------------------------------------------------------------------------------------
mt_tagtab_full_dump()
{
echo "--- TAGTAB Dump ---"
for key in "${!TAGTAB[@]}"
do
printf "TAGTAB[%q]=\"%s\"\n" "$key" "${TAGTAB[$key]}"
done
echo "--- End Dump ---"
}
#----------------------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------------------
# TagTab Dump # TagTab Dump
#----------------------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------------------
@@ -376,7 +396,7 @@ mt_tagtab_dump()
;; ;;
"PASSTHROUGH") "PASSTHROUGH")
dump_list="${taglist//:/ }" dump_list="${TAGLIST//:/ }"
;; ;;
"CUSTOM") "CUSTOM")
@@ -386,12 +406,11 @@ mt_tagtab_dump()
esac esac
for tag in ${dump_list} for tag in ${dump_list}
do do
if [[ "${tagtab["${track_id},${tag}"]}" != "" ]] if [[ -v "TAGTAB[\"${track_id},${tag}\"]" ]]
then then
echo "${tag}=${tagtab["${track_id},${tag}"]}" echo "${tag}=${TAGTAB["${track_id},${tag}"]}"
fi fi
done done
} }
@@ -411,11 +430,11 @@ mt_tag_get()
local tag=$3 local tag=$3
return="${tagtab["${track_id},${tag}"]}" return="${TAGTAB["${track_id},${tag}"]}"
if [[ "${return}" == "" ]] if [[ "${return}" == "" ]]
then then
return="${tagtab["0,${tag}"]}" return="${TAGTAB["0,${tag}"]}"
if [[ "${return}" == "" ]] && [[ "${tag}" == "TRACKNUMBER" ]] if [[ "${return}" == "" ]] && [[ "${tag}" == "TRACKNUMBER" ]]
then then
@@ -446,16 +465,16 @@ mt_tag_save()
for tag in ${MT_FLAC_TAG_LIST} for tag in ${MT_FLAC_TAG_LIST}
do do
# if [[ "${tagtab["${track_id},${tag}"]}" == "" ]] # if [[ "${TAGTAB["${track_id},${tag}"]}" == "" ]]
# then # then
# value="${tagtab["0,${tag}"]}" # value="${TAGTAB["0,${tag}"]}"
# #
# if [[ "${value}" == "" ]] && [[ "${tag}" == "TRACKNUMBER" ]] # if [[ "${value}" == "" ]] && [[ "${tag}" == "TRACKNUMBER" ]]
# then # then
# value="$(printf "%02d" ${track_id})" # value="$(printf "%02d" ${track_id})"
# fi # fi
# else # else
# value="${tagtab["${track_id},${tag}"]}" # value="${TAGTAB["${track_id},${tag}"]}"
# fi # fi
mt_tag_get value "${track_id}" "${tag}" mt_tag_get value "${track_id}" "${tag}"