mirror of
https://github.com/mrworf/plexupdate.git
synced 2025-08-20 05:13:19 -07:00
Improve server in use check when using live TV/DVR
Monitor live TV and DVR sessions in addition to regular streams when doing a in use check for the server. Paused streams are not considered to be "in use" so if all streams that are playing are currently paused, the updated will continue regardless. Closes #177
This commit is contained in:
parent
ec5e3b7fa4
commit
69c5e52cea
1 changed files with 11 additions and 18 deletions
|
@ -180,36 +180,29 @@ getLocalSHA() {
|
||||||
running() {
|
running() {
|
||||||
# If a server is unclaimed, it probably doesn't have TLS enabled either
|
# If a server is unclaimed, it probably doesn't have TLS enabled either
|
||||||
local DATA
|
local DATA
|
||||||
|
# get Plex sessions
|
||||||
DATA="$(wget -q -O - http://$1:$2/status/sessions)"
|
DATA="$(wget -q -O - http://$1:$2/status/sessions)"
|
||||||
local RET=$?
|
local RET=$?
|
||||||
|
# and live TV/DVR sessions
|
||||||
|
DATA+="$(wget -q -O - http://$1:$2/livetv/sessions)"
|
||||||
|
|
||||||
if [ ${RET} -eq 6 ]; then
|
if [ ${RET} -eq 6 ]; then
|
||||||
# Server may be claimed, in which case we should use TLS and pass a token
|
# Server may be claimed, in which case we should use TLS and pass a token
|
||||||
getPlexToken
|
getPlexToken
|
||||||
DATA="$(wget --no-check-certificate -q -O - https://$1:$2/status/sessions?X-Plex-Token=$TOKEN)"
|
DATA="$(wget --no-check-certificate -q -O - https://$1:$2/status/sessions?X-Plex-Token=$TOKEN)"
|
||||||
RET=$?
|
RET=$?
|
||||||
|
DATA+="$(wget --no-check-certificate -q -O - https://$1:$2/livetv/sessions?X-Plex-Token=$TOKEN)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${RET} -eq 0 ]; then
|
if [ ${RET} -eq 0 ]; then
|
||||||
if [ -z "${DATA}" ]; then
|
# Get a total count of active media (MediaContainer size), then deduct one for every paused stream.
|
||||||
# Odd, but usually means noone is watching
|
# If all streams are paused, we consider the server to not be active.
|
||||||
return 1
|
local mediacount="$(awk -F'"' '/<MediaContainer size="[0-9]+">/ {count+=$2}; /<Player[^>]* state="paused"/ {count--}; END {print count}' <<< ${DATA})"
|
||||||
fi
|
[ $mediacount -gt 0 ] && return 0
|
||||||
echo "${DATA}" | grep -q '<MediaContainer size="0">'
|
|
||||||
if [ $? -eq 1 ]; then
|
|
||||||
# not found means that one or more medias are being played
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
return 1
|
|
||||||
elif [ ${RET} -eq 4 ]; then
|
|
||||||
# No response, assume not running
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
# We do not know what this means...
|
|
||||||
warn "Unknown response (${RET}) from server >>>"
|
|
||||||
warn "${DATA}"
|
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# if we don't know for sure that Plex is busy, assume that it's not so the update can proceed
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyToken() {
|
verifyToken() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue