[cmd_import] Updated documentation
[cmd_import_tracks] Rewrote function to accomodate fragmented files [cmd_import_images] Renamed cmd_import_cueripper to cmd_import_images in preparation for rewri te of import_images functions [gen_cue] Adjusted variable names to fit actual output of print_meta functions [gen_image] Removed error messages in favor of exit codes [gen_mtag] Rewrote to accomodate multiple track files. [import_dir] Added to deal with importing directories after consolidation by import_track [import_cueripper] Renamed to import_images in preparation for rewrite [import_track] Added to deal with consolidation of disparate track files [import_tracks] Removed in favor of import_track and import_dir functions [iszip] Added as an easy way to see if zip file [print_meta_track] Renamed function
This commit is contained in:
parent
7b9f56f5d3
commit
35fbaad084
12 changed files with 183 additions and 136 deletions
|
@ -9,18 +9,12 @@
|
|||
# cmd_import <source> </path/to/git/dir> </path/to/import/dir> [<...>]
|
||||
#
|
||||
# SOURCES
|
||||
# cueripper Files generated by cueripper. Organized using following format:
|
||||
# batch_<no>/<artist> - <album>/<disk_no>.<ext>
|
||||
# Cover image is going to found under same folder and named "folder.jpg"
|
||||
# images Import images into git repository. Image file must be accompanied
|
||||
# by cue sheet of the same name in folder. Will also import any
|
||||
# accompanying .log, .accurip, .jpg file barring they share the same
|
||||
# name.
|
||||
#
|
||||
# eac Files generated by EAC. Organized using following format:
|
||||
# batch_<no>/<artist> - <album>/disc_no>.<ext>
|
||||
# Cover image is going to found under same folder and named "folder.jpg"
|
||||
#
|
||||
# tracks Flac datafiles organized using following format:
|
||||
# <genre>/<artist>/<date> - <album>/<disk_no>.<track_no> - <track title>.<ext>
|
||||
# Cover image is going to found under same folder and named "cover.jpg"
|
||||
#
|
||||
# tracks Import tracks, or archive containing tracks, into git directory
|
||||
#
|
||||
|
||||
cmd_import() {
|
||||
|
|
|
@ -6,17 +6,43 @@
|
|||
# cmd_import_tracks - Wrapper for import_tracks
|
||||
#
|
||||
# USAGE
|
||||
# cmd_import_tracks </path/to/work/dir> <subpath/to/album>
|
||||
# cmd_import_tracks </path/to/git/dir> </path/to/dir_or_archive>
|
||||
#
|
||||
# }
|
||||
|
||||
cmd_import_tracks() {
|
||||
local ROOT="${1}"; shift 1
|
||||
local 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
|
||||
import_tracks ${ROOT} "${folder}"
|
||||
local GIT_DIR="${1}"; shift
|
||||
local srcList=(${@})
|
||||
|
||||
for src in ${srcList}; do
|
||||
if iszip ${src}; then
|
||||
_msg EXEC "Uncompressing ${archive}"
|
||||
7z x "${src}" -o"${_OPT_TMP}/${src}/" >${STDERR} 2>&1
|
||||
local EXIT=$?
|
||||
[[ ${EXIT} -eq 0 ]] && { _msg OK; local src="${_OPT_TMP}/${src}"; } || _msg WARN
|
||||
fi
|
||||
local fileList=($(find "${src}" -name '*.flac' -o -name '*.mp3'))
|
||||
|
||||
for file in ${fileList}; do
|
||||
if ismp3 ${file}; then
|
||||
_msg EXEC "Converting ${file} to FLAC format"
|
||||
med_convert flac ${file}
|
||||
local EXIT=$?
|
||||
[[ ${EXIT} -eq 0 ]] && _msg OK || { _msg WARN "Conversion of ${file} failed, continuing"; continue; }
|
||||
fi
|
||||
_msg EXEC "Consolidating ${file}"
|
||||
import_track "${GIT_DIR}" "${file}"
|
||||
local EXIT=$?
|
||||
[[ ${EXIT} -eq 0 ]] && _msg OK || { _msg WARN "Consolidation of ${file} failed, continuing"; continue; }
|
||||
done
|
||||
done
|
||||
|
||||
local importList=($(find ${GIT_DIR}/.import/ -maxdepth 1 -type d -print '%p\t'))
|
||||
for import in ${importList[@]}; do
|
||||
_msg EXEC "Importing ${import}"
|
||||
import_dir "${GIT_DIR}" "${import}"
|
||||
local EXIT=$?
|
||||
[[ ${EXIT} -eq 0 ]] && _msg OK || { _msg WARN "Importation of ${import} failed, continuing"; continue; }
|
||||
done
|
||||
|
||||
}
|
||||
|
|
12
src/gen_cue
12
src/gen_cue
|
@ -28,12 +28,12 @@ gen_cue() {
|
|||
# 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}\""
|
||||
[[ ! -z "${DATE+x}" ]] && echo "REM DATE ${DATE}"
|
||||
[[ ! -z "${COMPOSER+x}" ]] && echo "PERFORMER \"${COMPOSER}\""
|
||||
[[ ! -z "${CONDUCTOR+x}" ]] && echo "REM CONDUCTOR \"${CONDUCTOR}\""
|
||||
[[ ! -z "${ORCHESTRA+x}" ]] && echo "REM ORCHESTRA \"${ORCHESTRA}\""
|
||||
[[ ! -z "${ARTIST+x}" ]] && echo "PERFORMER \"${ARTIST}\""
|
||||
[[ ! -z "${ALBUM+x}" ]] && echo "TITLE \"${ALBUM}\""
|
||||
echo "FILE \"${FILE_NAME}.flac\" WAVE"
|
||||
local COUNT=0
|
||||
while [[ ${COUNT} -lt ${#breakList[@]} ]]; do
|
||||
|
|
|
@ -18,15 +18,15 @@ gen_image() {
|
|||
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; }
|
||||
[[ $? -ne 0 ]] && 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
|
||||
[[ $? -ne 0 ]] && return 1
|
||||
return 2
|
||||
fi
|
||||
fi
|
||||
echo "Image generated with no errors"; return 0
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
78
src/gen_mtag
78
src/gen_mtag
|
@ -6,49 +6,57 @@
|
|||
# gen_mtag - Generates mtag output based on output from print_meta_cue
|
||||
#
|
||||
# USAGE
|
||||
# gen_mtag <output from file_name> <output from print_meta_cue>
|
||||
# gen_mtag <print_meta_flac-output-track-1> <print_meta_flac-output-track-2> <...>
|
||||
#
|
||||
# }
|
||||
|
||||
gen_mtag() {
|
||||
local FILE_NAME="${1}"
|
||||
local METADATA="${2}"
|
||||
local metadata_trackList=(${@})
|
||||
|
||||
# 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 "["
|
||||
# Generates list of tags to be parsed
|
||||
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 ))\""
|
||||
for metadata_track in ${metadata_trackList[@]}; do
|
||||
local tagList[${COUNT}]=($(awk 'BEGIN{RS=";";FS="="}{print $1";"}' <<< ${metadata_track}))
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
echo " }"
|
||||
echo "]"
|
||||
local tagList=($(tr ';' \\n <<< ${tagList[@]} | awk '!seen[$0]++'))
|
||||
|
||||
|
||||
# Header echo
|
||||
echo "["
|
||||
|
||||
# Track echo
|
||||
local COUNT=0
|
||||
for metadata_trackList in ${metadata_trackList[@]}; do
|
||||
|
||||
# Track header and file name
|
||||
local FILE_NAME=$(awk -v tag="IMAGEID" 'BEGIN{RS=";";FS="=";}{if($1=tag){print $2}}' <<< ${metadata_track})
|
||||
echo -e " {\n \"@\" : \"${FILE_NAME}.cue|$(( ${COUNT} + 1 ))\","
|
||||
|
||||
# Tag loop
|
||||
for tag in ${tagList[@]}; do
|
||||
|
||||
# Determines current tag value
|
||||
local CUR_TAG=$(awk -v tag="${tag}" 'BEGIN{RS=";";FS="=";}{if($1=tag){print $2}}' <<< ${metadata_track})
|
||||
|
||||
# Determines previous tag value
|
||||
local PREV_TAG=$(awk -v tag="${tag}" 'BEGIN{RS=";";FS="=";}{if($1=tag){print $2}}' <<< ${metadata_trackList[$(( ${COUNT} - 1 ))]})
|
||||
|
||||
# Compares previous tag value and current tag value. If there is a difference or we're dealing with the first track,
|
||||
# print the value in MTAG format
|
||||
if [[ "${CUR_TAG}" != "${PREV_TAG}" ]] || [[ ${COUNT} -eq 0 ]]; then
|
||||
echo -n " \"${tag}\" : \"${CUR_TAG}\""
|
||||
[[ "${tag}" != "${tagList[-1]}" ]] && echo ";" || echo
|
||||
fi
|
||||
done
|
||||
# Track footer
|
||||
echo " }"
|
||||
|
||||
local COUNT=$(( ${COUNT} + 1 ))
|
||||
done
|
||||
|
||||
# Footer echo
|
||||
echo -e " }\n]"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
23
src/import_dir
Normal file
23
src/import_dir
Normal file
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc import_dir {
|
||||
#
|
||||
# DESCRIPTION
|
||||
# import_dir - Imports consolidated tracks into git repository
|
||||
#
|
||||
# USAGE
|
||||
# import_dir </path/to/git/dir> </path/to/track/dir>
|
||||
#
|
||||
# }
|
||||
|
||||
import_dir() {
|
||||
local GIT_DIR="${1}"
|
||||
local TRACK_DIR="${2}"
|
||||
|
||||
local trackList=($(find ${TRACK_DIR} -maxdepth=1 -name *.flac -print '%p\t'))
|
||||
|
||||
for track in ${trackList[@]}; do
|
||||
|
||||
done
|
||||
|
||||
}
|
46
src/import_track
Normal file
46
src/import_track
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc import_track {
|
||||
#
|
||||
# DESCRIPTION
|
||||
# import_track - Consolidates track of .import subdirectory in git repository
|
||||
# in ARTIST--ALBUM--DISCNUMBER subfolder, to then import later. This is done
|
||||
# to allow the possibility of importing tracks that are a part of the same
|
||||
# album, but are found in different directories..
|
||||
#
|
||||
# USAGE
|
||||
# import_track </path/to/git/dir> </path/to/track>
|
||||
#
|
||||
# }
|
||||
|
||||
import_track() {
|
||||
local GIT_DIR="${1}"
|
||||
local TRACK="${2}"
|
||||
local DIR_NAME="$(dirname \"${TRACK}\")"
|
||||
|
||||
# Cover image finder
|
||||
local coverList=($(find "${DIR_NAME}" -maxdepth 1 -name '*.jpg' -o -name '*.png' -print '%p\t'))
|
||||
|
||||
# Metadata parsing
|
||||
local metadataList=($(print_meta_flac ${TRACK}) | sed 's|;| |g' )
|
||||
for metadata in ${metadataList[@]}; do
|
||||
eval local ${metadata}
|
||||
done
|
||||
|
||||
# Setting TARGET_DIT
|
||||
[[ -z "${DISCNUMBER}" ]] && local DISCNUMBER=1
|
||||
local TARGET_DIR="${GIT_DIR}/.import/${ARTIST}--${ALBUM}--$(printf '%02d' ${DISCNUMBER})"
|
||||
mkdir -p ${TARGET_DIR}
|
||||
[[ ${EXIT} -eq 0 ]] || return 1
|
||||
|
||||
|
||||
# Moving cover to TARGET_DIR
|
||||
if [[ ${#coverList[@]} -eq 1 ]] && [[ ! -f "${TARGET_DIR}/folder.png" ]]; then
|
||||
convert ${coverList[@]} "${TARGET_DIR}/folder.png"
|
||||
fi
|
||||
|
||||
# Moving track to TARGET_DIR
|
||||
mv "${TRACK}" "${TARGET_DIR}/$(printf %02d ${TRACKNUMBER}).flac" >${STDERR} 2>&1
|
||||
local EXIT=$?
|
||||
[[ ${EXIT} -eq 0 ]] && return 0 || return 1
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc import_tracks
|
||||
#
|
||||
# DESCRIPTION
|
||||
# import_tracks - Import tracks into git directory
|
||||
#
|
||||
# USAGE
|
||||
# import_tracks "</path/to/work/dir> <subpath/to/album>
|
||||
#
|
||||
# }
|
||||
|
||||
import_tracks() {
|
||||
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
|
||||
|
||||
}
|
21
src/iszip
Normal file
21
src/iszip
Normal file
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
# doc iszip {
|
||||
#
|
||||
# DESCRIPTION
|
||||
# iszip - Returns true if any file present is a zip file.
|
||||
#
|
||||
# USAGE
|
||||
# iszip <files>
|
||||
#
|
||||
# }
|
||||
|
||||
iszip() {
|
||||
local fileList=("${@}")
|
||||
for file in ${fileList[@]}; do
|
||||
local FILE_EXT="$(echo "${file}" | sed 's|.*\.||')"
|
||||
[[ "${FILE_EXT}" == "zip" ]] && local ZIP=0 || local ZIP=1
|
||||
done
|
||||
[[ ${ZIP} -eq 0 ]] && return 0 || return 1
|
||||
}
|
||||
|
|
@ -10,6 +10,8 @@
|
|||
#
|
||||
# }
|
||||
|
||||
print_meta_tracks
|
||||
|
||||
gen_metadata() {
|
||||
local FOLDER="${1}"
|
||||
local DISC_NO="${2}"
|
||||
|
|
Loading…
Reference in a new issue