From e2b8791304f3675bf1f3c13e369b796a07241a85 Mon Sep 17 00:00:00 2001 From: Neszt Tibor Date: Thu, 7 Dec 2017 23:13:48 +0100 Subject: [PATCH] added player restart possibility --- config_default.json | 2 +- index.php | 31 ++++++++++++++++++++++++++++--- js/main.js | 14 ++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/config_default.json b/config_default.json index 1869f2a..ce14fc6 100755 --- a/config_default.json +++ b/config_default.json @@ -1 +1 @@ -{"player":"sudo omxplayer -s -o alsa:plughw:0,1 -y --threshold %Buffer% --no-osd --layer 100 --timeout 3 --aspect-mode stretch '%URL%'","background":"\/var\/www\/html\/yawep\/pictures/originalcolorbars480.png","name":"Player #new","volume":"100","buffer":"0.70","url":"udp:\/\/@1.2.3.4:12345","is_bg":0,"is_boot":0} +{"player":"sudo omxplayer -s -o alsa:plughw:0,1 -y --threshold %Buffer% --no-osd --layer 100 --timeout 3 --aspect-mode stretch '%URL%'","background":"\/var\/www\/html\/yawep\/pictures/originalcolorbars480.png","name":"Player #new","volume":"100","buffer":"0.70","url":"udp:\/\/@1.2.3.4:12345","is_bg":0,"is_boot":0,"restart":"03:00"} diff --git a/index.php b/index.php index ae0dd3b..de0088d 100755 --- a/index.php +++ b/index.php @@ -35,7 +35,8 @@ $config_file = 'config.json'; $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"; +$cron_boot_file = "/etc/cron.d/yawep_boot"; +$cron_restart_file = "/etc/cron.d/yawep_player_restart"; $is_bg_checked_html = ''; if ( isset($config['is_bg']) && $config['is_bg'] ) { @@ -85,6 +86,27 @@ if ( isset($_GET['config']) ) { exec("screen -X -S yawep_screen_player quit"); } + if ( isset($_GET['restart']) ) { + $h_m = explode(':', $_GET['restart']); + if ( $_GET['restart'] != '' && isset($h_m[0]) && isset($h_m[1]) ) { + $h = sprintf("%02d", $h_m[0]); + $m = sprintf("%02d", $h_m[1]); + if ( $h < 0 or $h > 23 or $m < 0 or $m > 59 ) { + $config['restart'] = ''; + exec("sudo sh -c 'rm $cron_restart_file'"); + } else { + $config['restart'] = "$h:$m"; + exec("sudo sh -c 'cp /var/www/html/yawep/crontab_player_restart $cron_restart_file'"); + exec("sudo sed -i 's/__MINUTE__/$m/;s/__HOUR__/$h/' $cron_restart_file"); + } + } else { + $config['restart'] = ''; + exec("sudo sh -c 'rm $cron_restart_file'"); + } + $r = array(); + $r['restart'] = $config['restart']; + print json_encode($r); + } if ( isset($_GET['reboot']) ) { exec("sudo reboot"); @@ -102,10 +124,10 @@ if ( isset($_GET['config']) ) { if ( isset($_GET['bootonoff']) ) { if ( $_GET['bootonoff'] == 'true' ) { $config['is_boot'] = 1; - exec("sudo sh -c 'cp /var/www/html/yawep/crontab_reboot $cron_file'"); + exec("sudo sh -c 'cp /var/www/html/yawep/crontab_reboot $cron_boot_file'"); } else { $config['is_boot'] = 0; - exec("sudo sh -c 'rm $cron_file'"); + exec("sudo sh -c 'rm $cron_boot_file'"); } } if ( isset($_GET['status']) ) { @@ -152,6 +174,9 @@ if ( isset($_GET['config']) ) { print ""; print ""; print ""; + print ""; + print ""; + print ""; print ""; print "
"; print ""; diff --git a/js/main.js b/js/main.js index 8f5aa52..5214f98 100644 --- a/js/main.js +++ b/js/main.js @@ -85,6 +85,20 @@ function init() { ; }) }); + $('input[name=restart]').change(function() { + $.ajax({ + type: 'GET', + url: 'index.php', + dataType: 'json', + data: { config: '1', restart: $(this).val()} + }) + .done(function(msg) { + $('input[name=restart]').val(msg['restart']); + }) + .fail(function(msg) { + ; + }) + }); $('button[name=start]').click(function() { $.ajax({ type: 'GET', -- 2.1.4