Tested and bug fixed deploy_image_id and its dependant functions

This commit is contained in:
ayakael 2018-03-28 09:52:57 -04:00
parent d024a0dc02
commit 7dcd6db0b7
No known key found for this signature in database
GPG key ID: 575626A4AE5F4026
19 changed files with 231 additions and 238 deletions

10
build.sh Executable file
View file

@ -0,0 +1,10 @@
#!/bin/bash
EXEC=dam
echo -e "#!/bin/bash\n" > ${EXEC}
for file in $(find src/ -type f); do
awk '!/^ *#/ && NF' ${file} >> ${EXEC}
done
echo 'eval $@' >> ${EXEC}

View file

@ -1,27 +0,0 @@
#!/bin/bash
# doc clean_target {
#
# DESCRIPTION
# clean_target - Cleans target of IMAGEID
#
# USAGE
# clean_target </path/to/target> <IMAGEID> </path/to/db/file>
#
# }
clean_target() {
local TARGET="${1}"
local IMAGEID="${2}"
local DB_FILE="${3}"
rownoList=($(_cfg query '$2=='${IMAGEID} ${DB_FILE}))
for rowno in ${rownoList[@]}; do
FILE_PATH=$(_cfg print TARGET_PATH ${rowno} ${DB_FILE})
rm "${TARGET}/${FILE_PATH}"
_cfg drop row ${rowno}
done
find ${TARGET}/* -empty -type d -delete >/dev/null 2>&1
}

3
src/dam Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
eval $@

View file

@ -1,88 +0,0 @@
#!/bin/bash
# doc deploy {
#
# DESCRIPTION
# deploy - Deploys IMAGEID to TARGET and then updates DB file.
#
# USAGE
# deploy </path/to/git/dir> </path/to/target> <path/to/db/file> <imageid>
#
deploy() {
local GIT_DIR="${1}"
local TARGET="${2}"
local DB_FILE="${TARGET}/${3}"
local IMAGEID="${4}"
## targetmetaList, targetpathList, deployedpathList, deployedmetaList generators
# targetmetaList and targetpathList are used to define both the metadata, and path
# of split files. deployedpathList and deployedmetaList are used later to determine
# if a change occured in the targetpath and targetmeta, if the IMAGEID has already been
# deployed.
# Defines the TARGET and DEPLOYED total tracks.
local TOTALTRACKS="$(grep -e TITLE "${GITDIR}/${IMAGEID}.tags" | wc -l)"
local TARGET_TOTALTRACKS="$(grep -e TITLE "${GITDIR}/${IMAGEID}.tags" | wc -l)"
local DEPLOYED_TOTALTRACKS="$(grep -e ${IMAGEID} "${DB_FILE}" | wc -l)"
# Current working track variable
local COUNT=1
while [[ ${COUNT} -le ${TARGET_TOTALTRACKS} ]]; do
local targetmetaList[${COUNT}]="$(print_target_meta ${IMAGEID}.tags ${COUNT})"
local targetpathList[${COUNT}]="${TARGET}/$(print_target_path ${targetmetaList[${COUNT}]})"
local deployedpathList[${COUNT}]="${TARGET}/$(print_deployed_path ${IMAGEID} ${COUNT} ${DB_FILE})"
local deployedmetaList[${COUNT}]="$(print_deployed_meta ${deployedpathList[${COUNT}]})"
# Bumps up working track number
local COUNT=$(( ${COUNT} + 1 ))
done
# Checks is there's a discrepancy between what has been deployed and what is targetted to be deployed.
# This can be caused by an unclean deployment, or a change in the cue files. In this case, the clean_target
# function will be used to clean the target of the unclean imageid, and then normal deployment will occur.
if [[ ${TARGET_TOTALTRACKS} -ne ${DEPLOYED_TOTALTRACKS} ]] && [[ ${DEPLOYED_TOTALTRACKS} -ne 0 ]]; then
clean_target ${TARGET} ${IMAGEID} ${DB_FILE}
fi
if [[ -z "${deployedpathList[@]}" ]]; then
## FLAC Splitter
# Splits the provided IMAGEID's FLAC file into multiple tracks using the provided CUE file.
# A hack is sort of applies here by populating the deployedpathList with the output files of split_flac.
split_flac "${GITDIR}" "${IMAGEID}"
local COUNT=1
while ${COUNT} -le ${TARGET_TOTALTRACKS}; do
local deployedpathList[${COUNT}]="${GITDIR}/$(printf 'split-track%02d.flac' ${COUNT})"
local deployedmetaList[${COUNT}]=""
local COUNT=$(( ${COUNT} + 1 ))
done
fi
## Metadata application
# Applies metadata to flac files that are either newly generated by split_flac to already deployed files that require it.
local COUNT=1
while [[ ${COUNT} -le ${TARGET_TOTALTRACKS} ]]; do
# If ${targetmetaList[${COUNT}]} in ${deployedmetaList[${COUNT}]} are not equal, it means that either the already deployed
# flac file needs metadata updating, or a newly generated split flac needs metadata application
if [[ "${targetmetaList[${COUNT}]}" != "${deployedmetaList[${COUNT}]}" ]]; then
[[ ! -z "${deployedmetaList[${COUNT}]}" ]] && metaflac --remove-all ${deployedpathList[${COUNT}]}
awk 'BEGIN {RS=";"}{print $0}' <<< ${targetmetaList[${COUNT}]} | head -n -1 | metaflac --import-tags-from=- --import-picture-from="${IMAGEID}.jpg" ${deployedpathList[${COUNT}]}
fi
local COUNT=$(( ${COUNT} + 1 ))
done
## Track deployment
# Deploys files to appropriate targetpath, of course only if necessary.
local COUNT=1
while [[ ${COUNT} -le ${TARGET_TOTALTRACKS} ]]; do
if [[ "${targetpathList[${COUNT}]}" != "${deployedpathList[${COUNT}]}" ]]; then
mkdir -p "$(dirname "${targetpathList[${COUNT}]}")"
mv "${deployedpathList[${COUNT}]}" "${targetpathList[${COUNT}]}"
local ROW_NO=$(_cfg query '$2=='${IMAGEID}' && $3=='${COUNT}'' ${DB_FILE})
_cfg drop row ${ROW_NO} ${DB_FILE}
_cfg insert row "true" ${IMAGEID} ${COUNT} "${targetpathList[${COUNT}]}" ${DB_FILE}
fi
local COUNT=$(( ${COUNT} + 1 ))
done
}

View file

@ -7,15 +7,12 @@
# formatted under the CUE specification
#
# USAGE
# deploy_gen </path/to/git/dir> </path/to/db_file> <image-id> <track-id>
# deploy_gen </path/to/git/dir> <IMAGEID>
# }
deploy_gen() {
local GITDIR="${1}"
local DB_FILE="${2}"
local IMAGEID="${3}"
local TRACKID="${4}"
local TRACKNO=$(print_track_no ${DB_FILE} ${IMAGEID} ${TRACKID})
local IMAGEID="${2}"
## breakpointList generator
# Generates list with cuebreakpoints utility
@ -23,13 +20,13 @@ deploy_gen() {
# In the event that breakpointList is empty because image represents only one track,
# no split occurs, and returns a 0.
[[ -z "${breakpointList[@]}" ]] && { cat "${GITDIR}/${IMAGEID}.flac" > ${GITDIR}/${TRACKID}.flac; return 0; }
[[ -z "${breakpointList[@]}" ]] && { cat "${GITDIR}/${IMAGEID}.flac" > ${GITDIR}/split-track01.flac; return 0; }
# Attempts first split. If fails because of lack of CD quality file, retries with modified breakpointList
if ! printf '%s\n' ${breakpointList[@]} | shntool split "${GITDIR}/${IMAGEID}.flac" -o flac -O always -x ${TRACKNO} -d "${GITDIR}" -f ${TRACKID}.flac; then
printf '%s\n' ${breakpointList[@]} | sed s/$/0/ | shntool split "${GITDIR}/${IMAGEID}.flac" -o flac -O always -x ${TRACKNO} -d "${GITDIR}" -f ${TRACKID}.flac
[[ $? -eq 0 ]] && return 2 || return 1
if ! printf '%s\n' ${breakpointList[@]} | shntool split "${GITDIR}/${IMAGEID}.flac" -o flac -O always -d "${GITDIR}"; then
printf '%s\n' ${breakpointList[@]} | sed s/$/0/ | shntool split "${GITDIR}/${IMAGEID}.flac" -o flac -O always -d "${GITDIR}"
[[ $? -ne 0 ]] && return 2 || return 1
fi
return 0
}

29
src/deploy_imageid Normal file
View file

@ -0,0 +1,29 @@
#!/bin/bash
# doc deploy_imageid {
#
# DESCRIPTION
# deploy_imageid - Wraps the deploy_trackid function on a per imageid basis
#
# USAGE
# deploy_imageid <path/to/git/dir> </path/to/target> <IMAGEID>
#
# }
deploy_imageid() {
## Argument parsing
local GIT_DIR="${1}"
local TARGET="${2}"
local DB_FILE="${3}"
local IMAGEID="${4}"
[[ -n "$(awk -v imageid=${IMAGEID} 'BEGIN{FS="\t"}{if($1=="true" && $2==imageid && $4=="null"){print NR}}' ${DB_FILE})" ]] && { deploy_gen ${GIT_DIR} ${IMAGEID}; deploy_mv ${GIT_DIR} ${IMAGEID}; }
local trackidList=($(awk -v imageid=${IMAGEID} 'BEGIN{FS="\t"}{if($2==imageid){print $3}}' ${DB_FILE}))
for trackid in ${trackidList[@]}; do
_msg ECHO "Processing ${trackid} of ${IMAGEID}"
deploy_trackid ${GIT_DIR} ${TARGET} ${DB_FILE} ${IMAGEID} ${trackid}
done
}

27
src/deploy_mv Normal file
View file

@ -0,0 +1,27 @@
#!/bin/bash
# doc deploy_mv {
#
# DESCRIPTION
# deploy_mv - Renames output files from deploy_gen to associated TRACKID
#
# USAGE
# deploy_mv </path/to/git/dir> <IMAGEID.
# }
deploy_mv() {
local GITDIR="${1}"
local IMAGEID="${2}"
# Generated trackidList to know what id to assign to each file
local trackidList=$(awk 'BEGIN{RS="\",*\n * \"";FS="\" : \""}{if($1=="TRACKID"){print $2}}' "${GITDIR}/${IMAGEID}.tags")
# Then renames the ouput files to TRACKID
local COUNT=1
for trackid in ${trackidList[@]}; do
mv "${GITDIR}/$(printf 'split-track%02d.flac' ${COUNT})" "${GITDIR}/${IMAGEID}-${trackid}.flac"
local COUNT=$(( ${COUNT} + 1 ))
done
return 0
}

67
src/deploy_trackid Normal file
View file

@ -0,0 +1,67 @@
#!/bin/bash
# doc deploy_trackid {
#
# DESCRIPTION
# deploy_trackid - Deploys TRACKID of IMAGEID to TARGET
#
# USAGE
# deploy_trackid <path/to/git/dir> <path/to/target> <path/to/db/file> <IMAGEID> <TRACKID>
#
# }
deploy_trackid() {
## Argument parsing
local GIT_DIR="${1}"
local TARGET="${2}"
local DB_FILE="${3}"
local IMAGEID="${4}"
local TRACKID="${5}"
local TRACKNO="$(print_track_no ${GIT_DIR} ${IMAGEID} ${TRACKID})"
## Path and metadata parsing
local FUTURE_META="$(print_future_meta ${GIT_DIR}/${IMAGEID}.tags ${TRACKNO})"
local FUTURE_PATH="$(print_future_path ${FUTURE_META}})"
local PRESENT_PATH="$(print_present_path ${DB_FILE} ${IMAGEID} ${TRACKID})"
local PRESENT_META="$(print_present_meta "${TARGET}/${PRESENT_PATH}")"
local ROW_NO=$(awk -v imageid=${IMAGEID} -v trackid=${TRACKID} 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print NR}}' ${DB_FILE})
# If the track is selected, we will check if the trackid has already been deployed, if not deploy. If the metadata to be
# applied is different than what's deployed, apply new metadata. If the path has changed, move file to new path.
if is_selected ${DB_FILE} ${IMAGEID} ${TRACKID}; then
# In the event that PRESENT_PATH is null, that is to say the trackid is not present on target, transfers it there and then defined the PRESENT_PATH as the transfered FLAC
if [[ "${PRESENT_PATH}" == "null" ]]; then
_msg ECHO "${TRACKID} is not deployed. Deploying"
mv "${GIT_DIR}/${IMAGEID}-${TRACKID}.flac" "${TARGET}/${IMAGEID}-${TRACKID}.flac"
PRESENT_PATH="${IMAGEID}-${TRACKID}.flac"
fi
# If the PRESENT_META and FUTURE_META diverge, wipe the old metadata, and reapply
if [[ "${PRESENT_META}" != "${FUTURE_META}" ]]; then
_msg ECHO "${TRACKID} has different metadata. Updating"
[[ "${PRESENT_PATH}" == "null" ]] || metaflac --remove-all "${TARGET}/${PRESENT_PATH}"
awk 'BEGIN {RS=";"}{print $0}' <<< ${FUTURE_META} | head -n -1 | metaflac --import-tags-from=- --import-picture-from="${GIT_DIR}/${IMAGEID}.jpg" "${TARGET}/${PRESENT_PATH}"
fi
# If the PRESENT_PATH and FUTURE_PATH diverge, move to new location
if [[ "${PRESENT_PATH}" != "${FUTURE_PATH}" ]]; then
_msg ECHO "${TRACKID} has differing paths. Moving"
mkdir -p "$(dirname "${TARGET}/${FUTURE_PATH}")"
mv "${TARGET}/${PRESENT_PATH}" "${TARGET}/${FUTURE_PATH}"
awk -v rowno=${ROW_NO} -v value="${FUTURE_PATH}" 'BEGIN{FS="\t";OFS="\t"}{if(NR==rowno){$4=value}{print $0}}' ${DB_FILE} > ${DB_FILE}.tmp; mv ${DB_FILE}.tmp ${DB_FILE}
fi
else
if [[ ${PRESENT_PATH} != "null" ]]; then
_msg ECHO "${TARGETID} was previouslty selected, and is now unselected. Deleting"
rm "${TARGET}/${PRESENT_PATH}"
awk -v rowno=${ROW_NO} -v value=null 'BEGIN{FS="\t";OFS="\t"}{if(NR==rowno){$4=value}{print $0}}' ${DB_FILE} > ${DB_FILE}.tmp; mv ${DB_FILE}.tmp ${DB_FILE}
else
_msg ECHO "${TARGETID} not selected"
rm "${GIT_DIR}/${IMAGEID}-${TRACKID}.flac"
fi
fi
return 0
}

View file

@ -1,56 +0,0 @@
#!/bin/bash
# doc deploy_trackid {
#
# DESCRIPTION
# deploy_trackid - Deploys TRACKID of IMAGEID to TARGET
#
# USAGE
# deploy_trackid <path/to/git/dir> <path/to/target> <path/to/db/file> <IMAGEID> <TRACKID_1> [<TRACKID_2>] [<...>]
#
# }
deploy_trackid() {
## Argument parsing
local GIT_DIR="${1}"
local TARGET="${2}"
local DB_FILE="${3}"
local IMAGEID="${4}"
local TRACKID="${5}"
## Path and metadata parsing
local TRACKNO=$(print_track_no ${DB_FILE} ${IMAGEID} ${TRACKID})
local FUTURE_META="$(print_future_meta ${IMAGEID}.tags ${TRACKNO})"
local FUTURE_PATH="${TARGET}/$(print_future_path$ ${FUTURE_META}})"
local PRESENT_PATH="${TARGET}/$(print_future_path ${IMAGEID} ${TRACKNO} ${DB_FILE})"
local PRESENT_META="$(print_future_meta ${PRESENT_PATH})"
local ROW_NO==$(_cfg query '$2=="'${IMAGEID}'" && $3=="'${TRACKID}'"' ${DB_FILE})
# If the track is selected, we will check if the trackid has already been deployed, if not deploy. If the metadata to be
# applied is different than what's deployed, apply new metadata. If the path has changed, move file to new path.
if is_selected ${DB_FILE} ${IMAGEID} ${TRACKID}; then
if [[ -z "${PRESENT_PATH}" ]]; then
deploy_gen ${GIT_DIR} ${IMAGEID} ${TRACKNO}
local PRESENT_PATH="${GIT_DIR}/output.flac"
fi
if [[ "${PRESENT_META}" != "${FUTURE_META}" ]]; then
[[ -z "${PRESENT_META}" ]] || metaflac --remove-all ${PRESENT_PATH}
awk 'BEGIN {RS=";"}{print $0}' <<< ${FUTURE_META} | head -n -1 | metaflac --import-tags-from=- --import-picture-from="${GIT_DIR}/${IMAGEID}.jpg" "${PRESENT_PATH}"
fi
if [[ "${PRESENT_PATH}" != "${FUTURE_PATH}" ]]; then
mkdir -p "$(dirname "${FUTURE_PATH}")"
mv "${PRESENT_PATH}" "${FUTURE_PATH}"
_cfg change TARGET_PATH ${ROW_NO} "${FUTURE_PATH}" ${DB_FILE}
fi
else
if [[ ! -z "${PRESENT_PATH}" ]]; then
rm "${PRESENT_PATH}"
_cfg change TARGET_PATH ${ROW_NO} ""
fi
fi
return 0
}

View file

@ -15,7 +15,6 @@ is_selected() {
local IMAGEID="${2}"
local TRACKID="${3}"
ROWNO=$(_cfg query '$2=="'${IMAGEID}'" && $3=="'${TRACKID}'"' ${DB_FILE})
[[ "$(_cfg print SELECTED ${ROWNO} ${DB_FILE})" == "true" ]] && return 0 || return 1
[[ "$(awk -v imageid=${IMAGEID} -v trackid=${TRACKID} 'BEGIN{FS"\t"}{if($2==imageid && $3==trackid){print $1}}' ${DB_FILE})" == "true" ]] && return 0 || return 1
}

View file

@ -1,13 +0,0 @@
#!/bin/bash
###
# Prints IDs that are already deployed by parsing the IMAGEID field in all of the FLAC files
# that are present in the TARGET directory.
###
print_deployed_ids() {
local TARGET="${@}"
for flac in $(find "${TARGET}" -name '*.flac' -not -path '*/\.*' -printf "%P\t"); do
echo "${flac}=$(metaflac --list ${TARGET}/${flac} | grep IMAGEID | cut -d= -f2);"
done
}

View file

@ -16,13 +16,12 @@
print_future_meta() {
local MTAG=${1}
local TRACKNUMBER="${2}"
local TAGS=$(cat ${MTAG} | sed -e 's/^[[:space:]]*\"//')
local tagList=($(echo ${TAGS} | awk 'BEGIN {RS="\", ";FS="\" : \""}{if($1!~"{"){print $1}}' | awk '!seen[$0]++'))
local tagList=($(awk 'BEGIN{RS="\",*\n * \"";FS="\" : \""}{if($1!~"@"){print $1}}' ${MTAG} | awk '!seen[$0]++'))
for tag in ${tagList[@]}; do
local COUNT=1
while [[ ${COUNT} -le ${TRACKNUMBER} ]]; do
local PRTVAR=$(print_meta_field ${COUNT} ${tag} ${TAGS})
local PRTVAR=$(print_meta_field ${MTAG} ${COUNT} ${tag})
[[ ! -z ${PRTVAR} ]] && local CURVAR=${PRTVAR}
local COUNT=$(( ${COUNT} + 1 ))
done
@ -30,6 +29,6 @@ print_future_meta() {
unset CURVAR
unset PRTVAR
done
echo -n "IMAGEID=$(sed 's|.tags||g' <<< ${MTAG})"
echo -n "IMAGEID=$(sed 's|.tags||g' <<< $(basename "${MTAG}"))"
}

View file

@ -1,42 +1,42 @@
#!/bin/bash
# doc print_target_path {
# doc print_future_path {
#
# DESCRIPTION
# Prints relative output path based on provided metadata TAGS. Expects input from print_meta
# function.
#
# USAGE
# print_target_path <output from print_meta>
# print_future_path <output from print_meta>
#
# }
print_target_path() {
print_future_path() {
local TAGS="${@}"
local tagList=(GENRE COMPOSER ALBUM ARTIST PERFORMER DATE DISCNUMBER TOTALDISCS TRACKNUMBER TITLE)
local tagList=(GENRE COMPOSER ALBUM ARTIST CONDUCTOR PERFORMER DATE DISCNUMBER TOTALDISCS TRACKNUMBER TITLE)
for tag in ${tagList[@]}; do
CURTAG="$(awk -v field=${tag} 'BEGIN{RS=";";FS="="}{if($1==field){printf $2}}' <<< ${TAGS})"
eval local ${tag}='${CURTAG}'
done
[[ -z "${GENRE+x}" ]] && echo -n "${GENRE}/"
if [[ -z "${CONDUCTOR+x}" ]]; then
[[ -z "${COMPOSER+x}" ]] && echo -n "${COMPOSER}/"
[[ -z "${ALBUM+x}" ]] && echo -n "${ALBUM}/"
[[ -z "${ARTIST+x}" ]] && echo -n "${ARTIST}/"
[[ -z "${DATE+x}" ]] && echo -n "${DATE}"
if [[ -z "${DATE+x}" ]] && [[ -z "${PERFORMER+x}" ]]; then echo -n "-"; fi
[[ -z "${PERFORMER+x}" ]] && echo -n "${PERFORMER}/"
[[ -n "${GENRE}" ]] && echo -n "${GENRE}/"
if [[ -n "${CONDUCTOR}" ]]; then
[[ -n "${ARTIST}" ]] && echo -n "${ARTIST}/"
[[ -n "${ALBUM}" ]] && echo -n "${ALBUM}/"
[[ -n "${CONDUCTOR}" ]] && echo -n "${CONDUCTOR}/"
[[ -n "${DATE}" ]] && echo -n "${DATE}"
if [[ -n "${DATE}" ]] && [[ -n "${PERFORMER}" ]]; then echo -n " - "; fi
[[ -n "${PERFORMER+x}" ]] && echo -n "${PERFORMER}/"
else
[[ -z "${ARTIST+x}" ]] && echo -n "${ARTIST}/"
[[ -z "${DATE+x}" ]] && echo -n "${DATE}"
if [[ -z "${DATE+x}" ]] && [[ -z "${ARTIST+x}" ]]; then echo -n "-"; fi
[[ -z "${ALBUM+x}" ]] && echo -n "${ALBUM}/\t"
[[ -n "${ARTIST}" ]] && echo -n "${ARTIST}/"
[[ -n "${DATE}" ]] && echo -n "${DATE}"
if [[ -n "${DATE}" ]] && [[ -n "${ALBUM}" ]]; then echo -n " - "; fi
[[ -n "${ALBUM}" ]] && echo -n "${ALBUM}/"
fi
[[ ${TOTALDISCS} -gt 1 ]] && echo -n "${DISCNUMBER}."
printf "%02d" ${TRACKNUMBER}
echo -n " - $(sed 's|/|-|g' <<< ${TITLE} | sed 's|?||g')"
echo -n " - $(sed 's|/|-|g' <<< ${TITLE} | sed 's|?||g').flac"
}

View file

@ -1,14 +1,20 @@
#!/bin/bash
###
# Prints VALUE of FIELD, for specific TRACK NUMBER out of a JSON string. Expects to be used
# doc print_meta_field {
#
# DESCRIPTION
# print_meta_field - Prints VALUE of FIELD, for specific TRACK NUMBER out of a JSON string. Expects to be used
# by print_meta()
###
#
# USAGE
# print_meta_field <file> <track_no> <field_name>
#
# }
print_meta_field() {
local TRACK_NO="${1}"
local FIELD="${2}"; shift 2
local TAGS="${@}"
local FILE="${1}"
local TRACK_NO="${2}"
local FIELD="${3}"
awk -v track="${TRACK_NO}" 'BEGIN {RS="\" * }"}{if(NR==track){print $0}}' <<< ${TAGS} | awk -v field="${FIELD}" 'BEGIN {RS="\", ";FS="\" : \"";}{if($1==field){print $2}}'
awk -v track="${TRACK_NO}" 'BEGIN {RS="\"\n * }"}{if(NR==track){print $0}}' ${FILE} | awk -v field="${FIELD}" 'BEGIN{RS="\",*\n * \"";FS="\" : \""}{if($1==field){print $2}}'
}

View file

@ -11,7 +11,9 @@
# }
print_present_meta() {
local FLAC="${1}"
local FILE="${1}"
metaflac --list --block-type=VORBIS_COMMENT "${FLAC}" | grep "comment\[" | awk 'BEGIN{FS=": ";ORS=";"}{print $2}'
if [[ -f ${FILE} ]]; then
awk 'BEGIN{FS=": ";ORS=";"}{if($1 ~ /comment\[/){print $2}}' <<< $(metaflac --list --block-type=VORBIS_COMMENT "${FILE}") | sed 's|.$||'
fi
}

View file

@ -6,15 +6,14 @@
# Prints path of exiting TRACKID for IMAGEID.
#
# USAGE
# print_present_path <imageid> <track number> </path/to/db/file>
# print_present_path </path/to/db/file> <imageid> <trackid>
#
# }
print_present_path() {
local IMAGEID="${1}"
local TRACKID="${2}"
local DB_FILE="${3}"
local DB_FILE="${1}"
local IMAGEID="${2}"
local TRACKID="${3}"
local ROW=$(_cfg query '$2=="'${IMAGEID}'" && $3=="'${TRACKNO}'"' ${DB_FILE})
_cfg print TARGET_PATH ${ROW} ${DB_FILE}
awk -v imageid=${IMAGEID} -v trackid=${TRACKID} 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $4}}' ${DB_FILE}
}

26
src/print_track_no Normal file
View file

@ -0,0 +1,26 @@
#!/bin/bash
# doc print_track_no {
#
# DESCRIPTION
# print_track_no - Prints track number of TRACKID using MTAG file
#
# USAGE
# print_track_no <path/to/git/dir> <IMAGEID> <TRACKID>
#
# }
print_track_no() {
local GIT_DIR="${1}"
local IMAGEID="${2}"
local TRACKID="${3}"
local TOTALTRACKS=$(grep TITLE ${GIT_DIR}/${IMAGEID}.tags | wc -l)
local COUNT=1
while [[ ${COUNT} -le ${TOTALTRACKS} ]]; do
[[ "$(print_meta_field ${GIT_DIR}/${IMAGEID}.tags ${COUNT} TRACKID)" == "${TRACKID}" ]] && echo ${COUNT}
local COUNT=$(( ${COUNT} + 1 ))
done
}

View file

@ -11,15 +11,16 @@
# }
update_db() {
local GITDIR="${1}"
local GIT_DIR="${1}"
local TARGET="${2}"
local DB_FILE="${3}"; shift 3
local imageidList=(${@})
[[ -f "${DB_FILE}" ]] || touch "${DB_FILE}"
for imageid in ${imageidList[@]}; do
trackidList=($(awk 'BEGIN{FS="\" : \"";RS="\",\n * \""}{if($1=="TRACKID"){print $2}}'))
trackidList=($(awk 'BEGIN{FS="\" : \"";RS="\",\n * \""}{if($1=="TRACKID"){print $2}}' ${GIT_DIR}/${imageid}.tags))
for trackid in ${trackidList[@]}; do
[[ -z $(_cfg query '$2=="'${imageid}'" && $3=="'${trackid}'"' ${DB_FILE}) ]] && _cfg insert true ${imageid} ${trackid}
[[ -z $(awk -v imageid="${imageid}" -v trackid="${trackid}" 'BEGIN{FS="\t"}{if($2==imageid && $3==trackid){print $0}}' ${DB_FILE}) ]] && echo -e "true\t${imageid}\t${trackid}\tnull" >> ${DB_FILE}
done
done
}

12
tst/test_update_db Normal file
View file

@ -0,0 +1,12 @@
#!/bin/bash
source ../src/env
source ../src/update_db
GIT_DIR=~/media/music
TARGET=~/media/target
DB_FILE=~/media/target/.dam.db
IMAGEID=SHA256-zyVXHCNCiYlngNrv5cpTXfOWsm8--82bc52d968f90a4e3b4ec316e67c6e0acae66112db9f237cb4b11df623cf20c2
update_db ${GIT_DIR} ${TARGET} ${DB_FILE} ${IMAGEID}