Changes to accommodate disabling the output video
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
"instance_name": "Test",
|
"instance_name": "Test",
|
||||||
"db_name": "videocommander.db",
|
"db_name": "videocommander.db",
|
||||||
|
"display_config": ":1",
|
||||||
|
"disabled_name": "Disable Video",
|
||||||
"video_tool": "ffplay",
|
"video_tool": "ffplay",
|
||||||
"buttons": [
|
"buttons": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,6 +56,16 @@ db = sqlite3.connect(config_json["db_name"])
|
|||||||
db.execute(destroy_table)
|
db.execute(destroy_table)
|
||||||
db.execute(make_table)
|
db.execute(make_table)
|
||||||
|
|
||||||
|
db.execute(insert_row, [
|
||||||
|
config_json["disabled_name"],
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
])
|
||||||
|
|
||||||
|
db.commit()
|
||||||
|
|
||||||
for button in config_json["buttons"]:
|
for button in config_json["buttons"]:
|
||||||
db.execute(insert_row, [
|
db.execute(insert_row, [
|
||||||
button["name"],
|
button["name"],
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import time
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
get_active_video = r'''
|
get_active_video = r'''
|
||||||
SELECT video_url, video_arguments FROM buttons
|
SELECT video_url, video_arguments, button_name FROM buttons
|
||||||
WHERE is_active = 1
|
WHERE is_active = 1
|
||||||
LIMIT 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:
|
if not previous_process is None:
|
||||||
os.killpg(os.getpgid(previous_process.pid), signal.SIGTERM)
|
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,
|
stdout = subprocess.PIPE,
|
||||||
stderr = subprocess.PIPE,
|
stderr = subprocess.PIPE,
|
||||||
shell = True,
|
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)
|
cursor = db.execute(get_active_video)
|
||||||
return cursor.fetchall()[0]
|
return cursor.fetchall()[0]
|
||||||
|
|
||||||
with open("config.json", "r") as config_file:
|
with open("config.json", "r") as config_file:
|
||||||
config_json = json.loads(config_file.read())
|
config_json = json.loads(config_file.read())
|
||||||
|
|
||||||
|
my_env = os.environ.copy()
|
||||||
|
my_env["DISPLAY"] = config_json["display_config"]
|
||||||
|
|
||||||
current_process = None
|
current_process = None
|
||||||
current_video = None
|
current_video = None
|
||||||
db = sqlite3.connect(config_json["db_name"])
|
db = sqlite3.connect(config_json["db_name"])
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if current_process is None:
|
active_video = get_active_video(db)
|
||||||
current_video = get_active_video_url(db)
|
|
||||||
|
|
||||||
current_process = play_video(
|
if current_video[2] != active_video[2]:
|
||||||
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]:
|
|
||||||
current_video = active_video
|
current_video = active_video
|
||||||
|
|
||||||
current_process = play_video(
|
if current_video[2] == config_json["disabled_name"] and not current_process is None:
|
||||||
current_process,
|
os.killpg(os.getpgid(current_process.pid), signal.SIGTERM)
|
||||||
config_json["video_tool"],
|
current_process = None
|
||||||
current_video[0],
|
else:
|
||||||
current_video[1]
|
current_process = play_video(
|
||||||
)
|
current_process,
|
||||||
|
config_json["video_tool"],
|
||||||
|
current_video[0],
|
||||||
|
current_video[1],
|
||||||
|
my_env
|
||||||
|
)
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
Reference in New Issue
Block a user