v1.0.122 - Move Tidal search to it's own function, support multiple Tidal Artist ID's

pull/16/head
RandomNinjaAtk 2 years ago committed by GitHub
parent cf03e2f1e7
commit d3caa72c0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
scriptVersion="1.0.121" scriptVersion="1.0.122"
lidarrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)" lidarrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)"
if [ "$lidarrUrlBase" = "null" ]; then if [ "$lidarrUrlBase" = "null" ]; then
lidarrUrlBase="" lidarrUrlBase=""
@ -864,7 +864,7 @@ SearchProcess () {
lidarrArtistName=$(echo "${lidarrArtistData}" | jq -r ".artistName") lidarrArtistName=$(echo "${lidarrArtistData}" | jq -r ".artistName")
lidarrArtistForeignArtistId=$(echo "${lidarrArtistData}" | jq -r ".foreignArtistId") 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)" tidalArtistIds="$(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")
lidarrAlbumReleaseIds=$(echo "$lidarrAlbumData" | jq -r ".releases | sort_by(.trackCount) | reverse | .[].id") lidarrAlbumReleaseIds=$(echo "$lidarrAlbumData" | jq -r ".releases | sort_by(.trackCount) | reverse | .[].id")
lidarrAlbumReleaseDate=$(echo "$lidarrAlbumData" | jq -r .releaseDate) lidarrAlbumReleaseDate=$(echo "$lidarrAlbumData" | jq -r .releaseDate)
@ -1061,6 +1061,8 @@ SearchProcess () {
mkdir -p /config/extended/cache/tidal mkdir -p /config/extended/cache/tidal
fi fi
for tidalArtistId in $(echo $tidalArtistIds); do
if [ ! -f /config/extended/cache/tidal/$tidalArtistId-videos.json ]; then if [ ! -f /config/extended/cache/tidal/$tidalArtistId-videos.json ]; then
curl -s "https://api.tidal.com/v1/artists/${tidalArtistId}/videos?limit=10000&countryCode=$tidalCountryCode&filter=ALL" -H 'x-tidal-token: CzET4vdadNUFQ5JU' > /config/extended/cache/tidal/$tidalArtistId-videos.json curl -s "https://api.tidal.com/v1/artists/${tidalArtistId}/videos?limit=10000&countryCode=$tidalCountryCode&filter=ALL" -H 'x-tidal-token: CzET4vdadNUFQ5JU' > /config/extended/cache/tidal/$tidalArtistId-videos.json
sleep $sleepTimer sleep $sleepTimer
@ -1070,6 +1072,7 @@ SearchProcess () {
curl -s "https://api.tidal.com/v1/artists/${tidalArtistId}/albums?limit=10000&countryCode=$tidalCountryCode&filter=ALL" -H 'x-tidal-token: CzET4vdadNUFQ5JU' > /config/extended/cache/tidal/$tidalArtistId-albums.json curl -s "https://api.tidal.com/v1/artists/${tidalArtistId}/albums?limit=10000&countryCode=$tidalCountryCode&filter=ALL" -H 'x-tidal-token: CzET4vdadNUFQ5JU' > /config/extended/cache/tidal/$tidalArtistId-albums.json
sleep $sleepTimer sleep $sleepTimer
fi fi
done
fi fi
@ -1095,7 +1098,6 @@ SearchProcess () {
ArtistDeezerSearch "$processNumber of $wantedListAlbumTotal" "$wantedAlbumId" "$deezeArtistId" "true" ArtistDeezerSearch "$processNumber of $wantedListAlbumTotal" "$wantedAlbumId" "$deezeArtistId" "true"
done done
fi fi
fi
LidarrTaskStatusCheck LidarrTaskStatusCheck
CheckLidarrBeforeImport "$lidarrAlbumForeignAlbumId" "notbeets" CheckLidarrBeforeImport "$lidarrAlbumForeignAlbumId" "notbeets"
@ -1104,17 +1106,14 @@ SearchProcess () {
continue continue
fi fi
# Search for clean matches # Tidal search
if [ $audioLyricType = both ] || [ $audioLyricType = clean ]; then if [ "$skipTidal" = "false" ]; then
# Deezer search for tidalArtistId in $(echo $tidalArtistIds); do
if [ "$skipDeezer" = "false" ]; then if [ ! -f "/config/extended/cache/tidal/$tidalArtistId-albums.json" ]; then
for dId in ${!deezeArtistIds[@]}; do
deezeArtistId="${deezeArtistIds[$dId]}"
if [ ! -f "/config/extended/cache/deezer/$deezeArtistId-albums.json" ]; then
continue continue
fi fi
ArtistDeezerSearch "$processNumber of $wantedListAlbumTotal" "$wantedAlbumId" "$deezeArtistId" "false" ArtistTidalSearch "$processNumber of $wantedListAlbumTotal" "$wantedAlbumId" "$tidalArtistId" "true"
done done
fi fi
fi fi
@ -1126,61 +1125,17 @@ SearchProcess () {
continue continue
fi fi
for lidarrAlbumReleaseId in $(echo "$lidarrAlbumReleaseIds"); do # Search for clean matches
lidarrAlbumReleaseData=$(echo "$lidarrAlbumData" | jq -r ".releases[] | select(.id==$lidarrAlbumReleaseId)") if [ $audioLyricType = both ] || [ $audioLyricType = clean ]; then
lidarrAlbumReleaseTitle=$(echo "$lidarrAlbumReleaseData" | jq -r .title) # Deezer search
lidarrAlbumReleaseTrackCount=$(echo "$lidarrAlbumReleaseData" | jq -r .trackCount) if [ "$skipDeezer" = "false" ]; then
lidarrAlbumReleaseTitleClean=$(echo "$lidarrAlbumReleaseTitle" | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g') for dId in ${!deezeArtistIds[@]}; do
lidarrAlbumReleaseTitleSpaces=$(echo "$lidarrAlbumReleaseTitle" | sed -e "s%[^[:alpha:][:digit:]]% %g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g') deezeArtistId="${deezeArtistIds[$dId]}"
#echo "$lidarrAlbumReleaseTitle" if [ ! -f "/config/extended/cache/deezer/$deezeArtistId-albums.json" ]; then
#echo $lidarrAlbumReleaseTrackCount
if [ "$skipTidal" = "false" ]; then
tidalArtistAlbumsData=$(cat "/config/extended/cache/tidal/$tidalArtistId-albums.json" | jq -r ".items | sort_by(.numberOfTracks) | sort_by(.explicit) | reverse |.[] | select(.numberOfTracks==$lidarrAlbumReleaseTrackCount)")
fi
# Search for explicit matches
if [ $audioLyricType = both ] || [ $audioLyricType = explicit ]; then
LidarrTaskStatusCheck
CheckLidarrBeforeImport "$lidarrAlbumForeignAlbumId" "notbeets"
if [ $alreadyImported = true ]; then
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Already Imported, skipping..."
continue
fi
# Tidal search
if [ "$skipTidal" = "false" ]; then
tidalArtistAlbumsIds=($(echo "${tidalArtistAlbumsData}" | jq -r "select(.explicit=="true") | .id"))
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 "^$lidarrAlbumReleaseTitleClean" | 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 :: $lidarrAlbumReleaseTitleClean vs $tidalArtistAlbumTitleClean :: Explicit Tidal Match Found"
if [ -f /config/extended/logs/downloaded/tidal/$tidalArtistAlbumId ]; then
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Previously Downloaded, skipping..."
continue continue
fi fi
DownloadProcess "$tidalArtistAlbumId" "TIDAL" "$downloadedReleaseYear" "$downloadedAlbumTitle"
LidarrTaskStatusCheck ArtistDeezerSearch "$processNumber of $wantedListAlbumTotal" "$wantedAlbumId" "$tidalArtistId" "false"
CheckLidarrBeforeImport "$lidarrAlbumForeignAlbumId" "notbeets"
if [ $alreadyImported = true ]; then
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Already Imported, skipping..."
break 2
fi
else
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $lidarrAlbumReleaseTitleClean vs $tidalArtistAlbumTitleClean :: Explicit Tidal Match NOT Found"
fi
done done
fi fi
@ -1190,58 +1145,26 @@ SearchProcess () {
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Already Imported, skipping..." log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Already Imported, skipping..."
continue continue
fi fi
else
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Explicit Albums Disabled, skipping explicit search..."
fi
# Search for clean matches
if [ $audioLyricType = both ] || [ $audioLyricType = clean ]; then
# Tidal search
if [ "$skipTidal" = "false" ]; then
LidarrTaskStatusCheck for tidalArtistId in $(echo $tidalArtistIds); do
CheckLidarrBeforeImport "$lidarrAlbumForeignAlbumId" "notbeets" if [ ! -f "/config/extended/cache/tidal/$tidalArtistId-albums.json" ]; then
if [ $alreadyImported = true ]; then
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Already Imported, skipping..."
continue continue
fi fi
# Tidal search ArtistTidalSearch "$processNumber of $wantedListAlbumTotal" "$wantedAlbumId" "$tidalArtistId" "false"
if [ "$skipTidal" = "false" ]; then done
tidalArtistAlbumsIds=($(echo "${tidalArtistAlbumsData}" | jq -r "select(.explicit=="false") | .id"))
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 "^$lidarrAlbumReleaseTitleClean" | 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 fi
downloadedReleaseYear="${downloadedReleaseDate:0:4}"
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $lidarrAlbumReleaseTitleClean vs $tidalArtistAlbumTitleClean :: CLEAN Tidal Match Found"
if [ -f /config/extended/logs/downloaded/tidal/$tidalArtistAlbumId ]; then
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Previously Downloaded, skipping..."
continue
fi fi
DownloadProcess "$tidalArtistAlbumId" "TIDAL" "$downloadedReleaseYear" "$downloadedAlbumTitle"
LidarrTaskStatusCheck 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..."
break 2 continue
fi
else
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: $lidarrAlbumReleaseTitleClean vs $tidalArtistAlbumTitleClean :: CLEAN Tidal MATCH NOT Found"
fi
done
fi
else
log ":: $processNumber of $wantedListAlbumTotal :: $lidarrArtistNameSanitized :: $lidarrAlbumTitle :: Clean Albums Disabled, skipping clean search..."
fi fi
done
# Fallback/last resort Fuzzy Search # Fallback/last resort Fuzzy Search
if [ $audioLyricType = both ]; then if [ $audioLyricType = both ]; then
@ -1301,7 +1224,7 @@ ArtistDeezerSearch () {
lidarrAlbumReleaseTrackCount=$(echo "$lidarrAlbumReleaseData" | jq -r .trackCount) lidarrAlbumReleaseTrackCount=$(echo "$lidarrAlbumReleaseData" | jq -r .trackCount)
lidarrAlbumReleaseTitleClean=$(echo "$lidarrAlbumReleaseTitle" | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g') lidarrAlbumReleaseTitleClean=$(echo "$lidarrAlbumReleaseTitle" | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')
log ":: $1 :: $lidarrArtistName :: $lidarrAlbumTitle :: Searching Deezer for $lidarrAlbumReleaseTitle ($lidarrAlbumReleaseTrackCount)..." log ":: $1 :: $lidarrArtistName :: $lidarrAlbumTitle :: Searching Deezer ($3) for $lidarrAlbumReleaseTitle ($lidarrAlbumReleaseTrackCount)..."
deezerArtistAlbumsData=$(cat "/config/extended/cache/deezer/$3-albums.json" | jq -r "sort_by(.nb_tracks) | sort_by(.explicit_lyrics) | reverse | .[] | select(.nb_tracks==$lidarrAlbumReleaseTrackCount)") deezerArtistAlbumsData=$(cat "/config/extended/cache/deezer/$3-albums.json" | jq -r "sort_by(.nb_tracks) | sort_by(.explicit_lyrics) | reverse | .[] | select(.nb_tracks==$lidarrAlbumReleaseTrackCount)")
deezerArtistAlbumsIds=$(echo "${deezerArtistAlbumsData}" | jq -r "select(.explicit_lyrics=="$4") | .id") deezerArtistAlbumsIds=$(echo "${deezerArtistAlbumsData}" | jq -r "select(.explicit_lyrics=="$4") | .id")
@ -1334,7 +1257,12 @@ ArtistDeezerSearch () {
if [ $alreadyImported = true ]; then if [ $alreadyImported = true ]; then
return return
else else
log ":: $1 :: $lidarrArtistName :: $lidarrAlbumTitle :: ERROR :: Album not found via Artist Search..." if [ $4 = true ]; then
type=Explicit
else
type=Clean
fi
log ":: $1 :: $lidarrArtistName :: $lidarrAlbumTitle :: ERROR :: Album not found via $type Artist Search..."
fi fi
} }
@ -1393,6 +1321,75 @@ FuzzyDeezerSearch () {
} }
ArtistTidalSearch () {
# Required Inputs
# $1 Process ID
# $2 Lidarr Album ID
# $3 Tidal Artist ID
# $4 Lyric Type (true or false) - false = Clean, true = Explicit
lidarrAlbumData="$(curl -s "$lidarrUrl/api/v1/album/$2?apikey=${lidarrApiKey}")"
lidarrAlbumTitle=$(echo "$lidarrAlbumData" | jq -r ".title")
lidarrAlbumReleaseDate=$(echo "$lidarrAlbumData" | jq -r .releaseDate)
lidarrAlbumReleaseYear="${lidarrAlbumReleaseDate:0:4}"
lidarrAlbumReleaseIds=$(echo "$lidarrAlbumData" | jq -r ".releases | sort_by(.trackCount) | reverse | .[].id")
lidarrArtistData=$(echo "${lidarrAlbumData}" | jq -r ".artist")
lidarrArtistName=$(echo "${lidarrArtistData}" | jq -r ".artistName")
lidarrArtistNameSanitized="$(basename "${lidarrArtistPath}" | sed 's% (.*)$%%g')"
for lidarrAlbumReleaseId in $(echo "$lidarrAlbumReleaseIds"); do
lidarrAlbumReleaseData=$(echo "$lidarrAlbumData" | jq -r ".releases[] | select(.id==$lidarrAlbumReleaseId)")
lidarrAlbumReleaseTitle=$(echo "$lidarrAlbumReleaseData" | jq -r .title)
lidarrAlbumReleaseTrackCount=$(echo "$lidarrAlbumReleaseData" | jq -r .trackCount)
lidarrAlbumReleaseTitleClean=$(echo "$lidarrAlbumReleaseTitle" | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')
log ":: $1 :: $lidarrArtistName :: $lidarrAlbumTitle :: Searching Tidal ($3) for $lidarrAlbumReleaseTitle ($lidarrAlbumReleaseTrackCount)..."
tidalArtistAlbumsData=$(cat "/config/extended/cache/tidal/$3-albums.json" | jq -r ".items | sort_by(.numberOfTracks) | sort_by(.explicit) | reverse |.[] | select(.numberOfTracks==$lidarrAlbumReleaseTrackCount)")
tidalArtistAlbumsIds=$(echo "${tidalArtistAlbumsData}" | jq -r "select(.explicit=="$4") | .id")
for tidalArtistAlbumId in $(echo $tidalArtistAlbumsIds); do
tidalArtistAlbumData=$(echo "$tidalArtistAlbumsData" | jq -r "select(.id=="$tidalArtistAlbumId")")
downloadedAlbumTitle="$(echo ${tidalArtistAlbumData} | jq -r .title)"
tidalAlbumTitleClean=$(echo ${downloadedAlbumTitle} | sed -e "s%[^[:alpha:][:digit:]]%%g" -e "s/ */ /g" | sed 's/^[.]*//' | sed 's/[.]*$//g' | sed 's/^ *//g' | sed 's/ *$//g')
downloadedReleaseDate="$(echo ${tidalArtistAlbumData} | jq -r .releaseDate)"
if [ "$downloadedReleaseDate" = "null" ]; then
downloadedReleaseDate=$(echo $tidalArtistAlbumData | jq -r '.streamStartDate')
fi
downloadedReleaseYear="${downloadedReleaseDate:0:4}"
diff=$(levenshtein "${lidarrAlbumReleaseTitleClean,,}" "${tidalAlbumTitleClean,,}")
log ":: $1 :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumReleaseTitleClean vs $tidalAlbumTitleClean :: Checking for Match..."
if [ "$diff" -le "5" ]; then
log ":: $1 :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumReleaseTitleClean vs $tidalAlbumTitleClean :: Tidal MATCH Found :: Calculated Difference = $diff"
# Execute Download
DownloadProcess "$tidalArtistAlbumId" "TIDAL" "$downloadedReleaseYear" "$downloadedAlbumTitle"
# Verify it was successfully imported into Lidarr
LidarrTaskStatusCheck
CheckLidarrBeforeImport "$lidarrAlbumForeignAlbumId" "notbeets"
if [ $alreadyImported = true ]; then
break 2
fi
fi
done
done
if [ $alreadyImported = true ]; then
return
else
if [ $4 = true ]; then
type=Explicit
else
type=Clean
fi
log ":: $1 :: $lidarrArtistName :: $lidarrAlbumTitle :: ERROR :: Album not found via $type Artist Search..."
fi
}
ProcessWithBeets () { ProcessWithBeets () {
trackcount=$(find "$1" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l) trackcount=$(find "$1" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | wc -l)

Loading…
Cancel
Save