new feature, add top album artists & top track artists, simplify code

pull/6/head
RandomNinjaAtk 2 years ago committed by GitHub
parent 15ecbfe43d
commit 2208e2943d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -28,28 +28,45 @@ Configuration () {
log ""
sleep 2
log "############# $dockerTitle"
log "############# SCRIPT VERSION 1.0.0002"
log "############# SCRIPT VERSION 1.0.0003"
log "############# DOCKER VERSION $dockerVersion"
}
AddDeezerTopArtists () {
getDeezerArtistsIds=($(curl -s https://api.deezer.com/chart/0/artists | jq -r ".data[].id"))
getDeezerArtistsIdsCount=$(curl -s https://api.deezer.com/chart/0/artists | jq -r ".data[].id" | wc -l)
description="Top Artists"
AddDeezerArtistToLidarr
}
AddDeezerTopAlbumArtists () {
getDeezerArtistsIds=($(curl -s https://api.deezer.com/chart/0/albums | jq -r ".data[].artist.id"))
getDeezerArtistsIdsCount=$(curl -s https://api.deezer.com/chart/0/albums | jq -r ".data[].artist.id" | wc -l)
description="Top Album Artists"
AddDeezerArtistToLidarr
}
AddDeezerTopTrackArtists () {
getDeezerArtistsIds=($(curl -s https://api.deezer.com/chart/0/tracks | jq -r ".data[].artist.id"))
getDeezerArtistsIdsCount=$(curl -s https://api.deezer.com/chart/0/tracks | jq -r ".data[].artist.id" | wc -l)
description="Top Track Artists"
}
AddDeezerArtistToLidarr () {
lidarrArtistsData="$(curl -s "$lidarrUrl/api/v1/artist?apikey=${lidarrApiKey}")"
lidarrArtistIds="$(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId")"
deezerArtistsUrl=$(echo "${lidarrArtistsData}" | jq -r ".[].links | .[] | select(.name==\"deezer\") | .url")
deezeArtistIds="$(echo "$deezerArtistsUrl" | grep -o '[[:digit:]]*' | sort -u)"
getDeezerTopArtistsData=$(curl -s https://api.deezer.com/chart/0/artists | jq -r ".data[]")
getDeezerTopArtistsIds=($(curl -s https://api.deezer.com/chart/0/artists | jq -r ".data[].id"))
getDeezerTopArtistsIdsCount=$(curl -s https://api.deezer.com/chart/0/artists | jq -r ".data[].id" | wc -l)
log ":: Finding Top Artists..."
log ":: $getDeezerTopArtistsIdsCount Top Artists Found"
for id in ${!getDeezerTopArtistsIds[@]}; do
log ":: Finding $description..."
log ":: $getDeezerArtistsIdsCount $description Found..."
for id in ${!getDeezerArtistsIds[@]}; do
currentprocess=$(( $id + 1 ))
deezerArtistId="${getDeezerTopArtistsIds[$id]}"
deezerArtistName="$(echo $getDeezerTopArtistsData | jq -r "select(.id==$deezerArtistId) | .name")"
log ":: $currentprocess of $getDeezerTopArtistsIdsCount :: $deezerArtistName :: Searching Musicbrainz for Deezer artist id ($deezerArtistId)"
deezerArtistId="${getDeezerArtistsIds[$id]}"
deezerArtistName="$(curl -s https://api.deezer.com/artist/$deezerArtistId | jq -r .name)"
log ":: $currentprocess of $getDeezerArtistsIdsCount :: $deezerArtistName :: Searching Musicbrainz for Deezer artist id ($deezerArtistId)"
if echo "$deezeArtistIds" | grep "^${deezerArtistId}$" | read; then
log ":: $currentprocess of $getDeezerTopArtistsIdsCount :: $deezerArtistName :: $deezerArtistId already in Lidarr..."
log ":: $currentprocess of $getDeezerArtistsIdsCount :: $deezerArtistName :: $deezerArtistId already in Lidarr..."
continue
fi
@ -100,14 +117,14 @@ AddDeezerTopArtists () {
}"
if echo "$lidarrArtistIds" | grep "^${musicbrainz_main_artist_id}$" | read; then
log ":: $currentprocess of $getDeezerTopArtistsIdsCount :: $deezerArtistName :: Already in Lidarr ($musicbrainz_main_artist_id), skipping..."
log ":: $currentprocess of $getDeezerArtistsIdsCount :: $deezerArtistName :: Already in Lidarr ($musicbrainz_main_artist_id), skipping..."
continue
fi
log ":: $currentprocess of $getDeezerTopArtistsIdsCount :: $deezerArtistName :: Adding $artistName to Lidarr ($musicbrainz_main_artist_id)..."
log ":: $currentprocess of $getDeezerArtistsIdsCount :: $deezerArtistName :: Adding $artistName to Lidarr ($musicbrainz_main_artist_id)..."
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 "$lidarrUrl/api/v1/artist" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $lidarrApiKey" --data-raw "$data")
else
log ":: $currentprocess of $getDeezerTopArtistsIdsCount :: $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"
fi
done
}
@ -739,7 +756,7 @@ AddRelatedArtists () {
lidarrArtistList=($(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId"))
lidarrArtistIds="$(echo "${lidarrArtistsData}" | jq -r ".[].foreignArtistId")"
lidarrArtistLinkDeezerIds="$(echo "${lidarrArtistsData}" | jq -r ".[] | .links[] | select(.name==\"deezer\") | .url" | grep -o '[[:digit:]]*')"
log "$lidarrArtistTotal Artists Found"
log ":: $lidarrArtistTotal Artists Found"
deezerArtistsUrl=$(echo "${lidarrArtistsData}" | jq -r ".[].links | .[] | select(.name==\"deezer\") | .url")
deezeArtistIds="$(echo "$deezerArtistsUrl" | grep -o '[[:digit:]]*' | sort -u)"
@ -754,80 +771,12 @@ AddRelatedArtists () {
for dId in ${!deezerArtistIds[@]}; do
deezerArtistId="${deezerArtistIds[$dId]}"
deezerRelatedArtistData=$(curl -sL --fail "https://api.deezer.com/artist/$deezerArtistId/related")
deezerRelatedArtistIds=($(echo $deezerRelatedArtistData | jq -r .data[].id))
for dRId in ${!deezerRelatedArtistIds[@]}; do
deezerRelatedArtistId="${deezerRelatedArtistIds[$dRId]}"
if echo "$deezeArtistIds" | grep "^${deezerRelatedArtistId}$" | read; then
log "$deezerRelatedArtistId already in Lidarr..."
continue
fi
query_data=$(curl -s -A "$agent" "https://musicbrainz.org/ws/2/url?query=url:%22https://www.deezer.com/artist/${deezerRelatedArtistId}%22&fmt=json")
count=$(echo "$query_data" | jq -r ".count")
if [ "$count" == "0" ]; then
sleep 1.5
query_data=$(curl -s -A "$agent" "https://musicbrainz.org/ws/2/url?query=url:%22http://www.deezer.com/artist/${deezerRelatedArtistId}%22&fmt=json")
count=$(echo "$query_data" | jq -r ".count")
sleep 1.5
fi
if [ "$count" == "0" ]; then
query_data=$(curl -s -A "$agent" "https://musicbrainz.org/ws/2/url?query=url:%22http://deezer.com/artist/${deezerRelatedArtistId}%22&fmt=json")
count=$(echo "$query_data" | jq -r ".count")
sleep 1.5
fi
if [ "$count" == "0" ]; then
query_data=$(curl -s -A "$agent" "https://musicbrainz.org/ws/2/url?query=url:%22https://deezer.com/artist/${deezerRelatedArtistId}%22&fmt=json")
count=$(echo "$query_data" | jq -r ".count")
fi
if [ "$count" != "0" ]; then
musicbrainz_main_artist_id=$(echo "$query_data" | jq -r '.urls[]."relation-list"[].relations[].artist.id' | head -n 1)
sleep 1.5
artist_data=$(curl -s -A "$agent" "https://musicbrainz.org/ws/2/artist/$musicbrainz_main_artist_id?fmt=json")
artist_sort_name="$(echo "$artist_data" | jq -r '."sort-name"')"
artist_formed="$(echo "$artist_data" | jq -r '."begin-area".name')"
artist_born="$(echo "$artist_data" | jq -r '."life-span".begin')"
gender="$(echo "$artist_data" | jq -r ".gender")"
matched_id=true
data=$(curl -s "$lidarrUrl/api/v1/search?term=lidarr%3A$musicbrainz_main_artist_id" -H "X-Api-Key: $lidarrApiKey" | jq -r ".[]")
artistName="$(echo "$data" | jq -r ".artist.artistName")"
foreignId="$(echo "$data" | jq -r ".foreignId")"
data=$(curl -s "$lidarrUrl/api/v1/rootFolder" -H "X-Api-Key: $lidarrApiKey" | jq -r ".[]")
path="$(echo "$data" | jq -r ".path")"
qualityProfileId="$(echo "$data" | jq -r ".defaultQualityProfileId")"
metadataProfileId="$(echo "$data" | jq -r ".defaultMetadataProfileId")"
data="{
\"artistName\": \"$artistName\",
\"foreignArtistId\": \"$foreignId\",
\"qualityProfileId\": $qualityProfileId,
\"metadataProfileId\": $metadataProfileId,
\"monitored\":true,
\"monitor\":\"all\",
\"rootFolderPath\": \"$path\"
}"
if echo "$lidarrArtistIds" | grep "^${musicbrainz_main_artist_id}$" | read; then
log "$artistName to already in Lidarr ($musicbrainz_main_artist_id)..."
continue
fi
log "Adding $artistName to Lidarr ($musicbrainz_main_artist_id)..."
LidarrTaskStatusCheck
lidarrAddArtist=$(curl -s "$lidarrUrl/api/v1/artist" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $lidarrApiKey" --data-raw "$data")
else
matched_id=false
fi
done
getDeezerArtistsIds=($(echo $deezerRelatedArtistData | jq -r .data[].id))
getDeezerArtistsIdsCount=$(echo $deezerRelatedArtistData | jq -r .data[].id | wc -l)
description="$lidarrArtistName Related Artists"
AddDeezerArtistToLidarr
done
done
}
LidarrTaskStatusCheck () {
@ -849,11 +798,22 @@ if [ "$addDeezerTopArtists" = "true" ]; then
else
log ":: ERROR :: addDeezerTopArtists is disabled"
fi
if [ "$addDeezerTopAlbumArtists" = "true" ]; then
AddDeezerTopAlbumArtists
else
log ":: ERROR :: addDeezerTopAlbumArtists is disabled"
fi
if [ "$AddRelatedArtists" = "true" ]; then
if [ "$addDeezerTopTrackArtists" = "true" ]; then
AddDeezerTopTrackArtists
else
log ":: ERROR :: addDeezerTopTrackArtists is disabled"
fi
if [ "$addRelatedArtists" = "true" ]; then
AddRelatedArtists
else
log ":: ERROR :: AddRelatedArtists is disabled"
log ":: ERROR :: addRelatedArtists is disabled"
fi
if [ "$dlClientSource" = "deezer" ] || [ "$dlClientSource" = "both" ]; then

Loading…
Cancel
Save