-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqobuz.py
88 lines (67 loc) · 2.33 KB
/
qobuz.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
import time
from pypresence import Presence
import win32gui
import win32process
import psutil
import ctypes
EnumWindows = ctypes.windll.user32.EnumWindows
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
GetWindowText = ctypes.windll.user32.GetWindowTextW
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
IsWindowVisible = ctypes.windll.user32.IsWindowVisible
client_id = "928957672907227147"
def getProcessIDByName():
qobuz_pids = []
process_name = "Qobuz.exe"
for proc in psutil.process_iter():
if process_name in proc.name():
qobuz_pids.append(proc.pid)
return qobuz_pids
def get_hwnds_for_pid(pid):
def callback(hwnd, hwnds):
#if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
_, found_pid = win32process.GetWindowThreadProcessId(hwnd)
if found_pid == pid:
hwnds.append(hwnd)
return True
hwnds = []
win32gui.EnumWindows(callback, hwnds)
return hwnds
def getWindowTitleByHandle(hwnd):
length = GetWindowTextLength(hwnd)
buff = ctypes.create_unicode_buffer(length + 1)
GetWindowText(hwnd, buff, length + 1)
return buff.value
def getQobuzHandle():
pids = getProcessIDByName()
for i in pids:
hwnds = get_hwnds_for_pid(i)
for hwnd in hwnds:
if IsWindowVisible(hwnd):
return hwnd
if __name__ == '__main__':
qobuz_handle = getQobuzHandle()
if qobuz_handle is None:
while True:
qobuz_handle = getQobuzHandle()
if qobuz_handle is not None:
break
RPC = Presence(client_id)
RPC.connect()
title = ""
while True:
while True:
new_title = getWindowTitleByHandle(qobuz_handle)
if title != new_title:
title = new_title
break
if title == 'Qobuz':
print('resetting')
RPC.clear()
else:
try:
title_parts = title.rsplit(' - ', 1)
print(title_parts)
RPC.update(details=title_parts[0], state="by " + title_parts[1], large_image="qobuz")
except:
print("split not worked")