From 02e113230165a9d0edc0b19402d71595d5c35839 Mon Sep 17 00:00:00 2001 From: fabh2o Date: Thu, 4 Feb 2021 09:59:19 +0100 Subject: [PATCH] validate files --- AAXtoMP3 | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 55151a7..3fcc16a 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -284,7 +284,7 @@ validate_aax() { # Test for existence if [[ ! -r "${media_file}" ]] ; then log "ERROR File NOT Found: ${media_file}" - return + return 1 else if [[ "${VALIDATE}" == "1" ]]; then log "Test 1 SUCCESS: ${media_file}" @@ -323,6 +323,36 @@ validate_aax() { set -e errexit } +validate_extra_files() { + local extra_media_file extra_title extra_chapter_file + extra_media_file="$1" + # Bash trick to delete, non greedy, from the end up until the first '-' + extra_title="${extra_media_file%-*}" + + # Using this is not ideal, because if the naming scheme is changed then + # this part of the script will break + # AAX file: BookTitle-LC_128_44100_stereo.aax + # Cover file: BookTitle_(1215).jpg + # Chapter file: BookTitle-chapters.json + extra_chapter_file="${extra_title}-chapters.json" + + debug_vars "Audible-cli files" extra_media_file extra_title extra_chapter_file + + # Test for chapter file existence + if [[ ! -r "${extra_chapter_file}" ]] ; then + log "ERROR File NOT Found: ${extra_chapter_file}" + return 1 + fi + + # Test for cover art existence (any resolution) + if [[ ! $(find -maxdepth 1 -regex ".*/${extra_title}_([0-9]+)\\.jpg") ]]; then + log "ERROR Cover File NOT Found" + return 1 + fi + + debug "All expected audible-cli related file are here" +} + # ----- # Inspect the AAX and extract the metadata associated with the file. save_metadata() { @@ -368,6 +398,12 @@ do # Don't bother doing anything else with this file. continue fi + + if [[ ${audibleCli} == "1" ]] ; then + # If we have additional files (obtained via audible-cli), be sure that they + # exists and they are in the correct location. + validate_extra_files "${aax_file}" + fi # ----- # Make sure everything is a variable. Simplifying Command interpretation