Add main data structure passing, add graceful kill
This commit is contained in:
parent
0174cd3f01
commit
4303347cac
42
lib.py
42
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
|
||||
|
20
main.py
20
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"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user