diff --git a/src/print_meta_field b/src/print_meta_field index e5fdc4d..1f2b709 100644 --- a/src/print_meta_field +++ b/src/print_meta_field @@ -16,5 +16,10 @@ 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}}' | tail -n 1 | sed -e 's/^"//' -e 's/"$//' + # The first awk command prints out all the FIELD information for every TRACK preceeding TRACK_NO. The second + # awk command then keeps only the lines that match the FIELD we want, then using tail and sed, we keep only + # the last line (Thus the only relevant value). This permits us to use the MTAG's specs where tracks inherit + # the values of its previous tracks when not set. Thus, one needs only to define the ALBUM once on the first + # track for all other TRACKs to inherit it. + 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_meta_mtag b/src/print_meta_mtag index 1d7691b..18e45af 100644 --- a/src/print_meta_mtag +++ b/src/print_meta_mtag @@ -15,14 +15,21 @@ print_meta_mtag() { local FILE=${1} - local TRACKNO="${2}"; shift 2 + local TRACK_NO="${2}"; shift 2 local tagList=(${@}) [[ -z "${tagList[@]}" ]] && local tagList=($(awk 'BEGIN{RS="\",*\n * \"";FS="\" : \""}{if($1!~"@"){print $1}}' ${FILE} | awk '!seen[$0]++') IMAGEID) for tag in ${tagList[@]}; do + # Finalizes output with IMAGEID [[ "${tag}" == "IMAGEID" ]] && { echo -n "IMAGEID=$(sed 's|.tags||g' <<< $(basename "${FILE}"))"; continue; } - echo -n "${tag}=$(print_meta_field ${FILE} ${TRACKNO} ${tag});" + + # Skips print_meta_field for field TITLE to keep it unique. Thus, if a track + # does not have a defined TITLE, it won't inherit it from previous tracks + [[ "${tag}" == "TITLE" ]] && { [[ -z "$(awk -v track=${TRACK_NO} 'BEGIN {RS="\n * }"}{if(NR==track){print $0}}' ${FILE} | awk -v field="\"TITLE\"" 'BEGIN{RS="[,]?\n";FS=" : "}{if($1~field){print $2}}')" ]] && continue; } + + # Prints out VALUE of that TAG for that TRACK NO + echo -n "${tag}=$(print_meta_field ${FILE} ${TRACK_NO} ${tag});" done }