@ -1,6 +1,8 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bash
lidarrApiKey = " $( grep "<ApiKey>" /config/config.xml | sed "s/\ <ApiKey>//;s/<\/ApiKey>//" ) "
lidarrApiKey = " $( grep "<ApiKey>" /config/config.xml | sed "s/\ <ApiKey>//;s/<\/ApiKey>//" ) "
lidarrUrl = "http://127.0.0.1:8686"
lidarrUrl = "http://127.0.0.1:8686"
agent = "lidarr-extended ( https://github.com/RandomNinjaAtk/docker-lidarr-extended )"
musicbrainzMirror = https://musicbrainz.org
CountryCode = US
CountryCode = US
log ( ) {
log ( ) {
@ -207,109 +209,191 @@ SearchProcess () {
lidarrArtistPath = " $( echo " ${ lidarrArtistData } " | jq -r " .path" ) "
lidarrArtistPath = " $( echo " ${ lidarrArtistData } " | jq -r " .path" ) "
lidarrArtistFolder = " $( basename " ${ lidarrArtistPath } " ) "
lidarrArtistFolder = " $( basename " ${ lidarrArtistPath } " ) "
lidarrArtistNameSanitized = " $( basename " ${ lidarrArtistPath } " | sed 's% (.*)$%%g' ) "
lidarrArtistNameSanitized = " $( basename " ${ lidarrArtistPath } " | sed 's% (.*)$%%g' ) "
lidarrArtistName = $( echo " ${ lidarrArtistData } " | jq -r ".artistName" )
lidarrArtistForeignArtistId = $( echo " ${ lidarrArtistData } " | jq -r ".foreignArtistId" )
tidalArtistUrl = $( echo " ${ lidarrArtistData } " | jq -r ".links | .[] | select(.name==\"tidal\") | .url" )
tidalArtistUrl = $( echo " ${ lidarrArtistData } " | jq -r ".links | .[] | select(.name==\"tidal\") | .url" )
tidalArtistId = " $( echo " $tidalArtistUrl " | grep -o '[[:digit:]]*' | sort -u) "
tidalArtistId = " $( echo " $tidalArtistUrl " | grep -o '[[:digit:]]*' | sort -u) "
deezerArtistUrl = $( echo " ${ lidarrArtistData } " | jq -r ".links | .[] | select(.name==\"deezer\") | .url" )
deezerArtistUrl = $( echo " ${ lidarrArtistData } " | jq -r ".links | .[] | select(.name==\"deezer\") | .url" )
deezeArtistIds = ( $( echo " $deezerArtistUrl " | grep -o '[[:digit:]]*' | sort -u) )
deezeArtistIds = ( $( echo " $deezerArtistUrl " | grep -o '[[:digit:]]*' | sort -u) )
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName Sanitized :: $lidarrAlbumTitle :: Starting Search... "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: Starting Search... "
if [ -f " /config/logs/downloaded/notfound/ $lidarrAlbumForeignAlbumId " ] ; then
if [ -f " /config/logs/downloaded/notfound/ $lidarrAlbumForeignAlbumId " ] ; then
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName Sanitized :: $lidarrAlbumTitle :: Previously Not Found, skipping... "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: Previously Not Found, skipping... "
continue
continue
fi
fi
for dId in ${ !deezeArtistIds[@] } ; do
skipDeezer = false
deezeArtistId = " ${ deezeArtistIds [ $dId ] } "
if [ -z " $deezerArtistUrl " ] ; then
if [ ! -d /config/cache/deezer ] ; then
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: DEEZER :: ERROR :: musicbrainz id: $lidarrArtistForeignArtistId is missing Tidal link, see: \"/config/logs/error/ $lidarrArtistNameSanitized .log\" for more detail... "
mkdir -p /config/cache/deezer
if [ ! -d /config/logs/error ] ; then
fi
mkdir -p /config/logs/error
if [ ! -f /config/cache/deezer/$deezeArtistId -albums.json ] ; then
fi
curl -s " https://api.deezer.com/artist/ $deezeArtistId /albums?limit=1000 " > /config/cache/deezer/$deezeArtistId -albums.json
if [ ! -f " /config/logs/error/ $lidarrArtistNameSanitized .log " ] ; then
fi
echo " Update Musicbrainz Relationship Page: https://musicbrainz.org/artist/ $lidarrArtistForeignArtistId /relationships for \" ${ lidarrArtistName } \" with Deezer Artist Link " >> " /config/logs/error/ $lidarrArtistNameSanitized .log "
done
fi
skipDeezer = true
if [ ! -d /config/cache/tidal ] ; then
mkdir -p /config/cache/tidal
fi
if [ ! -f /config/cache/tidal/$tidalArtistId -videos.json ] ; then
curl -s " https://api.tidal.com/v1/artists/ ${ tidalArtistId } /videos?limit=10000&countryCode= $CountryCode &filter=ALL " -H 'x-tidal-token: CzET4vdadNUFQ5JU' > /config/cache/tidal/$tidalArtistId -videos.json
fi
fi
if [ ! -f /config/cache/tidal/$tidalArtistId -albums.json ] ; then
curl -s " https://api.tidal.com/v1/artists/ ${ tidalArtistId } /albums?limit=10000&countryCode= $CountryCode &filter=ALL " -H 'x-tidal-token: CzET4vdadNUFQ5JU' > /config/cache/tidal/$tidalArtistId -albums.json
fi
tidalArtistAlbumsData = $( cat " /config/cache/tidal/ $tidalArtistId -albums.json " | jq -r ".items | sort_by(.numberOfTracks) | sort_by(.explicit) | reverse |.[]" )
tidalArtistAlbumsIds = ( $( echo " ${ tidalArtistAlbumsData } " | jq -r "select(.explicit==" true") | .id" ) )
for dId in ${ !deezeArtistIds[@] } ; do
if [ " $skipDeezer " = "false" ] ; then
deezeArtistId = " ${ deezeArtistIds [ $dId ] } "
for dId in ${ !deezeArtistIds[@] } ; do
deezerArtistAlbumsData = $( cat " /config/cache/deezer/ $deezeArtistId -albums.json " | jq -r ".data | sort_by(.release_date) | sort_by(.explicit_lyrics) | reverse | .[]" )
deezeArtistId = " ${ deezeArtistIds [ $dId ] } "
deezerArtistAlbumsIds = ( $( echo " ${ deezerArtistAlbumsData } " | jq -r "select(.explicit_lyrics==" true") | .id" ) )
if [ ! -d /config/cache/deezer ] ; then
mkdir -p /config/cache/deezer
fi
if [ ! -f /config/cache/deezer/$deezeArtistId -albums.json ] ; then
curl -s " https://api.deezer.com/artist/ $deezeArtistId /albums?limit=1000 " > /config/cache/deezer/$deezeArtistId -albums.json
fi
done
fi
skipTidal = false
if [ -z " $tidalArtistUrl " ] ; then
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: TIDAL :: ERROR :: musicbrainz id: $lidarrArtistForeignArtistId is missing Tidal link, see: \"/config/logs/error/ $lidarrArtistNameSanitized .log\" for more detail... "
if [ ! -d /config/logs/error ] ; then
mkdir -p /config/logs/error
fi
if [ ! -f " /config/logs/error/ $lidarrArtistNameSanitized .log " ] ; then
echo " Update Musicbrainz Relationship Page: https://musicbrainz.org/artist/ $lidarrArtistForeignArtistId /relationships for \" ${ lidarrArtistName } \" with Tidal Artist Link " >> " /config/logs/error/ $lidarrArtistNameSanitized .log "
fi
skipTidal = true
fi
done
if [ " $skipTidal " = "false" ] ; then
if [ ! -d /config/cache/tidal ] ; then
mkdir -p /config/cache/tidal
fi
if [ ! -f /config/cache/tidal/$tidalArtistId -videos.json ] ; then
curl -s " https://api.tidal.com/v1/artists/ ${ tidalArtistId } /videos?limit=10000&countryCode= $CountryCode &filter=ALL " -H 'x-tidal-token: CzET4vdadNUFQ5JU' > /config/cache/tidal/$tidalArtistId -videos.json
fi
if [ ! -f /config/cache/tidal/$tidalArtistId -albums.json ] ; then
curl -s " https://api.tidal.com/v1/artists/ ${ tidalArtistId } /albums?limit=10000&countryCode= $CountryCode &filter=ALL " -H 'x-tidal-token: CzET4vdadNUFQ5JU' > /config/cache/tidal/$tidalArtistId -albums.json
fi
tidalArtistAlbumsData = $( cat " /config/cache/tidal/ $tidalArtistId -albums.json " | jq -r ".items | sort_by(.numberOfTracks) | sort_by(.explicit) | reverse |.[]" )
tidalArtistAlbumsIds = ( $( echo " ${ tidalArtistAlbumsData } " | jq -r "select(.explicit==" true") | .id" ) )
fi
if [ " $skipDeezer " = "false" ] ; then
for dId in ${ !deezeArtistIds[@] } ; do
deezeArtistId = " ${ deezeArtistIds [ $dId ] } "
deezerArtistAlbumsData = $( cat " /config/cache/deezer/ $deezeArtistId -albums.json " | jq -r ".data | sort_by(.release_date) | sort_by(.explicit_lyrics) | reverse | .[]" )
deezerArtistAlbumsIds = ( $( echo " ${ deezerArtistAlbumsData } " | jq -r "select(.explicit_lyrics==" true") | .id" ) )
done
fi
LidarrTaskStatusCheck
CheckLidarrBeforeImport " $lidarrAlbumForeignAlbumId " "notbeets"
CheckLidarrBeforeImport " $lidarrAlbumForeignAlbumId " "notbeets"
if [ $alreadyImported = true ] ; then
if [ $alreadyImported = true ] ; then
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Already Imported, skipping... "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Already Imported, skipping... "
continue
continue
fi
fi
if [ " $skipDeezer " = "false" ] ; then
for dId in ${ !deezeArtistIds[@] } ; do
deezeArtistId = " ${ deezeArtistIds [ $dId ] } "
deezerArtistAlbumsData = $( cat " /config/cache/deezer/ $deezeArtistId -albums.json " | jq -r ".data | sort_by(.release_date) | sort_by(.explicit_lyrics) | reverse | .[]" )
deezerArtistAlbumsIds = ( $( echo " ${ deezerArtistAlbumsData } " | jq -r "select(.explicit_lyrics==" true") | .id" ) )
if echo " ${ deezerArtistAlbumsData } " | jq -r .title | grep -i " ^ $lidarrAlbumTitle " | read; then
for id in ${ !deezerArtistAlbumsIds[@] } ; do
processNumberTwo = $(( $id + 1 ))
deezerArtistAlbumId = " ${ deezerArtistAlbumsIds [ $id ] } "
deezerArtistAlbumData = $( echo " $deezerArtistAlbumsData " | jq -r "select(.id==" $deezerArtistAlbumId ")" )
deezerArtistAlbumTitleClean = $( echo ${ deezerArtistAlbumData } | jq -r .title | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g' )
if echo ${ deezerArtistAlbumTitleClean } | grep -i " ^ $lidarrAlbumTitleClean " | read; then
downloadedAlbumTitle = " $( echo ${ deezerArtistAlbumData } | jq -r .title) "
downloadedReleaseDate = " $( echo ${ deezerArtistAlbumData } | jq -r .release_date) "
downloadedReleaseYear = " ${ downloadedReleaseDate : 0 : 4 } "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $lidarrAlbumTitleClean vs $deezerArtistAlbumTitleClean :: Explicit Deezer MATCH Found "
if [ -f /config/logs/downloaded/deezer/$deezerArtistAlbumId ] ; then
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Previously Downloaded, skipping... "
continue
fi
DownloadProcess " $deezerArtistAlbumId " "DEEZER" " $downloadedReleaseYear "
fi
LidarrTaskStatusCheck
done
else
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: No Explicit Deezer Match Found "
fi
done
fi
for dId in ${ !deezeArtistIds[@] } ; do
LidarrTaskStatusCheck
deezeArtistId = " ${ deezeArtistIds [ $dId ] } "
CheckLidarrBeforeImport " $lidarrAlbumForeignAlbumId " "notbeets"
deezerArtistAlbumsData = $( cat " /config/cache/deezer/ $deezeArtistId -albums.json " | jq -r ".data | sort_by(.release_date) | sort_by(.explicit_lyrics) | reverse | .[]" )
if [ $alreadyImported = true ] ; then
deezerArtistAlbumsIds = ( $( echo " ${ deezerArtistAlbumsData } " | jq -r "select(.explicit_lyrics==" true") | .id" ) )
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Already Imported, skipping... "
continue
fi
if echo " ${ deezerArtistAlbumsData } " | jq -r .title | grep -i " ^ $lidarrAlbumTitle " | read; then
if [ " $skipTidal " = "false" ] ; then
for id in ${ !deezerArtistAlbumsIds[@] } ; do
if echo " ${ tidalArtistAlbumsData } " | jq -r .title | grep -i " ^ $lidarrAlbumTitle " | read; then
for id in ${ !tidalArtistAlbumsIds[@] } ; do
processNumberTwo = $(( $id + 1 ))
processNumberTwo = $(( $id + 1 ))
deezerArtistAlbumId = " ${ deezerArtistAlbumsIds [ $id ] } "
tidalArtistAlbumId = " ${ tidalArtistAlbumsIds [ $id ] } "
deezerArtistAlbumData = $( echo " $deezerArtistAlbumsData " | jq -r "select(.id==" $deezerArtistAlbumId ")" )
tidalArtistAlbumData = $( echo " $tidalArtistAlbumsData " | jq -r "select(.id==" $tidalArtistAlbumId ")" )
deezerArtistAlbumTitleClean = $( echo ${ deezerArtistAlbumData } | jq -r .title | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g' )
tidalArtistAlbumTitleClean = $( echo ${ tidalArtistAlbumData } | jq -r .title | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g' )
if echo ${ deezerArtistAlbumTitleClean } | grep -i " ^ $lidarrAlbumTitleClean " | read; then
if echo ${ tidalArtistAlbumTitleClean } | grep -i " ^ $lidarrAlbumTitleClean " | read; then
downloadedAlbumTitle = " $( echo ${ deezerArtistAlbumData } | jq -r .title) "
downloadedAlbumTitle = " $( echo ${ tidalArtistAlbumData } | jq -r .title) "
downloadedReleaseDate = " $( echo ${ deezerArtistAlbumData } | jq -r .release_date) "
downloadedReleaseDate = " $( echo ${ tidalArtistAlbumData } | jq -r .releaseDate) "
if [ " $downloadedReleaseDate " = "null" ] ; then
downloadedReleaseDate = $( echo $tidalArtistAlbumData | jq -r '.streamStartDate' )
fi
downloadedReleaseYear = " ${ downloadedReleaseDate : 0 : 4 } "
downloadedReleaseYear = " ${ downloadedReleaseDate : 0 : 4 } "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $lidarrAlbumTitleClean vs $deezerArtistAlbumTitleClean :: Explicit Deezer MATCH Found "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $lidarrAlbumTitleClean vs $ tidalArtistAlbumTitleClean :: Explicit Tidal Match Found"
if [ -f /config/logs/downloaded/deezer/$deezerArtistAlbumId ] ; then
if [ -f /config/logs/downloaded/tidal/$tidal ArtistAlbumId ] ; then
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Previously Downloaded, skipping... "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Previously Downloaded, skipping... "
continue
continue
fi
fi
DownloadProcess " $deezerArtistAlbumId " "DEEZER" " $downloadedReleaseYear "
DownloadProcess " $ tidalArtistAlbumId" "TIDAL " " $downloadedReleaseYear "
fi
fi
LidarrTaskStatusCheck
done
done
else
else
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: No Explicit Deezer Match Found "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: No Explicit Tidal Match Found"
fi
fi
done
fi
LidarrTaskStatusCheck
CheckLidarrBeforeImport " $lidarrAlbumForeignAlbumId " "notbeets"
CheckLidarrBeforeImport " $lidarrAlbumForeignAlbumId " "notbeets"
if [ $alreadyImported = true ] ; then
if [ $alreadyImported = true ] ; then
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Already Imported, skipping... "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Already Imported, skipping... "
continue
continue
fi
fi
if echo " ${ tidalArtistAlbumsData } " | jq -r .title | grep -i " ^ $lidarrAlbumTitle " | read; then
if [ " $skipDeezer " = "false" ] ; then
for id in ${ !tidalArtistAlbumsIds[@] } ; do
for dId in ${ !deezeArtistIds[@] } ; do
processNumberTwo = $(( $id + 1 ))
deezeArtistId = " ${ deezeArtistIds [ $dId ] } "
tidalArtistAlbumId = " ${ tidalArtistAlbumsIds [ $id ] } "
deezerArtistAlbumsData = $( cat " /config/cache/deezer/ $deezeArtistId -albums.json " | jq -r ".data | sort_by(.release_date) | sort_by(.explicit_lyrics) | reverse | .[]" )
tidalArtistAlbumData = $( echo " $tidalArtistAlbumsData " | jq -r "select(.id==" $tidalArtistAlbumId ")" )
deezerArtistAlbumsIds = ( $( echo " ${ deezerArtistAlbumsData } " | jq -r "select(.explicit_lyrics==" false") | .id" ) )
tidalArtistAlbumTitleClean = $( echo ${ tidalArtistAlbumData } | jq -r .title | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g' )
if echo ${ tidalArtistAlbumTitleClean } | grep -i " ^ $lidarrAlbumTitleClean " | read; then
if echo " ${ deezerArtistAlbumsData } " | jq -r .title | grep -i " ^ $lidarrAlbumTitle " | read; then
downloadedAlbumTitle = " $( echo ${ tidalArtistAlbumData } | jq -r .title) "
for id in ${ !deezerArtistAlbumsIds[@] } ; do
downloadedReleaseDate = " $( echo ${ tidalArtistAlbumData } | jq -r .releaseDate) "
processNumberTwo = $(( $id + 1 ))
if [ " $downloadedReleaseDate " = "null" ] ; then
deezerArtistAlbumId = " ${ deezerArtistAlbumsIds [ $id ] } "
downloadedReleaseDate = $( echo $tidalArtistAlbumData | jq -r '.streamStartDate' )
deezerArtistAlbumData = $( echo " $deezerArtistAlbumsData " | jq -r "select(.id==" $deezerArtistAlbumId ")" )
fi
deezerArtistAlbumExplicit = $( echo ${ deezerArtistAlbumData } | jq -r .explicit_lyrics)
downloadedReleaseYear = " ${ downloadedReleaseDate : 0 : 4 } "
deezerArtistAlbumTitleClean = $( echo ${ deezerArtistAlbumData } | jq -r .title | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g' )
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $lidarrAlbumTitleClean vs $tidalArtistAlbumTitleClean :: Explicit Tidal Match Found "
if echo ${ deezerArtistAlbumTitleClean } | grep -i " ^ $lidarrAlbumTitleClean " | read; then
if [ -f /config/logs/downloaded/tidal/$tidalArtistAlbumId ] ; then
downloadedAlbumTitle = " $( echo ${ deezerArtistAlbumData } | jq -r .title) "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Previously Downloaded, skipping... "
downloadedReleaseDate = " $( echo ${ deezerArtistAlbumData } | jq -r .release_date) "
continue
downloadedReleaseYear = " ${ downloadedReleaseDate : 0 : 4 } "
fi
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $lidarrAlbumTitleClean vs $deezerArtistAlbumTitleClean :: CLEAN Deezer MATCH Found "
DownloadProcess " $tidalArtistAlbumId " "TIDAL" " $downloadedReleaseYear "
if [ -f /config/logs/downloaded/deezer/$deezerArtistAlbumId ] ; then
fi
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Previously Downloaded, skipping... "
done
continue
else
fi
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: No Explicit Tidal Match Found "
DownloadProcess " $deezerArtistAlbumId " "DEEZER" " $downloadedReleaseYear "
fi
fi
LidarrTaskStatusCheck
done
else
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: No Clean Deezer Match Found "
fi
LidarrTaskStatusCheck
done
fi
LidarrTaskStatusCheck
CheckLidarrBeforeImport " $lidarrAlbumForeignAlbumId " "notbeets"
CheckLidarrBeforeImport " $lidarrAlbumForeignAlbumId " "notbeets"
if [ $alreadyImported = true ] ; then
if [ $alreadyImported = true ] ; then
@ -317,67 +401,38 @@ SearchProcess () {
continue
continue
fi
fi
for dId in ${ !deezeArtistIds[@] } ; do
if [ " $skipTidal " = "false" ] ; then
deezeArtistId = " ${ deezeArtistIds [ $dId ] } "
deezerArtistAlbumsData = $( cat " /config/cache/deezer/ $deezeArtistId -albums.json " | jq -r ".data | sort_by(.release_date) | sort_by(.explicit_lyrics) | reverse | .[]" )
deezerArtistAlbumsIds = ( $( echo " ${ deezerArtistAlbumsData } " | jq -r "select(.explicit_lyrics==" false") | .id" ) )
if echo " ${ deezerArtistAlbumsData } " | jq -r .title | grep -i " ^ $lidarrAlbumTitle " | read; then
tidalArtistAlbumsIds = ( $( echo " ${ tidalArtistAlbumsData } " | jq -r "select(.explicit==" false") | .id" ) )
for id in ${ !deezerArtistAlbumsIds[@] } ; do
if echo " ${ tidalArtistAlbumsData } " | jq -r .title | grep -i " ^ $lidarrAlbumTitle " | read; then
for id in ${ !tidalArtistAlbumsIds[@] } ; do
processNumberTwo = $(( $id + 1 ))
processNumberTwo = $(( $id + 1 ))
deezerArtistAlbumId = " ${ deezerArtistAlbumsIds [ $id ] } "
tidalArtistAlbumId = " ${ tidalArtistAlbumsIds [ $id ] } "
deezerArtistAlbumData = $( echo " $deezerArtistAlbumsData " | jq -r "select(.id==" $deezerArtistAlbumId ")" )
tidalArtistAlbumData = $( echo " $tidalArtistAlbumsData " | jq -r "select(.id==" $tidalArtistAlbumId ")" )
deezerArtistAlbumExplicit = $( echo ${ deezerArtistAlbumData } | jq -r .explicit_lyrics)
tidalArtistAlbumTitleClean = $( echo ${ tidalArtistAlbumData } | jq -r .title | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g' )
deezerArtistAlbumTitleClean = $( echo ${ deezerArtistAlbumData } | jq -r .title | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g' )
if echo ${ tidalArtistAlbumTitleClean } | grep -i " ^ $lidarrAlbumTitleClean " | read; then
if echo ${ deezerArtistAlbumTitleClean } | grep -i " ^ $lidarrAlbumTitleClean " | read; then
downloadedAlbumTitle = " $( echo ${ tidalArtistAlbumData } | jq -r .title) "
downloadedAlbumTitle = " $( echo ${ deezerArtistAlbumData } | jq -r .title) "
downloadedReleaseDate = " $( echo ${ tidalArtistAlbumData } | jq -r .releaseDate) "
downloadedReleaseDate = " $( echo ${ deezerArtistAlbumData } | jq -r .release_date) "
if [ " $downloadedReleaseDate " = "null" ] ; then
downloadedReleaseDate = $( echo $tidalArtistAlbumData | jq -r '.streamStartDate' )
fi
downloadedReleaseYear = " ${ downloadedReleaseDate : 0 : 4 } "
downloadedReleaseYear = " ${ downloadedReleaseDate : 0 : 4 } "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $lidarrAlbumTitleClean vs $deezerArtistAlbumTitleClean :: CLEAN Deezer MATCH Found "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $lidarrAlbumTitleClean vs $ tidalArtistAlbumTitleClean :: CLEAN Tidal Match Found"
if [ -f /config/logs/downloaded/deezer/$deezer ArtistAlbumId ] ; then
if [ -f /config/logs/downloaded/tidal/$tidal ArtistAlbumId ] ; then
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Previously Downloaded, skipping... "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Previously Downloaded, skipping... "
continue
continue
fi
fi
DownloadProcess " $ deezerArtistAlbumId" "DEEZER " " $downloadedReleaseYear "
DownloadProcess " $ tidalArtistAlbumId" "TIDAL " " $downloadedReleaseYear "
fi
fi
LidarrTaskStatusCheck
done
done
else
else
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: No Clean Deezer Match Found"
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: No Clean Tidal Match Found"
fi
fi
done
CheckLidarrBeforeImport " $lidarrAlbumForeignAlbumId " "notbeets"
if [ $alreadyImported = true ] ; then
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Already Imported, skipping... "
continue
fi
fi
tidalArtistAlbumsIds = ( $( echo " ${ tidalArtistAlbumsData } " | jq -r "select(.explicit==" false") | .id" ) )
if echo " ${ tidalArtistAlbumsData } " | jq -r .title | grep -i " ^ $lidarrAlbumTitle " | read; then
for id in ${ !tidalArtistAlbumsIds[@] } ; do
processNumberTwo = $(( $id + 1 ))
tidalArtistAlbumId = " ${ tidalArtistAlbumsIds [ $id ] } "
tidalArtistAlbumData = $( echo " $tidalArtistAlbumsData " | jq -r "select(.id==" $tidalArtistAlbumId ")" )
tidalArtistAlbumTitleClean = $( echo ${ tidalArtistAlbumData } | jq -r .title | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g' )
if echo ${ tidalArtistAlbumTitleClean } | grep -i " ^ $lidarrAlbumTitleClean " | read; then
downloadedAlbumTitle = " $( echo ${ tidalArtistAlbumData } | jq -r .title) "
downloadedReleaseDate = " $( echo ${ tidalArtistAlbumData } | jq -r .releaseDate) "
if [ " $downloadedReleaseDate " = "null" ] ; then
downloadedReleaseDate = $( echo $tidalArtistAlbumData | jq -r '.streamStartDate' )
fi
downloadedReleaseYear = " ${ downloadedReleaseDate : 0 : 4 } "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $lidarrAlbumTitleClean vs $tidalArtistAlbumTitleClean :: CLEAN Tidal Match Found "
if [ -f /config/logs/downloaded/tidal/$tidalArtistAlbumId ] ; then
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Previously Downloaded, skipping... "
continue
fi
DownloadProcess " $tidalArtistAlbumId " "TIDAL" " $downloadedReleaseYear "
fi
done
else
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: No Clean Tidal Match Found "
fi
mkdir -p /config/logs/downloaded/notfound
mkdir -p /config/logs/downloaded/notfound
touch /config/logs/downloaded/notfound/$lidarrAlbumForeignAlbumId
touch /config/logs/downloaded/notfound/$lidarrAlbumForeignAlbumId
done
done
@ -493,16 +548,18 @@ ProcessWithBeets () {
CheckLidarrBeforeImport ( ) {
CheckLidarrBeforeImport ( ) {
alreadyImported = false
alreadyImported = false
lidarrAlbumData = $( curl -s --header "X-Api-Key:" ${ lidarrApiKey } --request GET " $lidarrUrl /api/v1/album/ " | jq -r ".[]" )
if [ " $2 " = "beets" ] ; then
lidarrAlbumData = $( curl -s --header "X-Api-Key:" ${ lidarrApiKey } --request GET " $lidarrUrl /api/v1/album/ " | jq -r ".[]" )
lidarrPercentOfTracks = $( echo " $lidarrAlbumData " | jq -r " select(.foreignAlbumId==\" $1 \") | .statistics.percentOfTracks " )
lidarrPercentOfTracks = $( echo " $lidarrAlbumData " | jq -r " select(.foreignAlbumId==\" $1 \") | .statistics.percentOfTracks " )
if [ " $lidarrPercentOfTracks " = "null" ] ; then
if [ " $lidarrPercentOfTracks " = "null" ] ; then
lidarrPercentOfTracks = 0
lidarrPercentOfTracks = 0
fi
fi
if [ $lidarrPercentOfTracks -gt 0 ] ; then
if [ $lidarrPercentOfTracks -gt 0 ] ; then
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: ERROR :: Already Imported "
log " :: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: ERROR :: Already Imported "
alreadyImported = true
alreadyImported = true
return
return
fi
fi
fi
if [ " $2 " = "notbeets" ] ; then
if [ " $2 " = "notbeets" ] ; then
@ -514,7 +571,120 @@ CheckLidarrBeforeImport () {
fi
fi
}
}
AddRelatedArtists ( ) {
lidarrArtistsData = $( curl -s --header "X-Api-Key:" ${ lidarrApiKey } --request GET " $lidarrUrl /api/v1/Artist/ " )
lidarrArtistTotal = $( echo " ${ lidarrArtistsData } " | jq -r '.[].sortName' | wc -l)
lidarrList = ( $( echo " ${ lidarrArtistsData } " | jq -r ".[].foreignArtistId" ) )
lidarrListIds = " $( echo " ${ lidarrArtistsData } " | jq -r ".[].foreignArtistId" ) "
log " $lidarrArtistTotal Artists Found "
deezerArtistsUrl = $( echo " ${ lidarrArtistsData } " | jq -r ".[].links | .[] | select(.name==\"deezer\") | .url" )
deezeArtistIds = " $( echo " $deezerArtistsUrl " | grep -o '[[:digit:]]*' | sort -u) "
for id in ${ !lidarrList[@] } ; do
artistNumber = $(( $id + 1 ))
musicbrainzId = " ${ lidarrList [ $id ] } "
lidarrArtistData = $( echo " ${ lidarrArtistsData } " | jq -r " .[] | select(.foreignArtistId==\" ${ musicbrainzId } \") " )
lidarrArtistName = " $( echo " ${ lidarrArtistData } " | jq -r " .artistName" ) "
deezerArtistUrl = $( echo " ${ lidarrArtistData } " | jq -r ".links | .[] | select(.name==\"deezer\") | .url" )
deezerArtistIds = ( $( echo " $deezerArtistUrl " | grep -o '[[:digit:]]*' | sort -u) )
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 " $lidarrListIds " | 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
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
done
done
}
LidarrTaskStatusCheck ( ) {
until false
do
if curl -s " $lidarrUrl /api/v1/command?apikey= ${ lidarrApiKey } " | jq -r .[ ] .status | grep -v completed | grep -v failed | read; then
sleep 1
else
break
fi
done
}
GetMissingCutOffList
GetMissingCutOffList
SearchProcess
SearchProcess
AddRelatedArtists
exit
exit