diff --git a/resources/js/custom.js b/resources/js/custom.js index 7c5da4ff..a28fc1f3 100644 --- a/resources/js/custom.js +++ b/resources/js/custom.js @@ -52,12 +52,16 @@ function modal(btOK, btCan, video, title, content, x, y, callback) { } //get date -function get_date(hour, seek_day) { - var raw_date = moment(); - if (raw_date.format("H") < parseInt(hour) && seek_day) { - return raw_date.add(-1, 'days'); +function get_date(t, seek_day) { + var datetime = moment(); + var l_time = t.split(":"); + l_stamp = parseInt(l_time[0]) * 3600 + parseInt(l_time[1]) * 60 + parseInt(l_time[2]); + t_stamp = moment.duration(datetime.format("H:M:S")).asSeconds(); + + if (l_stamp > 0 && l_stamp > t_stamp && seek_day) { + return datetime.add(-1, 'days'); } else { - return raw_date; + return datetime; } } @@ -137,12 +141,12 @@ function init_browse_click() { } // call php script to navigatge to the selected folder on the server -function browse(current_data) { - $.get("functions.php" + current_data + "&head=get", function(data) { +function browse(c_data) { + $.get("functions.php" + c_data + "&head=get", function(data) { $('#browserHead').html(data); }); - $.get("functions.php" + current_data + "&ul=get", function(data) { + $.get("functions.php" + c_data + "&ul=get", function(data) { $('#rootDirectory').html(data); init_browse_click(); }); @@ -151,13 +155,17 @@ function browse(current_data) { // first page load will open the media directory window.onload = function() { $.get("resources/list_op.php?clips_root=get", function(result) { - browse("?dir=" + result); + browse("?dir=" + result.replace(/^\//g, '')); }); $.get("resources/list_op.php?list_start=get", function(result) { + var l_time = result.split(":"); + var l_stamp = parseInt(l_time[0]) * 3600 + parseInt(l_time[1]) * 60 + parseInt(l_time[2]); + var list_date = get_date(result, true); // write playlist date to list attribute, for later use $('#playlistBody').attr('listday', list_date.format("YYYY-MM-DD")); + $('#playlistBody').attr('liststart', l_stamp); // read playlist from current day get_json(list_date.format("YYYY-MM-DD"), true); }); @@ -252,7 +260,8 @@ function reorder_playlist() { // get start time from: /etc/ffplayout/ffplayout.conf $.get("resources/list_op.php?list_start=get", function(result) { var reorder = document.getElementById("playlistBody").getElementsByClassName("list-item"); - var start_time = parseFloat(result * 3600); + var l_time = result.split(":"); + var start_time = parseFloat(l_time[0]) * 3600 + parseFloat(l_time[1]) * 60 + parseFloat(l_time[2]); var time_format, cur_in, cur_out; for (var i = 0; i < reorder.length; i++) { @@ -281,39 +290,37 @@ function jump_and_colorize_title(jump) { var play_begin, play_dur; $.get("resources/list_op.php?list_start=get", function(result) { - list_date = get_date(result, true); + var list_date = get_date(result, true); if (list_date.format("H") < parseInt(result)) { time_in_seconds += 86400 } - $.get("resources/list_op.php?time_shift=get", function(shift) { - if ($('#playlistBody').attr('listday') === list_date.format("YYYY-MM-DD")) { - for (var i = 0; i < play_items.length; i++) { - play_begin = parseFloat($(play_items[i]).attr('begin')) - parseFloat(shift); - play_dur = parseFloat($(play_items[i]).attr('dur')); - if (play_begin + play_dur >= time_in_seconds) { - // jump to position only after page load - if (jump) { - $('#list-container').animate({ - scrollTop: $('#playlistBody li:nth-child(' + (i-1) + ')').position().top - }, 500, "easeOutQuint"); - } - - // colorize items - $(play_items[i]).addClass('current_item'); - $(play_items[i+1]).addClass('next_item'); - $('.list-item:gt('+(i+1)+')').addClass('last_items'); - break; + if ($('#playlistBody').attr('listday') === list_date.format("YYYY-MM-DD")) { + for (var i = 0; i < play_items.length; i++) { + play_begin = parseFloat($(play_items[i]).attr('begin')); + play_dur = parseFloat($(play_items[i]).attr('dur')); + if (play_begin + play_dur >= time_in_seconds) { + // jump to position only after page load + if (jump) { + $('#list-container').animate({ + scrollTop: $('#playlistBody li:nth-child(' + (i-1) + ')').position().top + }, 500, "easeOutQuint"); } - } - } else { - // scroll to playlist top - if (jump) { - $('#list-container').animate({scrollTop: 0}, 500, "easeOutQuint"); + + // colorize items + $(play_items[i]).addClass('current_item'); + $(play_items[i+1]).addClass('next_item'); + $('.list-item:gt('+(i+1)+')').addClass('last_items'); + break; } } - }); + } else { + // scroll to playlist top + if (jump) { + $('#list-container').animate({scrollTop: 0}, 500, "easeOutQuint"); + } + } }); } @@ -355,24 +362,24 @@ header functions var intervalId = null; function get_track_list(interval) { - var begin, src, dur, seek, out, time_left; + var begin, seek, out, time_left; $.get("resources/player.php?track=get", function(result) { function get_track() { var moment_time = moment().format('HH:mm:ss'); var time_in_seconds = parseFloat(moment.duration(moment_time).asSeconds()); var json = $.parseJSON(result); - var playlist_start = parseFloat(json[0]['start'][0]); + var playlist_start = parseFloat($('#playlistBody').attr('liststart')); - if (0.0 <= time_in_seconds && time_in_seconds < playlist_start * 3600.0) { + if (0.0 <= time_in_seconds && time_in_seconds < playlist_start) { time_in_seconds += 86400.0; } - $.each(json, function (index, value) { - begin = parseFloat(value['begin'][0]); - dur = parseFloat(value['dur'][0]); - seek = parseFloat(value['in'][0]); - out = parseFloat(value['out'][0]); + begin = playlist_start; + + $.each(json, function (_index, value) { + seek = parseFloat(value['in']); + out = parseFloat(value['out']); if (time_in_seconds < begin + out - seek ) { time_left = begin + out - seek - time_in_seconds; @@ -380,6 +387,8 @@ function get_track_list(interval) { $('#title').html((value['src'])); return false; } + + begin += out - seek; }); } if (interval) { @@ -387,7 +396,6 @@ function get_track_list(interval) { } else { clearInterval(refreshIntervalId); } - }); } @@ -521,7 +529,6 @@ $(document).ready(function() { var save_list = []; $('#playlistBody li.list-item').each(function(){ save_list.push({ - begin:$(this).attr('begin'), src:$(this).attr('src'), dur:$(this).attr('dur'), in:$(this).attr('in'), @@ -562,7 +569,6 @@ $(document).ready(function() { var save_list = []; $('#playlistBody li.list-item').each(function(){ save_list.push({ - begin:$(this).attr('begin'), src:$(this).attr('src'), dur:$(this).attr('dur'), in:$(this).attr('in'), @@ -581,7 +587,6 @@ $(document).ready(function() { modal(null, null, null, "Fill Playlist", "Filling Playlist in progress...", 'auto', 'auto', function(result) {}); }, success: function(result) { - // console.log(result); $('#dialog-confirm').dialog("close"); modal(true, null, null, "Fill Playlist", result + "
Filled Time: " + moment.utc(Math.abs(missed_length) * 1000).format('HH:mm:ss'), 'auto', 'auto', function(result) {}); get_json(date, false); diff --git a/resources/list_op.php b/resources/list_op.php index d0d69bb3..d2e9e99b 100644 --- a/resources/list_op.php +++ b/resources/list_op.php @@ -5,43 +5,22 @@ read values from ffplayout config file ------------------------------------------------------------------------------*/ // get config file -function get_config() { - return file_get_contents("/etc/ffplayout/ffplayout.conf"); +function get_ini() { + return parse_ini_file("/etc/ffplayout/ffplayout.conf", TRUE, INI_SCANNER_RAW); } // get start time if(!empty($_GET['list_start'])) { - $get_ini = get_config(); - $get_start = "/^day_start.*\$/m"; - preg_match_all($get_start, $get_ini, $matches); - $line = implode("\n", $matches[0]); - echo explode("= ", $line)[1]; + $ini = get_ini(); + echo $ini['PLAYLIST']['day_start']; } // get clips root directory if(!empty($_GET['clips_root'])) { - $get_ini = get_config(); - $get_root = "/^clips_root.*\$/m"; - preg_match_all($get_root, $get_ini, $matches); - $line = implode("\n", $matches[0]); - $root = substr(explode("= ", $line)[1], 1); - echo $root; + $ini = get_ini(); + echo $ini['STORAGE']['path']; } -// get time_shift -if (!empty($_GET['time_shift'])) { - $get_ini = get_config(); - $get_shift = "/^time_shift.*\$/m"; - preg_match_all($get_shift, $get_ini, $shift_arr); - $line_shift = implode("\n", $shift_arr[0]); - $time_shift = explode("= ", $line_shift)[1]; - - if(empty($time_shift)) { - echo 0; - } else { - echo $time_shift; - } -} /* ----------------------------------------------------------------------------- json playlist operations @@ -65,19 +44,16 @@ $ext = implode('|', $except); if(!empty($_GET['json_path'])) { $json_date = $_GET['json_path']; $date_str = explode('-', $json_date); - $get_ini = get_config(); - $get_dir = "/^playlist_path.*\$/m"; - preg_match_all($get_dir, $get_ini, $matches); - $line = implode("\n", $matches[0]); - $path_root = explode("= ", $line)[1]; + $ini = get_ini(); + $dir = $ini['PLAYLIST']['path']; - $json_path = $path_root . "/" . $date_str[0] . "/" . $date_str[1] . "/" . $json_date . ".json"; + $json_path = $dir . "/" . $date_str[0] . "/" . $date_str[1] . "/" . $json_date . ".json"; if (file_exists($json_path)) { $content = file_get_contents($json_path) or die("Error: Cannot create object"); $json = json_decode($content, true); - list($hh, $mm, $ss) = explode(":", $json["begin"]); + list($hh, $mm, $ss) = explode(":", $ini['PLAYLIST']['day_start']); list($l_hh, $l_mm, $l_ss) = explode(":", $json["length"]); $start = $hh * 3600 + $mm * 60 + $ss; @@ -185,22 +161,15 @@ if(!empty($_POST['save'])) { $date = $_POST['date']; $date_str = explode('-', $date); // get save path - $get_ini = get_config(); - $get_dir = "/^playlist_path.*\$/m"; - preg_match_all($get_dir, $get_ini, $matches); - $line = implode("\n", $matches[0]); - $path_root = explode("= ", $line)[1]; - $json_path = $path_root . "/" . $date_str[0] . "/" . $date_str[1]; + $ini = get_ini(); + $dir = $ini['PLAYLIST']['path']; + $json_path = $dir . "/" . $date_str[0] . "/" . $date_str[1]; $json_output = $json_path . "/" . $date . ".json"; - $beginRaw = round($raw_arr[0]->begin); - $start = sprintf('%02d:%02d:%02d', ($beginRaw/3600),($beginRaw/60%60), $beginRaw%60); - // prepare header $list = array( "channel" => "Test 1", "date" => $date, - "begin" => $start, "length" => "24:00:00.000", "program" => [] ); @@ -232,69 +201,4 @@ if(!empty($_POST['save'])) { printf('Save playlist "%s.json" done...', $date); } -// fill playlist to 24 hours -if(!empty($_POST['fill_playlist'])) { - $list_date = $_POST['fill_playlist']; - $diff_len = $_POST['diff_len']; - $start_time = $_POST['start_time']; - $raw_arr = json_decode(urldecode($_POST['old_list'])); - - $get_ini = get_config(); - $date_str = explode('-', $list_date); - $get_dir = "/^playlist_path.*\$/m"; - preg_match_all($get_dir, $get_ini, $matches); - $line = implode("\n", $matches[0]); - $path_root = explode("= ", $line)[1]; - $json_path = $path_root . "/" . $date_str[0] . "/" . $date_str[1]; - $json_output = $json_path . "/" . $list_date . ".json"; - - $fill = shell_exec("./sh/fill.sh '".$diff_len."'"); - - $beginRaw = round($raw_arr[0]->begin); - $start = sprintf('%02d:%02d:%02d', ($beginRaw/3600),($beginRaw/60%60), $beginRaw%60); - - // prepare header - $list = array( - "channel" => "Test 1", - "date" => $list_date, - "begin" => $start, - "length" => "24:00:00.000", - "program" => [] - ); - - // create json video element - foreach($raw_arr as $rawline) { - $clipItem = array( - "in" => floatval($rawline->in), - "out" => floatval($rawline->out), - "duration" => floatval($rawline->dur), - "source" => $rawline->src - ); - - $list["program"][] = $clipItem; - } - - foreach(preg_split("/((\r?\n)|(\r\n?))/", $fill) as $line){ - $line_arr = explode('|', $line); - - $clipItem = array( - "in" => floatval($line_arr[0]), - "out" => floatval($line_arr[1]), - "duration" => floatval($line_arr[2]), - "source" => $line_arr[3] - ); - - if ($line_arr[3]) { - $list["program"][] = $clipItem; - } - } - - if (!is_dir($json_path)) { - mkdir($json_path, 0777, true); - } - - file_put_contents($json_output, json_encode( - $list, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT)); - printf('Filled and save playlist "%s.json" done...', $list_date); -} ?> diff --git a/resources/player.php b/resources/player.php index 11efbce0..20e2ac5c 100644 --- a/resources/player.php +++ b/resources/player.php @@ -1,8 +1,8 @@ body[0]->video as $video) { - $src = preg_replace('/^\//', '', $video['src']); + foreach($json["program"] as $video) { + $src = preg_replace('/^\//', '', $video['source']); $src_arr = explode('/', $src); $name = preg_replace($src_re, '', end($src_arr)); $name = str_replace('ยง', '?', $name); - $begin = $video['begin']; - $dur = $video['dur']; + $dur = $video['duration']; + $in = $video['in']; $out = $video['out']; - $videos[] = array('start' => $start_hour, 'begin'=> $begin, 'src' => $name, 'dur' => $dur, 'in' => $in, 'out' => $out); + $videos[] = array('start' => $start_time, 'begin'=> $begin, 'src' => $name, 'dur' => $dur, 'in' => $in, 'out' => $out); + + $begin += $out - $in; } echo json_encode($videos);