This commit is contained in:
Phin 2022-05-22 22:33:17 +05:30
parent 9f1113c07f
commit 98846bc216
4 changed files with 42 additions and 42 deletions

View file

@ -4,7 +4,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.3
Current Version: 2.2.4
## Getting Started
@ -25,7 +25,7 @@ The script must be running on the same machine as your Discord client.
* `logging`
* `debug` (boolean, default: `true`) - Outputs additional debug-helpful information to the console if enabled.
* `writeToFile` (boolean, default: `false`) - Writes everything outputted to console to a `console.log` file if enabled.
* `writeToFile` (boolean, default: `false`) - Writes everything outputted to the console to a `console.log` file if enabled.
* `display`
* `useRemainingTime` (boolean, default: `false`) - Displays your media's remaining time instead of elapsed time in your Rich Presence if enabled.
* `posters`

25
main.py
View file

@ -10,19 +10,20 @@ import sys
import time
import urllib.parse
loadConfig()
if config["logging"]["debug"]:
plexAlertListeners: list[PlexAlertListener] = []
try:
loadConfig()
if config["logging"]["debug"]:
logger.setLevel(logging.DEBUG)
if config["logging"]["writeToFile"]:
if config["logging"]["writeToFile"]:
fileHandler = logging.FileHandler(logFilePath)
fileHandler.setFormatter(formatter)
logger.addHandler(fileHandler)
os.system("clear" if isUnix else "cls")
logger.info("%s - v%s", name, version)
loadCache()
if len(config["users"]) == 0:
os.system("clear" if isUnix else "cls")
logger.info("%s - v%s", name, version)
loadCache()
if len(config["users"]) == 0:
logger.info("No users found in the config file. Initiating authentication flow.")
response = requests.post("https://plex.tv/api/v2/pins.json?strong=true", headers = {
"X-Plex-Product": name,
@ -46,16 +47,14 @@ if len(config["users"]) == 0:
else:
logger.info("Authentication failed.")
exit()
plexAlertListeners: list[PlexAlertListener] = []
try:
plexAlertListeners = [PlexAlertListener(user["token"], server) for user in config["users"] for server in user["servers"]]
while True:
if sys.stdin:
while True:
userInput = input()
if userInput in ["exit", "quit"]:
raise KeyboardInterrupt
else:
while True:
time.sleep(3600)
except KeyboardInterrupt:
for plexAlertListener in plexAlertListeners:

View file

@ -44,8 +44,9 @@ class PlexAlertListener(threading.Thread):
connected = False
while not connected:
try:
self.logger.info("Signing into Plex")
self.account = MyPlexAccount(token = self.token)
self.logger.info("Signed in as Plex User \"%s\"", self.account.username)
self.logger.info("Signed in as Plex user \"%s\"", self.account.username)
self.listenForUser = self.serverConfig.get("listenForUser", self.account.username)
self.server = None
for resource in self.account.resources():

View file

@ -2,7 +2,7 @@ import os
import sys
name = "Discord Rich Presence for Plex"
version = "2.2.3"
version = "2.2.4"
plexClientID = "discord-rich-presence-plex"
discordClientID = "413407336082833418"