mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-06 03:50:04 +02:00
Generate a better stats based on on_publish and on_publish_done
This commit is contained in:
parent
7d6b48d5a9
commit
30d941ade3
7 changed files with 113 additions and 43 deletions
|
@ -414,6 +414,24 @@ abstract class ObjectYPT implements ObjectInterface
|
||||||
ObjectYPT::deleteCacheFromPattern($name);
|
ObjectYPT::deleteCacheFromPattern($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function deleteCachePattern($pattern) {
|
||||||
|
$tmpDir = self::getCacheDir();
|
||||||
|
$array = _glob($tmpDir, $pattern);
|
||||||
|
foreach ($array as $value) {
|
||||||
|
_error_log("Object::deleteCachePattern file [{$value}]");
|
||||||
|
@unlink($value);
|
||||||
|
}
|
||||||
|
_session_start();
|
||||||
|
foreach ($_SESSION['user']['sessionCache'] as $key => $value) {
|
||||||
|
if (preg_match($pattern, $key)) {
|
||||||
|
_error_log("Object::deleteCachePattern session [{$key}]");
|
||||||
|
$_SESSION['user']['sessionCache'][$key] = null;
|
||||||
|
unset($_SESSION['user']['sessionCache'][$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function deleteALLCache()
|
public static function deleteALLCache()
|
||||||
{
|
{
|
||||||
$tmpDir = self::getCacheDir();
|
$tmpDir = self::getCacheDir();
|
||||||
|
@ -425,13 +443,13 @@ abstract class ObjectYPT implements ObjectInterface
|
||||||
public static function getCacheDir()
|
public static function getCacheDir()
|
||||||
{
|
{
|
||||||
$tmpDir = getTmpDir();
|
$tmpDir = getTmpDir();
|
||||||
$tmpDir = rtrim($tmpDir, DIRECTORY_SEPARATOR) . "/";
|
$tmpDir = rtrim($tmpDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||||
$tmpDir .= "YPTObjectCache" . "/";
|
$tmpDir .= "YPTObjectCache" . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
if (class_exists("User_Location")) {
|
if (class_exists("User_Location")) {
|
||||||
$loc = User_Location::getThisUserLocation();
|
$loc = User_Location::getThisUserLocation();
|
||||||
if (!empty($loc) && !empty($loc['country_code'])) {
|
if (!empty($loc) && !empty($loc['country_code'])) {
|
||||||
$tmpDir .= $loc['country_code'] . "/";
|
$tmpDir .= $loc['country_code'] . DIRECTORY_SEPARATOR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4590,11 +4590,11 @@ function getTmpDir($subdir = "") {
|
||||||
if (empty($_SESSION['getTmpDir'][$subdir . "_"])) {
|
if (empty($_SESSION['getTmpDir'][$subdir . "_"])) {
|
||||||
$tmpDir = sys_get_temp_dir();
|
$tmpDir = sys_get_temp_dir();
|
||||||
if (empty($tmpDir) || !_isWritable($tmpDir)) {
|
if (empty($tmpDir) || !_isWritable($tmpDir)) {
|
||||||
$tmpDir = getVideosDir() . "cache/";
|
$tmpDir = getVideosDir() . "cache".DIRECTORY_SEPARATOR;
|
||||||
}
|
}
|
||||||
$tmpDir = rtrim($tmpDir, '/') . '/';
|
$tmpDir = rtrim($tmpDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||||
$tmpDir = "{$tmpDir}{$subdir}";
|
$tmpDir = "{$tmpDir}{$subdir}";
|
||||||
$tmpDir = rtrim($tmpDir, '/') . '/';
|
$tmpDir = rtrim($tmpDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||||
if (!is_dir($tmpDir)) {
|
if (!is_dir($tmpDir)) {
|
||||||
mkdir($tmpDir, 0755, true);
|
mkdir($tmpDir, 0755, true);
|
||||||
}
|
}
|
||||||
|
@ -5353,7 +5353,7 @@ function _glob($dir, $pattern) {
|
||||||
if (isset($_glob[$name])) {
|
if (isset($_glob[$name])) {
|
||||||
return $_glob[$name];
|
return $_glob[$name];
|
||||||
}
|
}
|
||||||
$dir = rtrim($dir, '/') . '/';
|
$dir = rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||||
$array = array();
|
$array = array();
|
||||||
if ($handle = opendir($dir)) {
|
if ($handle = opendir($dir)) {
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
@ -5361,6 +5361,7 @@ function _glob($dir, $pattern) {
|
||||||
if ($file_name == '.' || $file_name == '..') {
|
if ($file_name == '.' || $file_name == '..') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
//_error_log("_glob: {$dir}{$file_name} [$pattern]");
|
||||||
if (preg_match($pattern, $file_name)) {
|
if (preg_match($pattern, $file_name)) {
|
||||||
$array[] = "{$dir}{$file_name}";
|
$array[] = "{$dir}{$file_name}";
|
||||||
}
|
}
|
||||||
|
@ -5956,7 +5957,6 @@ function getStatsNotifications() {
|
||||||
}
|
}
|
||||||
|
|
||||||
$appArray = AVideoPlugin::getLiveApplicationArray();
|
$appArray = AVideoPlugin::getLiveApplicationArray();
|
||||||
|
|
||||||
if (!empty($appArray)) {
|
if (!empty($appArray)) {
|
||||||
if (empty($json)) {
|
if (empty($json)) {
|
||||||
$json = array();
|
$json = array();
|
||||||
|
@ -5994,6 +5994,7 @@ function getStatsNotifications() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$_getStatsNotifications[$key] = $json;
|
$_getStatsNotifications[$key] = $json;
|
||||||
return $json;
|
return $json;
|
||||||
}
|
}
|
||||||
|
|
|
@ -474,7 +474,16 @@ class Live extends PluginAbstract {
|
||||||
}
|
}
|
||||||
$user = new User($users_id);
|
$user = new User($users_id);
|
||||||
$trasnmition = LiveTransmition::createTransmitionIfNeed($users_id);
|
$trasnmition = LiveTransmition::createTransmitionIfNeed($users_id);
|
||||||
return self::getServer() . "?p=" . $user->getPassword() . "/" . $trasnmition['key'];
|
|
||||||
|
return self::getServer() . "?p=" . $user->getPassword() . "/" . self::getDynamicKey($trasnmition['key']);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function getDynamicKey($key){
|
||||||
|
$objLive = AVideoPlugin::getDataObject("Live");
|
||||||
|
if ($objLive->allowMultipleLivesPerUser) {
|
||||||
|
$key .= '-'.date('His');
|
||||||
|
}
|
||||||
|
return $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getPlayerServer() {
|
static function getPlayerServer() {
|
||||||
|
@ -590,8 +599,8 @@ class Live extends PluginAbstract {
|
||||||
return $getStatsObject[$live_servers_id];
|
return $getStatsObject[$live_servers_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = "getStatsObject_{$live_servers_id}";
|
$name = DIRECTORY_SEPARATOR."getStats".DIRECTORY_SEPARATOR."live_servers_id_{$live_servers_id}".DIRECTORY_SEPARATOR."getStatsObject";
|
||||||
//$result = ObjectYPT::getCache($name, 30);
|
$result = ObjectYPT::getCache($name, 0);
|
||||||
if(!empty($result)){
|
if(!empty($result)){
|
||||||
return json_decode($result);
|
return json_decode($result);
|
||||||
}
|
}
|
||||||
|
@ -647,22 +656,7 @@ class Live extends PluginAbstract {
|
||||||
if(!IsValidURL($url)){
|
if(!IsValidURL($url)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$name = "get_data_" . md5($url);
|
return url_get_contents($url, $timeout);
|
||||||
$result = ObjectYPT::getCache($name, 10);
|
|
||||||
if (empty($result)) {
|
|
||||||
$result = ObjectYPT::getCache($name, 0);
|
|
||||||
$file = "{$global['systemRootPath']}plugin/Live/asyncGetStats.php";
|
|
||||||
if(empty($result)){
|
|
||||||
$byPassCommandLine = 1;
|
|
||||||
$argv[1] = $url;
|
|
||||||
include $file;
|
|
||||||
}else{
|
|
||||||
$command = "php {$file} \"$url\"";
|
|
||||||
execAsync($command);
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getChartTabs() {
|
public function getChartTabs() {
|
||||||
|
@ -1018,8 +1012,8 @@ class Live extends PluginAbstract {
|
||||||
return $_getStats[$live_servers_id][$_REQUEST['name']];
|
return $_getStats[$live_servers_id][$_REQUEST['name']];
|
||||||
}
|
}
|
||||||
|
|
||||||
$cacneName = "_getStats[$live_servers_id][{$_REQUEST['name']}]" . User::getId();
|
$cacheName = DIRECTORY_SEPARATOR."getStats".DIRECTORY_SEPARATOR."live_servers_id_{$live_servers_id}".DIRECTORY_SEPARATOR."{$_REQUEST['name']}_" . User::getId();
|
||||||
$result = ObjectYPT::getCache($cacneName, 30);
|
$result = ObjectYPT::getCache($cacheName, 0);
|
||||||
if (!empty($result)) {
|
if (!empty($result)) {
|
||||||
return json_decode($result);
|
return json_decode($result);
|
||||||
}
|
}
|
||||||
|
@ -1187,7 +1181,7 @@ class Live extends PluginAbstract {
|
||||||
$obj->error = false;
|
$obj->error = false;
|
||||||
$_getStats[$live_servers_id][$_REQUEST['name']] = $obj;
|
$_getStats[$live_servers_id][$_REQUEST['name']] = $obj;
|
||||||
//_error_log("Live::_getStats NON cached result {$_REQUEST['name']} " . json_encode($obj));
|
//_error_log("Live::_getStats NON cached result {$_REQUEST['name']} " . json_encode($obj));
|
||||||
ObjectYPT::setCache($cacneName, json_encode($obj));
|
ObjectYPT::setCache($cacheName, json_encode($obj));
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1493,6 +1487,14 @@ class Live extends PluginAbstract {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function deleteStatsCache($live_servers_id) {
|
||||||
|
$tmpDir = ObjectYPT::getCacheDir();
|
||||||
|
$cacheDir = $tmpDir."getStats".DIRECTORY_SEPARATOR."live_servers_id_{$live_servers_id}";
|
||||||
|
rrmdir($cacheDir);
|
||||||
|
$pattern = "/.getStats.{$live_servers_id}.*/";
|
||||||
|
ObjectYPT::deleteCachePattern($pattern);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getRestreamObject($liveTransmitionHistory_id) {
|
public static function getRestreamObject($liveTransmitionHistory_id) {
|
||||||
|
|
||||||
if (empty($liveTransmitionHistory_id)) {
|
if (empty($liveTransmitionHistory_id)) {
|
||||||
|
|
|
@ -195,20 +195,21 @@ class LiveTransmitionHistory extends ObjectYPT {
|
||||||
$key = $lth->getKey();
|
$key = $lth->getKey();
|
||||||
foreach ($stats['applications'] as $k => $value) {
|
foreach ($stats['applications'] as $k => $value) {
|
||||||
$value = object_to_array($value);
|
$value = object_to_array($value);
|
||||||
if(empty($value['key']) || $value['key']==$key){ // application is already in the list
|
if(!empty($value['key']) && $value['key']==$key){ // application is already in the list
|
||||||
unset($stats['applications'][$k]);
|
unset($stats['applications'][$k]);
|
||||||
$stats['countLiveStream']--;
|
$stats['countLiveStream']--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(empty($stats['hidden_applications'])){
|
if(empty($stats['hidden_applications'])){
|
||||||
$stats['hidden_applications'] = array();
|
$stats['hidden_applications'] = array();
|
||||||
}
|
}else{
|
||||||
foreach ($stats['hidden_applications'] as $k => $value) {
|
foreach ($stats['hidden_applications'] as $k => $value) {
|
||||||
$value = object_to_array($value);
|
$value = object_to_array($value);
|
||||||
if($value['key']==$key){ // application is already in the list
|
if($value['key']==$key){ // application is already in the list
|
||||||
unset($stats['hidden_applications'][$k]);
|
unset($stats['hidden_applications'][$k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $stats;
|
return $stats;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,18 @@ if (!empty($_GET['p'])) {
|
||||||
}
|
}
|
||||||
_error_log("NGINX ON Publish deciding ...");
|
_error_log("NGINX ON Publish deciding ...");
|
||||||
if (!empty($obj) && empty($obj->error)) {
|
if (!empty($obj) && empty($obj->error)) {
|
||||||
|
/*
|
||||||
|
if(strpos($_POST['name'], '-')===false){
|
||||||
|
_error_log("NGINX ON Publish redirect");
|
||||||
|
http_response_code(302);
|
||||||
|
header("HTTP/1.0 302 Publish Here");
|
||||||
|
$newKey = $_POST['name'].'-'. uniqid();
|
||||||
|
header("Location: rtmp://192.168.1.18/live/$newKey/?p={$_GET['p']}");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
_error_log("NGINX ON Publish success");
|
_error_log("NGINX ON Publish success");
|
||||||
http_response_code(200);
|
http_response_code(200);
|
||||||
header("HTTP/1.1 200 OK");
|
header("HTTP/1.1 200 OK");
|
||||||
|
@ -96,6 +108,7 @@ if (!empty($obj) && empty($obj->error)) {
|
||||||
outputAndContinueInBackground();
|
outputAndContinueInBackground();
|
||||||
_error_log("NGINX Live::on_publish start");
|
_error_log("NGINX Live::on_publish start");
|
||||||
Live::on_publish($obj->liveTransmitionHistory_id);
|
Live::on_publish($obj->liveTransmitionHistory_id);
|
||||||
|
Live::deleteStatsCache($lth->getLive_servers_id());
|
||||||
_error_log("NGINX Live::on_publish end");
|
_error_log("NGINX Live::on_publish end");
|
||||||
if (AVideoPlugin::isEnabledByName('YPTSocket')) {
|
if (AVideoPlugin::isEnabledByName('YPTSocket')) {
|
||||||
$array = setLiveKey($lth->getKey(), $lth->getLive_servers_id());
|
$array = setLiveKey($lth->getKey(), $lth->getLive_servers_id());
|
||||||
|
|
|
@ -47,6 +47,7 @@ if (strpos($_GET['p'], '/') !== false) {
|
||||||
|
|
||||||
$row = LiveTransmitionHistory::getLatest($_POST['name']);
|
$row = LiveTransmitionHistory::getLatest($_POST['name']);
|
||||||
LiveTransmitionHistory::finishFromTransmitionHistoryId($row['id']);
|
LiveTransmitionHistory::finishFromTransmitionHistoryId($row['id']);
|
||||||
|
Live::deleteStatsCache($row['live_servers_id']);
|
||||||
$array = setLiveKey($row['key'], $row['live_servers_id']);
|
$array = setLiveKey($row['key'], $row['live_servers_id']);
|
||||||
$array['stats'] = LiveTransmitionHistory::getStatsAndRemoveApplication($row['id']);
|
$array['stats'] = LiveTransmitionHistory::getStatsAndRemoveApplication($row['id']);
|
||||||
$socketObj = sendSocketMessageToAll($array, "socketLiveOFFCallback");
|
$socketObj = sendSocketMessageToAll($array, "socketLiveOFFCallback");
|
||||||
|
|
|
@ -1,4 +1,25 @@
|
||||||
|
<?php
|
||||||
|
$objLive = AVideoPlugin::getDataObject("Live");
|
||||||
|
if ($objLive->allowMultipleLivesPerUser) {
|
||||||
|
$stats = getStatsNotifications();
|
||||||
|
$onliveApplications = array();
|
||||||
|
foreach ($stats["applications"] as $value) {
|
||||||
|
if (empty($value['key'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (preg_match('/' . $key . '/', $value['key'])) {
|
||||||
|
$onliveApplications[] = '<a class="btn btn-default btn-block" href="' . $value['href'] . '" target="_blank"><span class="label label-danger liveNow faa-flash faa-slow animated">' . __('LIVE NOW') . '</span> ' . $value['title'] . '</a>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$key = Live::getDynamicKey($trasnmition['key']);
|
||||||
|
?>
|
||||||
|
<style>
|
||||||
|
#streamkey{
|
||||||
|
border-top-left-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading"><i class="fas fa-hdd"></i> <?php echo __("Devices Stream Info"); ?> (<?php echo $channelName; ?>)</div>
|
<div class="panel-heading"><i class="fas fa-hdd"></i> <?php echo __("Devices Stream Info"); ?> (<?php echo $channelName; ?>)</div>
|
||||||
<div class="panel-body" style="overflow: hidden;">
|
<div class="panel-body" style="overflow: hidden;">
|
||||||
|
@ -17,13 +38,26 @@
|
||||||
<a class="btn btn-default" href="<?php echo $global['webSiteRootURL']; ?>plugin/Live/?resetKey=1" data-toggle="tooltip" title="<?php echo __("This also reset the Chat and views counter"); ?>"><i class="fa fa-refresh"></i> <?php echo __("Reset Key"); ?></a>
|
<a class="btn btn-default" href="<?php echo $global['webSiteRootURL']; ?>plugin/Live/?resetKey=1" data-toggle="tooltip" title="<?php echo __("This also reset the Chat and views counter"); ?>"><i class="fa fa-refresh"></i> <?php echo __("Reset Key"); ?></a>
|
||||||
</span>
|
</span>
|
||||||
<?php
|
<?php
|
||||||
getInputCopyToClipboard('streamkey', $trasnmition['key']);
|
getInputCopyToClipboard('streamkey', $key);
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="myUsedKeys<?php echo $trasnmition['key']; ?> ">
|
<?php
|
||||||
|
if (!empty($onliveApplications)) {
|
||||||
|
?>
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<?php echo __('Active Livestreams'); ?>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="panel-body myUsedKeys<?php echo $key; ?>">
|
||||||
|
<?php
|
||||||
|
echo implode('', $onliveApplications);
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
|
@ -32,7 +66,7 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="serverAndStreamkey"><i class="fa fa-key"></i> <?php echo __("Server URL"); ?> + <?php echo __("Stream name/key"); ?>:</label>
|
<label for="serverAndStreamkey"><i class="fa fa-key"></i> <?php echo __("Server URL"); ?> + <?php echo __("Stream name/key"); ?>:</label>
|
||||||
<?php
|
<?php
|
||||||
getInputCopyToClipboard('serverAndStreamkey', Live::getServer() . "?p=" . User::getUserPass() . "/" . $trasnmition['key']);
|
getInputCopyToClipboard('serverAndStreamkey', Live::getServer() . "?p=" . User::getUserPass() . "/" . $key);
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue