mirror of
https://github.com/phin05/discord-rich-presence-plex
synced 2025-02-16 13:48:26 +00:00
Fixed state not resetting on timeout
Minor code cleanup
This commit is contained in:
parent
1f57d0f9a8
commit
444bf99c0c
7 changed files with 18 additions and 18 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
config.json
|
||||
cache.json
|
||||
lint.bat
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
A Python script that displays your [Plex](https://www.plex.tv) status on [Discord](https://discord.com) using [Rich Presence](https://discord.com/developers/docs/rich-presence/how-to).
|
||||
|
||||
Current Version: 2.2.0
|
||||
Current Version: 2.2.1
|
||||
|
||||
## Getting Started
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# type: ignore
|
||||
# type: ignore
|
||||
|
||||
from store.constants import discordClientID, isUnix, processID
|
||||
from utils.logging import logger
|
||||
|
|
|
@ -28,6 +28,9 @@ class PlexAlertListener(threading.Thread):
|
|||
self.discordRpcService = DiscordRpcService()
|
||||
self.updateTimeoutTimer = None
|
||||
self.connectionTimeoutTimer = None
|
||||
self.lastState = ""
|
||||
self.lastSessionKey = 0
|
||||
self.lastRatingKey = 0
|
||||
self.reset()
|
||||
self.start()
|
||||
|
||||
|
@ -37,9 +40,6 @@ class PlexAlertListener(threading.Thread):
|
|||
self.plexServer = None
|
||||
self.isServerOwner = False
|
||||
self.plexAlertListener = None
|
||||
self.lastState = ""
|
||||
self.lastSessionKey = 0
|
||||
self.lastRatingKey = 0
|
||||
self.ignoreCount = 0
|
||||
|
||||
def run(self):
|
||||
|
@ -76,12 +76,11 @@ class PlexAlertListener(threading.Thread):
|
|||
time.sleep(10)
|
||||
|
||||
def disconnect(self):
|
||||
self.discordRpcService.disconnect()
|
||||
self.cancelTimers()
|
||||
try:
|
||||
self.plexAlertListener.stop()
|
||||
except:
|
||||
pass
|
||||
self.disconnectRpc()
|
||||
self.reset()
|
||||
self.logger.info("Stopped listening for alerts")
|
||||
|
||||
|
@ -91,6 +90,11 @@ class PlexAlertListener(threading.Thread):
|
|||
self.logger.error("Reconnecting")
|
||||
self.run()
|
||||
|
||||
def disconnectRpc(self):
|
||||
self.lastState, self.lastSessionKey, self.lastRatingKey = "", 0, 0
|
||||
self.discordRpcService.disconnect()
|
||||
self.cancelTimers()
|
||||
|
||||
def cancelTimers(self):
|
||||
if self.updateTimeoutTimer:
|
||||
self.updateTimeoutTimer.cancel()
|
||||
|
@ -101,8 +105,7 @@ class PlexAlertListener(threading.Thread):
|
|||
|
||||
def updateTimeout(self):
|
||||
self.logger.debug("No recent updates from session key %s", self.lastSessionKey)
|
||||
self.discordRpcService.disconnect()
|
||||
self.cancelTimers()
|
||||
self.disconnectRpc()
|
||||
|
||||
def connectionTimeout(self):
|
||||
try:
|
||||
|
@ -143,12 +146,10 @@ class PlexAlertListener(threading.Thread):
|
|||
else:
|
||||
self.ignoreCount = 0
|
||||
if state == "stopped":
|
||||
self.lastState, self.lastSessionKey, self.lastRatingKey = None, None, None
|
||||
self.discordRpcService.disconnect()
|
||||
self.cancelTimers()
|
||||
self.disconnectRpc()
|
||||
return
|
||||
elif state == "stopped":
|
||||
self.logger.debug("Received \"stopped\" state alert from unknown session key, ignoring")
|
||||
self.logger.debug("Received \"stopped\" state alert from unknown session, ignoring")
|
||||
return
|
||||
if self.isServerOwner:
|
||||
self.logger.debug("Searching sessions for session key %s", sessionKey)
|
||||
|
@ -201,7 +202,7 @@ class PlexAlertListener(threading.Thread):
|
|||
else:
|
||||
self.logger.debug("Unsupported media type \"%s\", ignoring", mediaType)
|
||||
return
|
||||
thumbUrl = None
|
||||
thumbUrl = ""
|
||||
if config["display"]["posters"]["enabled"]:
|
||||
if not (thumbUrl := getKey(plexThumb)):
|
||||
self.logger.debug("Uploading image")
|
||||
|
|
|
@ -22,7 +22,6 @@ def setKey(key: str, value: Any) -> None:
|
|||
cache[key] = value
|
||||
try:
|
||||
with open(cacheFilePath, "w", encoding = "UTF-8") as cacheFile:
|
||||
json.dump(cache, cacheFile, indent = "\t")
|
||||
cacheFile.write("\n")
|
||||
json.dump(cache, cacheFile, separators = (",", ":"))
|
||||
except:
|
||||
logger.exception("Failed to write to the application's cache file.")
|
||||
|
|
|
@ -16,4 +16,3 @@ def uploadImage(url: str) -> Optional[str]:
|
|||
return data["data"]["link"]
|
||||
except:
|
||||
logger.exception("An unexpected error occured while uploading an image")
|
||||
return None
|
||||
|
|
|
@ -2,7 +2,7 @@ import os
|
|||
import sys
|
||||
|
||||
name = "Discord Rich Presence for Plex"
|
||||
version = "2.2.0"
|
||||
version = "2.2.1"
|
||||
|
||||
plexClientID = "discord-rich-presence-plex"
|
||||
discordClientID = "413407336082833418"
|
||||
|
|
Loading…
Add table
Reference in a new issue