-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (70 loc) · 2.02 KB
/
main.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
import pygetwindow as gw
from pynput import keyboard
from pynput.keyboard import Key, Controller
import win32gui,win32process
import pywinauto
import os
import psutil
import time
SpotifyDir = "%appdata%/Spotify/Spotify.exe"
os.system('start '+SpotifyDir)
time.sleep(3)
emptyspace=" "
WindowName = "Spotify Free"
hwnd=win32gui.FindWindow(None, WindowName)
pid=win32process.GetWindowThreadProcessId(hwnd)
print(pid)
if pid[0] == 0:
os.system('cls')
print('\nNot hooked, please pause the music.\n')
print('Exiting now.')
time.sleep(5)
exit()
o=1
def AdKiller():
global hwnd
global pid
truefalse = 1
time.sleep(0.5)
WindowTitle=win32gui.GetWindowText(hwnd)
if WindowTitle != "":
print(WindowTitle+emptyspace,end="\r")
if WindowTitle != "Spotify Free":
truefalse = WindowTitle.find('-')
if truefalse == -1:
time.sleep(3)
p = psutil.Process(pid[1])
p.terminate()
os.system('start '+SpotifyDir)
activewindow = (win32gui.GetWindowText(win32gui.GetForegroundWindow()))
try:
pywinauto.application.Application().connect(best_match=activewindow).top_window().set_focus()
except:
pass
time.sleep(7)
WindowName = "Spotify Free"
hwnd=win32gui.FindWindow(None, WindowName)
pid=win32process.GetWindowThreadProcessId(hwnd)
print(pid)
try:
handle = gw.getWindowsWithTitle('Spotify Free')[0]
except:
pass
try:
pywinauto.application.Application().connect(best_match='Spotify').top_window().set_focus()
except:
pass
try:
handle.activate()
handle.maximize()
time.sleep(0.5)
keyboard = Controller()
keyboard.press(Key.space)
handle.minimize()
os.system('cls')
print('Closed Ad')
except:
pass
return
while o==1:
AdKiller()