Added cue2git and git2git scripts, to be converted into functions and implemented in code
This commit is contained in:
parent
f06fdf7ac0
commit
4d529f0e2a
2 changed files with 487 additions and 0 deletions
201
cue2git.sh
Normal file
201
cue2git.sh
Normal file
|
@ -0,0 +1,201 @@
|
|||
#!/bin/bash
|
||||
source /usr/lib/bash/bunc
|
||||
IFS='
|
||||
'
|
||||
|
||||
file_name() {
|
||||
local SOURCE="${1}"
|
||||
local SHA256="${2}"
|
||||
echo "SHA256-${SOURCE}-${SHA256}"
|
||||
}
|
||||
|
||||
fix_apos() {
|
||||
local fileList=("${@}")
|
||||
for file in ${fileList[@]}; do
|
||||
sed -i 's/\xc2\x92/\x27/g' "${file}"
|
||||
sed -i 's/\xc2\x85/\x2e\x2e\x2e/g' "${file}"
|
||||
sed -i 's/\xc2\x96/\x2d/g' "${file}"
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
addbom() {
|
||||
local fileList=("${@}")
|
||||
for file in ${fileList[@]}; do
|
||||
sed -i '1s/^\(\xef\xbb\xbf\)\?/\xef\xbb\xbf/' "${file}"
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
deploy_split() {
|
||||
local FLAC="${1}"
|
||||
local CUE="${2}"
|
||||
|
||||
## breakpointList generator
|
||||
# Generates list with cuebreakpoints utility
|
||||
local breakpointList=($(cuebreakpoints "${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 "${FLAC}" > split-track01.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 "${FLAC}" -o flac -O always ; then
|
||||
printf '%s\n' ${breakpointList[@]} | sed s/$/0/ | shntool split "${FLAC}" -o flac -O always
|
||||
[[ $? -eq 0 ]] && return 2 || return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
gen_trackid() {
|
||||
FLAC="${1}"
|
||||
CUE="${2}"
|
||||
|
||||
deploy_split ${FLAC} ${CUE} >/dev/null 2>&1
|
||||
local TOTALTRACKS="$(grep -e "TRACK [0-9][0-9] AUDIO" "${CUE}" | wc -l)"
|
||||
|
||||
local COUNT=1
|
||||
while [[ ${COUNT} -le ${TOTALTRACKS} ]]; do
|
||||
local TRACKID="$(metaflac --list --block-number=0 $(printf "split-track%02d.flac" ${COUNT}) | awk 'BEGIN{FS=": "}{if($1==" MD5 signature") {print $2}}')"
|
||||
printf "%s\t" ${TRACKID}
|
||||
rm $(printf "split-track%02d.flac" ${COUNT})
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
gen_mtag() {
|
||||
local FILE_NAME="${1}"
|
||||
local METADATA="${2}"
|
||||
|
||||
# Metadata Parsing
|
||||
metadataList=($(echo ${METADATA} | sed 's|;| |g'))
|
||||
for metadata in ${metadataList[@]}; do
|
||||
eval local ${metadata}
|
||||
done
|
||||
|
||||
for file in ${fileList[@]}; do
|
||||
local trackList=(${trackList[@]} $(echo ${file} | sed 's|.*/||' | cut -d- -f2 | sed 's| ||' | sed 's|\.flac||'))
|
||||
done
|
||||
echo "["
|
||||
local COUNT=0
|
||||
while [[ ${COUNT} -lt ${#titleList[@]} ]]; do
|
||||
[[ ${COUNT} -ne 0 ]] && echo " },"
|
||||
echo " {"
|
||||
echo " \"@\" : \"${FILE_NAME}.cue|$(( ${COUNT} + 1 ))\","
|
||||
if [[ ${COUNT} -eq 0 ]]; then
|
||||
[[ ! -z "${ALBUM+x}" ]] && echo " \"ALBUM\" : \"${ALBUM}\","
|
||||
[[ ! -z "${PERFORMER+x}" ]] && echo " \"ARTIST\" : \"${PERFORMER}\","
|
||||
[[ ! -z "${META_COMPOSER+x}" ]] && echo " \"COMPOSER\" : \"${META_COMPOSER}\","
|
||||
[[ ! -z "${META_CONDUCTOR+x}" ]] && echo " \"CONDUCTOR\" : \"${META_CONDUCTOR}\","
|
||||
[[ ! -z "${META_ORCHESTRA+x}" ]] && echo " \"ORCHESTRA\" : \"${META_ORCHESTRA}\","
|
||||
[[ ! -z "${DATE+x}" ]] && echo " \"DATE\" : \"${DATE}\","
|
||||
[[ ! -z "${DISCNUMBER+x}" ]] && echo " \"DISCNUMBER\" : \"${DISCNUMBER}\","
|
||||
[[ ! -z "${TOTALDISCS+x}" ]] && echo " \"TOTALDISCS\" : \"${TOTALDISCS}\","
|
||||
[[ ! -z "${BATCHNUMBER+x}" ]] && echo " \"BATCHNUMBER\" : \"${BATCHNUMBER}\","
|
||||
echo " \"TOTALTRACKS\" : \"${#titleList[@]}\","
|
||||
fi
|
||||
[[ ! -z "${performerList[${COUNT}]+x}" ]] && echo " \"PERFORMER\" : \"${performerList[${COUNT}]}\","
|
||||
echo " \"TITLE\" : \"${titleList[${COUNT}]}\","
|
||||
echo " \"TRACKID\" : \"${trackidList[${COUNT}]}\","
|
||||
echo " \"TRACKNUMBER\" : \"$(( ${COUNT} + 1 ))\""
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
echo " }"
|
||||
echo "]"
|
||||
return 0
|
||||
}
|
||||
|
||||
cueparser() {
|
||||
local FLAC="${1}"
|
||||
local CUE="${2}"
|
||||
dos2unix -q -R "${CUE}"
|
||||
|
||||
## [Input] metaList generator
|
||||
# Generates lists that are later used for the parsing of the cuesheet. This is necessary
|
||||
# because cue sheets are have two sections: a general metadata section that applies to the
|
||||
# whole disc, and a track-specific section that applies to each track. PERFORMER defined
|
||||
# in the general section gets overriden by a PERFORMER defined in a track, thus it is
|
||||
# important to seperate the two. Another thing of import is seperating the different tracks
|
||||
# so they can be parsed as seperate elements. The trackmetaList uses tr to remove the new
|
||||
# line, and then uses awk to have every line have a specific track's information
|
||||
local trackmetaList=($( sed -n '/TRACK 01/,$p' ${CUE} | tr -d '\n' | awk 'BEGIN {RS="TRACK"}{print $0}' | tail -n +2))
|
||||
local trackidList=($(gen_trackid ${FLAC} ${CUE}))
|
||||
|
||||
# [Output] variable generator
|
||||
echo -n "PERFORMER=\"$(sed 's|\ \ .*||' "${CUE}" | grep -a "PERFORMER" | sed 's|PERFORMER ||' | sed 's|\"||g')\";"
|
||||
echo -n "ALBUM=\"$(sed 's|\ \ .*||' "${CUE}" | grep -a "TITLE" | sed 's|TITLE ||' | sed 's|\"||g')\";"
|
||||
echo -n "DATE=$(sed 's|\ \ .*||' "${CUE}" | grep -a "REM DATE" | sed 's|REM DATE ||');"
|
||||
echo -n "DISCNUMBER=$(sed 's|\ \ .*||' "${CUE}" | grep -a "REM DISCNUMBER" | sed 's|REM DISCNUMBER ||');"
|
||||
echo -n "TOTALDISCS=$(sed 's|\ \ .*||' "${CUE}" | grep -a "REM TOTALDISCS" | sed 's|REM TOTALDISCS ||');"
|
||||
local COUNT=0
|
||||
for trackmeta in ${trackmetaList[@]}; do
|
||||
echo -n "titleList[${COUNT}]=\"$(echo ${trackmeta} | awk 'BEGIN {RS=" "}{print $0}' | grep -a TITLE | sed 's|TITLE ||' | sed 's|\"||g')\";"
|
||||
echo -n "performerList[${COUNT}]=\"$(echo ${trackmeta} | awk 'BEGIN {RS=" "}{print $0}' | grep -a PERFORMER | sed 's|PERFORMER ||' | sed 's|\"||g')\";"
|
||||
echo -n "trackidList[${COUNT}]=\"${trackidList[${COUNT}]}\";"
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
}
|
||||
|
||||
gen_cover() {
|
||||
local FOLDER="${1}"
|
||||
[[ -f "${FOLDER}/folder.jpg" ]] && convert "${FOLDER}/folder.jpg" "${FOLDER}/folder.png" || { convert -size 480x480 xc:white "${FOLDER}/folder.png"; local ERROR=1; }
|
||||
cat "${FOLDER}/folder.png"
|
||||
[[ ${ERROR} -eq 1 ]] && return 1
|
||||
local IMG_SIZE="$(identify -format "%wx%h" "${FOLDER}/folder.jpg")"
|
||||
local IMG_WIDTH=$(echo ${IMG_SIZE} | cut -dx -f1)
|
||||
local IMG_HEIGHT=$(echo ${IMG_SIZE} | cut -dx -f2)
|
||||
if [[ ${IMG_WIDTH} -lt 480 ]] && [[ ${IMG_HEIGHT} -lt 480 ]]; then return 2; fi
|
||||
return 0
|
||||
}
|
||||
|
||||
gen() {
|
||||
local FOLDER="${1}"
|
||||
_msg EXEC "Processing ${FOLDER}"
|
||||
local flacList=($(find "${FOLDER}" -name '*.flac' | sed 's|.flac||'))
|
||||
[[ ${#flacList[@]} -eq 0 ]] && { _msg FAIL "No such file or directory"; return 1; }
|
||||
|
||||
for flac in ${flacList[@]}; do
|
||||
# Sanity check
|
||||
[[ -f "${flac}.cue" ]] || { _msg FAIL "No cue file present"; return 1; }
|
||||
[[ -f "${flac}.accurip" ]] || { _msg FAIL "No accurip file present"; return 1; }
|
||||
[[ -f "${flac}.log" ]] || { _msg FAIL "No EAC log file present"; return 1; }
|
||||
|
||||
# Determines file name based on image's CHKSUM and acts accordingly
|
||||
cat ${flac}.flac > output.flac 2>/dev/null
|
||||
metaflac --remove-all --dont-use-padding "output.flac"
|
||||
local SHA256=$(sha256sum ${flac}.flac 2>/dev/null | cut -d' ' -f1)
|
||||
local SOURCE=$(grep "CTDB TOCID:" ${flac}.accurip 2>/dev/null | cut -d' ' -f3 | sed 's|]||')
|
||||
local FILE_NAME=$(file_name ${SOURCE} ${SHA256})
|
||||
mv "output.flac" ${FILE_NAME}.flac > /dev/null 2>&1
|
||||
cat "${flac}.cue" | iconv -f ISO-8859-1 -t UTF-8 | sed '1s/^\(\xef\xbb\xbf\)\?/\xef\xbb\xbf/' | awk "!/FILE/{print} /FILE/{print \"FILE ${FILE_NAME}.flac WAVE\"}" > ${FILE_NAME}.cue 2> /dev/null
|
||||
cat "${flac}.accurip" | iconv -f ISO-8859-1 -t UTF-8 > ${FILE_NAME}.accurip
|
||||
cat "${flac}.log" | iconv -f ISO-8859-1 -t UTF-8 > ${FILE_NAME}.log
|
||||
addbom ${FILE_NAME}.cue
|
||||
|
||||
# Generates METADATA and MTAG
|
||||
local METADATA="$(cueparser ${FILE_NAME}.flac ${FILE_NAME}.cue);BATCHNUMBER=$(echo "${FOLDER}" | awk 'BEGIN{RS="/";}{print $0}' | grep batch | sed 's|.*_|_|' | sed -e 's/_0*//g');"
|
||||
gen_mtag "${FILE_NAME}" ${METADATA} > ${FILE_NAME}.tags
|
||||
addbom ${FILE_NAME}.tags
|
||||
fix_apos ${FILE_NAME}.tags
|
||||
gen_cover "${FOLDER}" > ${FILE_NAME}.png
|
||||
local EXIT="$?"
|
||||
if [[ ${EXIT} -eq 1 ]]; then
|
||||
_msg WARN "No folder.jpg in directory. Placeholder created"
|
||||
elif [[ ${EXIT} -eq 2 ]]; then
|
||||
_msg WARN "folder.jpg is under 480x480 in quality"
|
||||
else
|
||||
_msg OK
|
||||
fi
|
||||
|
||||
done
|
||||
}
|
||||
|
||||
dirList=("${@}")
|
||||
for dir in ${dirList[@]}; do
|
||||
folderList=($(find "${dir}" -name '*.cue' -printf '%h\n' | awk '!seen[$0]++'))
|
||||
for folder in ${folderList[@]}; do
|
||||
gen "${folder}"
|
||||
done
|
||||
done
|
286
git2git.sh
Normal file
286
git2git.sh
Normal file
|
@ -0,0 +1,286 @@
|
|||
#!/bin/bash
|
||||
source /usr/lib/bash/bunc
|
||||
IFS='
|
||||
'
|
||||
|
||||
sec2min() {
|
||||
local secList=("${@}")
|
||||
for sec in ${secList[@]}; do
|
||||
MIN=$(($sec%3600/60))
|
||||
SEC=$(($sec%60))
|
||||
[[ ${sec} -ge 3600 ]] && MIN=$(( ${MIN} + 60 ))
|
||||
printf '%02d:%02d:%02d\n' ${MIN} ${SEC} 00
|
||||
done
|
||||
}
|
||||
|
||||
med_convert() {
|
||||
local EXT="${1}"; shift 1
|
||||
local fileList=("${@}")
|
||||
for file in ${fileList[@]}; do
|
||||
local FILE_EXT="$(echo "${file}" | sed 's|.*\.||')"
|
||||
ffmpeg -loglevel 24 -y -i "${file}" "$(echo ${file} | sed "s|${FILE_EXT}|${EXT}|")" >${STDERR} 2>&1
|
||||
[[ $? -ne 0 ]] && local ERROR=true
|
||||
done
|
||||
[[ ${ERROR} ]] && return 1 || return 0
|
||||
}
|
||||
|
||||
file_name() {
|
||||
local SOURCE="${1}"
|
||||
local SHA256="${2}"
|
||||
echo "SHA256-${SOURCE}--${SHA256}"
|
||||
}
|
||||
|
||||
cdcount() {
|
||||
local FOLDER="${1}"
|
||||
local tracknoList=($(find "${1}"/* -type f -follow -not -name '*cover*' -not -name '*.pdf' -printf '%f\n' | cut -d' ' -f1))
|
||||
|
||||
for trackno in ${tracknoList[@]}; do
|
||||
if [[ ${trackno} == *.* ]]; then
|
||||
local CDCOUNT=$(echo ${trackno} | cut -d. -f1)
|
||||
else
|
||||
local CDCOUNT=1
|
||||
fi
|
||||
done
|
||||
echo ${CDCOUNT}
|
||||
}
|
||||
|
||||
ismp3() {
|
||||
local fileList=("${@}")
|
||||
for file in ${fileList[@]}; do
|
||||
local FILE_EXT="$(echo "${file}" | sed 's|.*\.||')"
|
||||
[[ "${FILE_EXT}" == "mp3" ]] && local MP3=0 || local MP3=1
|
||||
done
|
||||
[[ ${MP3} -eq 0 ]] && return 0 || return 1
|
||||
}
|
||||
|
||||
addbom() {
|
||||
local fileList=("${@}")
|
||||
for file in ${fileList[@]}; do
|
||||
sed -i '1s/^\(\xef\xbb\xbf\)\?/\xef\xbb\xbf/' "${file}"
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
gen_breaklist() {
|
||||
local fileList=("${@}")
|
||||
local breakList=(0:00:00)
|
||||
if shntool cue ${fileList[@]} >/dev/null 2>&1; then
|
||||
shntool cue ${fileList[@]} > joined.cue
|
||||
local breakList=(${breakList[@]} $(cuebreakpoints joined.cue | sed 's|\.|:|g'))
|
||||
rm joined.cue
|
||||
else
|
||||
local durList=($(soxi -D "${fileList[@]}"))
|
||||
local breaksecList=(0)
|
||||
local COUNT=0
|
||||
while [[ $(( ${COUNT} + 1 )) -lt ${#durList[@]} ]]; do
|
||||
local breaksecList=(${breaksecList[@]} $(awk "BEGIN {printf ${breaksecList[-1]} + ${durList[${COUNT}]}}" ))
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
local breaksecList=($(printf "%s\n" ${breaksecList[@]} | sed 's|\..*||g'))
|
||||
local breakList=($(sec2min ${breaksecList[@]}))
|
||||
fi
|
||||
printf '%s\n' ${breakList[@]}
|
||||
}
|
||||
|
||||
gen_image() {
|
||||
local fileList=("${@}")
|
||||
if [[ ${#fileList[@]} -eq 1 ]]; then
|
||||
cat ${fileList[@]} > joined.flac
|
||||
else
|
||||
shntool join -O always ${fileList[@]} -o flac
|
||||
if [[ $? -ne 0 ]]; then
|
||||
med_convert wav ${fileList[@]}
|
||||
[[ $? -ne 0 ]] && { echo "Image generation failed with fatal errors"; return 1; }
|
||||
echo ${fileList[@]}
|
||||
fileList=($(printf '%s\n' ${fileList[@]} | sed 's|flac|wav|'))
|
||||
echo ${fileList[@]}
|
||||
shntool join -O always ${fileList[@]} -o flac
|
||||
[[ $? -ne 0 ]] && { echo "Image generation failed with fatal errors"; return 1; }
|
||||
echo "Image generated with non-fatal error"; return 2
|
||||
fi
|
||||
fi
|
||||
echo "Image generated with no errors"; return 0
|
||||
}
|
||||
|
||||
gen_cue() {
|
||||
local FILE_NAME="${1}"
|
||||
local METADATA="${2}"; shift 2
|
||||
local fileList=("${@}")
|
||||
|
||||
# Metadata Parsing
|
||||
metadataList=($(echo ${METADATA} | sed 's|;| |g'))
|
||||
for metadata in ${metadataList[@]}; do
|
||||
eval local ${metadata}
|
||||
done
|
||||
|
||||
for file in ${fileList[@]}; do
|
||||
local trackList=(${trackList[@]} $(echo ${file} | sed 's|.*/||' | awk 'BEGIN{ FS="-"; OFS=":"}{$1=""}{print $0}' | sed 's|: ||'))
|
||||
done
|
||||
|
||||
# Generates breaklist
|
||||
breakList=($(gen_breaklist ${fileList[@]}))
|
||||
|
||||
[[ ! -z "${META_DATE+x}" ]] && echo "REM DATE ${META_DATE}"
|
||||
[[ ! -z "${META_COMPOSER+x}" ]] && echo "PERFORMER \"${META_COMPOSER}\""
|
||||
[[ ! -z "${META_CONDUCTOR+x}" ]] && echo "REM CONDUCTOR \"${META_CONDUCTOR}\""
|
||||
[[ ! -z "${META_ORCHESTRA+x}" ]] && echo "REM ORCHESTRA \"${META_ORCHESTRA}\""
|
||||
[[ ! -z "${META_ARTIST+x}" ]] && echo "PERFORMER \"${META_ARTIST}\""
|
||||
[[ ! -z "${META_ALBUM+x}" ]] && echo "TITLE \"${META_ALBUM}\""
|
||||
echo "FILE \"${FILE_NAME}.flac\" WAVE"
|
||||
local COUNT=0
|
||||
while [[ ${COUNT} -lt ${#breakList[@]} ]]; do
|
||||
[[ ${COUNT} -le 8 ]] && local TRACK_NO="0$(( ${COUNT} + 1 ))" || local TRACK_NO="$(( ${COUNT} + 1 ))"
|
||||
echo " TRACK ${TRACK_NO} AUDIO"
|
||||
echo " TITLE \"${trackList[${COUNT}]}\""
|
||||
echo " INDEX 01 ${breakList[${COUNT}]}"
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
gen_mtag() {
|
||||
local FILE_NAME="${1}"
|
||||
local METADATA="${2}"; shift 2
|
||||
local fileList=("${@}")
|
||||
|
||||
# Metadata Parsing
|
||||
metadataList=($(echo ${METADATA} | sed 's|;| |g'))
|
||||
for metadata in ${metadataList[@]}; do
|
||||
eval local ${metadata}
|
||||
done
|
||||
|
||||
for file in ${fileList[@]}; do
|
||||
local trackList=(${trackList[@]} $(echo ${file} | sed 's|.*/||' | awk 'BEGIN {FS="-"; OFS=":"}{$1=""}{print $0}' | sed 's|: ||'))
|
||||
done
|
||||
echo "["
|
||||
local COUNT=0
|
||||
while [[ ${COUNT} -lt ${#trackList[@]} ]]; do
|
||||
[[ ${COUNT} -ne 0 ]] && echo " },"
|
||||
echo " {"
|
||||
echo " \"@\" : \"${FILE_NAME}.cue|$(( ${COUNT} + 1 ))\","
|
||||
if [[ ${COUNT} -eq 0 ]]; then
|
||||
[[ ! -z "${META_ALBUM+x}" ]] && echo " \"ALBUM\" : \"${META_ALBUM}\","
|
||||
[[ ! -z "${META_ARTIST+x}" ]] && echo " \"ARTIST\" : \"${META_ARTIST}\","
|
||||
[[ ! -z "${META_ALBUMARTIST+x}" ]] && echo " \"ALBUMARTIST\" : \"${META_ALBUMARTIST}\","
|
||||
[[ ! -z "${META_COMPOSER+x}" ]] && echo " \"COMPOSER\" : \"${META_COMPOSER}\","
|
||||
[[ ! -z "${META_CONDUCTOR+x}" ]] && echo " \"CONDUCTOR\" : \"${META_CONDUCTOR}\","
|
||||
[[ ! -z "${META_ORCHESTRA+x}" ]] && echo " \"ORCHESTRA\" : \"${META_ORCHESTRA}\","
|
||||
[[ ! -z "${META_DATE+x}" ]] && echo " \"DATE\" : \"${META_DATE}\","
|
||||
[[ ! -z "${META_GENRE+x}" ]] && echo " \"GENRE\" : \"${META_GENRE}\","
|
||||
[[ ! -z "${META_DISCNUM+x}" ]] && echo " \"DISCNUMBER\" : \"${META_DISCNUM}\","
|
||||
[[ ! -z "${META_DISCTOT+x}" ]] && echo " \"TOTALDISCS\" : \"${META_DISCTOT}\","
|
||||
echo " \"TOTALTRACKS\" : \"${#trackList[@]}\","
|
||||
echo " \"BATCHNUMBER\" : \"0\","
|
||||
fi
|
||||
echo " \"TITLE\" : \"${trackList[${COUNT}]}\","
|
||||
echo " \"TRACKNUMBER\" : \"$(( ${COUNT} + 1 ))\""
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
echo " }"
|
||||
echo "]"
|
||||
return 0
|
||||
}
|
||||
|
||||
gen_metadata() {
|
||||
local FOLDER="${1}"
|
||||
local DISC_NO="${2}"
|
||||
local META_DISCTOT="${3}"
|
||||
local META_GENRE=$(echo ${FOLDER} | cut -d/ -f1)
|
||||
echo -n "META_GENRE=\"${META_GENRE}\";"
|
||||
echo -n "META_DISCTOT=${META_DISCTOT};"
|
||||
echo -n "META_DISCNUM=${DISC_NO};"
|
||||
if [[ "${META_GENRE}" == "Classical" ]] && [[ "$(echo ${FOLDER} | cut -d/ -f5 | cut -d- -f2 | sed 's| ||')" != "" ]]; then
|
||||
echo -n "META_COMPOSER=\"$(echo ${FOLDER} | cut -d/ -f2)\";"
|
||||
echo -n "META_ALBUM=\"$(echo ${FOLDER} | cut -d/ -f3)\";"
|
||||
echo -n "META_CONDUCTR=\"$(echo ${FOLDER} | cut -d/ -f4)\";"
|
||||
echo -n "META_DATE=\"$(echo ${FOLDER} | cut -d/ -f5 | cut -d- -f1 | rev | sed 's| ||' | rev)\";"
|
||||
echo -n "META_ORCHESTRA=\"$(echo ${FOLDER} | cut -d/ -f5 | cut -d- -f2 | sed 's| ||')\";"
|
||||
elif [[ "${META_GENRE}" == "Soundtrack" ]]; then
|
||||
echo -n "META_ALBUM=\"$(echo ${FOLDER} | cut -d/ -f2)\""
|
||||
else
|
||||
echo -n "META_ARTIST=\"$(echo ${FOLDER} | cut -d/ -f2)\";"
|
||||
echo -n "META_DATE=\"$(echo ${FOLDER} | cut -d/ -f3 | cut -d- -f1 | rev | sed 's| ||' | rev)\";"
|
||||
echo -n "META_ALBUM=\"$(echo ${FOLDER} | cut -d/ -f3 | sed 's|.*\ -\ ||')\";"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
gen_cover() {
|
||||
local FOLDER="${1}"
|
||||
[[ -f "${FOLDER}/full_cover.tiff" ]] && local IMAGE="full_cover.tiff" || local IMAGE="cover.jpg"
|
||||
convert "${FOLDER}/${IMAGE}" jpeg:-
|
||||
return 0
|
||||
}
|
||||
|
||||
gen() {
|
||||
local ROOT="${1}"
|
||||
local SUBFOL="${2}"
|
||||
local FOLDER="${ROOT}/${SUBFOL}"
|
||||
local CDCOUNT="$(cdcount "${FOLDER}")"
|
||||
local COUNT=1
|
||||
local SOURCE=FLAC
|
||||
|
||||
while [[ ${COUNT} -le ${CDCOUNT} ]]; do
|
||||
|
||||
# Generates file list depending on CD count
|
||||
if [[ "${CDCOUNT}" == 1 ]]; then
|
||||
local fileList=($(find "${FOLDER}"/* \( -name '*.flac' -or -name '*.mp3' -or -name '*.wav' \) -printf '%p\t'))
|
||||
else
|
||||
local fileList=($(find "${FOLDER}"/${COUNT}.* \( -name '*.flac' -or -name '*.mp3' \) -printf '%p\t'))
|
||||
fi
|
||||
|
||||
if ismp3 ${fileList[@]}; then
|
||||
_msg EXEC "Converting MP3 files to FLAC"
|
||||
med_convert flac ${fileList[@]} >${STDERR} 2>&1
|
||||
[[ $? -eq 0 ]] && _msg OK || _msg WARN
|
||||
local SOURCE=MP3
|
||||
fi
|
||||
[[ "${SOURCE}" == "MP3" ]] && local fileList=($(printf "%s\t" ${fileList[@]} | sed 's|mp3|flac|g'))
|
||||
|
||||
# Generates image
|
||||
_msg EXEC "Generating data for ${FOLDER} disk ${COUNT} of ${CDCOUNT}"
|
||||
gen_image ${fileList[@]} >${STDERR} 2>&1
|
||||
local EXIT="$?"
|
||||
if [[ ${EXIT} -eq 0 ]]; then
|
||||
_msg OK
|
||||
elif [[ ${EXIT} -eq 2 ]]; then
|
||||
_msg WARN
|
||||
else
|
||||
_msg FAIL
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
continue
|
||||
fi
|
||||
|
||||
# Determines file name based on image's CHKSUM and acts accordingly
|
||||
metaflac --remove-all --dont-use-padding joined.flac
|
||||
local SHA256=$(sha256sum joined.flac | cut -d' ' -f1)
|
||||
local FILE_NAME=$(file_name ${SOURCE} ${SHA256})
|
||||
mv joined.flac ${FILE_NAME}.flac
|
||||
|
||||
# Generates METADATA, CUE and MTAG
|
||||
_msg EXEC "Generating metadata for ${FOLDER} disk ${COUNT} of ${CDCOUNT}"
|
||||
local METADATA="$(gen_metadata "${SUBFOL}" ${COUNT} ${CDCOUNT})"
|
||||
gen_cue "${FILE_NAME}" ${METADATA} ${fileList[@]} > ${FILE_NAME}.cue
|
||||
[[ $? -ne 0 ]] && _msg WARN
|
||||
addbom ${FILE_NAME}.cue
|
||||
gen_mtag "${FILE_NAME}" ${METADATA} ${fileList[@]} > ${FILE_NAME}.tags
|
||||
[[ $? -ne 0 ]] && _msg WARN
|
||||
addbom ${FILE_NAME}.tags
|
||||
gen_cover "${FOLDER}" > ${FILE_NAME}.jpg
|
||||
[[ $? -ne 0 ]] && _msg WARN || _msg OK
|
||||
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
|
||||
ROOT="${1}"; shift 1
|
||||
dirList=("${@}")
|
||||
for dir in ${dirList[@]}; do
|
||||
folderList=($(find ${ROOT}/${dir} -name '*cover*' -printf '%h\n' | awk '!seen[$0]++' | sed "s|${ROOT}/||g"))
|
||||
for folder in ${folderList[@]}; do
|
||||
gen ${ROOT} "${folder}"
|
||||
#echo ${folder}
|
||||
done
|
||||
done
|
Loading…
Reference in a new issue