From e025acf4d127cfdb568f8afd3e43ac7fe1337bfe Mon Sep 17 00:00:00 2001 From: ayakael Date: Thu, 12 Jul 2018 17:04:57 -0800 Subject: [PATCH] [import_dir] Renamed to import_src [import_src] Moved error handling to exit codes [import_src] SOURCE var is now defined by last subfolder [import_src] Now checks if SOURCE is supported --- src/{import_dir => import_src} | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) rename src/{import_dir => import_src} (78%) diff --git a/src/import_dir b/src/import_src similarity index 78% rename from src/import_dir rename to src/import_src index d8bc2fb..43e67fd 100644 --- a/src/import_dir +++ b/src/import_src @@ -1,38 +1,43 @@ #!/bin/bash -# doc import_dir { +# doc import_src { # # DESCRIPTION -# import_dir - Imports consolidated tracks into git repository +# import_src - Imports source into git directory # # USAGE -# import_dir +# import_src # # DEPENDENCIES src/gen_mtag # # } -import_dir() { +import_src() { local GIT_DIR="${1}" local TRACK_DIR="${2}" - local SOURCE="${3}" + local SOURCE=$(basename "${2}") + local supportedsrcList=$(FLAC CUETOOLS EAC) + + # Checks if source supported + if ! _if_array_contains ${SOURCE} ${supportedsrcList[@]}; then return 1; fi + local trackList=($(find ${TRACK_DIR} -maxdepth 1 -name '*.flac' -printf '%p\n' | sort)) # Join trackList - _msg EXEC "Processing audio files" + echo "Processing audio files" gen_image "${TRACK_DIR}/flac" $(printf "%s\t" ${trackList[@]}) > ${STDERR} 2>&1 local EXIT="$?" - [[ $? -eq 0 ]] && _msg OK || { _msg WARN; return 1; } + [[ $? -eq 0 ]] || return 2 # Generates IMAGEID - _msg EXEC "Generating IMAGEID" + echo "Generating IMAGEID" [[ "${SOURCE}" == "CUETOOLS" ]] && local SOURCE=$(grep "CTDB TOCID:" ${TRACK_DIR}/accurip) local IMAGEID="SHA256-${SOURCE}--$(sha256sum "${TRACK_DIR}/flac" | cut -d' ' -f1)" - _msg OK # Generate metadata_trackList + echo "Generating metadata" local COUNT=0 for track in ${trackList[@]}; do if [[ "${SOURCE}" == "FLAC" ]]; then @@ -47,17 +52,17 @@ import_dir() { done # Generate cuesheet - _msg EXEC "Generating cue file" + echo "Generating cue file" gen_cue "${TRACK_DIR}" $(printf '%s\t' ${metadata_trackList[@]}) > "${GIT_DIR}/${IMAGEID}.cue" local EXIT=$? - [[ $? -eq 0 ]] && _msg OK || { _msg WARN; return 1; } + [[ $? -eq 0 ]] || return 3 add_bom "${GIT_DIR}/${IMAGEID}.cue" # Generate tags file _msg EXEC "Generating tags file" gen_mtag $(printf '%s\t' ${metadata_trackList[@]}) > "${GIT_DIR}/${IMAGEID}.tags" local EXIT=$? - [[ $? -eq 0 ]] && _msg OK || { _msg WARN; return 1; } + [[ $? -eq 0 ]] || return 4 add_bom "${GIT_DIR}/${IMAGEID}.tags"