Last active 1670065456

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

S Smith revised this gist 1560166536. Go to revision

1 file changed, 8 insertions, 1 deletion

discord_presence_plex.py

@@ -1,6 +1,7 @@
1 1 from pypresence import Presence # https://github.com/qwertyquerty/pypresence
2 2 from requests import get
3 3 from time import sleep
4 + from sys import exit
4 5
5 6 client_id = "556909532417228919"
6 7 user = "blha303"
@@ -12,7 +13,13 @@ RPC.connect()
12 13 while 1:
13 14 my = [s for s in get(tautulli_instance + "/get_activity").json()["sessions"] if s["user"] == user]
14 15 if my:
15 - RPC.update(state=" | ".join(_["full_title"] for _ in 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))
16 23 else:
17 24 RPC.clear()
18 25 sleep(15)

S Smith revised this gist 1552849429. Go to revision

1 file changed, 18 insertions

discord_presence_plex.py(file created)

@@ -0,0 +1,18 @@
1 + from pypresence import Presence # https://github.com/qwertyquerty/pypresence
2 + from requests import get
3 + from time import sleep
4 +
5 + client_id = "556909532417228919"
6 + user = "blha303"
7 + tautulli_instance = "https://tau.home.b303.me" # https://github.com/Tautulli/Tautulli
8 +
9 + RPC = Presence(client_id)
10 + RPC.connect()
11 +
12 + while 1:
13 + my = [s for s in get(tautulli_instance + "/get_activity").json()["sessions"] if s["user"] == user]
14 + if my:
15 + RPC.update(state=" | ".join(_["full_title"] for _ in my))
16 + else:
17 + RPC.clear()
18 + sleep(15)
Newer Older