Update discordRichPresencePlex.py

This commit is contained in:
Phin 2018-08-24 11:03:49 +05:30
parent 3d4f92a3d3
commit 03c2ebd2c6

View file

@ -77,18 +77,26 @@ class discordRichPresence:
self.child.log("Closing Discord IPC Pipe") self.child.log("Closing Discord IPC Pipe")
self.child.lastState, self.child.lastSessionKey, self.child.lastRatingKey = None, None, None self.child.lastState, self.child.lastSessionKey, self.child.lastRatingKey = None, None, None
self.process.kill() self.process.kill()
try: if (self.pipeWriter):
self.pipeWriter.close() try:
except: self.pipeWriter.close()
pass except:
try: pass
self.loop.run_until_complete(self.pipeReader.read(1024)) try:
except: self.loop.run_until_complete(self.pipeReader.read(1024))
pass except:
pass
self.pipeWriter, self.pipeReader = None, None
try: try:
self.loop.close() self.loop.close()
except: except:
pass pass
if (self.child.stopTimer):
self.child.stopTimer.cancel()
self.child.stopTimer = None
if (self.child.stopTimer2):
self.child.stopTimer2.cancel()
self.child.stopTimer2 = None
self.running = False self.running = False
def send(self, activity): def send(self, activity):
@ -106,23 +114,25 @@ class discordRichPresence:
class discordRichPresencePlex(discordRichPresence): class discordRichPresencePlex(discordRichPresence):
productName = "Plex Media Server" productName = "Plex Media Server"
plexAccount = None
plexServer = None
plexAlertListener = None
lastState = None
lastSessionKey = None
lastRatingKey = None
stopTimer = None
stopTimerInterval = 5 stopTimerInterval = 5
stopTimer2 = None
stopTimer2Interval = 35 stopTimer2Interval = 35
checkConnectionTimer = None
checkConnectionTimerInterval = 60 checkConnectionTimerInterval = 60
maximumIgnores = 3
def __init__(self, plexConfig): def __init__(self, plexConfig):
self.plexConfig = plexConfig self.plexConfig = plexConfig
self.instanceID = hashlib.md5(str(id(self)).encode("UTF-8")).hexdigest()[:5] self.instanceID = hashlib.md5(str(id(self)).encode("UTF-8")).hexdigest()[:5]
super().__init__("413407336082833418", self) super().__init__("413407336082833418", self)
self.plexAccount = None
self.plexServer = None
self.plexAlertListener = None
self.lastState = None
self.lastSessionKey = None
self.lastRatingKey = None
self.stopTimer = None
self.stopTimer2 = None
self.checkConnectionTimer = None
self.ignoreCount = 0
def run(self): def run(self):
self.reset() self.reset()
@ -213,10 +223,14 @@ class discordRichPresencePlex(discordRichPresence):
self.stopTimer2.cancel() self.stopTimer2.cancel()
self.stopTimer2 = None self.stopTimer2 = None
if (self.lastState == state): if (self.lastState == state):
self.log("Nothing changed, ignoring", "yellow", extra = True) if (self.ignoreCount == self.maximumIgnores):
self.stopTimer2 = threading.Timer(self.stopTimer2Interval, self.stopOnNoUpdate) self.ignoreCount = 0
self.stopTimer2.start() else:
return self.log("Nothing changed, ignoring", "yellow", extra = True)
self.ignoreCount += 1
self.stopTimer2 = threading.Timer(self.stopTimer2Interval, self.stopOnNoUpdate)
self.stopTimer2.start()
return
elif (state == "stopped"): elif (state == "stopped"):
self.lastState, self.lastSessionKey, self.lastRatingKey = None, None, None self.lastState, self.lastSessionKey, self.lastRatingKey = None, None, None
self.stopTimer = threading.Timer(self.stopTimerInterval, self.stop) self.stopTimer = threading.Timer(self.stopTimerInterval, self.stop)