-
Notifications
You must be signed in to change notification settings - Fork 0
/
muter.py
71 lines (54 loc) · 1.54 KB
/
muter.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
import subprocess
import sys
import time
WAITING_TIME = 2
muted = False
def exec_output(some_command):
"""executes and returns the output of some shell program"""
output = subprocess.check_output(some_command, shell=True)
return output
def spotify_playing():
out = exec_output('tasklist /fi "imagename eq Spotify.exe" /fo csv /v ')
lines = out.split('\r\n')
line2 = lines[1]
fields = line2.split(',')
return fields[8].strip('"')
def mute_div(what):
base_cmd = "nircmd muteappvolume spotify.exe"
out = ''
if what == 'yes':
out = exec_output(base_cmd + ' 1')
elif what == 'no':
out = exec_output(base_cmd + ' 0')
print out
def does_file_contains(filename, expr):
f = open(filename, 'r')
lines = []
for line in f.readlines():
lines.append(line.rstrip('\n'))
f.close()
return expr in lines
def do():
global muted
playing = (spotify_playing())
print ("Playing " + playing)
is_playing_ad = does_file_contains('blacklist.txt', playing)
if is_playing_ad and (not muted):
print ("Detected ad!")
mute_div('yes')
print ('MUTING!')
muted = True
elif not (is_playing_ad) and muted:
mute_div('no')
print ('UNMUTING!')
muted = False
def main():
global WAITING_TIME
if (sys.argv > 0):
WAITING_TIME = int(sys.argv[1])
print ("Waiting period is " + str(WAITING_TIME) + " seconds")
while True:
do()
time.sleep(WAITING_TIME)
if __name__ == '__main__':
main()