Changes to accommodate disabling the output video

This commit is contained in:
2025-09-28 13:00:08 -04:00
parent f25b9d88b4
commit 8db9f3bd9f
3 changed files with 33 additions and 22 deletions

View File

@@ -1,6 +1,8 @@
{
"instance_name": "Test",
"db_name": "videocommander.db",
"display_config": ":1",
"disabled_name": "Disable Video",
"video_tool": "ffplay",
"buttons": [
{

View File

@@ -56,6 +56,16 @@ db = sqlite3.connect(config_json["db_name"])
db.execute(destroy_table)
db.execute(make_table)
db.execute(insert_row, [
config_json["disabled_name"],
"",
"",
0,
0
])
db.commit()
for button in config_json["buttons"]:
db.execute(insert_row, [
button["name"],

View File

@@ -6,12 +6,12 @@ import time
import json
get_active_video = r'''
SELECT video_url, video_arguments FROM buttons
SELECT video_url, video_arguments, button_name FROM buttons
WHERE is_active = 1
LIMIT 1
'''
def play_video(previous_process, video_player_path, player_arguments, video_url):
def play_video(previous_process, video_player_path, player_arguments, video_url, env):
if not previous_process is None:
os.killpg(os.getpgid(previous_process.pid), signal.SIGTERM)
@@ -24,42 +24,41 @@ def play_video(previous_process, video_player_path, player_arguments, video_url)
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
shell = True,
preexec_fn = os.setsid
preexec_fn = os.setsid,
env = env
)
def get_active_video_url(db):
def get_active_video(db):
cursor = db.execute(get_active_video)
return cursor.fetchall()[0]
with open("config.json", "r") as config_file:
config_json = json.loads(config_file.read())
my_env = os.environ.copy()
my_env["DISPLAY"] = config_json["display_config"]
current_process = None
current_video = None
db = sqlite3.connect(config_json["db_name"])
while True:
if current_process is None:
current_video = get_active_video_url(db)
active_video = get_active_video(db)
current_process = play_video(
current_process,
config_json["video_tool"],
current_video[0],
current_video[1]
)
active_video = get_active_video_url(db)
if current_video[0] != active_video[0]:
if current_video[2] != active_video[2]:
current_video = active_video
current_process = play_video(
current_process,
config_json["video_tool"],
current_video[0],
current_video[1]
)
if current_video[2] == config_json["disabled_name"] and not current_process is None:
os.killpg(os.getpgid(current_process.pid), signal.SIGTERM)
current_process = None
else:
current_process = play_video(
current_process,
config_json["video_tool"],
current_video[0],
current_video[1],
my_env
)
time.sleep(1)