Added listenForUser config option for servers

This commit is contained in:
Phin 2022-05-11 07:20:06 +05:30
parent 54cd1f6eb1
commit 52c13511a8
4 changed files with 11 additions and 6 deletions

View file

@ -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.0.3
Current Version: 2.1.0
## Getting Started
@ -29,6 +29,7 @@ The script must be running on the same machine as your Discord client.
* `token` - An access token associated with your Plex account. ([X-Plex-Token](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token), [Authenticating with Plex](https://forums.plex.tv/t/authenticating-with-plex/609370))
* `servers` (list)
* `name` - Name of the Plex Media Server you wish to connect to.
* `listenForUser` (optional) - The script will respond to alerts originating only from this username. Defaults to the parent user's username if not set.
* `blacklistedLibraries` (optional list) - Alerts originating from libraries in this list are ignored.
* `whitelistedLibraries` (optional list) - If set, alerts originating from libraries that are not in this list are ignored.
@ -51,6 +52,7 @@ The script must be running on the same machine as your Discord client.
},
{
"name": "A Friend's Server",
"listenForUser": "xyz",
"whitelistedLibraries": ["Movies"]
}
]

View file

@ -8,6 +8,7 @@ class Display(TypedDict):
class Server(TypedDict, total = False):
name: str
listenForUser: str
blacklistedLibraries: list[str]
whitelistedLibraries: list[str]

View file

@ -29,6 +29,7 @@ class PlexAlertListener:
def reset(self):
self.plexAccount = None
self.listenForUser = ""
self.plexServer = None
self.isServerOwner = False
self.plexAlertListener = None
@ -43,6 +44,7 @@ class PlexAlertListener:
try:
self.plexAccount = MyPlexAccount(token = self.token)
self.logger.info("Signed in as Plex User \"%s\"", self.plexAccount.username)
self.listenForUser = self.serverConfig.get("listenForUser", self.plexAccount.username)
self.plexServer = None
for resource in self.plexAccount.resources():
if resource.product == self.productName and resource.name.lower() == self.serverConfig["name"].lower():
@ -56,7 +58,7 @@ class PlexAlertListener:
self.logger.info("Connected to %s \"%s\"", self.productName, resource.name)
self.plexAlertListener = AlertListener(self.plexServer, self.handlePlexAlert, self.reconnect)
self.plexAlertListener.start()
self.logger.info("Listening for alerts from user \"%s\"", self.plexAccount.username)
self.logger.info("Listening for alerts from user \"%s\"", self.listenForUser)
self.connectionTimeoutTimer = threading.Timer(self.connectionTimeoutTimerInterval, self.connectionTimeout)
self.connectionTimeoutTimer.start()
connected = True
@ -155,11 +157,11 @@ class PlexAlertListener:
if session.sessionKey == sessionKey:
self.logger.debug("Session found")
sessionUsername = session.usernames[0].lower()
if sessionUsername == self.plexAccount.username:
self.logger.debug("Username \"%s\" matches \"%s\", continuing", sessionUsername, self.plexAccount.username)
if sessionUsername == self.listenForUser:
self.logger.debug("Username \"%s\" matches \"%s\", continuing", sessionUsername, self.listenForUser)
break
else:
self.logger.debug("Username \"%s\" doesn't match \"%s\", ignoring", sessionUsername, self.plexAccount.username)
self.logger.debug("Username \"%s\" doesn't match \"%s\", ignoring", sessionUsername, self.listenForUser)
return
else:
self.logger.debug("No matching session found, ignoring")

View file

@ -2,7 +2,7 @@ import sys
import os
name = "Discord Rich Presence for Plex"
version = "2.0.3"
version = "2.1.0"
plexClientID = "discord-rich-presence-plex"
isUnix = sys.platform in ["linux", "darwin"]
processID = os.getpid()