mirror of
https://github.com/levogevo/add-synced-lyrics.git
synced 2026-07-21 21:45:21 +00:00
switch to dedicated echo_ functions
This commit is contained in:
@@ -58,14 +58,18 @@ process_inputs() {
|
|||||||
download_with_deezer
|
download_with_deezer
|
||||||
)
|
)
|
||||||
|
|
||||||
for input in "${INPUTS[@]}"; do
|
local numInputs="${#INPUTS[@]}"
|
||||||
|
for ((i = 0; i < numInputs; i++)); do
|
||||||
if [[ ${IGNORE} == false && ${ret} -ne 0 ]]; then
|
if [[ ${IGNORE} == false && ${ret} -ne 0 ]]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local input="${INPUTS[${i}]}"
|
||||||
|
echo_info "processing $((i + 1))/${numInputs}: ${input}"
|
||||||
|
|
||||||
if [[ "${input,,}" == *'instrumental'* ||
|
if [[ "${input,,}" == *'instrumental'* ||
|
||||||
"${input,,}" == *'acoustic'* ]]; then
|
"${input,,}" == *'acoustic'* ]]; then
|
||||||
echo "${input} is instrumental, skipping"
|
echo_pass "${input} is instrumental, skipping"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -74,13 +78,13 @@ process_inputs() {
|
|||||||
|
|
||||||
if [[ -f "${output}" ]]; then
|
if [[ -f "${output}" ]]; then
|
||||||
if is_valid_lrc "${output}"; then
|
if is_valid_lrc "${output}"; then
|
||||||
|
echo_pass "${input} already has lyrics, skipping"
|
||||||
continue
|
continue
|
||||||
else
|
else
|
||||||
rm "${output}" || return 1
|
rm "${output}" || return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "processing ${input}"
|
|
||||||
isrc=''
|
isrc=''
|
||||||
if ! isrc="$(get_file_isrc "${input}")"; then
|
if ! isrc="$(get_file_isrc "${input}")"; then
|
||||||
ret=1
|
ret=1
|
||||||
@@ -101,11 +105,11 @@ process_inputs() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if ! void test -f "${output}"; then
|
if ! void test -f "${output}"; then
|
||||||
echo "failed to get lyrics for ${input}"
|
echo_fail "could not find lyrics for ${input}"
|
||||||
ret=1
|
ret=1
|
||||||
continue
|
continue
|
||||||
else
|
else
|
||||||
void echo "added lyrics for ${input}"
|
void echo_pass "added lyrics for ${input}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
+39
-20
@@ -20,29 +20,48 @@ jq_result_valid() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
stderr() { echo "$*" 1>&2; }
|
# ANSI colors
|
||||||
info() { stderr "INFO [${FUNCNAME[1]}]: $*"; }
|
readonly RED='\e[0;31m'
|
||||||
error() { stderr "ERROR [${FUNCNAME[1]}]: $*"; }
|
readonly GREEN='\e[0;32m'
|
||||||
|
readonly PURPLE='\e[0;35m'
|
||||||
|
readonly YELLOW='\e[0;33m'
|
||||||
|
readonly CYAN='\e[0;36m'
|
||||||
|
readonly NC='\e[0m'
|
||||||
|
|
||||||
# only echo "$@" if ${DEBUG} is true
|
stderr() {
|
||||||
|
local word="${WORD:-}"
|
||||||
|
local color="${COLOR:-}"
|
||||||
|
local function="${FUNCNAME[2]}"
|
||||||
|
if [[ "${function}" =~ void ]]; then
|
||||||
|
function="${FUNCNAME[3]}"
|
||||||
|
fi
|
||||||
|
echo \
|
||||||
|
-e \
|
||||||
|
"${color}${word}${NC}" \
|
||||||
|
"[${function}]" \
|
||||||
|
"$@" 1>&2
|
||||||
|
}
|
||||||
|
echo_info() { WORD=INFO COLOR="${CYAN}" stderr "$@"; }
|
||||||
|
echo_fail() { WORD=FAIL COLOR="${RED}" stderr "$@"; }
|
||||||
|
echo_pass() { WORD=PASS COLOR="${GREEN}" stderr "$@"; }
|
||||||
|
echo_dbug() { WORD=DBUG COLOR="${PURPLE}" stderr "$@"; }
|
||||||
|
|
||||||
|
# only perform the command given if ${DEBUG} is enabled
|
||||||
debug() {
|
debug() {
|
||||||
if [[ ${DEBUG} == false ]]; then
|
if [[ ${DEBUG} == false ]]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
stderr "$@"
|
"$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# do not do anything
|
# only perform the command given if ${DRY_RUN} is enabled
|
||||||
# if ${DRY_RUN} is enabled
|
|
||||||
void() {
|
void() {
|
||||||
local cmd=("$@")
|
|
||||||
if [[ ${DRY_RUN} == true ]]; then
|
if [[ ${DRY_RUN} == true ]]; then
|
||||||
return 0
|
return 0
|
||||||
else
|
|
||||||
"${cmd[@]}"
|
|
||||||
return $?
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
"$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# print out "$@" formatted for bash
|
# print out "$@" formatted for bash
|
||||||
@@ -80,7 +99,7 @@ check_required_utils() {
|
|||||||
local missing=false
|
local missing=false
|
||||||
for util in "${utils[@]}"; do
|
for util in "${utils[@]}"; do
|
||||||
if ! have_cmd "${util}"; then
|
if ! have_cmd "${util}"; then
|
||||||
error "missing ${util}!"
|
echo_fail "missing ${util}!"
|
||||||
missing=true
|
missing=true
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -127,8 +146,8 @@ create_tmp_dir() {
|
|||||||
check_tmp_dir_empty() {
|
check_tmp_dir_empty() {
|
||||||
for f in "${TMPDIR}"/*; do
|
for f in "${TMPDIR}"/*; do
|
||||||
if [[ -f "${f}" ]]; then
|
if [[ -f "${f}" ]]; then
|
||||||
error "tempdir ${TMPDIR} is not empty!"
|
echo_fail "tempdir ${TMPDIR} is not empty!"
|
||||||
error "aborting operation"
|
echo_fail "aborting operation"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -157,7 +176,7 @@ librelyrics_dl() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [[ ${librelyricsRet} -eq 0 && -z ${downloadedFile} ]]; then
|
if [[ ${librelyricsRet} -eq 0 && -z ${downloadedFile} ]]; then
|
||||||
error "failed to download file for ${url} despite no librelyrics error"
|
echo_fail "failed to download file for ${url} despite no librelyrics error"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -168,7 +187,7 @@ librelyrics_dl() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ${librelyricsRet} -eq 0 && -z ${fileContents} ]]; then
|
if [[ ${librelyricsRet} -eq 0 && -z ${fileContents} ]]; then
|
||||||
error "failed to read file for ${url} despite no librelyrics error"
|
echo_fail "failed to read file for ${url} despite no librelyrics error"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -181,7 +200,7 @@ download_with_librelyrics() {
|
|||||||
local urlType="$3"
|
local urlType="$3"
|
||||||
|
|
||||||
if [[ ! "${urlType}" =~ spotify|deezer ]]; then
|
if [[ ! "${urlType}" =~ spotify|deezer ]]; then
|
||||||
error "only spotify|deezer are supported"
|
echo_fail "only spotify|deezer are supported"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -194,11 +213,11 @@ download_with_librelyrics() {
|
|||||||
"${url}")"
|
"${url}")"
|
||||||
|
|
||||||
if [[ -z "${lyrics}" ]]; then
|
if [[ -z "${lyrics}" ]]; then
|
||||||
error "could not get lyrics for ${isrc} using ${urlType}"
|
debug echo_fail "could not find lyrics for ${isrc} using ${urlType}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "found lyrics for ${isrc} with ${urlType}"
|
debug echo_info "found lyrics for ${isrc} with ${urlType}"
|
||||||
echo "${lyrics}" >"${output}"
|
echo "${lyrics}" >"${output}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +247,7 @@ get_file_isrc() {
|
|||||||
jqResult="$(jq -r "${jqFilter}" <<<"${probe}")"
|
jqResult="$(jq -r "${jqFilter}" <<<"${probe}")"
|
||||||
|
|
||||||
if [[ "${jqResult}" == 'null' ]]; then
|
if [[ "${jqResult}" == 'null' ]]; then
|
||||||
error "failed to find ISRC for ${file}"
|
echo_fail "could not find ISRC for ${file}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
echo "${jqResult}"
|
echo "${jqResult}"
|
||||||
|
|||||||
+3
-3
@@ -6,7 +6,7 @@
|
|||||||
get_deezer_isrc_response() {
|
get_deezer_isrc_response() {
|
||||||
local isrc="$1"
|
local isrc="$1"
|
||||||
if [[ -z "${isrc}" ]]; then
|
if [[ -z "${isrc}" ]]; then
|
||||||
error "missing isrc"
|
echo_fail "missing isrc"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ get_deezer_isrc_response() {
|
|||||||
get_deezer_url() {
|
get_deezer_url() {
|
||||||
local isrc="$1"
|
local isrc="$1"
|
||||||
if [[ -z "${isrc}" ]]; then
|
if [[ -z "${isrc}" ]]; then
|
||||||
error "missing isrc"
|
echo_fail "missing isrc"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ get_deezer_url() {
|
|||||||
jqResult="$(jq -r .link <<<"${deezerResponse}")"
|
jqResult="$(jq -r .link <<<"${deezerResponse}")"
|
||||||
|
|
||||||
if ! jq_result_valid "${jqResult}"; then
|
if ! jq_result_valid "${jqResult}"; then
|
||||||
error "could not get link from deezer for ${isrc}"
|
echo_fail "could not find link from deezer for ${isrc}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -19,11 +19,11 @@ get_lrclib_api_response() {
|
|||||||
IFS=' ' read -r env jqFilter <<<"${data}"
|
IFS=' ' read -r env jqFilter <<<"${data}"
|
||||||
jqResult="$(jq -r "${jqFilter}" <<<"${deezerResponse}")"
|
jqResult="$(jq -r "${jqFilter}" <<<"${deezerResponse}")"
|
||||||
if ! jq_result_valid "${jqResult}"; then
|
if ! jq_result_valid "${jqResult}"; then
|
||||||
error "could not determine lrclib ${env} for ${isrc}"
|
echo_fail "could not determine lrclib ${env} for ${isrc}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
declare "${env}=${jqResult}"
|
declare "${env}=${jqResult}"
|
||||||
debug "${env}=${jqResult}"
|
debug echo_debug "${env}=${jqResult}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# variables assigned above
|
# variables assigned above
|
||||||
@@ -48,7 +48,7 @@ download_with_lrclib() {
|
|||||||
lrclibResponse="$(get_lrclib_api_response "${isrc}")"
|
lrclibResponse="$(get_lrclib_api_response "${isrc}")"
|
||||||
syncedLyrics="$(jq -r .syncedLyrics <<<"${lrclibResponse}")"
|
syncedLyrics="$(jq -r .syncedLyrics <<<"${lrclibResponse}")"
|
||||||
if ! jq_result_valid "${syncedLyrics}"; then
|
if ! jq_result_valid "${syncedLyrics}"; then
|
||||||
error "could not get lyrics for ${isrc}"
|
debug echo_fail "could not find lyrics for ${isrc}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -6,7 +6,7 @@
|
|||||||
get_spotify_url() {
|
get_spotify_url() {
|
||||||
local isrc="$1"
|
local isrc="$1"
|
||||||
if [[ -z "${isrc}" ]]; then
|
if [[ -z "${isrc}" ]]; then
|
||||||
error "missing isrc"
|
echo_fail "missing isrc"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ get_spotify_url() {
|
|||||||
|
|
||||||
for tag in "${tags[@]}"; do
|
for tag in "${tags[@]}"; do
|
||||||
declare -n spotifyTagValue="${tag}"
|
declare -n spotifyTagValue="${tag}"
|
||||||
debug "${tag}=${spotifyTagValue}"
|
debug echo_debug "${tag}=${spotifyTagValue}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
@@ -52,7 +52,7 @@ get_spotify_url() {
|
|||||||
done <<<"${jqOutput}"
|
done <<<"${jqOutput}"
|
||||||
|
|
||||||
if [[ "${foundMatching}" == false ]]; then
|
if [[ "${foundMatching}" == false ]]; then
|
||||||
error "could not find matching spotify track for ${isrc}"
|
debug echo_fail "could not find matching spotify track for ${isrc}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user