added player restart possibility
authorNeszt Tibor <neszt.tibor@euronetrt.hu>
Thu, 7 Dec 2017 22:13:48 +0000 (23:13 +0100)
committerNeszt Tibor <neszt.tibor@euronetrt.hu>
Thu, 7 Dec 2017 22:13:48 +0000 (23:13 +0100)
config_default.json
index.php
js/main.js

index 1869f2a..ce14fc6 100755 (executable)
@@ -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"}
index ae0dd3b..de0088d 100755 (executable)
--- 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 "<tr>";
        print "<td><label>Player</label></td><td class=\"col-md-2\"><input type=\"text\" class=\"form-control\" name=\"player\" value=\"" . $config['player']. "\"></input></td>";
        print "</tr>";
+       print "<tr>";
+       print "<td><label>Restart</label></td><td class=\"col-md-2\"><input type=\"text\" class=\"form-control\" name=\"restart\" value=\"" . $config['restart']. "\"></input></td>";
+       print "</tr>";
        print "</table>";
        print "<hr/>";
        print "<button type=\"button\" class=\"btn btn-success\" name=\"start\">Start</button>";
index 8f5aa52..5214f98 100644 (file)
@@ -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',