From d024a0dc02243ae8e7aee8f1b011be91ed2124aa Mon Sep 17 00:00:00 2001 From: ayakael Date: Mon, 26 Mar 2018 19:34:44 -0400 Subject: [PATCH] Program now executes on a track by track basis, rather than image id by image id basis Added support for track selection/exclusion. Rewrote code --- src/clean_target | 23 ++++--- src/cmd_select | 38 ++++++++++++ src/deploy | 88 +++++++++++++++++++++++++++ src/deploy_gen | 35 +++++++++++ src/deploy_imageid | 60 ------------------ src/deploy_trackid.sh | 56 +++++++++++++++++ src/env | 3 - src/is_not_excluded | 21 ------- src/is_selected | 21 +++++++ src/parser | 2 +- src/{print_meta => print_future_meta} | 18 ++++-- src/print_future_path | 42 +++++++++++++ src/print_present_meta | 17 ++++++ src/print_present_path | 20 ++++++ src/print_target_dir | 25 -------- src/split_flac | 16 ----- src/update_db.sh | 25 ++++++++ 17 files changed, 372 insertions(+), 138 deletions(-) create mode 100644 src/cmd_select create mode 100644 src/deploy create mode 100644 src/deploy_gen delete mode 100644 src/deploy_imageid create mode 100644 src/deploy_trackid.sh delete mode 100644 src/is_not_excluded create mode 100644 src/is_selected rename src/{print_meta => print_future_meta} (61%) create mode 100644 src/print_future_path create mode 100644 src/print_present_meta create mode 100644 src/print_present_path delete mode 100644 src/print_target_dir delete mode 100644 src/split_flac create mode 100644 src/update_db.sh diff --git a/src/clean_target b/src/clean_target index caeeeff..6694a9f 100644 --- a/src/clean_target +++ b/src/clean_target @@ -1,18 +1,27 @@ #!/bin/bash -### -# Cleans target of all FLAC files that are owned by IMAGEID that exist in TARGET directory -### +# doc clean_target { +# +# DESCRIPTION +# clean_target - Cleans target of IMAGEID +# +# USAGE +# clean_target +# +# } clean_target() { local TARGET="${1}" local IMAGEID="${2}" - local MANIFEST="${3}" + local DB_FILE="${3}" - for old_file in $(grep ${IMAGEID} ${MANIFEST} | cut -d'=' -f1); do - rm ${TARGET}/${old_file} + 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 - sed -i "/${IMAGEID}/d" ${MANIFEST} find ${TARGET}/* -empty -type d -delete >/dev/null 2>&1 } diff --git a/src/cmd_select b/src/cmd_select new file mode 100644 index 0000000..06712bf --- /dev/null +++ b/src/cmd_select @@ -0,0 +1,38 @@ +#!/bin/bash + +# doc cmd_select { +# +# DESCRIPTION +# cmd_select - Command selects all IMAGEID that matches the CONDITION +# +# USAGE +# cmd_select [<...>] +# +# CONDITIONS +# CONDITIONS are defined using the following format: +# = +# The metadata field can be anything that can be injected as metadata in a Vorbis or id3tag. +# +# } + +cmd_select() { + local GIT_DIR="${1}" + local DB_FILE="${2}" + local SELECTED="${3}"; shift 3 + local conditionList=(${@}) + + for condition in ${conditionList[@]}; do + local FIELD="$(echo ${condition} | cut -d'=' -f1)" + local VALUE="$(echo ${condition} | cut -d'=' -f2)" + local imageidList=($(sed 's/\(.*\)\..*/\1/' <<< $(grep -i -l '"'${FIELD}'" : "'${VALUE}'"' ${GIT_DIR}/*.tags))) + + for imageid in ${imageidList[@]}; do + local rowList=($(_cfg query '$3="'${imageid}'"' ${DB_FILE})) + + for rowno in ${rowList[@]}; do + _cfg change SELECTED ${rowno} ${SELECTED} ${DB_FILE} + done + done + done +} + diff --git a/src/deploy b/src/deploy new file mode 100644 index 0000000..678fce8 --- /dev/null +++ b/src/deploy @@ -0,0 +1,88 @@ +#!/bin/bash + +# doc deploy { +# +# DESCRIPTION +# deploy - Deploys IMAGEID to TARGET and then updates DB file. +# +# USAGE +# deploy +# + + +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 +} diff --git a/src/deploy_gen b/src/deploy_gen new file mode 100644 index 0000000..786abe6 --- /dev/null +++ b/src/deploy_gen @@ -0,0 +1,35 @@ +#!/bin/bash + +# doc deploy_gen { +# +# DESCRIPTION +# deploy_gen - Splits specified image into multiple files using a text file +# formatted under the CUE specification +# +# USAGE +# deploy_gen +# } + +deploy_gen() { + local GITDIR="${1}" + local DB_FILE="${2}" + local IMAGEID="${3}" + local TRACKID="${4}" + local TRACKNO=$(print_track_no ${DB_FILE} ${IMAGEID} ${TRACKID}) + + ## breakpointList generator + # Generates list with cuebreakpoints utility + local breakpointList=($(cuebreakpoints "${GITDIR}/${IMAGEID}.cue" 2>/dev/null)) + + # 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; } + + # 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 + fi + return 0 +} + diff --git a/src/deploy_imageid b/src/deploy_imageid deleted file mode 100644 index 76c4847..0000000 --- a/src/deploy_imageid +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -### -# Deploys IMAGEID to TARGET and then updates MANIFEST file -## - - -deploy_imageid() { - local IMAGEID="${1}" - local TARGET="${2}" - local MANIFEST="${3}" - local TOTALTRACKS="$(grep -e TITLE ${IMAGEID}.tags | wc -l)" - - if [[ ! -e "${IMAGEID}.flac" ]]; then - _msg EXEC "Downloading data for ${IMAGEID}" - git annex get ${IMAGEID}.* >${STDERR} 2>&1 - [[ $? -ne 0 ]] && _msg WARN || _msg OK - local DELETE=true - fi - - _msg EXEC "Generating data for ${IMAGEID}" - gen_flac ${IMAGEID}.flac ${IMAGEID}.cue >${STDERR} 2>&1 - local EXIT_CODE=$? - [[ ${EXIT_CODE} -eq 0 ]] && _msg OK || _msg WARN - - _msg EXEC "Parsing metadata for ${IMAGEID}" - local COUNT=1 - while [[ ${COUNT} -le ${TOTALTRACKS} ]]; do - metaList[${COUNT}]="$(gen_meta ${IMAGEID}.tags ${COUNT})" - local COUNT=$(( ${COUNT} + 1 )) - done - _msg OK - - _msg EXEC "Applying metadata for ${IMAGEID}" - local COUNT=1 - while [[ ${COUNT} -le ${TOTALTRACKS} ]]; do - awk 'BEGIN {RS=";"}{print $0}' <<< ${metaList[${COUNT}]} | head -n -1 | metaflac --import-tags-from=- --import-picture-from="${IMAGEID}.jpg" $(printf 'split-track%02d.flac' ${COUNT}) - [[ $? -ne 0 ]] && local GEN_META_ERR=true - local COUNT=$(( ${COUNT} + 1 )) - done - [[ ${GEN_META_ERR} ]] && _msg WARN || _msg OK - - _msg EXEC "Deploying ${IMAGEID} to ${TARGET}" - local COUNT=1 - while [[ ${COUNT} -le ${TOTALTRACKS} ]]; do - local DIR=$(gen_dir ${metaList[${COUNT}]} | sed s'|:|_|g') - mkdir -p "${TARGET}/$(dirname "${DIR}")" - mv $(printf 'split-track%02d.flac' ${COUNT}) "${TARGET}/${DIR}.flac" - echo "${DIR}.flac=${IMAGEID};" >> ${MANIFEST} - local COUNT=$(( ${COUNT} + 1 )) - done - _msg OK - - if [[ ${DELETE} ]]; then - _msg EXEC "Dropping data for ${IMAGEID}" - git annex drop ${IMAGEID}.* >${STDERR} 2>&1 - _msg OK - fi -} - diff --git a/src/deploy_trackid.sh b/src/deploy_trackid.sh new file mode 100644 index 0000000..44eaff6 --- /dev/null +++ b/src/deploy_trackid.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# doc deploy_trackid { +# +# DESCRIPTION +# deploy_trackid - Deploys TRACKID of IMAGEID to TARGET +# +# USAGE +# deploy_trackid [] [<...>] +# +# } + +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 +} diff --git a/src/env b/src/env index 9476553..2ad1a06 100644 --- a/src/env +++ b/src/env @@ -7,7 +7,4 @@ source /usr/lib/bash/bunc IFS=' ' -MANIFEST=".manifest" -LAST_COMMIT=".last_commit" -EXCLUDE=".exclude" diff --git a/src/is_not_excluded b/src/is_not_excluded deleted file mode 100644 index 9f89ac0..0000000 --- a/src/is_not_excluded +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -### -# Returns true if IMAGEID is not excluded from the OPT_EXCLUDE_FILE. -### - -is_not_excluded() { - local IMAGEID="${1}" - local EXCLUDE="${2}" - local excludeList=($(cat ${EXCLUDE})) - - [[ -z ${excludeList[@]} ]] && return 0 - - for exclude in ${excludeList[@]}; do - local FIELD=$(echo ${exclude} | cut -d'=' -f1) - local VALUE=$(echo ${exclude} | cut -d'=' -f2) - [[ -z "$(grep -i -l "\"${FIELD}\" : \"${VALUE}\"" ${IMAGEID}.tags)" ]] || return 1 - done - return 0 -} - diff --git a/src/is_selected b/src/is_selected new file mode 100644 index 0000000..b5739cc --- /dev/null +++ b/src/is_selected @@ -0,0 +1,21 @@ +#!/bin/bash + +# doc is_selected { +# +# DESCRIPTION +# is selected - Returns true if IMAGEID is defined as selected in DB_FILE. +# +# USAGE +# is_selected +# +# } + +is_selected() { + local DB_FILE="${1}" + 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 +} + diff --git a/src/parser b/src/parser index cb04d3d..e7ab855 100644 --- a/src/parser +++ b/src/parser @@ -1,4 +1,4 @@ -#! +#!/bin/bash ### # Parses arguments and commands from shell diff --git a/src/print_meta b/src/print_future_meta similarity index 61% rename from src/print_meta rename to src/print_future_meta index 98a016a..425120d 100644 --- a/src/print_meta +++ b/src/print_future_meta @@ -1,11 +1,19 @@ #!/bin/bash -### -# Prints metadata of specified TRACKNUMBER, from textfile following the MTAG specification. Outputs as standard FIELD=VALUE that can then be pipped into metaflac. -### +# doc print_future_meta { +# +# DESCRIPTION +# print_future_meta - Prints metadata of specified TRACKNUMBER, from textfile following +# the MTAG specification. Outputs as standard FIELD=VALUE that can then be pipped into +# metaflac. +# +# USAGE +# print_future_meta +# +# } -print_meta() { +print_future_meta() { local MTAG=${1} local TRACKNUMBER="${2}" local TAGS=$(cat ${MTAG} | sed -e 's/^[[:space:]]*\"//') @@ -14,7 +22,7 @@ print_meta() { for tag in ${tagList[@]}; do local COUNT=1 while [[ ${COUNT} -le ${TRACKNUMBER} ]]; do - local PRTVAR=$(print_meta_track ${COUNT} ${tag} ${TAGS}) + local PRTVAR=$(print_meta_field ${COUNT} ${tag} ${TAGS}) [[ ! -z ${PRTVAR} ]] && local CURVAR=${PRTVAR} local COUNT=$(( ${COUNT} + 1 )) done diff --git a/src/print_future_path b/src/print_future_path new file mode 100644 index 0000000..6d1b330 --- /dev/null +++ b/src/print_future_path @@ -0,0 +1,42 @@ +#!/bin/bash + +# doc print_target_path { +# +# DESCRIPTION +# Prints relative output path based on provided metadata TAGS. Expects input from print_meta +# function. +# +# USAGE +# print_target_path +# +# } + +print_target_path() { + local TAGS="${@}" + local tagList=(GENRE COMPOSER ALBUM ARTIST 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}/" + 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" + fi + + [[ ${TOTALDISCS} -gt 1 ]] && echo -n "${DISCNUMBER}." + printf "%02d" ${TRACKNUMBER} + echo -n " - $(sed 's|/|-|g' <<< ${TITLE} | sed 's|?||g')" +} + diff --git a/src/print_present_meta b/src/print_present_meta new file mode 100644 index 0000000..f1835b2 --- /dev/null +++ b/src/print_present_meta @@ -0,0 +1,17 @@ +#!/bin/bash + +# doc print_present_meta { +# +# DESCRIPTION +# print_present_meta - Prints metadata of remote flac in FIELD=VALUE; format. +# +# USAGE +# print_present_meta +# +# } + +print_present_path() { + local IMAGEID="${1}" + local TRACKID="${2}" + local DB_FILE="${3}" + + local ROW=$(_cfg query '$2=="'${IMAGEID}'" && $3=="'${TRACKNO}'"' ${DB_FILE}) + _cfg print TARGET_PATH ${ROW} ${DB_FILE} +} diff --git a/src/print_target_dir b/src/print_target_dir deleted file mode 100644 index cc17e1e..0000000 --- a/src/print_target_dir +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -### -# Prints output dir based on provided metadata TAGS. Expects input from print_meta function. -### - -print_target_dir() { - local TAGS="${@}" - local tagList=(GENRE COMPOSER ALBUM ARTIST 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 - - if [[ "${GENRE}" == "Classical" ]]; then - echo -n "${GENRE}/${COMPOSER}/${ALBUM}/${ARTIST}/${DATE} - ${PERFORMER}/" - else - echo -n "${GENRE}/${ARTIST}/${DATE} - ${ALBUM}/" - fi - [[ ${TOTALDISCS} -gt 1 ]] && echo -n "${DISCNUMBER}." - printf "%02d" ${TRACKNUMBER} - echo -n " - $(sed 's|/|-|g' <<< ${TITLE} | sed 's|?||g')" -} - diff --git a/src/split_flac b/src/split_flac deleted file mode 100644 index 789411f..0000000 --- a/src/split_flac +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -### -# Splits specified FLAC image into multiple flac files using a text file formatted under the -# CUE specification -### - -split_flac() { - local FLAC="${1}" - local CUE="${2}" - - [[ -z "$(cuebreakpoints ${CUE} 2>/dev/null)" ]] && { cat ${FLAC} > split-track01.flac; return 0; } - cuebreakpoints ${CUE} 2>/dev/null | shntool split ${FLAC} -o flac -O always - [[ $? -ne 0 ]] && { cuebreakpoints ${CUE} 2>/dev/null | sed s/$/0/ | shntool split ${FLAC} -o flac -O always; return 2; } || return 0 -} - diff --git a/src/update_db.sh b/src/update_db.sh new file mode 100644 index 0000000..8e4fd5c --- /dev/null +++ b/src/update_db.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# doc update_db { +# +# DESCRIPTION +# update_db - Updates TARGET's DB_FILE with defined IMAGEIDs +# +# USAGE +# update_db <...> +# +# } + +update_db() { + local GITDIR="${1}" + local TARGET="${2}" + local DB_FILE="${3}"; shift 3 + local imageidList=(${@}) + + for imageid in ${imageidList[@]}; do + trackidList=($(awk 'BEGIN{FS="\" : \"";RS="\",\n * \""}{if($1=="TRACKID"){print $2}}')) + for trackid in ${trackidList[@]}; do + [[ -z $(_cfg query '$2=="'${imageid}'" && $3=="'${trackid}'"' ${DB_FILE}) ]] && _cfg insert true ${imageid} ${trackid} + done + done +}