From 4303347cac8b33d1ef9c2f5ab6db5b83ec82d218 Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Thu, 9 Jan 2025 15:42:59 -0500 Subject: [PATCH] Add main data structure passing, add graceful kill --- lib.py | 42 +++++++++++++++++++++++++++--------------- main.py | 20 ++++++++++++++------ 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/lib.py b/lib.py index 0e32cf8..ec9e016 100644 --- a/lib.py +++ b/lib.py @@ -1,6 +1,6 @@ import sys - -MEDIAPLAYER = "vlc" +import os +import subprocess def mainMenu(): @@ -15,11 +15,16 @@ def mainMenu(): else: return 1 -def quitLKStream(): - #gracefully shut stuff down +def quitLKStream(mainData): + + #Terminate will raise a ProcessLookupError exception + #Close holesail - #Close MEDIAPLAYER + ##holesail.terminate() + ##holesail.wait() #Close mediamtx + mainData["playerProc"].terminate() + mainData["playerProc"].wait() sys.exit() def startLKStream(): @@ -31,21 +36,28 @@ def startLKStream(): print("TODO: Start Streaming") 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': - quitLKStream() + quitLKStream(mainData) elif x == 's': - holesailKey = startLKStream() - return holesailKey + return startLKStream() elif x == 'w': - #Ask for holesail key - #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 + return watchLKStream(mainData) else: print("invalid option x was: ", x) return 1 diff --git a/main.py b/main.py index 2bec054..a001465 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,19 @@ 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: - result = mainMenuHandling(mainMenu()) - - if result != 1 and result != 0: - holesailKey = result + result = mainMenuHandling(mainMenu(), mainData) - print("Key: ", holesailKey) + if type(result) is dict: + mainData = result + print("Key: ", mainData["holesailKey"])