- 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,48 +1,194 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Album Retitle
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function fix_file_name
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# 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_retitle"
|
||||
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] <source_dir> <target_dir> <title_file>"
|
||||
|
||||
declare -g SOURCE_DIR=""
|
||||
declare -g TARGET_DIR=""
|
||||
declare -g TITLE_FILE=""
|
||||
|
||||
declare -g MODE="DEFAULT"
|
||||
declare -g VERBOSE="FALSE"
|
||||
declare -g DRY_RUN="FALSE"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Version Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ar_version_print()
|
||||
{
|
||||
input="$1"
|
||||
|
||||
# echo ${input} | sed -e 's/ /_/g' -e "s/'/_/g" -e 's/_(/-/g' -e 's/)//g' -e 's/_-_/-/g' -e 's/\//_/g' | tr '[:upper:]' '[:lower:]'
|
||||
echo ${input} | sed -e 's/\(^[0-9]*\)./\1-/' -e 's/[ ,!/?]/_/g' -e 's/\[/-/g' -e 's/\]//g' -e "s/'/_/g" -e 's/(/-/g' -e 's/)//g' -e 's/__/_/g' -e 's/_\././' -e 's/_-/-/g' -e 's/--/-/g' -e 's/-_/-/g' -e 's/é/e/g' -e 's/è/e/g' -e 's/ê/e/g' -e 's/ë/e/g' -e 's/à/a/g' -e 's/[+&]/and/' -e 's/^-//' -e 's/"/_inch/' | tr '[:upper:]' '[:lower:]'
|
||||
version_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
shopt -s extglob
|
||||
|
||||
if [[ "$1" == "-h" ]]
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# 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"
|
||||
TITLE_FILE="$3"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ar_args_parse "$@"
|
||||
|
||||
|
||||
|
||||
if [[ "${MODE}" == "EXIT" ]]
|
||||
then
|
||||
echo "album_retitle [-h] | <source_dir> <target_dir> <title_file>"
|
||||
exit
|
||||
exit 0
|
||||
else
|
||||
if [[ "${MODE}" == "TEST" ]]
|
||||
then
|
||||
DRY_RUN="TRUE"
|
||||
fi
|
||||
fi
|
||||
|
||||
source_dir="$1"
|
||||
target_dir="$2"
|
||||
title_file="$3"
|
||||
|
||||
|
||||
echo_error "${NAME}: Mode: [${MODE}] Verbose: [${VERBOSE}] Source_Dir: [${SOURCE_DIR}] Target_Dir: [${TARGET_DIR}] Title_File: [${TITLE_FILE}]"
|
||||
|
||||
if [[ ! -d "${TARGET_DIR}" ]]
|
||||
then
|
||||
echo_error "Target directory doesn't exist !"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if [[ ! -f "${TITLE_FILE}" ]]
|
||||
then
|
||||
echo_error "Title file doesn't exist !"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
i=1
|
||||
|
||||
while read title
|
||||
while read -r title
|
||||
do
|
||||
file=(${source_dir}/$(printf %02d $i)-*.@(flac|mp3))
|
||||
suffix=${file##*.}
|
||||
target_file="${target_dir}/$( fix_file_name $( fix_file_name $( fix_file_name $(printf "%02d" $i)-"${title}.${file##*.}")))"
|
||||
j=$(printf "%02d" "${i}")
|
||||
file=("${SOURCE_DIR}"/${j}-*.@(.flac|.mp3))
|
||||
suffix="${file##*.}"
|
||||
target_file="${TARGET_DIR}/$(mt_fix_file_name "${j}-${title}.${suffix}")"
|
||||
|
||||
echo "${target_file}: '"${title}"'"
|
||||
cp "${file}" "${target_file}"
|
||||
echo_error "${NAME}: [${file}] -> [${target_file}]"
|
||||
|
||||
case "${suffix}"
|
||||
in
|
||||
flac)
|
||||
metaflac --remove-tag=TRACKNUMBER --set-tag=TRACKNUMBER=$i --remove-tag=TITLE --set-tag=TITLE="${title}" "${target_file}"
|
||||
;;
|
||||
cmd_exec cp "${file}" "${target_file}"
|
||||
|
||||
mp3)
|
||||
mid3v2 -T $i -t "${title}" "${target_file}"
|
||||
;;
|
||||
esac
|
||||
mt_tag_delete "${target_file}" "TRACKNUMBER"
|
||||
mt_tag_delete "${target_file}" "TITLE"
|
||||
mt_tag_write "${target_file}" "TRACKNUMBER" "${j}"
|
||||
mt_tag_write "${target_file}" "TITLE" "${title}"
|
||||
|
||||
i=$(($i + 1))
|
||||
done < ${title_file}
|
||||
i=$(( i + 1 ))
|
||||
done < "${TITLE_FILE}"
|
||||
|
||||
Reference in New Issue
Block a user