mirror of
https://github.com/phin05/discord-rich-presence-plex
synced 2024-11-22 01:23:02 +00:00
Update discordRichPresencePlex.py
This commit is contained in:
parent
3d4f92a3d3
commit
03c2ebd2c6
1 changed files with 35 additions and 21 deletions
|
@ -77,6 +77,7 @@ class discordRichPresence:
|
|||
self.child.log("Closing Discord IPC Pipe")
|
||||
self.child.lastState, self.child.lastSessionKey, self.child.lastRatingKey = None, None, None
|
||||
self.process.kill()
|
||||
if (self.pipeWriter):
|
||||
try:
|
||||
self.pipeWriter.close()
|
||||
except:
|
||||
|
@ -85,10 +86,17 @@ class discordRichPresence:
|
|||
self.loop.run_until_complete(self.pipeReader.read(1024))
|
||||
except:
|
||||
pass
|
||||
self.pipeWriter, self.pipeReader = None, None
|
||||
try:
|
||||
self.loop.close()
|
||||
except:
|
||||
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
|
||||
|
||||
def send(self, activity):
|
||||
|
@ -106,23 +114,25 @@ class discordRichPresence:
|
|||
class discordRichPresencePlex(discordRichPresence):
|
||||
|
||||
productName = "Plex Media Server"
|
||||
plexAccount = None
|
||||
plexServer = None
|
||||
plexAlertListener = None
|
||||
lastState = None
|
||||
lastSessionKey = None
|
||||
lastRatingKey = None
|
||||
stopTimer = None
|
||||
stopTimerInterval = 5
|
||||
stopTimer2 = None
|
||||
stopTimer2Interval = 35
|
||||
checkConnectionTimer = None
|
||||
checkConnectionTimerInterval = 60
|
||||
maximumIgnores = 3
|
||||
|
||||
def __init__(self, plexConfig):
|
||||
self.plexConfig = plexConfig
|
||||
self.instanceID = hashlib.md5(str(id(self)).encode("UTF-8")).hexdigest()[:5]
|
||||
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):
|
||||
self.reset()
|
||||
|
@ -213,7 +223,11 @@ class discordRichPresencePlex(discordRichPresence):
|
|||
self.stopTimer2.cancel()
|
||||
self.stopTimer2 = None
|
||||
if (self.lastState == state):
|
||||
if (self.ignoreCount == self.maximumIgnores):
|
||||
self.ignoreCount = 0
|
||||
else:
|
||||
self.log("Nothing changed, ignoring", "yellow", extra = True)
|
||||
self.ignoreCount += 1
|
||||
self.stopTimer2 = threading.Timer(self.stopTimer2Interval, self.stopOnNoUpdate)
|
||||
self.stopTimer2.start()
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue