Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Jun 7, 2024
1 parent dc9e2ac commit 1fe3cb4
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions objects/Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ public function setFilename($filename)

public function setStatus($status)
{
error_log("Encoder::setStatus($status) ".json_encode(debug_backtrace()));
if(!empty($this->id) && $status != $this->status){
self::setStreamerLog($this->id,"Status changed from {$this->status} to $status", Encoder::LOG_TYPE_StatusChanged);
error_log("Encoder::setStatus($status) " . json_encode(debug_backtrace()));
if (!empty($this->id) && $status != $this->status) {
self::setStreamerLog($this->id, "Status changed from {$this->status} to $status", Encoder::LOG_TYPE_StatusChanged);
}
$this->status = $status;
//error_log('Encoder::setStatus: '.json_encode(debug_backtrace()));
Expand All @@ -298,19 +298,18 @@ public function setStatus($status)
$this->setWorker_pid(null);
break;
}

}

public function setStatus_obs($status_obs)
{
if(empty($status_ob)){
if (empty($status_ob)) {
return false;
}
error_log("Encoder::setStatus_obs ".json_encode(debug_backtrace()));
error_log("Encoder::setStatus_obs " . json_encode(debug_backtrace()));
$old_status_obs = $this->status_obs;
$this->status_obs = substr($status_obs, 0, 200);
if(!empty($this->id) && $old_status_obs !== $this->status_obs){
self::setStreamerLog($this->id,$this->status_obs, Encoder::LOG_TYPE_StatusObs);
if (!empty($this->id) && $old_status_obs !== $this->status_obs) {
self::setStreamerLog($this->id, $this->status_obs, Encoder::LOG_TYPE_StatusObs);
}
}

Expand Down Expand Up @@ -603,7 +602,7 @@ public static function getYoutubeDl($videoURL, $queue_id, $destinationFile)
//echo "\n**ERROR Youtube DL **".$code . "\n" . print_r($output, true);
$error = $cmd . PHP_EOL . print_r($output, true);
error_log($error);
self::setStreamerLog($queue_id,'Fail to download line='.__LINE__.' '.$error, Encoder::LOG_TYPE_ERROR);
self::setStreamerLog($queue_id, 'Fail to download line=' . __LINE__ . ' ' . $error, Encoder::LOG_TYPE_ERROR);
$cmd = self::getYouTubeDLCommand() . " --no-check-certificate --force-ipv4 --no-playlist -k -o {$tmpfname}.mp4 {$videoURL}";
//echo "\n**Trying Youtube DL **".$cmd;
error_log("getYoutubeDl: Getting from Youtube other option DL {$cmd}");
Expand All @@ -612,7 +611,7 @@ public static function getYoutubeDl($videoURL, $queue_id, $destinationFile)
//echo "\n**ERROR Youtube DL **".$code . "\n" . print_r($output, true);
$error = $cmd . PHP_EOL . print_r($output, true);
error_log($error);
self::setStreamerLog($queue_id,'Fail to download line='.__LINE__.' '.$error, Encoder::LOG_TYPE_ERROR);
self::setStreamerLog($queue_id, 'Fail to download line=' . __LINE__ . ' ' . $error, Encoder::LOG_TYPE_ERROR);
$cmd = self::getYouTubeDLCommand() . " --no-check-certificate --no-playlist -k -o {$tmpfname}.mp4 {$videoURL}";
//echo "\n**Trying Youtube DL **".$cmd;
error_log("getYoutubeDl: Getting from Youtube other option DL {$cmd}");
Expand All @@ -621,7 +620,7 @@ public static function getYoutubeDl($videoURL, $queue_id, $destinationFile)
//echo "\n**ERROR Youtube DL **".$code . "\n" . print_r($output, true);
$error = $cmd . PHP_EOL . print_r($output, true);
error_log($error);
self::setStreamerLog($queue_id,'Fail to download line='.__LINE__.' '.$error, Encoder::LOG_TYPE_ERROR);
self::setStreamerLog($queue_id, 'Fail to download line=' . __LINE__ . ' ' . $error, Encoder::LOG_TYPE_ERROR);
$cmd = self::getYouTubeDLCommand() . " --no-check-certificate --force-ipv4 --no-playlist -k -o '{$tmpfname}.%(ext)s' {$videoURL}";
//echo "\n**Trying Youtube DL **".$cmd;
error_log("getYoutubeDl: Getting from Youtube other option DL {$cmd}");
Expand All @@ -630,7 +629,7 @@ public static function getYoutubeDl($videoURL, $queue_id, $destinationFile)
//echo "\n**ERROR Youtube DL **".$code . "\n" . print_r($output, true);
$error = $cmd . PHP_EOL . print_r($output, true);
error_log($error);
self::setStreamerLog($queue_id,'Fail to download line='.__LINE__.' '.$error, Encoder::LOG_TYPE_ERROR);
self::setStreamerLog($queue_id, 'Fail to download line=' . __LINE__ . ' ' . $error, Encoder::LOG_TYPE_ERROR);
return false;
}
}
Expand Down Expand Up @@ -722,7 +721,7 @@ public static function getVideoFile($videoURL, $queue_id, $downloadedFile, $dest

public static function areDownloading($status = array())
{
if(empty($status)){
if (empty($status)) {
$status = array(Encoder::$STATUS_DOWNLOADED, Encoder::$STATUS_DOWNLOADING);
}
return self::getQueue($status);
Expand Down Expand Up @@ -1008,7 +1007,7 @@ public function getNewVideosId()
'videoDownloadedLink' => $this->getVideoDownloadedLink(),
'encoderURL' => $global['webSiteRootURL'],
);
self::setStreamerLog($this->getId(),__FUNCTION__, Encoder::LOG_TYPE_INFO);
self::setStreamerLog($this->getId(), __FUNCTION__, Encoder::LOG_TYPE_INFO);
return self::sendToStreamer($target, $postFields, false, $this);
}

Expand Down Expand Up @@ -1039,7 +1038,7 @@ public static function run($try = 0)
return false;
}

if(self::areDownloading(array(Encoder::$STATUS_DOWNLOADING))){
if (self::areDownloading(array(Encoder::$STATUS_DOWNLOADING))) {
error_log("You have a video downloading now, please wait ");
return false;
}
Expand Down Expand Up @@ -1193,7 +1192,7 @@ private function notifyVideoIsDone($fail = 0)
if (!empty($this->override_status)) {
$postFields['overrideStatus'] = $this->override_status;
}
self::setStreamerLog($this->getId(),__FUNCTION__, Encoder::LOG_TYPE_INFO);
self::setStreamerLog($this->getId(), __FUNCTION__, Encoder::LOG_TYPE_INFO);
$obj = self::sendToStreamer($target, $postFields, $return_vars, $this);
}

Expand Down Expand Up @@ -1527,7 +1526,7 @@ public static function sendFile($file, $return_vars, $format, $encoder = null, $
}
}
//error_log("AVideo-Streamer sendFile sendToStreamer: " . json_encode($postFields));
self::setStreamerLog($encoder->getId(),__FUNCTION__, Encoder::LOG_TYPE_INFO);
self::setStreamerLog($encoder->getId(), __FUNCTION__, Encoder::LOG_TYPE_INFO);
$obj = self::sendToStreamer($target, $postFields, $return_vars, $encoder);
$obj->videoFileSize = humanFileSize(filesize($file));
//error_log("AVideo-Streamer sendFile sendToStreamer done: " . json_encode($obj) );
Expand Down Expand Up @@ -1714,7 +1713,7 @@ public static function sendFileToDownload($file, $return_vars, $format, $encoder
$obj->videoFileSize = humanFileSize(filesize($file));
}

self::setStreamerLog($encoder->getId(),__FUNCTION__, Encoder::LOG_TYPE_INFO);
self::setStreamerLog($encoder->getId(), __FUNCTION__, Encoder::LOG_TYPE_INFO);
$obj = self::sendToStreamer($target, $postFields, $return_vars, $encoder);
$obj->file = $file;
//var_dump($obj);exit;
Expand Down Expand Up @@ -1771,7 +1770,7 @@ public static function sendImages($file, $return_vars, $encoder)
return $obj;
}

self::setStreamerLog($encoder->getId(),__FUNCTION__, Encoder::LOG_TYPE_INFO);
self::setStreamerLog($encoder->getId(), __FUNCTION__, Encoder::LOG_TYPE_INFO);
$obj = self::sendToStreamer($target, $postFields, $return_vars, $encoder);
$obj->file = $file;
//var_dump($obj);exit;
Expand Down Expand Up @@ -1804,7 +1803,7 @@ public static function sendRawVideo($file, $return_vars, $encoder)
return $obj;
}

self::setStreamerLog($encoder->getId(),__FUNCTION__, Encoder::LOG_TYPE_INFO);
self::setStreamerLog($encoder->getId(), __FUNCTION__, Encoder::LOG_TYPE_INFO);
$obj = self::sendToStreamer($target, $postFields, $return_vars, $encoder);
$obj->file = $file;

Expand Down Expand Up @@ -1836,7 +1835,7 @@ public static function sendSpectrumFromMP3($file, $return_vars, $encoder)
return $obj;
}

self::setStreamerLog($encoder->getId(),__FUNCTION__, Encoder::LOG_TYPE_INFO);
self::setStreamerLog($encoder->getId(), __FUNCTION__, Encoder::LOG_TYPE_INFO);
$obj = self::sendToStreamer($target, $postFields, $return_vars, $encoder);
$obj->file = $file;

Expand Down Expand Up @@ -1956,7 +1955,7 @@ public static function sendToStreamer($target, $postFields, $return_vars = false
}
}
$time_end = microtime(true);
$execution_time = number_format($time_end - $time_start, 3);
$execution_time = number_format($time_end - $time_start, 3);
$error = "sendToStreamer {$url} in {$execution_time} seconds ";
error_log($error . json_encode($obj));

Expand Down Expand Up @@ -2382,7 +2381,7 @@ public function delete()
if (!empty($global['progressiveUpload'])) {
Upload::deleteFile($this->id);
}
self::setStreamerLog($this->id,'Files Deleted', Encoder::LOG_TYPE_INFO);
self::setStreamerLog($this->id, 'Files Deleted', Encoder::LOG_TYPE_INFO);
return parent::delete();
}

Expand Down Expand Up @@ -2579,6 +2578,7 @@ public static function getYouTubeDLCommand($forceYoutubeDL = false)

public static function setStreamerLog($encoder_queue_id, $msg, $type)
{
global $global;
$encoder = new Encoder($encoder_queue_id);
$return_vars = json_decode($encoder->getReturn_vars());
if (empty($return_vars->videos_id)) {
Expand All @@ -2590,6 +2590,9 @@ public static function setStreamerLog($encoder_queue_id, $msg, $type)
'type' => $type,
'videos_id' => $return_vars->videos_id,
);
if (file_exists($global['docker_vars'])) {
file_put_contents($global['systemRootPath'] . 'videos/aVideoEncoder.log', json_encode(array($postFields, debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))));
}
return self::sendToStreamer($target, $postFields, $return_vars, $encoder);
}
}
Expand Down

0 comments on commit 1fe3cb4

Please sign in to comment.