From 35f92513dd542b541fb3c956a98016db0ead3569 Mon Sep 17 00:00:00 2001 From: ayakael Date: Wed, 28 Mar 2018 11:07:17 -0400 Subject: [PATCH] Optmized print_meta_field function --- src/print_future_meta | 10 +--------- src/print_meta_field | 2 +- src/print_present_meta | 3 ++- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/print_future_meta b/src/print_future_meta index 63299af..756ff91 100644 --- a/src/print_future_meta +++ b/src/print_future_meta @@ -19,15 +19,7 @@ print_future_meta() { 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 ${MTAG} ${COUNT} ${tag}) - [[ ! -z ${PRTVAR} ]] && local CURVAR=${PRTVAR} - local COUNT=$(( ${COUNT} + 1 )) - done - echo -n "${tag}=${CURVAR};" - unset CURVAR - unset PRTVAR + echo -n "${tag}=$(print_meta_field ${MTAG} ${TRACKNUMBER} ${tag});" done echo -n "IMAGEID=$(sed 's|.tags||g' <<< $(basename "${MTAG}"))" } diff --git a/src/print_meta_field b/src/print_meta_field index 8dea73c..e5fdc4d 100644 --- a/src/print_meta_field +++ b/src/print_meta_field @@ -16,5 +16,5 @@ print_meta_field() { local TRACK_NO="${2}" local FIELD="${3}" - 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}}' + 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}}' | tail -n 1 | sed -e 's/^"//' -e 's/"$//' } diff --git a/src/print_present_meta b/src/print_present_meta index 7e67a91..ad7222b 100644 --- a/src/print_present_meta +++ b/src/print_present_meta @@ -14,6 +14,7 @@ print_present_meta() { local FILE="${1}" if [[ -f ${FILE} ]]; then - awk 'BEGIN{FS=": ";ORS=";"}{if($1 ~ /comment\[/){print $2}}' <<< $(metaflac --list --block-type=VORBIS_COMMENT "${FILE}") | sed 's|.$||' + awk 'BEGIN{FS=": ";ORS=";"}{if($1 ~ /comment\[/){print $2}}' <<< $(metaflac --list --block-type=VORBIS_COMMENT "${FILE}") | sed 's|.$||' + fi }