[chk_deployed_ids] Fixed bug during sanity check for both IMAGEID and TRACKID

[chk_import_images] Rewrote import images command
[db_set] Fixed bug where non-english characters wouldn't get pushed to upper case for non case-sensitive comparison
[import_images] Rewrote import_images
This commit is contained in:
ayakael 2018-12-26 17:06:59 -05:00
parent 3899c7cfd7
commit 2e9404349e
No known key found for this signature in database
GPG key ID: 575626A4AE5F4026
4 changed files with 30 additions and 27 deletions

View file

@ -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; }

View file

@ -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

View file

@ -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

View file

@ -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
}