spotify-playstate exits with the rest of the polybar-app if spotify is shut down
parent
d22b842a7e
commit
efd7fe7a3d
|
@ -1 +1 @@
|
||||||
1
|
0
|
||||||
|
|
|
@ -1,10 +1,31 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
|
def find_proc(proc_name):
|
||||||
|
this_proc = "pythonspotify-play.py"
|
||||||
|
proc_path = '/proc'
|
||||||
|
proc = next(os.walk('{}/'.format(proc_path)))[1]
|
||||||
|
for process in proc:
|
||||||
|
cmdline_path = '{}/{}/cmdline'.format(proc_path,process)
|
||||||
|
try:
|
||||||
|
with open(cmdline_path, 'r') as cmd:
|
||||||
|
proc_content = cmd.readline()
|
||||||
|
if (proc_name in proc_content):
|
||||||
|
return True
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def spotify_running():
|
||||||
|
return find_proc('/usr/bin/spotify')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
state = -1
|
state = -1
|
||||||
while 1:
|
while spotify_running():
|
||||||
with open('/home/tuan/.scripts/playstate', 'r') as f:
|
with open('/home/tuan/.scripts/playstate', 'r') as f:
|
||||||
try:
|
try:
|
||||||
file_state = int(f.readline().strip('\n'))
|
file_state = int(f.readline().strip('\n'))
|
||||||
|
@ -18,7 +39,7 @@ def main():
|
||||||
elif state == 1:
|
elif state == 1:
|
||||||
print("")
|
print("")
|
||||||
subprocess.run(["playerctl","play"])
|
subprocess.run(["playerctl","play"])
|
||||||
time.sleep(0.5)
|
time.sleep(0.1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue