- Add SPEC file,
- Add bash_completion, - Migrate album_convert, album_merge & album_name_fix commands.
This commit is contained in:
@@ -1,80 +1,120 @@
|
||||
#!/bin/bash
|
||||
|
||||
. /usr/global/lib/music.bash
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# System Constants
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Album Name Fix
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ANF_VERSION="$Name: album_name_fix-1_0_0-1 $"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Print Version
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Includes
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function version_print()
|
||||
: "${RX3_LIB_DIR:=/usr/lib/rx3}"
|
||||
. "${RX3_LIB_DIR}/music_tools.bash"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Global Variables
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
declare -g VERSION="1.0.0"
|
||||
declare -g NAME="album_name_fix "
|
||||
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] [-a <album_dir>] [-p|--music_pattern <music_pattern>] [-s|--sed_substitute_pattern <sed_substitue_pattern>]"
|
||||
|
||||
declare -g ALBUM_DIR="."
|
||||
declare -g MUSIC_PATTERN="."
|
||||
declare -g SSP=""
|
||||
|
||||
declare -g MODE="DEFAULT"
|
||||
declare -g VERBOSE="FALSE"
|
||||
declare -g DRY_RUN="FALSE"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Version Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
anf_version_print()
|
||||
{
|
||||
echo ${ANF_VERSION} | sed -e 's/.*: //' -e 's/-/ /' -e 's/_/\./g' -e 's/\$$//'
|
||||
version_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Prin Help
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Help Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function help_print()
|
||||
anf_help_print()
|
||||
{
|
||||
echo "album_name_fix [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] [-a <album_dir>] [-p|--music_pattern <music_pattern>] [-s|--sed_substitute_pattern <sed_substitue_pattern>]"
|
||||
anf_version_print
|
||||
help_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Arg Parse
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function args_parse()
|
||||
anf_args_parse()
|
||||
{
|
||||
mode="default"
|
||||
verbose="false"
|
||||
album_dir="."
|
||||
music_pattern="."
|
||||
|
||||
tmp_args=$(getopt -o a:p:s:ThVv --long album_dir:,music_pattern:,sed_substitute_pattern:,test,help,version,verbose -n 'album_name_fix' -- "$@")
|
||||
tmp_args=$(getopt -o a:p:s:ThVv --long album_dir:,music_pattern:,sed_substitute_pattern:,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
|
||||
# Path options
|
||||
-a|--album_dir) shift; album_dir="$1"; shift;;
|
||||
-a|--album_dir) shift; ALBUM_DIR="$1"; shift;;
|
||||
|
||||
# Options
|
||||
-p|--music_pattern) shift; music_pattern="$1"; shift;;
|
||||
-s|--sed_substitute_pattern) shift; ssp="$1"; shift;;
|
||||
-p|--music_pattern) shift; MUSIC_PATTERN="$1"; shift;;
|
||||
-s|--sed_substitute_pattern) shift; SSP="$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"; anf_help_print; shift;;
|
||||
-V|--version) MODE="EXIT"; anf_version_print; shift;;
|
||||
|
||||
# Global options
|
||||
-v|--verbose) verbose="true"; shift;;
|
||||
-v|--verbose) VERBOSE="TRUE"; shift;;
|
||||
|
||||
#
|
||||
--) shift; break;;
|
||||
--) shift; break;;
|
||||
*) echo "args_parse internal error [$1] !"; exit 1;;
|
||||
esac
|
||||
done
|
||||
@@ -84,52 +124,42 @@ function args_parse()
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
shopt -s extglob
|
||||
|
||||
args_parse "$@"
|
||||
anf_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}] album_dir: [${album_dir}] music_pattern: [${music_pattern}] sed_substitue_pattern: [${ssp}]" 1>&2
|
||||
echo_error "${NAME}: Mode: [${MODE}] Verbose: [${VERBOSE}] Album_Dir: [${ALBUM_DIR}] Music_Pattern: [${MUSIC_PATTERN}] Sed_Substitue_Pattern: [${SSP}]"
|
||||
|
||||
cd "${album_dir}"
|
||||
cd "${ALBUM_DIR}"
|
||||
|
||||
IFS="\n"
|
||||
find . -maxdepth 1 -name '*.flac' -o -name '*.FLAC' -o -name '*.ogg' -o -name '*.OGG' -o -name '*.mp3' -o -name '*.MP3' -o -name '*.m4a' -o -name '*.M4A' -o -name '*.ape' -o -name '*.APE' -o -name '*.wav' -o -name '*.WAV' -o -name '*.mp4' -o -name '*.MP4' -o -name '*.mkv' -o -name '*.MKV' | sed -e 's/^.\///' | grep -e "${music_pattern}" | sort |
|
||||
find . -maxdepth 1 -name '*.flac' -o -name '*.FLAC' -o -name '*.ogg' -o -name '*.OGG' -o -name '*.mp3' -o -name '*.MP3' -o -name '*.m4a' -o -name '*.M4A' -o -name '*.ape' -o -name '*.APE' -o -name '*.wav' -o -name '*.WAV' -o -name '*.mp4' -o -name '*.MP4' -o -name '*.mkv' -o -name '*.MKV' | sed -e 's/^.\///' | grep -e "${MUSIC_PATTERN}" | sort |
|
||||
while read track_file
|
||||
do
|
||||
IFS=" "
|
||||
new_track_file="$(fix_file_name "${track_file}" "${ssp}")"
|
||||
new_track_file="$(mt_fix_file_name "${track_file}" "${SSP}")"
|
||||
|
||||
if [[ "${new_track_file}" != "${track_file}" ]]
|
||||
then
|
||||
echo "Moving '${track_file}' into '${new_track_file}'..."
|
||||
if [[ "${dry_run}" != "true" ]]
|
||||
then
|
||||
mv -- "${track_file}" "${new_track_file}"
|
||||
else
|
||||
if [[ "${verbose}" == "true" ]]
|
||||
then
|
||||
echo mv -- "${track_file}" "${new_track_file}"
|
||||
fi
|
||||
fi
|
||||
|
||||
cmd_exec mv -- "${track_file}" "${new_track_file}"
|
||||
else
|
||||
echo "Skiping '${track_file}'..."
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user