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
 | 
					  if ((${#dirs[@]})); then
 | 
				
			||||||
    for dir in "${dirs[@]}"; do
 | 
					    for dir in "${dirs[@]}"; do
 | 
				
			||||||
      eval "$(parse-vars "$dir")"
 | 
					      eval "$(parse-vars "${dir}")"
 | 
				
			||||||
      if [[ -z "$title" ]]; then
 | 
					      if [[ -z "${title}" ]]; then
 | 
				
			||||||
        echo "Skipping '$dir': could not parse title" >&2
 | 
					        echo "Skipping '${dir}': could not parse title" >&2
 | 
				
			||||||
        continue
 | 
					        continue
 | 
				
			||||||
      fi
 | 
					      fi
 | 
				
			||||||
    if [[ -z "$author" ]]; then
 | 
					    if [[ -z "${author}" ]]; then
 | 
				
			||||||
      echo "Skipping '$dir': could not parse author" >&2
 | 
					      echo "Skipping '${dir}': could not parse author" >&2
 | 
				
			||||||
      continue
 | 
					      continue
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
    # Construct output path: ${OUT}/<author>/<series or standalone>/<series_index - >title {narrator}.m4b
 | 
					    # Construct output path
 | 
				
			||||||
    if [[ -n "$series" ]]; then
 | 
					    output_file="${out_root}/${author}/"
 | 
				
			||||||
      output_file="${out_root}/${author}/${series}/"
 | 
					    if [[ -n "${series}" && -n "${series_index}" ]]; then
 | 
				
			||||||
      [[ -n "$series_index" ]] && output_file+="Book ${series_index} - "
 | 
					      output_file+="${series}/Book ${series_index} - ${year} - ${title}"
 | 
				
			||||||
      [[ -n "$year" ]] && output_file+="${year} - "
 | 
					      
 | 
				
			||||||
      output_file+="${title}"
 | 
					 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      output_file="${out_root}/${author}/"
 | 
					      output_file+="${year} - ${title}"
 | 
				
			||||||
      [[ -n "$year" ]] && output_file+="${year} - "
 | 
					      [[ -n "${narrator}" ]] && output_file+=" {${narrator}}/"
 | 
				
			||||||
      output_file+="${title}"
 | 
					 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
    [[ -n "$narrator" ]] && output_file+=" {${narrator}}"
 | 
					    output_file+="/${year} - ${title}"
 | 
				
			||||||
 | 
					    [[ -n "${narrator}" ]] && output_file+=" {${narrator}}"
 | 
				
			||||||
    output_file+=".m4b"
 | 
					    output_file+=".m4b"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      echo "Processing '$dir' -> '$output_file'"
 | 
					      echo "Processing '${dir}' -> '${output_file}'"
 | 
				
			||||||
      m4b-merge "$output_file" "$dir" "$author" "$narrator" "$title" "$year" "$series" "$series_index"
 | 
					      m4b-merge "${output_file}" "${dir}" "${author}" "${narrator}" "${title}" "${year}" "${series}" "${series_index}"
 | 
				
			||||||
    done
 | 
					    done
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    echo "No book directories found under '${src_root}'." >&2
 | 
					    echo "No book directories found under '${src_root}'." >&2
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue