146 lines
3.4 KiB
Bash
Executable File
146 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Includes
|
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
. /usr/global/lib/music.bash
|
|
|
|
|
|
|
|
|
|
|
|
# System Constants
|
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
AM_NAME="album_merge"
|
|
AM_VERSION="$Name: album_merge-1_0_0-1 $"
|
|
|
|
|
|
|
|
|
|
|
|
# Print Version
|
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
function version_print()
|
|
{
|
|
echo ${AM_VERSION} | sed -e 's/.*: //' -e 's/-/ /' -e 's/_/\./g' -e 's/\$$//'
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Prin Help
|
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
function help_print()
|
|
{
|
|
echo "${AM_NAME} [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] <source_dir> <target_dir> <album_name> <prefix>"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Arg Parse
|
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
function 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}" -- "$@")
|
|
|
|
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"; help_print; shift;;
|
|
-V|--version) mode="exit"; version_print; shift;;
|
|
|
|
# Global options
|
|
-v|--verbose) verbose="true"; shift;;
|
|
|
|
#
|
|
--) shift; break;;
|
|
*) echo "args_parse internal error [$1] !"; exit 1;;
|
|
esac
|
|
done
|
|
|
|
if [[ "${mode}" != "exit" ]]
|
|
then
|
|
if [[ "${#}" != "4" ]]
|
|
then
|
|
if [[ "${#}" -lt "4" ]]
|
|
then
|
|
echo "Not enough args!"
|
|
else
|
|
echo "Too many args!"
|
|
fi
|
|
|
|
mode="exit"
|
|
help_print
|
|
else
|
|
source_dir="$1"
|
|
target_dir="$2"
|
|
album_name="$3"
|
|
prefix="$4"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Main
|
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
shopt -s extglob
|
|
|
|
args_parse "$@"
|
|
|
|
if [[ ${mode} == "exit" ]]
|
|
then
|
|
exit 0
|
|
else
|
|
if [[ ${mode} == "test" ]]
|
|
then
|
|
dry_run=true
|
|
else
|
|
dry_run=false
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
echo "mode: [${mode}] verbose: [${verbose}] source_dir: [${source_dir}] target_dir: [${target_dir}] album_name: [${album_name}] prefix: [${prefix}]" 1>&2
|
|
|
|
for file in "${source_dir}"/*@(.flac|.mp3)
|
|
do
|
|
id="$(basename $file | sed -e "s/-.*//")"
|
|
target_file="${target_dir}/${prefix}$(basename $file)"
|
|
|
|
cmd="cp \"${file}\" \"${target_file}\""
|
|
exec_cmd "${cmd}"
|
|
|
|
tag_delete "${target_file}" "ALBUM"
|
|
tag_write "${target_file}" "ALBUM" "${album_name}"
|
|
tag_delete "${target_file}" "TRACKNUMBER"
|
|
tag_write "${target_file}" "TRACKNUMBER" "${prefix}${id}"
|
|
done
|