Skip to content

Instantly share code, notes, and snippets.

@blha303
Last active December 3, 2022 21:04
Show Gist options
  • Save blha303/fc7a5ffc486fb4db933477a00c72d324 to your computer and use it in GitHub Desktop.
Save blha303/fc7a5ffc486fb4db933477a00c72d324 to your computer and use it in GitHub Desktop.
uses Tautulli as an easy way to get plex session data. has to be run on the same machine as your discord desktop client for access to RPC
from pypresence import Presence # https://github.com/qwertyquerty/pypresence
from requests import get
from time import sleep
from sys import exit
client_id = "556909532417228919"
user = "blha303"
tautulli_instance = "https://tau.home.b303.me" # https://github.com/Tautulli/Tautulli
RPC = Presence(client_id)
RPC.connect()
while 1:
my = [s for s in get(tautulli_instance + "/get_activity").json()["sessions"] if s["user"] == user]
if my:
my = my[0]
s = int(my["view_offset"])//1000
m,s = divmod(s,60)
h,m = divmod(m,60)
my["view_offset"] = "{:02d}:{:02d}:{:02d}".format(h,m,s)
RPC.update(details="{grandparent_title} ({studio}) {parent_title} - {title}".format(**my),
state="{state} | {view_offset} | {stream_video_width}x{stream_video_height}".format(**my))
else:
RPC.clear()
sleep(15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment