Use window variables for download error count
When playing an item, another plugin instance is created. It is impossible to share data otherwise
This commit is contained in:
parent
98f52d3b5e
commit
170b6c5066
2 changed files with 17 additions and 11 deletions
|
@ -33,9 +33,9 @@ class DownloadUtils():
|
||||||
# Requests session
|
# Requests session
|
||||||
timeout = 30
|
timeout = 30
|
||||||
# How many failed attempts before declaring PMS dead?
|
# How many failed attempts before declaring PMS dead?
|
||||||
connectionAttempts = 3
|
connectionAttempts = 2
|
||||||
# How many 401 returns before declaring unauthorized?
|
# How many 401 returns before declaring unauthorized?
|
||||||
unauthorizedAttempts = 3
|
unauthorizedAttempts = 2
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.__dict__ = self._shared_state
|
self.__dict__ = self._shared_state
|
||||||
|
@ -113,8 +113,11 @@ class DownloadUtils():
|
||||||
self.setUsername(window('plex_username'))
|
self.setUsername(window('plex_username'))
|
||||||
|
|
||||||
# Counters to declare PMS dead or unauthorized
|
# Counters to declare PMS dead or unauthorized
|
||||||
self.countUnauthorized = 0
|
# Use window variables because start of movies will be called with a
|
||||||
self.countError = 0
|
# new plugin instance - it's impossible to share data otherwise
|
||||||
|
if window('countUnauthorized') == '':
|
||||||
|
window('countUnauthorized', value='0')
|
||||||
|
window('countError', value='0')
|
||||||
|
|
||||||
# Retry connections to the server
|
# Retry connections to the server
|
||||||
self.s.mount("http://", requests.adapters.HTTPAdapter(max_retries=1))
|
self.s.mount("http://", requests.adapters.HTTPAdapter(max_retries=1))
|
||||||
|
@ -243,9 +246,9 @@ class DownloadUtils():
|
||||||
else:
|
else:
|
||||||
# We COULD contact the PMS, hence it ain't dead
|
# We COULD contact the PMS, hence it ain't dead
|
||||||
if authenticate is True:
|
if authenticate is True:
|
||||||
self.countError = 0
|
window('countError', value='0')
|
||||||
if r.status_code != 401:
|
if r.status_code != 401:
|
||||||
self.countUnauthorized = 0
|
window('countUnauthorized', value='0')
|
||||||
|
|
||||||
if r.status_code == 204:
|
if r.status_code == 204:
|
||||||
# No body in the response
|
# No body in the response
|
||||||
|
@ -260,8 +263,10 @@ class DownloadUtils():
|
||||||
self.logMsg(r.text, 1)
|
self.logMsg(r.text, 1)
|
||||||
if '401 Unauthorized' in r.text:
|
if '401 Unauthorized' in r.text:
|
||||||
# Truly unauthorized
|
# Truly unauthorized
|
||||||
self.countUnauthorized += 1
|
window('countUnauthorized',
|
||||||
if self.countUnauthorized >= self.unauthorizedAttempts:
|
value=str(int(window('countUnauthorized')) + 1))
|
||||||
|
if (int(window('countUnauthorized')) >=
|
||||||
|
self.unauthorizedAttempts):
|
||||||
self.logMsg('We seem to be truly unauthorized for PMS'
|
self.logMsg('We seem to be truly unauthorized for PMS'
|
||||||
% url, -1)
|
% url, -1)
|
||||||
if window('emby_serverStatus') not in ('401', 'Auth'):
|
if window('emby_serverStatus') not in ('401', 'Auth'):
|
||||||
|
@ -317,8 +322,9 @@ class DownloadUtils():
|
||||||
# And now deal with the consequences of the exceptions
|
# And now deal with the consequences of the exceptions
|
||||||
if authenticate is True:
|
if authenticate is True:
|
||||||
# Make the addon aware of status
|
# Make the addon aware of status
|
||||||
self.countError += 1
|
window('countError',
|
||||||
if self.countError >= self.connectionAttempts:
|
value=str(int(window('countError')) + 1))
|
||||||
|
if int(window('countError')) >= self.connectionAttempts:
|
||||||
self.logMsg('Failed to connect to %s too many times. Declare '
|
self.logMsg('Failed to connect to %s too many times. Declare '
|
||||||
'PMS dead' % url, -1)
|
'PMS dead' % url, -1)
|
||||||
window('emby_online', value="false")
|
window('emby_online', value="false")
|
||||||
|
|
|
@ -86,7 +86,7 @@ class Service():
|
||||||
"replaceSMB", "remapSMB", "remapSMBmovieOrg", "remapSMBtvOrg",
|
"replaceSMB", "remapSMB", "remapSMBmovieOrg", "remapSMBtvOrg",
|
||||||
"remapSMBmusicOrg", "remapSMBmovieNew", "remapSMBtvNew",
|
"remapSMBmusicOrg", "remapSMBmovieNew", "remapSMBtvNew",
|
||||||
"remapSMBmusicNew", "suspend_LibraryThread", "plex_terminateNow",
|
"remapSMBmusicNew", "suspend_LibraryThread", "plex_terminateNow",
|
||||||
"kodiplextimeoffset"
|
"kodiplextimeoffset", "countError", "countUnauthorized"
|
||||||
]
|
]
|
||||||
for prop in properties:
|
for prop in properties:
|
||||||
window(prop, clear=True)
|
window(prop, clear=True)
|
||||||
|
|
Loading…
Reference in a new issue