Compare commits

..

No commits in common. "361d338db2e55e90c2db7e0ab3e0738e1ebf2457" and "ceb06b640f15d3993214579e8af68a601ba18a3e" have entirely different histories.

6 changed files with 393 additions and 276 deletions

View file

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
scriptVersion="1.2"
scriptName="ArtworkExtractor" scriptName="ArtworkExtractor"
#### Import Settings #### Import Settings

View file

@ -1,59 +1,38 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bash
scriptVersion="2.48"
set -euo pipefail
while [[ $# -gt 0 ]]; do
case $1 in
--state-dir)
STATE_DIR="$2"
shift
shift
;;
--runtime-dir)
RUNTIME_DIR="$2"
shift
shift
;;
*)
echo "Unknown option $1"
exit 1
;;
esac
done
scriptName="Audio" scriptName="Audio"
### Import Settings ### Import Settings
# shellcheck source=./extended.conf source /config/extended.conf
source "${STATE_DIR}/lidarr-dl.conf"
#### Import Functions #### Import Functions
source ../universal/functions.bash source /config/extended/functions
AddTag () { AddTag () {
log "adding arr-extended tag" log "adding arr-extended tag"
lidarrProcessIt=$(curl -s "$arrUrl/api/v1/tag" --header "X-Api-Key:" "${arrApiKey}" -H "Content-Type: application/json" --data-raw '{"label":"arr-extended"}') lidarrProcessIt=$(curl -s "$arrUrl/api/v1/tag" --header "X-Api-Key:"${arrApiKey} -H "Content-Type: application/json" --data-raw '{"label":"arr-extended"}')
} }
AddDownloadClient () { AddDownloadClient () {
downloadClientsData=$(curl -s "$arrUrl/api/v1/downloadclient" --header "X-Api-Key:" "${arrApiKey}" -H "Content-Type: application/json") downloadClientsData=$(curl -s "$arrUrl/api/v1/downloadclient" --header "X-Api-Key:"${arrApiKey} -H "Content-Type: application/json")
downloadClientCheck="$(echo "$downloadClientsData" | grep "Arr-Extended")" downloadClientCheck="$(echo $downloadClientsData | grep "Arr-Extended")"
if [ -z "$downloadClientCheck" ]; then if [ -z "$downloadClientCheck" ]; then
AddTag AddTag
if [ ! -d "$importPath" ]; then if [ ! -d "$importPath" ]; then
mkdir -p "$importPath" mkdir -p "$importPath"
chmod 777 -R "$importPath"
fi fi
log "Adding download Client" log "Adding download Client"
lidarrProcessIt=$(curl -s "$arrUrl/api/v1/downloadclient" --header "X-Api-Key:" "${arrApiKey}" -H "Content-Type: application/json" --data-raw "{\"enable\":true,\"protocol\":\"usenet\",\"priority\":10,\"removeCompletedDownloads\":true,\"removeFailedDownloads\":true,\"name\":\"Arr-Extended\",\"fields\":[{\"name\":\"nzbFolder\",\"value\":\"$importPath\"},{\"name\":\"watchFolder\",\"value\":\"$importPath\"}],\"implementationName\":\"Usenet Blackhole\",\"implementation\":\"UsenetBlackhole\",\"configContract\":\"UsenetBlackholeSettings\",\"infoLink\":\"https://wiki.servarr.com/lidarr/supported#usenetblackhole\",\"tags\":[]}") lidarrProcessIt=$(curl -s "$arrUrl/api/v1/downloadclient" --header "X-Api-Key:"${arrApiKey} -H "Content-Type: application/json" --data-raw "{\"enable\":true,\"protocol\":\"usenet\",\"priority\":10,\"removeCompletedDownloads\":true,\"removeFailedDownloads\":true,\"name\":\"Arr-Extended\",\"fields\":[{\"name\":\"nzbFolder\",\"value\":\"$importPath\"},{\"name\":\"watchFolder\",\"value\":\"$importPath\"}],\"implementationName\":\"Usenet Blackhole\",\"implementation\":\"UsenetBlackhole\",\"configContract\":\"UsenetBlackholeSettings\",\"infoLink\":\"https://wiki.servarr.com/lidarr/supported#usenetblackhole\",\"tags\":[]}")
fi fi
} }
verifyConfig () { verifyConfig () {
### Import Settings ### Import Settings
# shellcheck source=./extended.conf source /config/extended.conf
source "${STATE_DIR}/lidarr-dl.conf"
if [ "$enableAudio" != "true" ]; then if [ "$enableAudio" != "true" ]; then
log "Script is not enabled, enable by setting enableAudio to \"true\" by modifying the \"/config/extended.conf\" config file..." log "Script is not enabled, enable by setting enableAudio to \"true\" by modifying the \"/config/extended.conf\" config file..."
exit 0 log "Sleeping (infinity)"
sleep infinity
fi fi
if [ -z "$audioScriptInterval" ]; then if [ -z "$audioScriptInterval" ]; then
@ -101,13 +80,32 @@ Configuration () {
sleepTimer=0.5 sleepTimer=0.5
tidaldlFail=0 tidaldlFail=0
deemixFail=0 deemixFail=0
log "-----------------------------------------------------------------------------"
log " |~) _ ._ _| _ ._ _ |\ |o._ o _ |~|_|_|"
log " |~\(_|| |(_|(_)| | || \||| |_|(_||~| | |<"
log " Presents: $scriptName ($scriptVersion)"
log " May the beats be with you!"
log "-----------------------------------------------------------------------------"
log "Donate: https://github.com/sponsors/RandomNinjaAtk"
log "Project: https://github.com/RandomNinjaAtk/arr-scripts"
log "Support: https://github.com/RandomNinjaAtk/arr-scripts/discussions"
log "-----------------------------------------------------------------------------"
sleep 5 sleep 5
log ""
log "Lift off in..."; sleep 0.5
log "5"; sleep 1
log "4"; sleep 1
log "3"; sleep 1
log "2"; sleep 1
log "1"; sleep 1
if [ ! -d "${STATE_DIR}/xdg" ]; then
mkdir -p "${STATE_DIR}/xdg"
if [ ! -d /config/xdg ]; then
mkdir -p /config/xdg
fi fi
if [ -z "$topLimit" ]; then if [ -z $topLimit ]; then
topLimit=10 topLimit=10
fi fi
@ -177,10 +175,10 @@ Configuration () {
if [ $enableBeetsTagging = true ]; then if [ $enableBeetsTagging = true ]; then
log "Beets Tagging Enabled" log "Beets Tagging Enabled"
log "Beets Matching Threshold ${beetsMatchPercentage}%" log "Beets Matching Threshold ${beetsMatchPercentage}%"
beetsMatchPercentage=$((100 - beetsMatchPercentage )) beetsMatchPercentage=$(expr 100 - $beetsMatchPercentage )
if grep "strong_rec_thresh: 0.04" "${STATE_DIR}/extended/beets-config.yaml" | read -r; then if cat /config/extended/beets-config.yaml | grep "strong_rec_thresh: 0.04" | read; then
log "Configuring Beets Matching Threshold" log "Configuring Beets Matching Threshold"
sed -i "s/strong_rec_thresh: 0.04/strong_rec_thresh: 0.${beetsMatchPercentage}/g" "${STATE_DIR}/extended/beets-config.yaml" sed -i "s/strong_rec_thresh: 0.04/strong_rec_thresh: 0.${beetsMatchPercentage}/g" /config/extended/beets-config.yaml
fi fi
else else
log "Beets Tagging Disabled" log "Beets Tagging Disabled"
@ -197,7 +195,11 @@ Configuration () {
} }
DownloadClientFreyr () { DownloadClientFreyr () {
timeout $downloadClientTimeOut freyr --no-bar --no-net-check -d "$audioPath/incomplete" "deezer:album:$1" 2>&1 timeout $downloadClientTimeOut freyr --no-bar --no-net-check -d $audioPath/incomplete deezer:album:$1 2>&1 | tee -a "/config/logs/$logFileName"
# Resolve issue 94
if [ -d /root/.cache/FreyrCLI ]; then
rm -rf /root/.cache/FreyrCLI/*
fi
} }
DownloadFormat () { DownloadFormat () {
@ -220,7 +222,9 @@ DownloadFormat () {
log "ERROR :: Change audioBitrate to a low, high, or lossless..." log "ERROR :: Change audioBitrate to a low, high, or lossless..."
log "ERROR :: Exiting..." log "ERROR :: Exiting..."
NotifyWebhook "FatalError" "Invalid audioFormat and audioBitrate options set" NotifyWebhook "FatalError" "Invalid audioFormat and audioBitrate options set"
exit 1 log "Script sleeping for $audioScriptInterval..."
sleep $audioScriptInterval
exit
fi fi
else else
bitrateError="false" bitrateError="false"
@ -242,7 +246,9 @@ DownloadFormat () {
log "ERROR :: Change audioBitrate to a desired bitrate number, example: 192..." log "ERROR :: Change audioBitrate to a desired bitrate number, example: 192..."
log "ERROR :: Exiting..." log "ERROR :: Exiting..."
NotifyWebhook "FatalError" "audioBitrate options set" NotifyWebhook "FatalError" "audioBitrate options set"
exit 1 log "Script sleeping for $audioScriptInterval..."
sleep $audioScriptInterval
exit
fi fi
case "$audioFormat" in case "$audioFormat" in
@ -275,32 +281,45 @@ DownloadFolderCleaner () {
if [ -d "$audioPath/complete" ]; then if [ -d "$audioPath/complete" ]; then
log "Removing prevously completed downloads that failed to import..." log "Removing prevously completed downloads that failed to import..."
# check for completed downloads older than 1 day # check for completed downloads older than 1 day
if find "$audioPath/complete" -mindepth 1 -type d -mtime +1 | read -r; then if find "$audioPath"/complete -mindepth 1 -type d -mtime +1 | read; then
# delete completed downloads older than 1 day, these most likely failed to import due to Lidarr failing to match # delete completed downloads older than 1 day, these most likely failed to import due to Lidarr failing to match
find "$audioPath/complete" -mindepth 1 -type d -mtime +1 -exec rm -rf "{}" \; &>/dev/null find "$audioPath"/complete -mindepth 1 -type d -mtime +1 -exec rm -rf "{}" \; &>/dev/null
fi
fi
}
NotFoundFolderCleaner () {
# check for completed download folder
if [ -d /config/extended/logs/notfound ]; then
# check for notfound entries older than X days
if find /config/extended/logs/notfound -mindepth 1 -type f -mtime +$retryNotFound | read; then
log "Removing prevously notfound lidarr album ids older than $retryNotFound days to give them a retry..."
# delete ntofound entries older than X days
find /config/extended/logs/notfound -mindepth 1 -type f -mtime +$retryNotFound -delete
fi fi
fi fi
} }
TidalClientSetup () { TidalClientSetup () {
log "TIDAL :: Verifying tidal-dl configuration" log "TIDAL :: Verifying tidal-dl configuration"
touch "${STATE_DIR}/xdg/.tidal-dl.log" touch /config/xdg/.tidal-dl.log
if [ -f "${STATE_DIR}/xdg/.tidal-dl.json" ]; then if [ -f /config/xdg/.tidal-dl.json ]; then
rm "${STATE_DIR}/xdg/.tidal-dl.json" rm /config/xdg/.tidal-dl.json
fi fi
if [ ! -f "${STATE_DIR}/xdg/.tidal-dl.json" ]; then if [ ! -f /config/xdg/.tidal-dl.json ]; then
log "TIDAL :: No default config found, importing default config \"tidal.json\"" log "TIDAL :: No default config found, importing default config \"tidal.json\""
if [ -f "${STATE_DIR}/extended/tidal-dl.json" ]; then if [ -f /config/extended/tidal-dl.json ]; then
cp "${STATE_DIR}/extended/tidal-dl.json" "${STATE_DIR}/xdg/.tidal-dl.json" cp /config/extended/tidal-dl.json /config/xdg/.tidal-dl.json
chmod 777 -R /config/xdg/
fi fi
fi fi
TidaldlStatusCheck TidaldlStatusCheck
tidal-dl -o "$audioPath/incomplete" 2>&1 tidal-dl -o "$audioPath"/incomplete 2>&1 | tee -a "/config/logs/$logFileName"
DownloadFormat DownloadFormat
if [ ! -f "${STATE_DIR}/xdg/.tidal-dl.token.json" ]; then if [ ! -f /config/xdg/.tidal-dl.token.json ]; then
TidaldlStatusCheck TidaldlStatusCheck
#log "TIDAL :: ERROR :: Downgrade tidal-dl for workaround..." #log "TIDAL :: ERROR :: Downgrade tidal-dl for workaround..."
#pip3 install tidal-dl==2022.3.4.2 --no-cache-dir &>/dev/null #pip3 install tidal-dl==2022.3.4.2 --no-cache-dir &>/dev/null
@ -310,19 +329,21 @@ TidalClientSetup () {
tidal-dl tidal-dl
fi fi
if [ ! -d "${STATE_DIR}/extended/cache/tidal" ]; then if [ ! -d /config/extended/cache/tidal ]; then
mkdir -p "${STATE_DIR}/extended/cache/tidal" mkdir -p /config/extended/cache/tidal
chmod 777 /config/extended/cache/tidal
fi fi
if [ -d "${STATE_DIR}/extended/cache/tidal" ]; then if [ -d /config/extended/cache/tidal ]; then
log "TIDAL :: Purging album list cache..." log "TIDAL :: Purging album list cache..."
rm "${STATE_DIR}/extended/cache/tidal/*-albums.json" &>/dev/null rm /config/extended/cache/tidal/*-albums.json &>/dev/null
fi fi
if [ ! -d "$audioPath/incomplete" ]; then if [ ! -d "$audioPath/incomplete" ]; then
mkdir -p "$audioPath"/incomplete mkdir -p "$audioPath"/incomplete
chmod 777 "$audioPath"/incomplete
else else
rm -rf "$audioPath/incomplete/*" rm -rf "$audioPath"/incomplete/*
fi fi
TidaldlStatusCheck TidaldlStatusCheck
@ -332,15 +353,16 @@ TidalClientSetup () {
} }
TidaldlStatusCheck () { TidaldlStatusCheck () {
until false; do until false
running=no do
if pgrep -f "tidal-dl" | read -r; then running=no
running=yes if ps aux | grep "tidal-dl" | grep -v "grep" | read; then
log "STATUS :: TIDAL-DL :: BUSY :: Pausing/waiting for all active tidal-dl tasks to end..." running=yes
sleep 2 log "STATUS :: TIDAL-DL :: BUSY :: Pausing/waiting for all active tidal-dl tasks to end..."
continue sleep 2
fi continue
break fi
break
done done
} }
@ -348,42 +370,37 @@ TidalClientTest () {
log "TIDAL :: tidal-dl client setup verification..." log "TIDAL :: tidal-dl client setup verification..."
i=0 i=0
while [ $i -lt 3 ]; do while [ $i -lt 3 ]; do
i=$(( i + 1 )) i=$(( $i + 1 ))
TidaldlStatusCheck TidaldlStatusCheck
tidal-dl -q Normal -o "$audioPath/incomplete" -l "$tidalClientTestDownloadId" 2>&1 tidal-dl -q Normal -o "$audioPath"/incomplete -l "$tidalClientTestDownloadId" 2>&1 | tee -a "/config/logs/$logFileName"
downloadCount=$(find "$audioPath/incomplete" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l) downloadCount=$(find "$audioPath"/incomplete -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
if [ "$downloadCount" -le 0 ]; then if [ $downloadCount -le 0 ]; then
continue continue
else else
break break
fi fi
done done
tidalClientTest="unknown" tidalClientTest="unknown"
if [ "$downloadCount" -le 0 ]; then if [ $downloadCount -le 0 ]; then
if [ -f "${STATE_DIR}/xdg/.tidal-dl.token.json" ]; then if [ -f /config/xdg/.tidal-dl.token.json ]; then
rm "${STATE_DIR}/xdg/.tidal-dl.token.json" rm /config/xdg/.tidal-dl.token.json
fi fi
log "TIDAL :: ERROR :: Download failed" log "TIDAL :: ERROR :: Download failed"
log "TIDAL :: ERROR :: You will need to re-authenticate on next script run..." log "TIDAL :: ERROR :: You will need to re-authenticate on next script run..."
log "TIDAL :: ERROR :: Exiting..." log "TIDAL :: ERROR :: Exiting..."
rm -rf "$audioPath/incomplete/*" rm -rf "$audioPath"/incomplete/*
NotifyWebhook "Error" "TIDAL not authenticated but configured" NotifyWebhook "Error" "TIDAL not authenticated but configured"
tidalClientTest="failed" tidalClientTest="failed"
log "Script sleeping for $audioScriptInterval..." log "Script sleeping for $audioScriptInterval..."
sleep $audioScriptInterval sleep $audioScriptInterval
exit exit
else else
rm -rf "$audioPath/incomplete/*" rm -rf "$audioPath"/incomplete/*
log "TIDAL :: Successfully Verified" log "TIDAL :: Successfully Verified"
tidalClientTest="success" tidalClientTest="success"
fi fi
} }
logDl () {
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: \
$lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: $1"
}
DownloadProcess () { DownloadProcess () {
# Required Input Data # Required Input Data
@ -395,71 +412,107 @@ DownloadProcess () {
# Create Required Directories # Create Required Directories
if [ ! -d "$audioPath/incomplete" ]; then if [ ! -d "$audioPath/incomplete" ]; then
mkdir -p "$audioPath/incomplete" mkdir -p "$audioPath"/incomplete
chmod 777 "$audioPath"/incomplete
else else
rm -rf "$audioPath/incomplete/*" rm -rf "$audioPath"/incomplete/*
fi fi
if [ ! -d "$audioPath/complete" ]; then if [ ! -d "$audioPath/complete" ]; then
mkdir -p "$audioPath/complete" mkdir -p "$audioPath"/complete
chmod 777 "$audioPath"/complete
else else
rm -rf "$audioPath/complete/*" rm -rf "$audioPath"/complete/*
fi fi
logPaths=( "deezer" "tidal" "failed/deezer" "failed/tidal" ) if [ ! -d "/config/extended/logs" ]; then
for p in "${!logPaths[@]}"; do mkdir -p /config/extended/logs
if [ ! -d "${STATE_DIR}/extended/logs/downloaded/${logPaths[$p]}" ]; then chmod 777 /config/extended/logs
mkdir -p "${STATE_DIR}/extended/logs/downloaded/${logPaths[$p]}" fi
fi
done if [ ! -d "/config/extended/logs/downloaded" ]; then
mkdir -p /config/extended/logs/downloaded
chmod 777 /config/extended/logs/downloaded
fi
if [ ! -d "/config/extended/logs/downloaded/deezer" ]; then
mkdir -p /config/extended/logs/downloaded/deezer
chmod 777 /config/extended/logs/downloaded/deezer
fi
if [ ! -d "/config/extended/logs/downloaded/tidal" ]; then
mkdir -p /config/extended/logs/downloaded/tidal
chmod 777 /config/extended/logs/downloaded/tidal
fi
if [ ! -d /config/extended/logs/downloaded/failed/deezer ]; then
mkdir -p /config/extended/logs/downloaded/failed/deezer
chmod 777 /config/extended/logs/downloaded/failed/deezer
fi
if [ ! -d /config/extended/logs/downloaded/failed/tidal ]; then
mkdir -p /config/extended/logs/downloaded/failed/tidal
chmod 777 /config/extended/logs/downloaded/failed/tidal
fi
if [ ! -d "$importPath" ]; then if [ ! -d "$importPath" ]; then
mkdir -p "$importPath" mkdir -p "$importPath"
chmod 777 "$importPath"
fi fi
AddDownloadClient AddDownloadClient
downloadedAlbumTitleClean="$(echo "$4" | sed -e "s%[^[:alpha:][:digit:]._' ]% %g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')" downloadedAlbumTitleClean="$(echo "$4" | sed -e "s%[^[:alpha:][:digit:]._' ]% %g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')"
if find "$audioPath/complete" -type d -iname "$lidarrArtistNameSanitized-$downloadedAlbumTitleClean ($3)-*-$1-$2" | read -r; then if find "$audioPath"/complete -type d -iname "$lidarrArtistNameSanitized-$downloadedAlbumTitleClean ($3)-*-$1-$2" | read; then
logDl "ERROR :: Previously Downloaded..." log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Previously Downloaded..."
return return
fi fi
# check for log file # check for log file
if [ "$2" == "DEEZER" ]; then
for i in "DEEZER" "TIDAL"; do if [ -f /config/extended/logs/downloaded/deezer/$1 ]; then
if [ "$2" == $i ]; then log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Previously Downloaded ($1)..."
if [ -f "${STATE_DIR}/extended/logs/downloaded/${i,,}/$1" ]; then return
logDl "ERROR :: Previously Downloaded ($1)..." fi
return if [ -f /config/extended/logs/downloaded/failed/deezer/$1 ]; then
fi log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Previously Attempted Download ($1)..."
if [ -f "${STATE_DIR}/extended/logs/downloaded/failed/${i,,}/$1" ]; then return
logDl "ERROR :: Previously Attempted Download ($1)..." fi
return fi
fi
fi
done
# check for log file
if [ "$2" == "TIDAL" ]; then
if [ -f /config/extended/logs/downloaded/tidal/$1 ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Previously Downloaded ($1)..."
return
fi
if [ -f /config/extended/logs/downloaded/failed/tidal/$1 ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Previously Attempted Download ($1)..."
return
fi
fi
downloadTry=0 downloadTry=0
until false until false
do do
downloadTry=$(( downloadTry + 1 )) downloadTry=$(( $downloadTry + 1 ))
if [ -f /tmp/temp-download ]; then if [ -f /temp-download ]; then
rm /tmp/temp-download rm /temp-download
sleep 0.1 sleep 0.1
fi fi
touch /tmp/temp-download touch /temp-download
sleep 0.1 sleep 0.1
logDl "Download Attempt number $downloadTry" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Download Attempt number $downloadTry"
if [ "$2" == "DEEZER" ]; then if [ "$2" == "DEEZER" ]; then
if [ -z "$arlToken" ]; then if [ -z $arlToken ]; then
DownloadClientFreyr "$1" DownloadClientFreyr $1
else else
deemix -b $deemixQuality -p "$audioPath"/incomplete "https://www.deezer.com/album/$1" 2>&1 deemix -b $deemixQuality -p "$audioPath"/incomplete "https://www.deezer.com/album/$1" 2>&1 | tee -a "/config/logs/$logFileName"
fi fi
if [ -d "/tmp/deemix-imgs" ]; then if [ -d "/tmp/deemix-imgs" ]; then
@ -468,43 +521,49 @@ DownloadProcess () {
# Verify Client Works... # Verify Client Works...
clientTestDlCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l) clientTestDlCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
if [ "$clientTestDlCount" -le 0 ]; then if [ $clientTestDlCount -le 0 ]; then
# Add +1 to failed attempts # Add +1 to failed attempts
deemixFail=$(( deemixFail + 1)) deemixFail=$(( $deemixFail + 1))
else else
# Reset for successful download # Reset for successful download
deemixFail=0 deemixFail=0
fi fi
# If download failes X times, exit with error... # If download failes X times, exit with error...
if [ $deemixFail -eq $failedDownloadAttemptThreshold ] && [ -z "$arlToken" ]; then if [ $deemixFail -eq $failedDownloadAttemptThreshold ]; then
rm -rf "$audioPath"/incomplete/* if [ -z $arlToken ]; then
logDl "All $failedDownloadAttemptThreshold Download Attempts failed, skipping..." rm -rf "$audioPath"/incomplete/*
else log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: All $failedDownloadAttemptThreshold Download Attempts failed, skipping..."
DeezerClientTest else
if [ "$deezerClientTest" == "success" ]; then DeezerClientTest
logDl "All $failedDownloadAttemptThreshold Download Attempts failed, skipping..." if [ "$deezerClientTest" == "success" ]; then
deemixFail=0 log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: All $failedDownloadAttemptThreshold Download Attempts failed, skipping..."
deemixFail=0
fi
fi fi
fi fi
fi fi
if [ "$2" == "DEEZER" ] && [ $deemixFail -eq $failedDownloadAttemptThreshold ] && [ -z "$arlToken" ]; then if [ "$2" == "DEEZER" ]; then
DownloadClientFreyr "$1" if [ $deemixFail -eq $failedDownloadAttemptThreshold ]; then
else if [ -z $arlToken ]; then
deemix -b $deemixQuality -p "$audioPath"/incomplete "https://www.deezer.com/album/$1" 2>&1 DownloadClientFreyr $1
fi else
deemix -b $deemixQuality -p "$audioPath"/incomplete "https://www.deezer.com/album/$1" 2>&1 | tee -a "/config/logs/$logFileName"
fi
fi
fi
if [ "$2" == "TIDAL" ]; then if [ "$2" == "TIDAL" ]; then
TidaldlStatusCheck TidaldlStatusCheck
tidal-dl -q $tidalQuality -o "$audioPath/incomplete" -l "$1" 2>&1 tidal-dl -q $tidalQuality -o "$audioPath/incomplete" -l "$1" 2>&1 | tee -a "/config/logs/$logFileName"
# Verify Client Works... # Verify Client Works...
clientTestDlCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l) clientTestDlCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)
if [ "$clientTestDlCount" -le 0 ]; then if [ $clientTestDlCount -le 0 ]; then
# Add +1 to failed attempts # Add +1 to failed attempts
tidaldlFail=$(( tidaldlFail + 1)) tidaldlFail=$(( $tidaldlFail + 1))
else else
# Reset for successful download # Reset for successful download
tidaldlFail=0 tidaldlFail=0
@ -512,29 +571,29 @@ DownloadProcess () {
# If download failes X times, exit with error... # If download failes X times, exit with error...
if [ $tidaldlFail -eq $failedDownloadAttemptThreshold ]; then if [ $tidaldlFail -eq $failedDownloadAttemptThreshold ]; then
TidalClientTest TidalClientTest
if [ "$tidalClientTest" == "success" ]; then if [ "$tidalClientTest" == "success" ]; then
logDl "All $failedDownloadAttemptThreshold Download Attempts failed, skipping..." log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: All $failedDownloadAttemptThreshold Download Attempts failed, skipping..."
fi fi
fi fi
fi fi
find "$audioPath/incomplete" -type f -iname "*.flac" -newer "/tmp/temp-download" -print0 | while IFS= read -r -d '' file; do find "$audioPath/incomplete" -type f -iname "*.flac" -newer "/temp-download" -print0 | while IFS= read -r -d '' file; do
audioFlacVerification "$file" audioFlacVerification "$file"
if [ "$verifiedFlacFile" == "0" ]; then if [ "$verifiedFlacFile" == "0" ]; then
logDl "Flac Verification :: $file :: Verified" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Flac Verification :: $file :: Verified"
else else
logDl "Flac Verification :: $file :: ERROR :: Failed Verification" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Flac Verification :: $file :: ERROR :: Failed Verification"
rm "$file" rm "$file"
fi fi
done done
downloadCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|m4a\|mp3\)" | wc -l) downloadCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|m4a\|mp3\)" | wc -l)
if [ "$downloadCount" -ne "$5" ]; then if [ "$downloadCount" -ne "$5" ]; then
logDl "ERROR :: download failed, missing tracks..." log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: download failed, missing tracks..."
completedVerification="false" completedVerification="false"
else else
logDl "Success" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Success"
completedVerification="true" completedVerification="true"
fi fi
@ -546,13 +605,13 @@ DownloadProcess () {
fi fi
break break
else else
logDl "Retry Download in 1 second fix errors..." log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Retry Download in 1 second fix errors..."
sleep 1 sleep 1
fi fi
done done
# Consolidate files to a single folder # Consolidate files to a single folder
logDl "Consolidating files to single folder" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Consolidating files to single folder"
find "$audioPath/incomplete" -type f -exec mv "{}" "$audioPath"/incomplete/ \; 2>/dev/null find "$audioPath/incomplete" -type f -exec mv "{}" "$audioPath"/incomplete/ \; 2>/dev/null
find $audioPath/incomplete/ -type d -mindepth 1 -maxdepth 1 -exec rm -rf {} \; 2>/dev/null find $audioPath/incomplete/ -type d -mindepth 1 -maxdepth 1 -exec rm -rf {} \; 2>/dev/null
@ -564,28 +623,34 @@ DownloadProcess () {
downloadCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|m4a\|mp3\)" | wc -l) downloadCount=$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|m4a\|mp3\)" | wc -l)
if [ "$downloadCount" -ne "$5" ]; then if [ "$downloadCount" -ne "$5" ]; then
logDl "ERROR :: All download Attempts failed..." log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: All download Attempts failed..."
logDl "Logging $1 as failed download..." log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Logging $1 as failed download..."
for awa in "DEEZER" "TIDAL"; do if [ "$2" == "DEEZER" ]; then
[ "$2" == $awa ] \ touch /config/extended/logs/downloaded/failed/deezer/$1
&& touch "${STATE_DIR}/extended/logs/downloaded/failed/${awa,,}/$1" fi
done if [ "$2" == "TIDAL" ]; then
touch /config/extended/logs/downloaded/failed/tidal/$1
fi
return return
fi fi
# Log Completed Download # Log Completed Download
logDl "Logging $1 as successfully downloaded..." log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Logging $1 as successfully downloaded..."
for awa in "DEEZER" "TIDAL"; do if [ "$2" == "DEEZER" ]; then
[ "$2" == $awa ] \ touch /config/extended/logs/downloaded/deezer/$1
&& touch "${STATE_DIR}/extended/logs/downloaded/${awa,,}/$1" fi
done if [ "$2" == "TIDAL" ]; then
touch /config/extended/logs/downloaded/tidal/$1
fi
# Tag with beets # Tag with beets
if [ "$enableBeetsTagging" == "true" ]; then if [ "$enableBeetsTagging" == "true" ]; then
[ -f "${STATE_DIR}/extended/beets-error" ] && rm "${STATE_DIR}/extended/beets-error" if [ -f /config/extended/beets-error ]; then
logDl "Processing files with beets..." rm /config/extended/beets-error
fi
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Processing files with beets..."
ProcessWithBeets "$audioPath/incomplete" ProcessWithBeets "$audioPath/incomplete"
fi fi
@ -593,30 +658,33 @@ DownloadProcess () {
find "$audioPath/incomplete" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' file; do find "$audioPath/incomplete" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' file; do
lrcFile="${file%.*}.lrc" lrcFile="${file%.*}.lrc"
if [ -f "$lrcFile" ]; then if [ -f "$lrcFile" ]; then
logDl "Embedding lyrics (lrc) into $file" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Embedding lyrics (lrc) into $file"
metaflac --remove-tag=Lyrics "$file" metaflac --remove-tag=Lyrics "$file"
metaflac --set-tag-from-file="Lyrics=$lrcFile" "$file" metaflac --set-tag-from-file="Lyrics=$lrcFile" "$file"
fi fi
done done
if [ "$audioFormat" != "native" ]; then if [ "$audioFormat" != "native" ]; then
logDl "Converting Flac Audio to ${audioFormat^^} ($audioBitrateText)" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Converting Flac Audio to ${audioFormat^^} ($audioBitrateText)"
if [ "$audioFormat" == "opus" ]; then
options="-c:a libopus -b:a ${audioBitrate}k -application audio -vbr off"
extension="opus"
fi
[ "$audioFormat" == "opus" ] \ if [ "$audioFormat" == "mp3" ]; then
&& options="-c:a libopus -b:a ${audioBitrate}k -application audio -vbr off" \ options="-c:a libmp3lame -b:a ${audioBitrate}k"
&& extension=$audioFormat extension="mp3"
fi
[ "$audioFormat" == "mp3" ] \ if [ "$audioFormat" == "aac" ]; then
&& options="-c:a libmp3lame -b:a ${audioBitrate}k" \ options="-c:a aac -b:a ${audioBitrate}k -movflags faststart"
&& extension=$audioFormat extension="m4a"
fi
[ "$audioFormat" == "aac" ] \ if [ "$audioFormat" == "alac" ]; then
&& options="-c:a aac -b:a ${audioBitrate}k -movflags faststart" \ options="-c:a alac -movflags faststart"
&& extension="m4a" extension="m4a"
fi
[ "$audioFormat" == "alac" ] \
&& options="-c:a alac -movflags faststart" \
&& extension="m4a"
find "$audioPath/incomplete" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' audio; do find "$audioPath/incomplete" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' audio; do
file="${audio}" file="${audio}"
@ -625,20 +693,20 @@ DownloadProcess () {
filenamenoext="${filename%.*}" filenamenoext="${filename%.*}"
if [ "$audioFormat" == "opus" ]; then if [ "$audioFormat" == "opus" ]; then
if opusenc --bitrate ${audioBitrate} --vbr --music "$file" "$foldername/${filenamenoext}.$extension"; then if opusenc --bitrate ${audioBitrate} --vbr --music "$file" "$foldername/${filenamenoext}.$extension"; then
logDl "$filename :: Conversion to $audioFormat ($audioBitrateText) successful" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: $filename :: Conversion to $audioFormat ($audioBitrateText) successful"
rm "$file" rm "$file"
else else
logDl "$filename :: ERROR :: Conversion Failed" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: $filename :: ERROR :: Conversion Failed"
rm "$foldername/${filenamenoext}.$extension" rm "$foldername/${filenamenoext}.$extension"
fi fi
continue continue
fi fi
if ffmpeg -loglevel warning -hide_banner -nostats -i "$file" -n -vn "$options" "$foldername/${filenamenoext}.$extension" < /dev/null; then if ffmpeg -loglevel warning -hide_banner -nostats -i "$file" -n -vn $options "$foldername/${filenamenoext}.$extension" < /dev/null; then
logDl "$filename :: Conversion to $audioFormat ($audioBitrateText) successful" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: $filename :: Conversion to $audioFormat ($audioBitrateText) successful"
rm "$file" rm "$file"
else else
logDl "$filename :: ERROR :: Conversion Failed" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: $filename :: ERROR :: Conversion Failed"
rm "$foldername/${filenamenoext}.$extension" rm "$foldername/${filenamenoext}.$extension"
fi fi
done done
@ -648,10 +716,10 @@ DownloadProcess () {
if [ "$enableReplaygainTags" == "true" ]; then if [ "$enableReplaygainTags" == "true" ]; then
AddReplaygainTags "$audioPath/incomplete" AddReplaygainTags "$audioPath/incomplete"
else else
logDl "Replaygain Tagging Disabled (set enableReplaygainTags=true to enable...)" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Replaygain Tagging Disabled (set enableReplaygainTags=true to enable...)"
fi fi
albumquality="$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | head -n 1 | grep -i -E -o "\.{1}\w*$" | sed 's/\.//g')" albumquality="$(find "$audioPath"/incomplete/ -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | head -n 1 | egrep -i -E -o "\.{1}\w*$" | sed 's/\.//g')"
downloadedAlbumFolder="${lidarrArtistNameSanitized}-${downloadedAlbumTitleClean:0:100} (${3})" downloadedAlbumFolder="${lidarrArtistNameSanitized}-${downloadedAlbumTitleClean:0:100} (${3})"
find "$audioPath/incomplete" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" -print0 | while IFS= read -r -d '' audio; do find "$audioPath/incomplete" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" -print0 | while IFS= read -r -d '' audio; do
@ -686,146 +754,172 @@ DownloadProcess () {
ProcessWithBeets () { ProcessWithBeets () {
# Input # Input
# $1 Download Folder to process # $1 Download Folder to process
for awa in "extended/beets-library.blb" "extended/beets.log" "beets-match"; do if [ -f /config/extended/beets-library.blb ]; then
[ -f "${STATE_DIR}/${awa}" ] \ rm /config/extended/beets-library.blb
&& rm "${STATE_DIR}/${awa}" \ sleep 0.5
&& sleep 0.5 fi
done if [ -f /config/extended/beets.log ]; then
rm /config/extended/beets.log
sleep 0.5
fi
if [ -f "/config/beets-match" ]; then
rm "/config/beets-match"
sleep 0.5
fi
touch "/config/beets-match" touch "/config/beets-match"
sleep 0.5 sleep 0.5
beet -c "${STATE_DIR}/extended/beets-config.yaml" \ beet -c /config/extended/beets-config.yaml -l /config/extended/beets-library.blb -d "$1" import -qC "$1"
-l "${STATE_DIR}/extended/beets-library.blb" -d "$1" import -qC "$1" if [ $(find "$1" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" -newer "/config/beets-match" | wc -l) -gt 0 ]; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: SUCCESS: Matched with beets!"
if [ "$(find "$1" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" -newer "${STATE_DIR}/beets-match" | wc -l)" -gt 0 ]; then log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: fixing track tags"
logDl "SUCCESS: Matched with beets!"
logDl "fixing track tags"
find "$audioPath/incomplete" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' file; do find "$audioPath/incomplete" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' file; do
getArtistCredit="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$file" | jq -r ".format.tags.ARTIST_CREDIT" | sed "s/null//g" | sed "/^$/d")" getArtistCredit="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$file" | jq -r ".format.tags.ARTIST_CREDIT" | sed "s/null//g" | sed "/^$/d")"
# album artist # album artist
metaflac \ metaflac --remove-tag=ALBUMARTIST "$file"
--remove-tag=ALBUMARTIST --remove-tag=ALBUMARTIST_CREDIT --remove-tag=ALBUM_ARTIST \ metaflac --remove-tag=ALBUMARTIST_CREDIT "$file"
--remove-tag="ALBUM ARTIST" --remove-tag=ARTIST --remove-tag=ARTIST_CREDIT \ metaflac --remove-tag=ALBUM_ARTIST "$file"
--remove-tag=ARTISTSORT --remove-tag=COMPOSERSORT --remove-tag=ALBUMARTISTSORT \ metaflac --remove-tag="ALBUM ARTIST" "$file"
--remove-tag=MUSICBRAINZ_ARTISTID --remove-tag=MUSICBRAINZ_ALBUMARTISTID \ # artist
"$file" metaflac --remove-tag=ARTIST "$file"
metaflac --remove-tag=ARTIST_CREDIT "$file"
metaflac \ if [ ! -z "$getArtistCredit" ]; then
--set-tag=ALBUMARTIST="$lidarrArtistName" \ metaflac --set-tag=ARTIST="$getArtistCredit" "$file"
--set-tag=MUSICBRAINZ_ARTISTID="$lidarrArtistForeignArtistId" \
--set-tag=MUSICBRAINZ_ALBUMARTISTID="$lidarrArtistForeignArtistId" \
"$file"
if [ -n "$getArtistCredit" ]; then
metaflac --set-tag=ARTIST="$getArtistCredit" "$file"
else else
metaflac --set-tag=ARTIST="$lidarrArtistName" "$file" metaflac --set-tag=ARTIST="$lidarrArtistName" "$file"
fi fi
# sorts
log "FIXED : $file" metaflac --remove-tag=ARTISTSORT "$file"
metaflac --remove-tag=COMPOSERSORT "$file"
metaflac --remove-tag=ALBUMARTISTSORT "$file"
# lidarr
metaflac --set-tag=ALBUMARTIST="$lidarrArtistName" "$file"
# mbrainz
metaflac --remove-tag=MUSICBRAINZ_ARTISTID "$file"
metaflac --remove-tag=MUSICBRAINZ_ALBUMARTISTID "$file"
metaflac --set-tag=MUSICBRAINZ_ARTISTID="$lidarrArtistForeignArtistId" "$file"
metaflac --set-tag=MUSICBRAINZ_ALBUMARTISTID="$lidarrArtistForeignArtistId" "$file"
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: FIXED : $file"
done done
else else
log "ERROR :: Unable to match using beets to a musicbrainz release..." log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Unable to match using beets to a musicbrainz release..."
return return
fi fi
[ -f "${STATE_DIR}/beets-match" ] \ if [ -f "/config/beets-match" ]; then
&& rm "${STATE_DIR}/beets-match" \ rm "/config/beets-match"
&& sleep 0.1 sleep 0.1
fi
# Get file metadata # Get file metadata
GetFile=$(find "$audioPath/incomplete" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | head -n1) GetFile=$(find "$audioPath/incomplete" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | head -n1)
extension="${GetFile##*.}" extension="${GetFile##*.}"
ffprobeGet=$(ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams \
-show_programs -show_chapters -show_private_data -print_format json \
"$GetFile"
)
if [ "$extension" == "opus" ]; then if [ "$extension" == "opus" ]; then
matchedTags=$(${ffprobeGet} | jq -r ".streams[].tags") matchedTags=$(ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams -show_programs -show_chapters -show_private_data -print_format json "$GetFile" | jq -r ".streams[].tags")
else else
matchedTags=$(${ffprobeGet} | jq -r ".format.tags") matchedTags=$(ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams -show_programs -show_chapters -show_private_data -print_format json "$GetFile" | jq -r ".format.tags")
fi fi
# Get Musicbrainz Release Group ID and Album Artist ID from tagged file # Get Musicbrainz Release Group ID and Album Artist ID from tagged file
if [ "$extension" == "flac" ] || [ "$extension" == "opus" ]; then if [ "$extension" == "flac" ] || [ "$extension" == "opus" ]; then
matchedTagsAlbumReleaseGroupId="$(echo "$matchedTags" | jq -r ".MUSICBRAINZ_RELEASEGROUPID")" matchedTagsAlbumReleaseGroupId="$(echo $matchedTags | jq -r ".MUSICBRAINZ_RELEASEGROUPID")"
matchedTagsAlbumArtistId="$(echo "$matchedTags" | jq -r ".MUSICBRAINZ_ALBUMARTISTID")" matchedTagsAlbumArtistId="$(echo $matchedTags | jq -r ".MUSICBRAINZ_ALBUMARTISTID")"
elif [ "$extension" == "mp3" ] || [ "$extension" == "m4a" ]; then elif [ "$extension" == "mp3" ] || [ "$extension" == "m4a" ]; then
matchedTagsAlbumReleaseGroupId="$(echo "$matchedTags" | jq -r '."MusicBrainz Release Group Id"')" matchedTagsAlbumReleaseGroupId="$(echo $matchedTags | jq -r '."MusicBrainz Release Group Id"')"
matchedLidarrAlbumArtistId="$(echo "$matchedTags" | jq -r '."MusicBrainz Ablum Artist Id"')" matchedLidarrAlbumArtistId="$(echo $matchedTags | jq -r '."MusicBrainz Ablum Artist Id"')"
fi fi
[ ! -d "${STATE_DIR}/extended/logs/downloaded/musicbrainz_matched" ] \ if [ ! -d "/config/extended/logs/downloaded/musicbrainz_matched" ]; then
&& mkdir -p "${STATE_DIR}/extended/logs/downloaded/musicbrainz_matched" mkdir -p "/config/extended/logs/downloaded/musicbrainz_matched"
chmod 777 "/config/extended/logs/downloaded/musicbrainz_matched"
fi
[ ! -f "${STATE_DIR}/extended/logs/downloaded/musicbrainz_matched/$matchedTagsAlbumReleaseGroupId" ] \ if [ ! -f "/config/extended/logs/downloaded/musicbrainz_matched/$matchedTagsAlbumReleaseGroupId" ]; then
&& log "Marking MusicBrainz Release Group ($matchedTagsAlbumReleaseGroupId) as successfully downloaded..." \ log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Marking MusicBrainz Release Group ($matchedTagsAlbumReleaseGroupId) as successfully downloaded..."
&& touch "/config/extended/logs/downloaded/musicbrainz_matched/$matchedTagsAlbumReleaseGroupId" touch "/config/extended/logs/downloaded/musicbrainz_matched/$matchedTagsAlbumReleaseGroupId"
fi
} }
DownloadQualityCheck () { DownloadQualityCheck () {
[ "$requireQuality" != "true" ] \ if [ "$requireQuality" == "true" ]; then
&& logDl "Skipping download quality check... (enable by setting: requireQuality=true)" \ log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Checking for unwanted files"
&& return
logDl "Checking for unwanted files" if [ "$audioFormat" != "native" ]; then
if find "$1" -type f -regex ".*/.*\.\(opus\|m4a\|mp3\)"| read; then
local deezer log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Unwanted files found!"
local tidal log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Performing cleanup..."
local other rm "$1"/*
local notNative else
notNative=$([ "$audioFormat" != "native" ] \ log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: No unwanted files found!"
&& find "$1" -type f -regex ".*/.*\.\(opus\|m4a\|mp3\)" | read -r fi
) fi
other=$([ "$audioBitrate" == "master" ] || [ "$audioBitrate" == "lossless" ] \ if [ "$audioFormat" == "native" ]; then
&& find "$1" -type f -regex ".*/.*\.\(opus\|m4a\|mp3\)" | read -r if [ "$audioBitrate" == "master" ]; then
) if find "$1" -type f -regex ".*/.*\.\(opus\|m4a\|mp3\)"| read; then
deezer=$([ "$2" == "DEEZER" ] \ log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Unwanted files found!"
&& find "$1" -type f -regex ".*/.*\.\(opus\|m4a\|flac\)" | read -r log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Performing cleanup..."
) rm "$1"/*
tidal=$([ "$2" == "TIDAL" ] \ else
&& find "$1" -type f -regex ".*/.*\.\(opus\|flac\|mp3\)" | read -r log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: No unwanted files found!"
) fi
elif [ "$audioBitrate" == "lossless" ]; then
if $notNative || $deezer || $tidal || $other; then if find "$1" -type f -regex ".*/.*\.\(opus\|m4a\|mp3\)"| read; then
logDl "Unwanted files found!" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Unwanted files found!"
logDl "Performing cleanup..." log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Performing cleanup..."
rm "$1"/* rm "$1"/*
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: No unwanted files found!"
fi
elif [ "$2" == "DEEZER" ]; then
if find "$1" -type f -regex ".*/.*\.\(opus\|m4a\|flac\)"| read; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Unwanted files found!"
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Performing cleanup..."
rm "$1"/*
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: No unwanted files found!"
fi
elif [ "$2" == "TIDAL" ]; then
if find "$1" -type f -regex ".*/.*\.\(opus\|flac\|mp3\)"| read; then
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Unwanted files found!"
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Performing cleanup..."
rm "$1"/*
else
log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: No unwanted files found!"
fi
fi
fi
else else
logDl "No unwanted files found!" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Skipping download quality check... (enable by setting: requireQuality=true)"
fi fi
} }
AddReplaygainTags () { AddReplaygainTags () {
# Input Data # Input Data
# $1 Folder path to scan and add tags # $1 Folder path to scan and add tags
logDl "Adding Replaygain Tags using r128gain" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Adding Replaygain Tags using r128gain"
r128gain -r -c 1 -a "$1" &>/dev/null r128gain -r -c 1 -a "$1" &>/dev/null
} }
NotifyLidarrForImport () { NotifyLidarrForImport () {
curl -s "$arrUrl/api/v1/command" --header "X-Api-Key:" "${arrApiKey}" -H "Content-Type: application/json" --data "{\"name\":\"DownloadedAlbumsScan\", \"path\":\"$1\"}" LidarrProcessIt=$(curl -s "$arrUrl/api/v1/command" --header "X-Api-Key:"${arrApiKey} -H "Content-Type: application/json" --data "{\"name\":\"DownloadedAlbumsScan\", \"path\":\"$1\"}")
logDl "LIDARR IMPORT NOTIFICATION SENT! :: $1" log "$page :: $wantedAlbumListSource :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: LIDARR IMPORT NOTIFICATION SENT! :: $1"
} }
DeemixClientSetup () { DeemixClientSetup () {
log "DEEZER :: Verifying deemix configuration" log "DEEZER :: Verifying deemix configuration"
if [ -n "$arlToken" ]; then if [ ! -z "$arlToken" ]; then
arlToken="$(echo "$arlToken" | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')" arlToken="$(echo $arlToken | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')"
# Create directories # Create directories
mkdir -p "${STATE_DIR}/xdg/deemix" mkdir -p /config/xdg/deemix
if [ -f "${STATE_DIR}/xdg/deemix/.arl" ]; then if [ -f "/config/xdg/deemix/.arl" ]; then
rm "${STATE_DIR}/xdg/deemix/.arl" rm "/config/xdg/deemix/.arl"
fi fi
if [ ! -f "${STATE_DIR}/xdg/deemix/.arl" ]; then if [ ! -f "/config/xdg/deemix/.arl" ]; then
echo -n "$arlToken" > "/${STATE_DIR}/xdg/deemix/.arl" echo -n "$arlToken" > "/config/xdg/deemix/.arl"
fi fi
log "DEEZER :: ARL Token: Configured" log "DEEZER :: ARL Token: Configured"
else else
@ -1689,6 +1783,9 @@ AudioProcess () {
Configuration Configuration
# Perform NotFound Folder Cleanup process
NotFoundFolderCleaner
LidarrRootFolderCheck LidarrRootFolderCheck
DownloadFormat DownloadFormat
@ -1724,13 +1821,14 @@ AudioProcess () {
log "Starting Script...." log "Starting Script...."
for (( ; ; )); do for (( ; ; )); do
(( i++ )) || true let i++
verifyConfig logfileSetup
verifyConfig
getArrAppInfo getArrAppInfo
verifyApiAccess verifyApiAccess
AudioProcess AudioProcess
log "Script sleeping for $audioScriptInterval..." log "Script sleeping for $audioScriptInterval..."
sleep "$audioScriptInterval" sleep $audioScriptInterval
done done
exit exit

View file

@ -1,4 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
scriptVersion="3.2"
scriptName="AutoConfig"
### Import Settings ### Import Settings
source /config/extended.conf source /config/extended.conf
@ -34,7 +36,7 @@ fi
if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ]; then if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ]; then
log "Configuring Lidarr Custom Scripts" log "Configuring Lidarr Custom Scripts"
if curl -s "$arrUrl/api/v1/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "PlexNotify.bash" | read -r; then if curl -s "$arrUrl/api/v1/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "PlexNotify.bash" | read; then
log "PlexNotify.bash Already added to Lidarr custom scripts" log "PlexNotify.bash Already added to Lidarr custom scripts"
else else
log "Adding PlexNotify.bash to Lidarr custom scripts" log "Adding PlexNotify.bash to Lidarr custom scripts"
@ -44,7 +46,7 @@ if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ];
fi fi
if curl -s "$arrUrl/api/v1/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "LyricExtractor.bash" | read -r; then if curl -s "$arrUrl/api/v1/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "LyricExtractor.bash" | read; then
log "LyricExtractor.bash Already added to Lidarr custom scripts" log "LyricExtractor.bash Already added to Lidarr custom scripts"
else else
log "Adding LyricExtractor.bash to Lidarr custom scripts" log "Adding LyricExtractor.bash to Lidarr custom scripts"
@ -54,7 +56,7 @@ if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ];
fi fi
if curl -s "$arrUrl/api/v1/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "ArtworkExtractor.bash" | read -r; then if curl -s "$arrUrl/api/v1/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "ArtworkExtractor.bash" | read; then
log "ArtworkExtractor.bash Already added to Lidarr custom scripts" log "ArtworkExtractor.bash Already added to Lidarr custom scripts"
else else
log "Adding ArtworkExtractor.bash to Lidarr custom scripts" log "Adding ArtworkExtractor.bash to Lidarr custom scripts"
@ -64,7 +66,7 @@ if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ];
fi fi
if curl -s "$arrUrl/api/v1/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "BeetsTagger.bash" | read -r; then if curl -s "$arrUrl/api/v1/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "BeetsTagger.bash" | read; then
log "BeetsTagger.bash Already added to Lidarr custom scripts" log "BeetsTagger.bash Already added to Lidarr custom scripts"
else else
log "Adding BeetsTagger.bash to Lidarr custom scripts" log "Adding BeetsTagger.bash to Lidarr custom scripts"

View file

@ -325,7 +325,7 @@ VideoTagProcess () {
if [[ $filenoext.$videoContainer == *.mkv ]]; then if [[ $filenoext.$videoContainer == *.mkv ]]; then
mv "$filenoext.$videoContainer" "$filenoext-temp.$videoContainer" mv "$filenoext.$videoContainer" "$filenoext-temp.$videoContainer"
log "${processCount}/${lidarrArtistIdsCount} :: $lidarrArtistName :: IMVDB :: ${imvdbProcessCount}/${imvdbArtistVideoCount} :: ${1}${2} $3 :: Tagging file" log "${processCount}/${lidarrArtistIdsCount} :: $lidarrArtistName :: IMVDB :: ${imvdbProcessCount}/${imvdbArtistVideoCount} :: ${1}${2} $3 :: Tagging file"
ffmpeg -y -nostdin \ ffmpeg -y \
-i "$filenoext-temp.$videoContainer" \ -i "$filenoext-temp.$videoContainer" \
-c copy \ -c copy \
-metadata TITLE="${1}" \ -metadata TITLE="${1}" \
@ -343,7 +343,7 @@ VideoTagProcess () {
else else
mv "$filenoext.$videoContainer" "$filenoext-temp.$videoContainer" mv "$filenoext.$videoContainer" "$filenoext-temp.$videoContainer"
log "${processCount}/${lidarrArtistIdsCount} :: $lidarrArtistName :: IMVDB :: ${imvdbProcessCount}/${imvdbArtistVideoCount} :: ${1}${2} $3 :: Tagging file" log "${processCount}/${lidarrArtistIdsCount} :: $lidarrArtistName :: IMVDB :: ${imvdbProcessCount}/${imvdbArtistVideoCount} :: ${1}${2} $3 :: Tagging file"
ffmpeg -y -nostdin \ ffmpeg -y \
-i "$filenoext-temp.$videoContainer" \ -i "$filenoext-temp.$videoContainer" \
-i "$videoDownloadPath/incomplete/${1}${2}.jpg" \ -i "$videoDownloadPath/incomplete/${1}${2}.jpg" \
-map 1 \ -map 1 \

3
lidarr/scripts_init.bash Normal file
View file

@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bash
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/lidarr/setup.bash | bash
exit

View file

@ -1,6 +1,19 @@
log () { log () {
m_time=$(date "+%F %T") m_time=`date "+%F %T"`
echo "$m_time :: $scriptName :: $1" echo $m_time" :: $scriptName :: $scriptVersion :: "$1
echo $m_time" :: $scriptName :: $scriptVersion :: "$1 >> "/config/logs/$logFileName"
}
logfileSetup () {
logFileName="$scriptName-$(date +"%Y_%m_%d_%I_%M_%p").txt"
# delete log files older than 5 days
find "/config/logs" -type f -iname "$scriptName-*.txt" -mtime +5 -delete
if [ ! -f "/config/logs/$logFileName" ]; then
echo "" > "/config/logs/$logFileName"
chmod 666 "/config/logs/$logFileName"
fi
} }
getArrAppInfo () { getArrAppInfo () {
@ -32,7 +45,7 @@ verifyApiAccess () {
arrApiVersion="v1" arrApiVersion="v1"
arrApiTest="$(curl -s "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" | jq -r .instanceName)" arrApiTest="$(curl -s "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" | jq -r .instanceName)"
fi fi
if [ -n "$arrApiTest" ]; then if [ ! -z "$arrApiTest" ]; then
break break
else else
log "$arrName is not ready, sleeping until valid response..." log "$arrName is not ready, sleeping until valid response..."