-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolve_rich_presence.py
107 lines (92 loc) · 3.39 KB
/
resolve_rich_presence.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import time
import sys
import psutil
# Add Resolve API path if needed
resolve_path = "/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules"
if resolve_path not in sys.path:
sys.path.append(resolve_path)
import DaVinciResolveScript as dvr
from pypresence import Presence
# Discord Application ID (Create a Discord App: https://discord.com/developers/applications)
DISCORD_CLIENT_ID = "1004088618857549844"
def is_process_running(process_name):
for proc in psutil.process_iter(['pid', 'name']):
if process_name.lower() in proc.info['name'].lower():
return True
return False
def wait_for_process(process_name):
print(f"Waiting for {process_name} to start...")
while not is_process_running(process_name):
time.sleep(5)
print(f"{process_name} has started.")
def get_resolve():
wait_for_process("resolve")
while True:
try:
resolve = dvr.scriptapp("Resolve")
if resolve:
print("Connected to DaVinci Resolve.")
return resolve
except Exception as e:
print(f"Could not connect to DaVinci Resolve: {e}. Retrying...")
time.sleep(5)
def get_project_info(resolve):
project_manager = resolve.GetProjectManager()
project = project_manager.GetCurrentProject()
if not project:
return None, None, None
project_name = project.GetName()
timeline = project.GetCurrentTimeline()
timeline_name = timeline.GetName() if timeline else None
return project, project_name, timeline_name
def update_presence(rpc, resolve):
start_time = int(time.time())
while True:
if not is_process_running("discord"):
print("Discord is not running.")
rpc.clear()
wait_for_process("discord")
rpc.connect()
if not is_process_running("resolve"):
print("DaVinci Resolve is not running.")
rpc.clear()
wait_for_process("resolve")
resolve = get_resolve()
start_time = int(time.time()) # Reset start time on Resolve restart
try:
project, project_name, timeline_name = get_project_info(resolve)
except AttributeError:
print("Failed to get project info. Retrying...")
resolve = get_resolve()
start_time = int(time.time()) # Reset start time on Resolve reconnect
continue
if not project:
rpc.clear()
print("No active project. Waiting...")
time.sleep(10)
continue
if timeline_name:
state = f"Editing: {timeline_name}"
details = f"Project: {project_name}"
else:
state = "Editing: No active Timeline"
details = "In: Project Manager"
rpc.update(
state=state,
details=details,
start=start_time,
large_image="davinci", # You can upload an image to your Discord app
large_text="DaVinci Resolve Studio"
)
print(f"Updated presence: {state} {details}")
time.sleep(15) # Update every 15 seconds
if __name__ == "__main__":
resolve = get_resolve()
rpc = Presence(DISCORD_CLIENT_ID)
rpc.connect()
try:
update_presence(rpc, resolve)
except KeyboardInterrupt:
print("Stopping Rich Presence...")
rpc.clear()
rpc.close()