[cmd_import_tracks] Does not convert MP3 to FLAC automatically

[import_track] Now handles conversion of non-flac audio files
This commit is contained in:
ayakael 2018-05-18 16:29:02 -07:00
parent d77ee127c8
commit 3ff8d2f4b8
No known key found for this signature in database
GPG key ID: 575626A4AE5F4026
2 changed files with 15 additions and 9 deletions

View file

@ -26,12 +26,6 @@ cmd_import_tracks() {
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=$?

View file

@ -19,7 +19,8 @@ import_track() {
local GIT_DIR="${1}"
local TRACK="${2}"
local DIR_NAME="$(dirname \"${TRACK}\")"
local SOURCE="FLAC"
# Cover image finder
local coverList=($(find "${DIR_NAME}" -maxdepth 1 -name '*.jpg' -o -name '*.png' -print '%p\t'))
@ -29,7 +30,7 @@ import_track() {
eval local ${metadata}
done
# Setting TARGET_DIT
# Setting TARGET_DIR
[[ -z "${DISCNUMBER}" ]] && local DISCNUMBER=1
local TARGET_DIR="${GIT_DIR}/.import/${ARTIST}--${ALBUM}--$(printf '%02d' ${DISCNUMBER})"
mkdir -p ${TARGET_DIR}
@ -41,8 +42,19 @@ import_track() {
convert ${coverList[@]} "${TARGET_DIR}/folder.png"
fi
# Converting to FLAC if need me
local TRACK_EXT="$(echo "${TRACK}" | sed 's|.*\.||' | tr "[a-z]" "[A-Z]")"
if [[ "${TRACK_EXT}" != "FLAC" ]]; then
echo "Converting ${TRACK} to FLAC format"
med_convert flac ${TRACK}
local EXIT=$?
[[ ${EXIT} -eq 0 ]] || return 1
local SOURCE="${TRACK_EXT}"
fi
# Moving track to TARGET_DIR
mv "${TRACK}" "${TARGET_DIR}/$(printf %02d ${TRACKNUMBER}).flac" >${STDERR} 2>&1
echo "Moving ${TRACK} to ${TARGET_DIR}"
mv "${TRACK}" "${TARGET_DIR}/$(printf %02d ${TRACKNUMBER}).${SOURCE}.flac"
local EXIT=$?
[[ ${EXIT} -eq 0 ]] && return 0 || return 1
}