1.0.009 - Move to functions, bugfix for NotifyPlex

pull/24/head
RandomNinjaAtk 2 years ago committed by GitHub
parent 34ac1d2aa5
commit 361cd4a300
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,5 @@
#!/usr/bin/env bash
scriptVersion="1.0.008"
scriptVersion="1.0.009"
arrEventType="$sonarr_eventtype"
arrItemId=$sonarr_series_id
tmdbApiKey="3b7751e3179f796565d88fdb2fcdf426"
@ -48,13 +48,14 @@ fi
exec &>> "/config/logs/Extras.txt"
chmod 666 "/config/logs/Extras.txt"
# Check to see if Extras are enabled via ENV
if [ "$enableExtras" != "true" ]; then
log "Script disabled, exiting..."
log "Enable by setting enableExtras=true"
exit
fi
# Get series information
arrItemData=$(curl -s "$arrUrl/api/v3/series/$arrItemId?apikey=$arrApiKey")
itemTitle=$(echo "$arrItemData" | jq -r .title)
itemHasFile=$(echo "$arrItemData" | jq -r .hasFile)
@ -62,7 +63,15 @@ itemPath="$(echo "$arrItemData" | jq -r ".path")"
imdbId="$(echo "$arrItemData" | jq -r ".imdbId")"
tmdbId=$(curl -s "https://api.themoviedb.org/3/find/$imdbId?api_key=$tmdbApiKey&external_source=imdb_id" | jq -r .tv_results[].id)
# Check if series folder path exists
if [ ! -d "$itemPath" ]; then
log "$itemTitle :: ERROR: Item Path does not exist ($itemPath), Skipping..."
exit
fi
DownloadExtras () {
# Check for cookies file
if find /config -type f -name "cookies.txt" | read; then
cookiesFile="$(find /config -type f -iname "cookies.txt" | head -n1)"
log "$itemTitle :: Cookies File Found!"
@ -71,20 +80,6 @@ else
cookiesFile=""
fi
if [ -f "/config/extended/logs/extras/$tmdbId" ]; then
find "/config/extended/logs/extras" -type f -mtime +7 -name "$tmdbId" -delete
fi
if [ -f "/config/extended/logs/extras/$tmdbId" ]; then
log "$itemTitle :: Already processed Extras, waiting 7 days to re-check..."
exit
fi
if [ ! -d "$itemPath" ]; then
log "$itemTitle :: ERROR: Item Path does not exist ($itemPath), Skipping..."
exit
fi
IFS=',' read -r -a filters <<< "$extrasLanguages"
for filter in "${filters[@]}"
do
@ -184,7 +179,7 @@ do
done
done
# Mark Complete
# Mark Series Extras Complete
if [ ! -d "/config/extended/logs/extras" ]; then
mkdir -p "/config/extended/logs/extras"
chmod 777 "/config/extended/logs/extras"
@ -193,6 +188,9 @@ log "$itemTitle :: Marking/logging as Extras downloads complete (/config/extende
touch "/config/extended/logs/extras/$tmdbId"
chmod 666 "/config/extended/logs/extras/$tmdbId"
}
NotifyPlex () {
# Process item with PlexNotify.bash if plexToken is configured
if [ ! -z "$plexToken" ]; then
# Always update plex if extra is downloaded
@ -212,6 +210,21 @@ if [ ! -z "$plexToken" ]; then
exit
fi
fi
}
# Check if series has been previously processed
if [ -f "/config/extended/logs/extras/$tmdbId" ]; then
# Delete log file older than 7 days, to allow re-processing
find "/config/extended/logs/extras" -type f -mtime +7 -name "$tmdbId" -delete
fi
if [ -f "/config/extended/logs/extras/$tmdbId" ]; then
log "$itemTitle :: Already processed Extras, waiting 7 days to re-check..."
NotifyPlex
exit
else
DownloadExtras
NotifyPlex
fi
exit

Loading…
Cancel
Save