-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvsc.py
73 lines (62 loc) · 2.27 KB
/
vsc.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
from re import A
from pythonosc.udp_client import SimpleUDPClient
import win32gui
import win32process
import psutil
import ctypes
import time
spotifyName = ""
a = ["", True]
b = [f"{spotifyName}", True]
ip = "127.0.0.1"
port = 9000
client = SimpleUDPClient(ip, port)
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
def getProcessIDByName():
spotify_pids = []
process_name = "Spotify.exe"
for proc in psutil.process_iter():
if process_name in proc.name():
spotify_pids.append(proc.pid)
return spotify_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 getspotifyHandle():
pids = getProcessIDByName()
for i in pids:
hwnds = get_hwnds_for_pid(i)
for hwnd in hwnds:
if IsWindowVisible(hwnd):
return hwnd
spotify_handle = getspotifyHandle()
while(True):
if(getWindowTitleByHandle(spotify_handle) == "Spotify Free" or getWindowTitleByHandle(spotify_handle) == "Spotify Premium"):
client.send_message("/chatbox/input", a)
print('play music')
else:
if(getWindowTitleByHandle(spotify_handle) != spotifyName):
spotifyName = getWindowTitleByHandle(spotify_handle)
b[0] = f"{spotifyName}"
client.send_message("/chatbox/input", b)
print("sent!")
else:
client.send_message("/chatbox/input", b)
print("we already had it but sending it again :D")
time.sleep(2)