From 52c13511a89b0724f9b540131febe3ac0f67f0c3 Mon Sep 17 00:00:00 2001 From: Phin <59180111+phin05@users.noreply.github.com> Date: Wed, 11 May 2022 07:20:06 +0530 Subject: [PATCH] Added `listenForUser` config option for servers --- README.md | 4 +++- models/config.py | 1 + services/PlexAlertListener.py | 10 ++++++---- store/constants.py | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 741f91a..9ecf7c4 100644 --- a/README.md +++ b/README.md @@ -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"] } ] diff --git a/models/config.py b/models/config.py index 7939f80..c43752c 100644 --- a/models/config.py +++ b/models/config.py @@ -8,6 +8,7 @@ class Display(TypedDict): class Server(TypedDict, total = False): name: str + listenForUser: str blacklistedLibraries: list[str] whitelistedLibraries: list[str] diff --git a/services/PlexAlertListener.py b/services/PlexAlertListener.py index 2a1d7ab..792aa06 100644 --- a/services/PlexAlertListener.py +++ b/services/PlexAlertListener.py @@ -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") diff --git a/store/constants.py b/store/constants.py index 7095725..a352026 100644 --- a/store/constants.py +++ b/store/constants.py @@ -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()