dam/src/print_future_path

43 lines
1.5 KiB
Bash

#!/bin/bash
# doc print_future_path {
#
# DESCRIPTION
# Prints relative output path based on provided metadata TAGS. Expects input from print_meta
# function.
#
# USAGE
# print_future_path <output from print_meta>
#
# }
print_future_path() {
local TAGS="${@}"
local tagList=(GENRE COMPOSER ALBUM ARTIST CONDUCTOR PERFORMER DATE DISCNUMBER TOTALDISCS TRACKNUMBER TITLE)
for tag in ${tagList[@]}; do
CURTAG="$(awk -v field=${tag} 'BEGIN{RS=";";FS="="}{if($1==field){printf $2}}' <<< ${TAGS})"
eval local ${tag}='${CURTAG}'
done
[[ -n "${GENRE}" ]] && echo -n "${GENRE}/"
if [[ -n "${CONDUCTOR}" ]]; then
[[ -n "${ARTIST}" ]] && echo -n "${ARTIST}/"
[[ -n "${ALBUM}" ]] && echo -n "${ALBUM}/"
[[ -n "${CONDUCTOR}" ]] && echo -n "${CONDUCTOR}/"
[[ -n "${DATE}" ]] && echo -n "${DATE}"
if [[ -n "${DATE}" ]] && [[ -n "${PERFORMER}" ]]; then echo -n " - "; fi
[[ -n "${PERFORMER+x}" ]] && echo -n "${PERFORMER}/"
else
[[ -n "${ARTIST}" ]] && echo -n "${ARTIST}/"
[[ -n "${DATE}" ]] && echo -n "${DATE}"
if [[ -n "${DATE}" ]] && [[ -n "${ALBUM}" ]]; then echo -n " - "; fi
[[ -n "${ALBUM}" ]] && echo -n "${ALBUM}/"
fi
[[ ${TOTALDISCS} -gt 1 ]] && echo -n "${DISCNUMBER}."
printf "%02d" ${TRACKNUMBER}
[[ -n "${TITLE}" ]] && echo -n " - $(sed 's|/|_|g' <<< ${TITLE})" || echo -n " - Track $(printf "%02d" ${TRACKNUMBER})"
echo -n ".flac"
}