#!/bin/bash # Includes #----------------------------------------------------------------------------------------------------------------------------------- . /usr/global/lib/music.bash # System Constants #----------------------------------------------------------------------------------------------------------------------------------- AMS_NAME="album_metadata_save" AMS_VERSION="$Name: album_metadata_save-1_0_0-1 $" # Print Version #----------------------------------------------------------------------------------------------------------------------------------- function version_print() { echo ${AMS_VERSION} | sed -e 's/.*: //' -e 's/-/ /' -e 's/_/\./g' -e 's/\$$//' } # Prin Help #----------------------------------------------------------------------------------------------------------------------------------- function help_print() { echo "${AMS_NAME} [-h | --help] | [-V | --version] | [-T | --test] [-v | --verbose] [-f | --factoring] [-s | standardising] " } # Arg Parse #----------------------------------------------------------------------------------------------------------------------------------- function args_parse() { mode="default" 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 # 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;; -f|--factoring) factoring="true"; shift;; -s|--standardising) standardising="true"; shift;; # --) shift; break;; *) echo "args_parse internal error [$1] !"; exit 1;; esac done if [[ "${mode}" != "exit" ]] then if [[ "${#}" != "2" ]] then if [[ "${#}" -lt "2" ]] then echo "Not enough args!" else echo "Too many args!" fi mode="exit" help_print else source_dir="$1" metadata_file="$2" fi fi } # Main #----------------------------------------------------------------------------------------------------------------------------------- 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}] factoring: [${factoring}] standardising: [${standardising}] source_dir: [${source_dir}] metadata_file: [${metadata_file}]" 1>&2 declare -g nb_track find "${source_dir}" -maxdepth 1 -name '*.flac' -o -name '*.mp3' | sort | ( tagtab_alloc while read track_file do nb_track=$((${nb_track} + 1)) if [[ "${factoring}" == "true" ]] then tagtab_read "${nb_track}" "${track_file}" "FACTORING" else tagtab_read "${nb_track}" "${track_file}" "NOFACTORING" fi done track_id=0 while [[ "${track_id}" -le "${nb_track}" ]] do if [[ "${track_id}" == 0 ]] then echo "DEF" else echo "SOT" fi if [[ "${standardising}" == "true" ]] then tagtab_dump "${track_id}" "STANDARD" else tagtab_dump "${track_id}" "PASSTHROUGH" 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 )