refactor: streamline output path construction and improve variable handling in main function

This commit is contained in:
Philip Henning 2025-09-10 15:13:57 +02:00
parent a324b207ec
commit 7f8c2202b0

View file

@ -195,31 +195,30 @@ main() {
if ((${#dirs[@]})); then
for dir in "${dirs[@]}"; do
eval "$(parse-vars "$dir")"
if [[ -z "$title" ]]; then
echo "Skipping '$dir': could not parse title" >&2
eval "$(parse-vars "${dir}")"
if [[ -z "${title}" ]]; then
echo "Skipping '${dir}': could not parse title" >&2
continue
fi
if [[ -z "$author" ]]; then
echo "Skipping '$dir': could not parse author" >&2
if [[ -z "${author}" ]]; then
echo "Skipping '${dir}': could not parse author" >&2
continue
fi
# Construct output path: ${OUT}/<author>/<series or standalone>/<series_index - >title {narrator}.m4b
if [[ -n "$series" ]]; then
output_file="${out_root}/${author}/${series}/"
[[ -n "$series_index" ]] && output_file+="Book ${series_index} - "
[[ -n "$year" ]] && output_file+="${year} - "
output_file+="${title}"
# Construct output path
output_file="${out_root}/${author}/"
if [[ -n "${series}" && -n "${series_index}" ]]; then
output_file+="${series}/Book ${series_index} - ${year} - ${title}"
else
output_file="${out_root}/${author}/"
[[ -n "$year" ]] && output_file+="${year} - "
output_file+="${title}"
output_file+="${year} - ${title}"
[[ -n "${narrator}" ]] && output_file+=" {${narrator}}/"
fi
[[ -n "$narrator" ]] && output_file+=" {${narrator}}"
output_file+="/${year} - ${title}"
[[ -n "${narrator}" ]] && output_file+=" {${narrator}}"
output_file+=".m4b"
echo "Processing '$dir' -> '$output_file'"
m4b-merge "$output_file" "$dir" "$author" "$narrator" "$title" "$year" "$series" "$series_index"
echo "Processing '${dir}' -> '${output_file}'"
m4b-merge "${output_file}" "${dir}" "${author}" "${narrator}" "${title}" "${year}" "${series}" "${series_index}"
done
else
echo "No book directories found under '${src_root}'." >&2