refactor: streamline output path construction and improve variable handling in main function
This commit is contained in:
parent
a324b207ec
commit
7f8c2202b0
1 changed files with 16 additions and 17 deletions
33
to-m4b.sh
33
to-m4b.sh
|
@ -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}"
|
||||
else
|
||||
# Construct output path
|
||||
output_file="${out_root}/${author}/"
|
||||
[[ -n "$year" ]] && output_file+="${year} - "
|
||||
output_file+="${title}"
|
||||
if [[ -n "${series}" && -n "${series_index}" ]]; then
|
||||
output_file+="${series}/Book ${series_index} - ${year} - ${title}"
|
||||
|
||||
else
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue