2018-04-29 18:54:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// get config file
|
2019-08-15 13:51:27 +02:00
|
|
|
function get_ini() {
|
|
|
|
return parse_ini_file("/etc/ffplayout/ffplayout.conf", TRUE, INI_SCANNER_RAW);
|
2018-04-29 18:54:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// file extension to filter
|
|
|
|
// for make it nicer
|
|
|
|
$except = array(
|
|
|
|
'avi',
|
|
|
|
'mp4',
|
|
|
|
'mov',
|
|
|
|
'mkv',
|
|
|
|
'mpg',
|
|
|
|
'mpeg',
|
|
|
|
);
|
|
|
|
|
|
|
|
$ext = implode('|', $except);
|
|
|
|
|
|
|
|
// get current track
|
|
|
|
if(!empty($_GET['track'])) {
|
2019-08-15 13:51:27 +02:00
|
|
|
$ini = get_ini();
|
|
|
|
$dir = $ini['PLAYLIST']['path'];
|
2018-04-29 18:54:05 +02:00
|
|
|
|
|
|
|
// list start
|
2019-08-15 13:51:27 +02:00
|
|
|
$start = $ini['PLAYLIST']['day_start'];
|
|
|
|
$st = date_parse($start);
|
|
|
|
$start_time = $st['hour'] * 3600 + $st['minute'] * 60 + $st['second'];
|
2018-04-29 18:54:05 +02:00
|
|
|
|
2019-08-15 13:51:27 +02:00
|
|
|
$t = date_parse(date("H:i:s"));
|
|
|
|
$time = $t['hour'] * 3600 + $t['minute'] * 60 + $t['second'];
|
2018-04-29 18:54:05 +02:00
|
|
|
|
2019-08-15 13:51:27 +02:00
|
|
|
if ($time < $start_time) {
|
2018-04-29 18:54:05 +02:00
|
|
|
$date = date("Y-m-d", strtotime( '-1 days' ) );
|
|
|
|
} else {
|
|
|
|
$date = date("Y-m-d");
|
|
|
|
}
|
|
|
|
|
|
|
|
$date_str = explode('-', $date);
|
2019-08-15 13:51:27 +02:00
|
|
|
$json_path = $dir . "/" . $date_str[0] . "/" . $date_str[1] . "/" . $date . ".json";
|
2018-04-29 18:54:05 +02:00
|
|
|
|
2019-08-15 13:51:27 +02:00
|
|
|
if (file_exists($json_path)) {
|
|
|
|
$content = file_get_contents($json_path) or die("Error: Cannot create object");
|
|
|
|
$json = json_decode($content, true);
|
|
|
|
|
|
|
|
list($l_hh, $l_mm, $l_ss) = explode(":", $json["length"]);
|
2019-10-05 16:22:16 +02:00
|
|
|
$begin = $start_time;
|
2019-08-15 13:51:27 +02:00
|
|
|
$length = $l_hh * 3600 + $l_mm * 60 + $l_ss;
|
2018-04-29 18:54:05 +02:00
|
|
|
|
|
|
|
$src_re = array();
|
|
|
|
$src_re[0] = '/# [0-9-]+.('.$ext.')$/';
|
|
|
|
$src_re[1] = '/^[0-9]+ # /';
|
|
|
|
$src_re[2] = '/.('.$ext.')$/';
|
|
|
|
$src_re[3] = '/^# /';
|
|
|
|
|
|
|
|
$videos = array();
|
|
|
|
|
2019-08-15 13:51:27 +02:00
|
|
|
foreach($json["program"] as $video) {
|
|
|
|
$src = preg_replace('/^\//', '', $video['source']);
|
2018-04-29 18:54:05 +02:00
|
|
|
$src_arr = explode('/', $src);
|
|
|
|
$name = preg_replace($src_re, '', end($src_arr));
|
|
|
|
$name = str_replace('§', '?', $name);
|
2019-08-15 13:51:27 +02:00
|
|
|
$dur = $video['duration'];
|
|
|
|
|
2018-04-29 18:54:05 +02:00
|
|
|
$in = $video['in'];
|
|
|
|
$out = $video['out'];
|
|
|
|
|
2019-08-15 13:51:27 +02:00
|
|
|
$videos[] = array('start' => $start_time, 'begin'=> $begin, 'src' => $name, 'dur' => $dur, 'in' => $in, 'out' => $out);
|
|
|
|
|
|
|
|
$begin += $out - $in;
|
2018-04-29 18:54:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode($videos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// start / stop playout
|
|
|
|
if(!empty($_POST['playout'])) {
|
|
|
|
$state = $_POST['playout'];
|
|
|
|
|
|
|
|
if ($state === "start") {
|
|
|
|
$out = shell_exec("./sh/playout.sh start");
|
|
|
|
echo "<b>Started Playout</b>";
|
|
|
|
} else if ($state === "stop") {
|
|
|
|
$out = shell_exec("./sh/playout.sh stop");
|
|
|
|
echo "<b>Stoped Playout</b>";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "$out";
|
|
|
|
}
|