Created
October 12, 2016 17:37
-
-
Save tzickel/87a1f9618a98d834e76a9624d14a1356 to your computer and use it in GitHub Desktop.
A simple python script to run Kodi only when someone has tried to connect to the webserver port.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import socket | |
import subprocess | |
import time | |
import sys | |
address = '0.0.0.0' | |
port = 8000 | |
kodi_path = r'C:\Program Files (x86)\Kodi\Kodi.exe' | |
listen_timeout = 5 | |
once = False | |
if __name__ == "__main__": | |
if len(sys.argv) > 1 and sys.argv[1] == '--once': | |
once = True | |
while True: | |
print('Listening for connection...') | |
sock = socket.socket() | |
try: | |
sock.bind((address, port)) | |
except socket.error: | |
print('Somebody is already listening...') | |
time.sleep(listen_timeout) | |
continue | |
sock.listen(1) | |
s = sock.accept() | |
s[0].close() | |
sock.close() | |
print('Starting Kodi...') | |
retval = subprocess.call(kodi_path) | |
if once: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment