From f50a139136739313fae60f8546c26a492a0dac7e Mon Sep 17 00:00:00 2001 From: Neszt Tibor Date: Sun, 3 Dec 2017 18:12:08 +0100 Subject: [PATCH] default config values json --- config_default.json | 1 + index.php | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) create mode 100755 config_default.json diff --git a/config_default.json b/config_default.json new file mode 100755 index 0000000..d85df39 --- /dev/null +++ b/config_default.json @@ -0,0 +1 @@ +{"player":"sudo omxplayer -s -o alsa:plughw:0,1 -y --threshold %Buffer% --no-osd --layer 100 --timeout 3 --aspect-mode stretch '%URL%'","background":"\/home\/pi\/bars\/originalcolorbars480.png","name":"Player #new","volume":"100","buffer":"0.70","url":"udp:\/\/@1.2.3.4:12345","status":"stopped","is_bg":1,"is_boot":1} \ No newline at end of file diff --git a/index.php b/index.php index cde0058..148e525 100755 --- a/index.php +++ b/index.php @@ -5,10 +5,24 @@ function get_status($cmd) { return str_replace("\n", '
', `$cmd`); } -function read_json_config($filename) { +function read_json_config($config_filename, $config_default_filename) { - $json_data = file_get_contents($filename); - return json_decode($json_data, true); + $config_json = file_get_contents($config_filename); + + if ( !$config_json === null || $config_json != '[]' ) { + $config = json_decode($config_json, true); + } else { + $config = array(); + } + + $defaults = json_decode(file_get_contents($config_default_filename), true); + foreach ($defaults as $k => $v) { + if ( !isset($config[$k]) ) { + $config[$k] = $v; + } + } + + return $config; } # @@ -18,8 +32,7 @@ function read_json_config($filename) { $player_script = '/tmp/yawep_screen_player_script.sh'; $config_file = 'config.json'; -$config = read_json_config($config_file); -$default_player_cmd = "sudo omxplayer -s -o alsa:plughw:0,1 -y --threshold %Buffer% --no-osd --layer 100 --timeout 3 --aspect-mode stretch '%URL%'"; +$config = read_json_config($config_file, 'config_default.json'); $screenrc_file = "/tmp/yawep_player_screenrc"; $screenlog_file = "/tmp/yawep_screen.log"; $cron_file = "/etc/cron.d/yawep_player"; @@ -34,10 +47,6 @@ if ( isset($config['is_boot']) && $config['is_boot'] ) { $is_boot_checked_html = 'checked="checked"'; } -if ( $config['player'] == '' ) { - $config['player'] = $default_player_cmd; -} - if ( isset($_GET['config']) ) { if ( isset($_GET['volume']) ) { $config['volume'] = $_GET['volume']; -- 2.1.4