forked from graysky2/xscreensaver-aerial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvid2
executable file
·65 lines (55 loc) · 2.49 KB
/
vid2
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
#!/usr/bin/python2
import sys
import json
import struct
import os
import commands
import subprocess
from time import sleep
try:
# Python 3.x version
# Read a message from stdin and decode it.
def checkIntegrated():
stat, out = commands.getstatusoutput("ps aux | egrep '[/]usr/bin/atv4wall' | awk '{print $2}'")
return any(char.isdigit() for char in out)
def getMessage():
rawLength = sys.stdin.buffer.read(4)
if len(rawLength) == 0:
sys.exit(0)
messageLength = struct.unpack('@I', rawLength)[0]
message = sys.stdin.buffer.read(messageLength).decode('utf-8')
return json.loads(message)
while True:
receivedMessage = getMessage()
if "watch?v" in receivedMessage:
isIntegrated = checkIntegrated()
if isIntegrated:
os.system("ps aux | egrep '[/]usr/bin/atv4wall'| awk '{print $2}' | xargs kill")
p = subprocess.Popen(['setsid', 'atv4wall', 'true', (receivedMessage)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT); print(p.communicate())
else:
p = subprocess.Popen(['setsid', 'atv4wall', 'false', (receivedMessage)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT); print(p.communicate())
sleep(1)
except AttributeError:
# Python 2.x version (if sys.stdin.buffer is not defined)
# Read a message from stdin and decode it.
def checkIntegrated():
stat, out = commands.getstatusoutput("ps aux | egrep '[/]usr/bin/atv4wall' | awk '{print $2}'")
return any(char.isdigit() for char in out)
def getMessage():
rawLength = sys.stdin.read(4)
if len(rawLength) == 0:
sys.exit(0)
messageLength = struct.unpack('@I', rawLength)[0]
message = sys.stdin.read(messageLength)
return json.loads(message)
while True:
receivedMessage = getMessage()
if "watch?v" in receivedMessage:
# receivedMessage=receivedMessage
isIntegrated = checkIntegrated()
if isIntegrated:
os.system("ps aux | egrep '[/]usr/bin/atv4wall'| awk '{print $2}' | xargs kill")
p = subprocess.Popen(['setsid', 'atv4wall', 'true', (receivedMessage)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT); print(p.communicate())
else:
p = subprocess.Popen(['setsid', 'atv4wall', 'false',(receivedMessage)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT); print(p.communicate())
sleep(1)