LKstream/lib.py

64 lines
1.5 KiB
Python
Raw Permalink Normal View History

2025-01-09 11:52:51 -05:00
import sys
import os
import subprocess
2025-01-09 11:52:51 -05:00
def mainMenu():
print("(S)tream")
print("(W)atch")
print("(Q)uit")
print()
x = input ("s/w/q: ").strip().lower()
if x in ("s","w","q"):
return x
else:
return 1
def quitLKStream(mainData):
#Terminate will raise a ProcessLookupError exception
2025-01-09 11:52:51 -05:00
#Close holesail
##holesail.terminate()
##holesail.wait()
2025-01-09 11:52:51 -05:00
#Close mediamtx
mainData["playerProc"].terminate()
mainData["playerProc"].wait()
2025-01-09 11:52:51 -05:00
sys.exit()
def startLKStream():
#start mediamtx server
#start holesail with randomized key
#start ffmpeg streaming to mediamtx
#For the moment, we won't be doing that but using OBS
print("TODO: Start Streaming")
return "Fake Key" #return holesail key
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):
2025-01-09 11:52:51 -05:00
if x == 'q':
quitLKStream(mainData)
2025-01-09 11:52:51 -05:00
elif x == 's':
return startLKStream()
2025-01-09 11:52:51 -05:00
elif x == 'w':
return watchLKStream(mainData)
2025-01-09 11:52:51 -05:00
else:
print("invalid option x was: ", x)
return 1