From f585973994cabb05107eeca95288eb779dd19b54 Mon Sep 17 00:00:00 2001 From: RandomNinjaAtk Date: Mon, 6 Mar 2023 08:20:16 -0500 Subject: [PATCH] 1.0.064 - Improve cache process and completed artist handeling #208 Addresses items 2 & 3 from: https://github.com/RandomNinjaAtk/docker-lidarr-extended/issues/208#issuecomment-1456073016 It removes the caching timeout and if the local cache is updated, it removes the log file that prevents the artist from being processed by the script. --- root/scripts/Video.sh | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/root/scripts/Video.sh b/root/scripts/Video.sh index b499d00..07a26d1 100644 --- a/root/scripts/Video.sh +++ b/root/scripts/Video.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -scriptVersion="1.0.063" +scriptVersion="1.0.064" if [ -z "$lidarrUrl" ] || [ -z "$lidarrApiKey" ]; then lidarrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)" @@ -107,8 +107,8 @@ CacheMusicbrainzRecords () { log "$processCount of $lidarrArtistIdsCount :: MBZDB :: $lidarrArtistName :: Processing..." log "$processCount of $lidarrArtistIdsCount :: MBZDB :: $lidarrArtistName :: Checking Musicbrainz for recordings..." musicbrainzArtistRecordings=$(curl -s -A "$agent" "$musicbrainzMirror/ws/2/recording?artist=$lidarrArtistMusicbrainzId&limit=1&offset=0&fmt=json") - sleep 1 - musicbrainzArtistRecordingsCount=$(echo "$musicbrainzArtistRecordings" | jq -r '."recording-count"') + sleep 1 + musicbrainzArtistRecordingsCount=$(echo "$musicbrainzArtistRecordings" | jq -r '."recording-count"') log "$processCount of $lidarrArtistIdsCount :: MBZDB :: $lidarrArtistName :: $musicbrainzArtistRecordingsCount recordings found..." if [ ! -d /config/extended/cache/musicbrainz ]; then @@ -116,18 +116,15 @@ CacheMusicbrainzRecords () { chmod 777 /config/extended/cache/musicbrainz fi - if [ -f "/config/extended/cache/musicbrainz/$lidarrArtistId--$lidarrArtistMusicbrainzId--recordings.json" ]; then - if ! [[ $(find "/config/extended/cache/musicbrainz" -type f -name "$lidarrArtistId--$lidarrArtistMusicbrainzId--recordings.json" -mtime +7 -print) ]]; then - log "$processCount of $lidarrArtistIdsCount :: MBZDB :: $lidarrArtistName :: Previously cached, skipping..." - return - fi - fi - if [ -f "/config/extended/cache/musicbrainz/$lidarrArtistId--$lidarrArtistMusicbrainzId--recordings.json" ]; then musicbrainzArtistDownloadedRecordingsCount=$(cat "/config/extended/cache/musicbrainz/$lidarrArtistId--$lidarrArtistMusicbrainzId--recordings.json" | jq -r .id | wc -l) if [ $musicbrainzArtistRecordingsCount -ne $musicbrainzArtistDownloadedRecordingsCount ]; then log "$processCount of $lidarrArtistIdsCount :: MBZDB :: $lidarrArtistName :: Previously cached, data needs to be updated..." rm "/config/extended/cache/musicbrainz/$lidarrArtistId--$lidarrArtistMusicbrainzId--recordings.json" + if [ -f /config/extended/extended/logs/video/complete/$lidarrArtistMusicbrainzId ]; then + log "$processCount of $lidarrArtistIdsCount :: MBZDB :: $lidarrArtistName :: Removing Artist completed log file to allow artist re-processing..." + rm /config/extended/extended/logs/video/complete/$lidarrArtistMusicbrainzId + fi fi fi @@ -265,7 +262,13 @@ ImvdbCache () { if [ "$artistImvdbVideoUrlsCount" == "$cachedArtistImvdbVideoUrlsCount" ]; then log "$processCount of $lidarrArtistIdsCount :: IMVDB :: $lidarrArtistName :: Chache is already up-to-date, skipping..." return + else + if [ -f /config/extended/extended/logs/video/complete/$lidarrArtistMusicbrainzId ]; then + log "$processCount of $lidarrArtistIdsCount :: IMVDB :: $lidarrArtistName :: Removing Artist completed log file to allow artist re-processing..." + rm /config/extended/extended/logs/video/complete/$lidarrArtistMusicbrainzId + fi fi + sleep 0.5 imvdbProcessCount=0 @@ -605,7 +608,7 @@ lidarrArtistIdsCount=$(echo "$lidarrArtistIds" | wc -l) processCount=0 for lidarrArtistId in $(echo $lidarrArtistIds); do processCount=$(( $processCount + 1)) - lidarrArtistData=$(wget --timeout=0 -q -O - "$lidarrUrl/api/v1/artist/$lidarrArtistId?apikey=$lidarrApiKey") + lidarrArtistData=$(wget --timeout=0 -q -O - "$lidarrUrl/api/v1/artist/$lidarrArtistId?apikey=$lidarrApiKey") lidarrArtistName=$(echo $lidarrArtistData | jq -r .artistName) lidarrArtistMusicbrainzId=$(echo $lidarrArtistData | jq -r .foreignArtistId) @@ -613,13 +616,6 @@ for lidarrArtistId in $(echo $lidarrArtistIds); do log "$processCount of $lidarrArtistIdsCount :: $lidarrArtistName :: Skipping, not processed by design..." continue fi - - if [ -d /config/extended/logs/video/complete ]; then - if [ -f "/config/extended/logs/video/complete/$lidarrArtistMusicbrainzId" ]; then - log "$processCount of $lidarrArtistIdsCount :: $lidarrArtistName :: Music Videos previously downloaded, skipping..." - continue - fi - fi lidarrArtistPath="$(echo "${lidarrArtistData}" | jq -r " .path")" lidarrArtistFolder="$(basename "${lidarrArtistPath}")" @@ -644,6 +640,13 @@ for lidarrArtistId in $(echo $lidarrArtistIds); do CacheMusicbrainzRecords ImvdbCache + + if [ -d /config/extended/logs/video/complete ]; then + if [ -f "/config/extended/logs/video/complete/$lidarrArtistMusicbrainzId" ]; then + log "$processCount of $lidarrArtistIdsCount :: $lidarrArtistName :: Music Videos previously downloaded, skipping..." + continue + fi + fi log "$processCount of $lidarrArtistIdsCount :: MBZDB :: $lidarrArtistName :: Checking records for videos..." musicbrainzArtistVideoRecordings=$(cat "/config/extended/cache/musicbrainz/$lidarrArtistId--$lidarrArtistMusicbrainzId--recordings.json" | jq -r "select(.video==true)")