v1.5 - Bugfix, wait for lidarr to start before runnining

This commit is contained in:
RandomNinjaAtk 2023-07-18 17:43:58 -04:00 committed by GitHub
parent 86447bcf49
commit f227abe49e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,5 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bash
scriptVersion="1.4" scriptVersion="1.5"
scriptName="AutoArtistAdder" scriptName="AutoArtistAdder"
log () { log () {
@ -38,18 +38,41 @@ verifyConfig () {
} }
if [ -z "$lidarrUrl" ] || [ -z "$lidarrApiKey" ]; then getArrAppInfo () {
lidarrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)" # Get Arr App information
if [ "$lidarrUrlBase" == "null" ]; then if [ -z "$arrUrl" ] || [ -z "$arrApiKey" ]; then
lidarrUrlBase="" arrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)"
if [ "$arrUrlBase" == "null" ]; then
arrUrlBase=""
else else
lidarrUrlBase="/$(echo "$lidarrUrlBase" | sed "s/\///g")" arrUrlBase="/$(echo "$arrUrlBase" | sed "s/\///g")"
fi fi
lidarrApiKey="$(cat /config/config.xml | xq | jq -r .Config.ApiKey)" arrName="$(cat /config/config.xml | xq | jq -r .Config.InstanceName)"
lidarrAgentInstanceId="$(echo "$lidarrApiKey" | cut -c1-10)" arrApiKey="$(cat /config/config.xml | xq | jq -r .Config.ApiKey)"
lidarrPort="$(cat /config/config.xml | xq | jq -r .Config.Port)" arrPort="$(cat /config/config.xml | xq | jq -r .Config.Port)"
lidarrUrl="http://localhost:${lidarrPort}${lidarrUrlBase}" arrUrl="http://127.0.0.1:${arrPort}${arrUrlBase}"
fi fi
}
verifyApiAccess () {
until false
do
arrApiTest=""
arrApiVersion=""
if [ "$arrPort" == "8989" ] || [ "$arrPort" == "7878" ]; then
arrApiVersion="v3"
elif [ "$arrPort" == "8686" ] || [ "$arrPort" == "8787" ]; then
arrApiVersion="v1"
fi
arrApiTest=$(curl -s "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" | jq -r .instanceName)
if [ "$arrApiTest" == "$arrName" ]; then
break
else
log "$arrName is not ready, sleeping until valid response..."
sleep 1
fi
done
}
sleepTimer=0.5 sleepTimer=0.5
@ -90,7 +113,7 @@ AddDeezerTopTrackArtists () {
} }
AddDeezerArtistToLidarr () { AddDeezerArtistToLidarr () {
lidarrArtistsData="$(curl -s "$lidarrUrl/api/v1/artist?apikey=${lidarrApiKey}")" lidarrArtistsData="$(curl -s "$arrUrl/api/v1/artist?apikey=${arrApiKey}")"
lidarrArtistIds="$(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId")" lidarrArtistIds="$(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId")"
deezerArtistsUrl=$(echo "${lidarrArtistsData}" | jq -r ".[].links | .[] | select(.name==\"deezer\") | .url") deezerArtistsUrl=$(echo "${lidarrArtistsData}" | jq -r ".[].links | .[] | select(.name==\"deezer\") | .url")
deezerArtistIds="$(echo "$deezerArtistsUrl" | grep -o '[[:digit:]]*' | sort -u)" deezerArtistIds="$(echo "$deezerArtistsUrl" | grep -o '[[:digit:]]*' | sort -u)"
@ -108,7 +131,7 @@ AddDeezerArtistToLidarr () {
log "$currentprocess of $getDeezerArtistsIdsCount :: $deezerArtistName :: $deezerArtistId already in Lidarr..." log "$currentprocess of $getDeezerArtistsIdsCount :: $deezerArtistName :: $deezerArtistId already in Lidarr..."
continue continue
fi fi
lidarrArtistSearchData="$(curl -s "$lidarrUrl/api/v1/search?term=${deezerArtistNameEncoded}&apikey=${lidarrApiKey}")" lidarrArtistSearchData="$(curl -s "$arrUrl/api/v1/search?term=${deezerArtistNameEncoded}&apikey=${arrApiKey}")"
lidarrArtistMatchedData=$(echo $lidarrArtistSearchData | jq -r ".[] | select(.artist) | select(.artist.links[].name==\"deezer\") | select(.artist.links[].url | contains (\"artist/$deezerArtistId\"))" 2>/dev/null) lidarrArtistMatchedData=$(echo $lidarrArtistSearchData | jq -r ".[] | select(.artist) | select(.artist.links[].name==\"deezer\") | select(.artist.links[].url | contains (\"artist/$deezerArtistId\"))" 2>/dev/null)
@ -118,12 +141,12 @@ AddDeezerArtistToLidarr () {
data="$lidarrArtistMatchedData" data="$lidarrArtistMatchedData"
artistName="$(echo "$data" | jq -r ".artist.artistName")" artistName="$(echo "$data" | jq -r ".artist.artistName")"
foreignId="$(echo "$data" | jq -r ".foreignId")" foreignId="$(echo "$data" | jq -r ".foreignId")"
importListExclusionData=$(curl -s "$lidarrUrl/api/v1/importlistexclusion" -H "X-Api-Key: $lidarrApiKey" | jq -r ".[].foreignId") importListExclusionData=$(curl -s "$arrUrl/api/v1/importlistexclusion" -H "X-Api-Key: $arrApiKey" | jq -r ".[].foreignId")
if echo "$importListExclusionData" | grep "^${foreignId}$" | read; then if echo "$importListExclusionData" | grep "^${foreignId}$" | read; then
log "$currentprocess of $getDeezerArtistsIdsCount :: $deezerArtistName :: ERROR :: Artist is on import exclusion block list, skipping...." log "$currentprocess of $getDeezerArtistsIdsCount :: $deezerArtistName :: ERROR :: Artist is on import exclusion block list, skipping...."
continue continue
fi fi
data=$(curl -s "$lidarrUrl/api/v1/rootFolder" -H "X-Api-Key: $lidarrApiKey" | jq -r ".[]") data=$(curl -s "$arrUrl/api/v1/rootFolder" -H "X-Api-Key: $arrApiKey" | jq -r ".[]")
path="$(echo "$data" | jq -r ".path")" path="$(echo "$data" | jq -r ".path")"
path=$(echo $path | cut -d' ' -f1) path=$(echo $path | cut -d' ' -f1)
qualityProfileId="$(echo "$data" | jq -r ".defaultQualityProfileId")" qualityProfileId="$(echo "$data" | jq -r ".defaultQualityProfileId")"
@ -146,7 +169,7 @@ AddDeezerArtistToLidarr () {
fi fi
log "$currentprocess of $getDeezerArtistsIdsCount :: $deezerArtistName :: Adding $artistName to Lidarr ($foreignId)..." log "$currentprocess of $getDeezerArtistsIdsCount :: $deezerArtistName :: Adding $artistName to Lidarr ($foreignId)..."
LidarrTaskStatusCheck LidarrTaskStatusCheck
lidarrAddArtist=$(curl -s "$lidarrUrl/api/v1/artist" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $lidarrApiKey" --data-raw "$data") lidarrAddArtist=$(curl -s "$arrUrl/api/v1/artist" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" --data-raw "$data")
else else
log "$currentprocess of $getDeezerArtistsIdsCount :: $deezerArtistName :: Artist not found in Musicbrainz, please add \"https://deezer.com/artist/${deezerArtistId}\" to the correct artist on Musicbrainz" log "$currentprocess of $getDeezerArtistsIdsCount :: $deezerArtistName :: Artist not found in Musicbrainz, please add \"https://deezer.com/artist/${deezerArtistId}\" to the correct artist on Musicbrainz"
NotifyWebhook "ArtistError" "Artist not found in Musicbrainz, please add <https://deezer.com/artist/${deezerArtistId}> to the correct artist on Musicbrainz" NotifyWebhook "ArtistError" "Artist not found in Musicbrainz, please add <https://deezer.com/artist/${deezerArtistId}> to the correct artist on Musicbrainz"
@ -158,7 +181,7 @@ AddDeezerArtistToLidarr () {
AddDeezerRelatedArtists () { AddDeezerRelatedArtists () {
log "Begin adding Lidarr related Artists from Deezer..." log "Begin adding Lidarr related Artists from Deezer..."
lidarrArtistsData="$(curl -s "$lidarrUrl/api/v1/artist?apikey=${lidarrApiKey}")" lidarrArtistsData="$(curl -s "$arrUrl/api/v1/artist?apikey=${arrApiKey}")"
lidarrArtistTotal=$(echo "${lidarrArtistsData}"| jq -r '.[].sortName' | wc -l) lidarrArtistTotal=$(echo "${lidarrArtistsData}"| jq -r '.[].sortName' | wc -l)
lidarrArtistList=($(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId")) lidarrArtistList=($(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId"))
lidarrArtistIds="$(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId")" lidarrArtistIds="$(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId")"
@ -197,7 +220,7 @@ LidarrTaskStatusCheck () {
alerted=no alerted=no
until false until false
do do
taskCount=$(curl -s "$lidarrUrl/api/v1/command?apikey=${lidarrApiKey}" | jq -r '.[] | select(.status=="started") | .name' | wc -l) taskCount=$(curl -s "$arrUrl/api/v1/command?apikey=${arrApiKey}" | jq -r '.[] | select(.status=="started") | .name' | wc -l)
if [ "$taskCount" -ge "1" ]; then if [ "$taskCount" -ge "1" ]; then
if [ "$alerted" == "no" ]; then if [ "$alerted" == "no" ]; then
alerted=yes alerted=yes
@ -212,7 +235,7 @@ LidarrTaskStatusCheck () {
AddTidalRelatedArtists () { AddTidalRelatedArtists () {
log "Begin adding Lidarr related Artists from Tidal..." log "Begin adding Lidarr related Artists from Tidal..."
lidarrArtistsData="$(curl -s "$lidarrUrl/api/v1/artist?apikey=${lidarrApiKey}")" lidarrArtistsData="$(curl -s "$arrUrl/api/v1/artist?apikey=${arrApiKey}")"
lidarrArtistTotal=$(echo "${lidarrArtistsData}"| jq -r '.[].sortName' | wc -l) lidarrArtistTotal=$(echo "${lidarrArtistsData}"| jq -r '.[].sortName' | wc -l)
lidarrArtistList=($(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId")) lidarrArtistList=($(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId"))
lidarrArtistIds="$(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId")" lidarrArtistIds="$(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId")"
@ -262,19 +285,19 @@ AddTidalArtistToLidarr () {
fi fi
serviceArtistNameEncoded="$(jq -R -r @uri <<<"$serviceArtistName")" serviceArtistNameEncoded="$(jq -R -r @uri <<<"$serviceArtistName")"
lidarrArtistSearchData="$(curl -s "$lidarrUrl/api/v1/search?term=${serviceArtistNameEncoded}&apikey=${lidarrApiKey}")" lidarrArtistSearchData="$(curl -s "$arrUrl/api/v1/search?term=${serviceArtistNameEncoded}&apikey=${arrApiKey}")"
lidarrArtistMatchedData=$(echo $lidarrArtistSearchData | jq -r ".[] | select(.artist) | select(.artist.links[].name==\"tidal\") | select(.artist.links[].url | contains (\"artist/$serviceArtistId\"))" 2>/dev/null) lidarrArtistMatchedData=$(echo $lidarrArtistSearchData | jq -r ".[] | select(.artist) | select(.artist.links[].name==\"tidal\") | select(.artist.links[].url | contains (\"artist/$serviceArtistId\"))" 2>/dev/null)
if [ ! -z "$lidarrArtistMatchedData" ]; then if [ ! -z "$lidarrArtistMatchedData" ]; then
data="$lidarrArtistMatchedData" data="$lidarrArtistMatchedData"
artistName="$(echo "$data" | jq -r ".artist.artistName")" artistName="$(echo "$data" | jq -r ".artist.artistName")"
foreignId="$(echo "$data" | jq -r ".foreignId")" foreignId="$(echo "$data" | jq -r ".foreignId")"
importListExclusionData=$(curl -s "$lidarrUrl/api/v1/importlistexclusion" -H "X-Api-Key: $lidarrApiKey" | jq -r ".[].foreignId") importListExclusionData=$(curl -s "$arrUrl/api/v1/importlistexclusion" -H "X-Api-Key: $arrApiKey" | jq -r ".[].foreignId")
if echo "$importListExclusionData" | grep "^${foreignId}$" | read; then if echo "$importListExclusionData" | grep "^${foreignId}$" | read; then
log "$artistNumber of $lidarrArtistTotal :: $lidarrArtistName :: $currentprocess of $numberOfRelatedArtistsToAddPerArtist :: $serviceArtistName :: ERROR :: Artist is on import exclusion block list, skipping...." log "$artistNumber of $lidarrArtistTotal :: $lidarrArtistName :: $currentprocess of $numberOfRelatedArtistsToAddPerArtist :: $serviceArtistName :: ERROR :: Artist is on import exclusion block list, skipping...."
continue continue
fi fi
data=$(curl -s "$lidarrUrl/api/v1/rootFolder" -H "X-Api-Key: $lidarrApiKey" | jq -r ".[]") data=$(curl -s "$arrUrl/api/v1/rootFolder" -H "X-Api-Key: $arrApiKey" | jq -r ".[]")
path="$(echo "$data" | jq -r ".path")" path="$(echo "$data" | jq -r ".path")"
path=$(echo $path | cut -d' ' -f1) path=$(echo $path | cut -d' ' -f1)
qualityProfileId="$(echo "$data" | jq -r ".defaultQualityProfileId")" qualityProfileId="$(echo "$data" | jq -r ".defaultQualityProfileId")"
@ -297,7 +320,7 @@ AddTidalArtistToLidarr () {
fi fi
log "$artistNumber of $lidarrArtistTotal :: $lidarrArtistName :: $currentprocess of $numberOfRelatedArtistsToAddPerArtist :: $serviceArtistName :: Adding $artistName to Lidarr ($foreignId)..." log "$artistNumber of $lidarrArtistTotal :: $lidarrArtistName :: $currentprocess of $numberOfRelatedArtistsToAddPerArtist :: $serviceArtistName :: Adding $artistName to Lidarr ($foreignId)..."
LidarrTaskStatusCheck LidarrTaskStatusCheck
lidarrAddArtist=$(curl -s "$lidarrUrl/api/v1/artist" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $lidarrApiKey" --data-raw "$data") lidarrAddArtist=$(curl -s "$arrUrl/api/v1/artist" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" --data-raw "$data")
else else
log "$artistNumber of $lidarrArtistTotal :: $lidarrArtistName :: $currentprocess of $numberOfRelatedArtistsToAddPerArtist :: $serviceArtistName :: ERROR :: Artist not found in Musicbrainz, please add \"https://listen.tidal.com/artist/${serviceArtistId}\" to the correct artist on Musicbrainz" log "$artistNumber of $lidarrArtistTotal :: $lidarrArtistName :: $currentprocess of $numberOfRelatedArtistsToAddPerArtist :: $serviceArtistName :: ERROR :: Artist not found in Musicbrainz, please add \"https://listen.tidal.com/artist/${serviceArtistId}\" to the correct artist on Musicbrainz"
NotifyWebhook "ArtistError" "Artist not found in Musicbrainz, please add <https://listen.tidal.com/artist/${serviceArtistId}> to the correct artist on Musicbrainz" NotifyWebhook "ArtistError" "Artist not found in Musicbrainz, please add <https://listen.tidal.com/artist/${serviceArtistId}> to the correct artist on Musicbrainz"
@ -311,7 +334,10 @@ AddTidalArtistToLidarr () {
for (( ; ; )); do for (( ; ; )); do
let i++ let i++
logfileSetup logfileSetup
log "Script starting..."
verifyConfig verifyConfig
getArrAppInfo
verifyApiAccess
if [ -z $lidarrSearchForMissing ]; then if [ -z $lidarrSearchForMissing ]; then
lidarrSearchForMissing=true lidarrSearchForMissing=true