From 7323b205cc5532b463eae887185b12ffc0efd485 Mon Sep 17 00:00:00 2001 From: Phin <59180111+phin05@users.noreply.github.com> Date: Sun, 1 Oct 2023 21:24:58 +0530 Subject: [PATCH] Fixed issues with non-interactive environments --- README.md | 4 ++++ main.py | 6 ++++-- store/constants.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e1428f9..8cde2d7 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,10 @@ During runtime, the following dynamic URL placeholders will get replaced with re } ``` +## Configuration - Environment Variables + +* `PLEX_SERVER_NAME` - Name of the Plex Media Server you wish to connect to. Used only during the initial setup (when the config file isn't present) for adding a server to the config after authentication. If this isn't set, the user is prompted for an input. In non-interactive environments, "ServerName" is used as a placeholder when this variable isn't set. + ## Configuration - Discord The "Display current activity as a status message" setting must be enabled in Discord Settings → Activity Settings → Activity Privacy. diff --git a/main.py b/main.py index 3649add..e834c63 100644 --- a/main.py +++ b/main.py @@ -51,7 +51,9 @@ try: }).json() if authCheckResponse["authToken"]: logger.info("Authentication successful.") - serverName = input("Enter the name of the Plex Media Server you wish to connect to: ") + serverName = os.environ.get("PLEX_SERVER_NAME") + if not serverName: + serverName = input("Enter the name of the Plex Media Server you wish to connect to: ") if sys.stdin.isatty() else "ServerName" config["users"].append({ "token": authCheckResponse["authToken"], "servers": [{ "name": serverName }] }) saveConfig() break @@ -60,7 +62,7 @@ try: logger.info("Authentication failed.") exit() plexAlertListeners = [PlexAlertListener(user["token"], server) for user in config["users"] for server in user["servers"]] - if sys.stdin: + if sys.stdin.isatty(): while True: userInput = input() if userInput in ["exit", "quit"]: diff --git a/store/constants.py b/store/constants.py index 5d3e947..78b30d2 100644 --- a/store/constants.py +++ b/store/constants.py @@ -2,7 +2,7 @@ import os import sys name = "Discord Rich Presence for Plex" -version = "2.3.3" +version = "2.3.4" plexClientID = "discord-rich-presence-plex" discordClientID = "413407336082833418"