[gen_cue] Function rewrite to support new API

This commit is contained in:
ayakael 2018-05-18 17:41:06 -07:00
parent 1287092bd9
commit 8c8edb9928
No known key found for this signature in database
GPG key ID: 575626A4AE5F4026

View file

@ -6,37 +6,42 @@
# gen_cue - Generates cue file from print_meta function # gen_cue - Generates cue file from print_meta function
# #
# USAGE # USAGE
# gen_cue <output from file_name> <output from print_meta_tracks> <file_1> [<file_2>] [<...>] # gen_cue <print_meta_flac-output-track-1> <print_meta_flac-output-track-2> <...>
# #
# DEPENDENCIES src/print_cue_breaklist # DEPENDENCIES src/print_cue_breaklist
# #
# } # }
gen_cue() { gen_cue() {
local FILE_NAME="${1}" local TARGET_DIR="${1}"; shift
local METADATA="${2}"; shift 2 local metadata_trackList=(${@})
local fileList=("${@}")
# Metadata Parsing # Generates list of tags to be parsed
metadataList=($(echo ${METADATA} | sed 's|;| |g')) local COUNT=0
for metadata in ${metadataList[@]}; do for metadata_track in ${metadata_trackList[@]}; do
eval local ${metadata} local tagList[${COUNT}]=$(awk 'BEGIN{RS=";";FS="=";ORS=";";}{print $1}' <<< ${metadata_track})
done local COUNT=$(( ${COUNT} + 1 ))
for file in ${fileList[@]}; do
local trackList=(${trackList[@]} $(echo ${file} | sed 's|.*/||' | awk 'BEGIN{ FS="-"; OFS=":"}{$1=""}{print $0}' | sed 's|: ||'))
done done
local tagList=($( sed -e 's| ; ||g' -e 's|; ;||' <<< ${tagList[@]} | tr ';' \\n | awk '!seen[$0]++' ))
# Generates breaklist # Generates breaklist
breakList=($(print_cue_breaklist ${fileList[@]})) local fileList=($(find ${TARGET_DIR} -name *.flac -print '%p\t'))
local breakList=($(print_cue_breaklist ${fileList[@]}))
[[ ! -z "${DATE+x}" ]] && echo "REM DATE ${DATE}" # Parses metadata
[[ ! -z "${COMPOSER+x}" ]] && echo "PERFORMER \"${COMPOSER}\"" local COUNT=0
[[ ! -z "${CONDUCTOR+x}" ]] && echo "REM CONDUCTOR \"${CONDUCTOR}\"" for tag in ${tagList[@]}; do
[[ ! -z "${ORCHESTRA+x}" ]] && echo "REM ORCHESTRA \"${ORCHESTRA}\"" local TAG_VALUE="$(awk -v tag="${tag}" 'BEGIN{RS=";";FS="=";}{if($1==tag){print $2}}' <<< ${metadata_track})"
[[ ! -z "${ARTIST+x}" ]] && echo "PERFORMER \"${ARTIST}\"" eval local ${tag}List[${COUNT}]="${TAG_VALUE}"
[[ ! -z "${ALBUM+x}" ]] && echo "TITLE \"${ALBUM}\"" done
echo "FILE \"${FILE_NAME}.flac\" WAVE"
[[ ! -z "${dateList[@]+x}" ]] && echo "REM DATE ${dateList[0]}}"
[[ ! -z "${composerList[@]+x}" ]] && echo "PERFORMER \"${composerList[0]}}\""
[[ ! -z "${conductorList[@]+x}" ]] && echo "REM CONDUCTOR \"${conductorList[0]}\""
[[ ! -z "${orchestraList[@]+x}" ]] && echo "REM ORCHESTRA \"${orchestraList[0]}\""
[[ ! -z "${artistLust[@]+x}" ]] && echo "PERFORMER \"${artistList[0]}\""
[[ ! -z "${albumList[@]+x}" ]] && echo "TITLE \"${albumList[0]}\""
echo "FILE \"${imageidList[0]}.flac\" WAVE"
local COUNT=0 local COUNT=0
while [[ ${COUNT} -lt ${#breakList[@]} ]]; do while [[ ${COUNT} -lt ${#breakList[@]} ]]; do
[[ ${COUNT} -le 8 ]] && local TRACK_NO="0$(( ${COUNT} + 1 ))" || local TRACK_NO="$(( ${COUNT} + 1 ))" [[ ${COUNT} -le 8 ]] && local TRACK_NO="0$(( ${COUNT} + 1 ))" || local TRACK_NO="$(( ${COUNT} + 1 ))"