discord_presence_plex.py
· 879 B · Python
Raw
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)
| 1 | from pypresence import Presence # https://github.com/qwertyquerty/pypresence |
| 2 | from requests import get |
| 3 | from time import sleep |
| 4 | from sys import exit |
| 5 | |
| 6 | client_id = "556909532417228919" |
| 7 | user = "blha303" |
| 8 | tautulli_instance = "https://tau.home.b303.me" # https://github.com/Tautulli/Tautulli |
| 9 | |
| 10 | RPC = Presence(client_id) |
| 11 | RPC.connect() |
| 12 | |
| 13 | while 1: |
| 14 | my = [s for s in get(tautulli_instance + "/get_activity").json()["sessions"] if s["user"] == user] |
| 15 | if my: |
| 16 | my = my[0] |
| 17 | s = int(my["view_offset"])//1000 |
| 18 | m,s = divmod(s,60) |
| 19 | h,m = divmod(m,60) |
| 20 | my["view_offset"] = "{:02d}:{:02d}:{:02d}".format(h,m,s) |
| 21 | RPC.update(details="{grandparent_title} ({studio}) {parent_title} - {title}".format(**my), |
| 22 | state="{state} | {view_offset} | {stream_video_width}x{stream_video_height}".format(**my)) |
| 23 | else: |
| 24 | RPC.clear() |
| 25 | sleep(15) |