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);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
$tmpDir = self::getCacheDir();
|
||||
|
@ -425,13 +443,13 @@ abstract class ObjectYPT implements ObjectInterface
|
|||
public static function getCacheDir()
|
||||
{
|
||||
$tmpDir = getTmpDir();
|
||||
$tmpDir = rtrim($tmpDir, DIRECTORY_SEPARATOR) . "/";
|
||||
$tmpDir .= "YPTObjectCache" . "/";
|
||||
$tmpDir = rtrim($tmpDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
$tmpDir .= "YPTObjectCache" . DIRECTORY_SEPARATOR;
|
||||
|
||||
if (class_exists("User_Location")) {
|
||||
$loc = User_Location::getThisUserLocation();
|
||||
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 . "_"])) {
|
||||
$tmpDir = sys_get_temp_dir();
|
||||
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 = rtrim($tmpDir, '/') . '/';
|
||||
$tmpDir = rtrim($tmpDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
if (!is_dir($tmpDir)) {
|
||||
mkdir($tmpDir, 0755, true);
|
||||
}
|
||||
|
@ -5353,7 +5353,7 @@ function _glob($dir, $pattern) {
|
|||
if (isset($_glob[$name])) {
|
||||
return $_glob[$name];
|
||||
}
|
||||
$dir = rtrim($dir, '/') . '/';
|
||||
$dir = rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
$array = array();
|
||||
if ($handle = opendir($dir)) {
|
||||
$count = 0;
|
||||
|
@ -5361,6 +5361,7 @@ function _glob($dir, $pattern) {
|
|||
if ($file_name == '.' || $file_name == '..') {
|
||||
continue;
|
||||
}
|
||||
//_error_log("_glob: {$dir}{$file_name} [$pattern]");
|
||||
if (preg_match($pattern, $file_name)) {
|
||||
$array[] = "{$dir}{$file_name}";
|
||||
}
|
||||
|
@ -5956,7 +5957,6 @@ function getStatsNotifications() {
|
|||
}
|
||||
|
||||
$appArray = AVideoPlugin::getLiveApplicationArray();
|
||||
|
||||
if (!empty($appArray)) {
|
||||
if (empty($json)) {
|
||||
$json = array();
|
||||
|
@ -5994,6 +5994,7 @@ function getStatsNotifications() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$_getStatsNotifications[$key] = $json;
|
||||
return $json;
|
||||
}
|
||||
|
|
|
@ -474,7 +474,16 @@ class Live extends PluginAbstract {
|
|||
}
|
||||
$user = new User($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() {
|
||||
|
@ -590,8 +599,8 @@ class Live extends PluginAbstract {
|
|||
return $getStatsObject[$live_servers_id];
|
||||
}
|
||||
|
||||
$name = "getStatsObject_{$live_servers_id}";
|
||||
//$result = ObjectYPT::getCache($name, 30);
|
||||
$name = DIRECTORY_SEPARATOR."getStats".DIRECTORY_SEPARATOR."live_servers_id_{$live_servers_id}".DIRECTORY_SEPARATOR."getStatsObject";
|
||||
$result = ObjectYPT::getCache($name, 0);
|
||||
if(!empty($result)){
|
||||
return json_decode($result);
|
||||
}
|
||||
|
@ -647,22 +656,7 @@ class Live extends PluginAbstract {
|
|||
if(!IsValidURL($url)){
|
||||
return false;
|
||||
}
|
||||
$name = "get_data_" . md5($url);
|
||||
$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;
|
||||
return url_get_contents($url, $timeout);
|
||||
}
|
||||
|
||||
public function getChartTabs() {
|
||||
|
@ -1018,8 +1012,8 @@ class Live extends PluginAbstract {
|
|||
return $_getStats[$live_servers_id][$_REQUEST['name']];
|
||||
}
|
||||
|
||||
$cacneName = "_getStats[$live_servers_id][{$_REQUEST['name']}]" . User::getId();
|
||||
$result = ObjectYPT::getCache($cacneName, 30);
|
||||
$cacheName = DIRECTORY_SEPARATOR."getStats".DIRECTORY_SEPARATOR."live_servers_id_{$live_servers_id}".DIRECTORY_SEPARATOR."{$_REQUEST['name']}_" . User::getId();
|
||||
$result = ObjectYPT::getCache($cacheName, 0);
|
||||
if (!empty($result)) {
|
||||
return json_decode($result);
|
||||
}
|
||||
|
@ -1187,7 +1181,7 @@ class Live extends PluginAbstract {
|
|||
$obj->error = false;
|
||||
$_getStats[$live_servers_id][$_REQUEST['name']] = $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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
||||
if (empty($liveTransmitionHistory_id)) {
|
||||
|
|
|
@ -195,20 +195,21 @@ class LiveTransmitionHistory extends ObjectYPT {
|
|||
$key = $lth->getKey();
|
||||
foreach ($stats['applications'] as $k => $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]);
|
||||
$stats['countLiveStream']--;
|
||||
}
|
||||
}
|
||||
if(empty($stats['hidden_applications'])){
|
||||
$stats['hidden_applications'] = array();
|
||||
}
|
||||
}else{
|
||||
foreach ($stats['hidden_applications'] as $k => $value) {
|
||||
$value = object_to_array($value);
|
||||
if($value['key']==$key){ // application is already in the list
|
||||
unset($stats['hidden_applications'][$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $stats;
|
||||
}
|
||||
|
|
|
@ -89,6 +89,18 @@ if (!empty($_GET['p'])) {
|
|||
}
|
||||
_error_log("NGINX ON Publish deciding ...");
|
||||
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");
|
||||
http_response_code(200);
|
||||
header("HTTP/1.1 200 OK");
|
||||
|
@ -96,6 +108,7 @@ if (!empty($obj) && empty($obj->error)) {
|
|||
outputAndContinueInBackground();
|
||||
_error_log("NGINX Live::on_publish start");
|
||||
Live::on_publish($obj->liveTransmitionHistory_id);
|
||||
Live::deleteStatsCache($lth->getLive_servers_id());
|
||||
_error_log("NGINX Live::on_publish end");
|
||||
if (AVideoPlugin::isEnabledByName('YPTSocket')) {
|
||||
$array = setLiveKey($lth->getKey(), $lth->getLive_servers_id());
|
||||
|
|
|
@ -47,6 +47,7 @@ if (strpos($_GET['p'], '/') !== false) {
|
|||
|
||||
$row = LiveTransmitionHistory::getLatest($_POST['name']);
|
||||
LiveTransmitionHistory::finishFromTransmitionHistoryId($row['id']);
|
||||
Live::deleteStatsCache($row['live_servers_id']);
|
||||
$array = setLiveKey($row['key'], $row['live_servers_id']);
|
||||
$array['stats'] = LiveTransmitionHistory::getStatsAndRemoveApplication($row['id']);
|
||||
$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-heading"><i class="fas fa-hdd"></i> <?php echo __("Devices Stream Info"); ?> (<?php echo $channelName; ?>)</div>
|
||||
<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>
|
||||
</span>
|
||||
<?php
|
||||
getInputCopyToClipboard('streamkey', $trasnmition['key']);
|
||||
getInputCopyToClipboard('streamkey', $key);
|
||||
?>
|
||||
</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 class="panel-body myUsedKeys<?php echo $key; ?>">
|
||||
<?php
|
||||
echo implode('', $onliveApplications);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
|
@ -32,7 +66,7 @@
|
|||
<div class="form-group">
|
||||
<label for="serverAndStreamkey"><i class="fa fa-key"></i> <?php echo __("Server URL"); ?> + <?php echo __("Stream name/key"); ?>:</label>
|
||||
<?php
|
||||
getInputCopyToClipboard('serverAndStreamkey', Live::getServer() . "?p=" . User::getUserPass() . "/" . $trasnmition['key']);
|
||||
getInputCopyToClipboard('serverAndStreamkey', Live::getServer() . "?p=" . User::getUserPass() . "/" . $key);
|
||||
?>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue