From 8db9f3bd9f876552163972d517edb8b2694e3b3b Mon Sep 17 00:00:00 2001 From: Bradley Bickford Date: Sun, 28 Sep 2025 13:00:08 -0400 Subject: [PATCH] Changes to accommodate disabling the output video --- config.json | 2 ++ video_dbbuilder.py | 10 ++++++++++ video_player.py | 43 +++++++++++++++++++++---------------------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/config.json b/config.json index b89e5be..32bb620 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,8 @@ { "instance_name": "Test", "db_name": "videocommander.db", + "display_config": ":1", + "disabled_name": "Disable Video", "video_tool": "ffplay", "buttons": [ { diff --git a/video_dbbuilder.py b/video_dbbuilder.py index c16fbfd..3eb9947 100644 --- a/video_dbbuilder.py +++ b/video_dbbuilder.py @@ -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"], diff --git a/video_player.py b/video_player.py index 9daa3f4..c11191b 100644 --- a/video_player.py +++ b/video_player.py @@ -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) \ No newline at end of file