Add main data structure passing, add graceful kill

This commit is contained in:
Logen Kain 2025-01-09 15:42:59 -05:00
parent 0174cd3f01
commit 4303347cac
2 changed files with 41 additions and 21 deletions

42
lib.py
View File

@ -1,6 +1,6 @@
import sys import sys
import os
MEDIAPLAYER = "vlc" import subprocess
def mainMenu(): def mainMenu():
@ -15,11 +15,16 @@ def mainMenu():
else: else:
return 1 return 1
def quitLKStream(): def quitLKStream(mainData):
#gracefully shut stuff down
#Terminate will raise a ProcessLookupError exception
#Close holesail #Close holesail
#Close MEDIAPLAYER ##holesail.terminate()
##holesail.wait()
#Close mediamtx #Close mediamtx
mainData["playerProc"].terminate()
mainData["playerProc"].wait()
sys.exit() sys.exit()
def startLKStream(): def startLKStream():
@ -31,21 +36,28 @@ def startLKStream():
print("TODO: Start Streaming") print("TODO: Start Streaming")
return "Fake Key" #return holesail key return "Fake Key" #return holesail key
def mainMenuHandling(x): def watchLKStream(mainData):
#Ask for holesail key
#Connect to holesail (subprocess?)
#Connect to stream with MEDIAPLAYER(subprocess?)
mainData["playerProc"] = subprocess.Popen(mainData["player"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
# Use a default stream location if streaming with FFMPEG, with OBS it's the default plus stream key
print("TODO Watch Stream")
return mainData
def connectToHolesail(key):
proc = subprocess.Popen(['holesail', key])
return proc
def mainMenuHandling(x, mainData):
if x == 'q': if x == 'q':
quitLKStream() quitLKStream(mainData)
elif x == 's': elif x == 's':
holesailKey = startLKStream() return startLKStream()
return holesailKey
elif x == 'w': elif x == 'w':
#Ask for holesail key return watchLKStream(mainData)
#Connect to holesail (subprocess?)
#Connect to stream with MEDIAPLAYER(subprocess?)
# Use a default stream location if streaming with FFMPEG, with OBS it's the default plus stream key
print("TODO Watch Stream")
return 0
else: else:
print("invalid option x was: ", x) print("invalid option x was: ", x)
return 1 return 1

20
main.py
View File

@ -1,11 +1,19 @@
from lib import * from lib import *
MEDIAPLAYER = 'vlc'
mainData = {
'holesailKey': "Holesail has not been started",
'holesailProc': 0,
'mediamtxProc' : 0,
'player' : MEDIAPLAYER,
'playerProc' : 0
}
holesailKey = "Holesail has not been started"
while True: while True:
result = mainMenuHandling(mainMenu()) result = mainMenuHandling(mainMenu(), mainData)
if result != 1 and result != 0: if type(result) is dict:
holesailKey = result mainData = result
print("Key: ", mainData["holesailKey"])
print("Key: ", holesailKey)