[print_meta_field] Added documentation

[print_meta_mtag] The value for "TITLE" field now does not get inherited.
This commit is contained in:
ayakael 2018-04-07 13:27:37 -04:00
parent 834594e217
commit 07cf6d3298
No known key found for this signature in database
GPG key ID: 575626A4AE5F4026
2 changed files with 15 additions and 3 deletions

View file

@ -16,5 +16,10 @@ print_meta_field() {
local TRACK_NO="${2}"
local FIELD="${3}"
# 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/"$//'
}

View file

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