-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnowplaying.py
44 lines (35 loc) · 1.05 KB
/
nowplaying.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
import pywintypes
import win32gui
import win32process
import psutil
def gethwndsforpid(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 getspwindowtext():
for PID in win32process.EnumProcesses():
if "Spotify" in psutil.Process(PID).name():
if gethwndsforpid(PID):
hwnd = gethwndsforpid(PID)[0]
windowText = win32gui.GetWindowText(hwnd)
return windowText
def artist():
try:
temp = getspwindowtext()
artist = temp.split(" - ")[0]
return artist
except:
return "ERROR: Can't Get Artist Info"
def song():
try:
temp = getspwindowtext()
song = temp.split(" - ")[1]
return song
except:
return "ERROR: Can't Get Song Info"