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
|
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):
|
||||||
if x == 'q':
|
|
||||||
quitLKStream()
|
|
||||||
|
|
||||||
elif x == 's':
|
|
||||||
holesailKey = startLKStream()
|
|
||||||
return holesailKey
|
|
||||||
|
|
||||||
elif x == 'w':
|
|
||||||
#Ask for holesail key
|
#Ask for holesail key
|
||||||
#Connect to holesail (subprocess?)
|
#Connect to holesail (subprocess?)
|
||||||
#Connect to stream with MEDIAPLAYER(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
|
# Use a default stream location if streaming with FFMPEG, with OBS it's the default plus stream key
|
||||||
print("TODO Watch Stream")
|
print("TODO Watch Stream")
|
||||||
return 0
|
return mainData
|
||||||
|
|
||||||
|
def connectToHolesail(key):
|
||||||
|
proc = subprocess.Popen(['holesail', key])
|
||||||
|
return proc
|
||||||
|
|
||||||
|
def mainMenuHandling(x, mainData):
|
||||||
|
if x == 'q':
|
||||||
|
quitLKStream(mainData)
|
||||||
|
|
||||||
|
elif x == 's':
|
||||||
|
return startLKStream()
|
||||||
|
|
||||||
|
elif x == 'w':
|
||||||
|
return watchLKStream(mainData)
|
||||||
else:
|
else:
|
||||||
print("invalid option x was: ", x)
|
print("invalid option x was: ", x)
|
||||||
return 1
|
return 1
|
||||||
|
20
main.py
20
main.py
@ -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)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user