diff --git a/src/chk_deployed_ids b/src/chk_deployed_ids index ce23561..bb6eaf8 100644 --- a/src/chk_deployed_ids +++ b/src/chk_deployed_ids @@ -23,11 +23,11 @@ chk_deployed_ids() { local COUNT=$(( ${COUNT} + 1 )) local ERR=false echo "[ ${COUNT} / ${#flacList[@]} ] Checking ${flac}" - local metadataList=($(awk 'BEGIN{RS=";";FS="="}{if($1=="IMAGEID" || $2=="TRACKID"){print $2}}' <<< $(print_meta_flac "${TARGET}/${flac}"))) - local IMAGEID=${metadataList[0]} - local TRACKID=${metadataList[1]} + local METADATA="$(print_meta_flac "${TARGET}/${flac}")" + local IMAGEID=$(awk 'BEGIN{RS=";";FS="="}{if($1=="IMAGEID"){print $2}}' <<< ${METADATA}) + local TRACKID=$(awk 'BEGIN{RS=";";FS="="}{if($1=="TRACKID"){print $2}}' <<< ${METADATA}) - if [[ -z "${IMAGEID}" ]] || [[ -z "${TRACKID}" ]]; then echo "${flac} does not contain IMAGEID or TRACKID metadata" > ${STDERR}; local ERR=true; fi + if [[ -z "${IMAGEID+x}" ]] || [[ -z "${TRACKID+x}" ]]; then echo "${flac} does not contain IMAGEID or TRACKID metadata" > ${STDERR}; local ERR=true; fi [[ "${ERR}" == "true" ]] && { cat ${STDERR}; continue; } diff --git a/src/cmd_import_images b/src/cmd_import_images index 2005b57..9ee960c 100644 --- a/src/cmd_import_images +++ b/src/cmd_import_images @@ -22,32 +22,30 @@ cmd_import_images() { for dir in ${dirList[@]}; do - folderList=($(find "${dir}" -name '*.cue' -printf '%h\n' | awk '!seen[$0]++')) + cueList=($(find "${dir}" -name '*.cue' -printf '%p\n')) # Consolidating all detected images - for folder in ${folderList[@]}; do - _msg EXEC "Consolidating ${folder}" - local fileList=($(find "${folder}" \( -name '*.flac' -o -name '*.cue' -o -name '*.accurip' -o -name '*.log' -o -name '*.jpg' -o -name '*.png' \) )) + for cue in ${cueList[@]}; do + _msg EXEC "Consolidating ${cue}" + for var in IMG CUE ACCURIP LOG COVER; do unset ${var}; done for ext in flac cue accurip log jpg; do - local fileList=($(find "${folder}" -name "*.${ext}")) - [[ ${#fileList[@]} -gt 1 ]] && return 1 + local file=$(sed "s|cue|${ext}|" <<< ${cue}) + [[ ! -f "${file}" ]] && continue case ${ext} in flac) - local IMG="${fileList}" - [[ -z "${IMG}" ]] && return 2 + local IMG="${file}" ;; cue) - local CUE="${fileList}" - [[ -z "${CUE}" ]] && return 2 + local CUE="${file}" ;; - (accurip) local ACCURIP="${fileList}" ;; - (log) local LOG="${fileList}" ;; - (jpg) local COVER="${fileList}" ;; + (accurip) local ACCURIP="${file}" ;; + (log) local LOG="${file}" ;; + (jpg) local COVER="${file}" ;; esac done - import_images "${GIT_DIR}" "${SOURCE}" "${IMG}" "${CUE}" $([[ -n "${ACCURIP}" ]] && echo "-a") "${ACCURIP}" $([[ -n "${LOG}" ]] && echo "-l") "${LOG}" $([[ -n "${COVER}" ]] && echo "-c") "${COVER}" >${STDERR} 2>&1 + import_images "${GIT_DIR}" "${SOURCE}" "${IMG}" "${CUE}" $([[ -n "${ACCURIP}" ]] && echo "-a") "${ACCURIP}" $([[ -n "${LOG}" ]] && echo "-l") "${LOG}" $([[ -n "${COVER}" ]] && echo "-c") "${COVER}" >${STDERR} 2>&1 local EXIT=$? [[ ${EXIT} -eq 0 ]] && _msg OK || _msg WARN "Import_images exited with code ${EXIT}" done diff --git a/src/db_set b/src/db_set index 0b89812..4f7cbcc 100644 --- a/src/db_set +++ b/src/db_set @@ -30,8 +30,8 @@ db_set() { fi # Defines what imageids are imported into database, as we're only going to act on those - local FIELD="$(echo ${CONDITION} | cut -d'=' -f1 | tr '[:lower:]' '[:upper:]' )" - local VALUE="$(echo ${CONDITION} | cut -d'=' -f2 | tr '[:lower:]' '[:upper:]' )" + local FIELD="$(echo ${CONDITION} | cut -d'=' -f1 | awk '{print toupper($0)}')" + local VALUE="$(echo ${CONDITION} | cut -d'=' -f2 | awk '{print toupper($0)}')" # Determines which IMAGEIDs present in the DB_FILE match the CONDITION local COUNT=1 diff --git a/src/import_images b/src/import_images index 3d9613f..985bcc8 100644 --- a/src/import_images +++ b/src/import_images @@ -34,29 +34,34 @@ import_images() { (*) break ;; esac done - + # Checks if path is valid + echo "Checking if all paths exists" for path in ${pathList[@]}; do - [[ -f "${path}" ]] || return 1 + [[ ! -f "${path}" ]] && { echo "${path} - No such file or directory"; return 1; } done + echo "Checking existence of ACCURIP file" # Checks if ACCURIP should exist or not - if [[ -n "${ACCURIP}" ]] && [[ "${SOURCE}" == "EAC" ]]; then return 2; fi - if [[ -z "${ACCURIP}" ]] && [[ "${SOURCE}" == "CUETOOLS" ]]; then return 2; fi + if [[ -n "${ACCURIP}" ]] && [[ "${SOURCE}" == "EAC" ]]; then echo "Accurip file specified, ignored"; unset ${ACCURIP}; fi + if [[ -z "${ACCURIP}" ]] && [[ "${SOURCE}" == "CUETOOLS" ]]; then echo "CUETOOLS requires an ACCURIP file, please make sure it is generated"; return 2; fi # Parses cue file for DISCID + echo "Parsing cue file to determine DISCID" local METADATA=$(print_meta_cue "${CUE}" | tr '\n' ';') local discidList=($(awk 'BEGIN{FS="=";RS=";"}{if($1=="DISCID"){print $2}}' <<<${METADATA} | awk '!seen[$0]++')) - [[ ${#discidList[@]} -ne 1 ]] && return 3 + [[ ${#discidList[@]} -ne 1 ]] && { echo "There should be only one DISCID specified in cue file"; return 3; } # Copies path to import folder + echo "Cleaning up .import dir" rm -Rf "${GIT_DIR}/.import/${SOURCE}/${discidList}" >/dev/null 2>&1 + echo "Creating ${GIT_DIR}/.import/${SOURCE}/${discidList}" mkdir -p "${GIT_DIR}/.import/${SOURCE}/${discidList}" for path in ${pathList[@]}; do case $(sed 's|.*\.||' <<< ${path}) in - (jpg) convert "${path}" "${GIT_DIR}/.import/${SOURCE}/${discidList}/png" ;; - (*) cp --no-preserve=mode "${path}" "${GIT_DIR}/.import/${SOURCE}/${discidList}/$(sed 's|.*\.||' <<< ${path})" ;; + (jpg) echo "Copying cover image"; convert "${path}" "${GIT_DIR}/.import/${SOURCE}/${discidList}/png" ;; + (*) local DEST="${GIT_DIR}/.import/${SOURCE}/${discidList}/$(sed 's|.*\.||' <<< ${path})"; echo "Copying ${path} to ${DEST}"; cp --no-preserve=mode "${path}" "${DEST}" ;; esac done }