Просмотр исходного кода

Retry the "unwatched" check.
Use the optimize script rather than calling cURL directly.

Zachary Kotlarek 13 лет назад
Родитель
Сommit
f3e2d5cdd6
2 измененных файлов с 28 добавлено и 14 удалено
  1. 18 11
      pms/PMSCheck.sh
  2. 10 3
      pms/optimize.sh

+ 18 - 11
pms/PMSCheck.sh

@@ -5,7 +5,8 @@ CURL_TIMEOUT=5
 RESTART_DELAY=120
 RESTART_DELAY=120
 PMS_URL="http://localhost:32400/"
 PMS_URL="http://localhost:32400/"
 UNWATCHED_URL="${PMS_URL}library/sections/2/unwatched"
 UNWATCHED_URL="${PMS_URL}library/sections/2/unwatched"
-UNWATCHED_TIMEOUT=$(( $CURL_TIMEOUT * 3 ))
+UNWATCHED_TIMEOUT=$(( $CURL_TIMEOUT * 2 ))
+UNWATCHED_RETRIES=3
 MIN_UNWATCHED_COUNT=10
 MIN_UNWATCHED_COUNT=10
 ADMIN_EMAIL="zach@kotlarek.com"
 ADMIN_EMAIL="zach@kotlarek.com"
 
 
@@ -42,15 +43,22 @@ while [ $LOOP -ne 0 ]; do
 
 
 	# Ask Plex for a list of unwatched TV series
 	# Ask Plex for a list of unwatched TV series
 	if [ -z "${FAILED}" ]; then
 	if [ -z "${FAILED}" ]; then
-		PAGE="`curl --silent --max-time "${UNWATCHED_TIMEOUT}" "${UNWATCHED_URL}"`"
-		if [ -z "${PAGE}" ]; then
-			FAILED="HTTP timeout"
-		else
-			COUNT="`echo "${PAGE}" | grep '</Directory>' | wc -l`"
-			if [ $COUNT -lt $MIN_UNWATCHED_COUNT ]; then
-				FAILED="Too few unwatched series"
+		TRY=1
+		FAILED="Too few unwatched series"
+		while [ $TRY -le $UNWATCHED_RETRIES ] && [ -n "${FAILED}" ]; do
+			TRY=$(( $TRY + 1 ))
+			PAGE="`curl --silent --max-time "${UNWATCHED_TIMEOUT}" "${UNWATCHED_URL}"`"
+			if [ -z "${PAGE}" ]; then
+				FAILED="HTTP timeout"
+			else
+				COUNT="`echo "${PAGE}" | grep '</Directory>' | wc -l`"
+				if [ $COUNT -ge $MIN_UNWATCHED_COUNT ]; then
+					FAILED=""
+				else
+					sleep 2
+				fi
 			fi
 			fi
-		fi
+		done
 	fi
 	fi
 
 
 	# If Plex has failed kill it
 	# If Plex has failed kill it
@@ -69,8 +77,7 @@ while [ $LOOP -ne 0 ]; do
 		sleep "${RESTART_DELAY}"
 		sleep "${RESTART_DELAY}"
 
 
 		# Re-index (in the background)
 		# Re-index (in the background)
-		~/bin/video/isScanning && \
-			curl --silent --upload-file /dev/null "${PMS_URL}library/optimize" &
+		~/bin/video/pms/optimize.sh &
 	fi
 	fi
 
 
 	# Sleep for the next loop or exit
 	# Sleep for the next loop or exit

+ 10 - 3
pms/optimize.sh

@@ -1,9 +1,16 @@
 #!/bin/bash
 #!/bin/bash
 
 
-# Delay if we are currently scanning
-WAIT=0
+# Defaults
 DELAY=5
 DELAY=5
 MAX_WAIT=600
 MAX_WAIT=600
+
+# Accept an alternate MAX_WAIT
+if [ -n "${1}" ]; then
+	MAX_WAIT="${1}"
+fi
+
+# Delay if we are currently scanning
+WAIT=0
 while ~/bin/video/pms/isScanning.sh; do
 while ~/bin/video/pms/isScanning.sh; do
 	sleep $DELAY
 	sleep $DELAY
 	WAIT=$(( $WAIT + $DELAY ))
 	WAIT=$(( $WAIT + $DELAY ))
@@ -14,4 +21,4 @@ while ~/bin/video/pms/isScanning.sh; do
 done
 done
 
 
 # Optimize
 # Optimize
-curl --silent --upload-file /dev/null 'http://localhost:32400/library/optimize'
+exec curl --silent --upload-file /dev/null 'http://localhost:32400/library/optimize'