Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Aug 14, 2024
1 parent e677ece commit 9ab7a18
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 58 deletions.
18 changes: 9 additions & 9 deletions API/get_queue_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
$object = API::checkCredentials();

$status = array(
Encoder::$STATUS_ENCODING,
Encoder::$STATUS_DOWNLOADING,
Encoder::$STATUS_DOWNLOADED,
Encoder::$STATUS_QUEUE,
Encoder::$STATUS_ERROR,
Encoder::$STATUS_DONE,
Encoder::$STATUS_TRANSFERRING,
Encoder::$STATUS_PACKING,
Encoder::$STATUS_FIXING,
Encoder::STATUS_ENCODING,
Encoder::STATUS_DOWNLOADING,
Encoder::STATUS_DOWNLOADED,
Encoder::STATUS_QUEUE,
Encoder::STATUS_ERROR,
Encoder::STATUS_DONE,
Encoder::STATUS_TRANSFERRING,
Encoder::STATUS_PACKING,
Encoder::STATUS_FIXING,
);

$object->queue = Encoder::getQueue($status, $object->login->streamers_id);
Expand Down
2 changes: 1 addition & 1 deletion API/restart_queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$object->queue_id = intval($_REQUEST['queue_id']);
$encoder = new Encoder($object->queue_id);

$encoder->setStatus(Encoder::$STATUS_QUEUE);
$encoder->setStatus(Encoder::STATUS_QUEUE);

$object->error = !$encoder->save();

Expand Down
83 changes: 42 additions & 41 deletions objects/Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

class Encoder extends ObjectYPT
{
public static $STATUS_ENCODING = 'encoding';
public static $STATUS_DOWNLOADING = 'downloading';
public static $STATUS_DOWNLOADED = 'downloaded';
public static $STATUS_QUEUE = 'queue';
public static $STATUS_ERROR = 'error';
public static $STATUS_DONE = 'done';
public static $STATUS_TRANSFERRING = 'transferring';
public static $STATUS_PACKING = 'packing';
public static $STATUS_FIXING = 'fixing';
const STATUS_ENCODING = 'encoding';
const STATUS_DOWNLOADING = 'downloading';
const STATUS_DOWNLOADED = 'downloaded';
const STATUS_QUEUE = 'queue';
const STATUS_ERROR = 'error';
const STATUS_DONE = 'done';
const STATUS_TRANSFERRING = 'transferring';
const STATUS_PACKING = 'packing';
const STATUS_FIXING = 'fixing';

const LOG_TYPE_StatusObs = 'StatusObs';
const LOG_TYPE_StatusChanged = 'StatusChanged';
Expand Down Expand Up @@ -157,7 +157,7 @@ public function save()
return false;
}
if (empty($this->id)) {
$this->setStatus(Encoder::$STATUS_QUEUE);
$this->setStatus(Encoder::STATUS_QUEUE);
}
if (empty($this->worker_ppid)) {
$this->worker_ppid = 0;
Expand Down Expand Up @@ -211,7 +211,7 @@ public static function getAll($onlyMine = false, $errorOnly = false)
$sql .= " AND streamers_id = " . Login::getStreamerId() . " ";
}
if ($errorOnly) {
$sql .= " AND status = '" . Encoder::$STATUS_ERROR . "' ";
$sql .= " AND status = '" . Encoder::STATUS_ERROR . "' ";
}
$sql .= self::getSqlFromPost();

Expand Down Expand Up @@ -339,16 +339,16 @@ public function setStatus($status)
$this->status = $status;
//_error_log('Encoder::setStatus: '.json_encode(debug_backtrace()));
switch ($status) {
case "done":
case "error":
case "queue":
case Encoder::STATUS_DONE:
case Encoder::STATUS_ERROR:
case Encoder::STATUS_QUEUE:
$this->setWorker_ppid(null);
$this->setWorker_pid(null);
break;
case "downloading":
case "encoding":
case "packing":
case "transferring":
case Encoder::STATUS_DOWNLOADING:
case Encoder::STATUS_ENCODING:
case Encoder::STATUS_PACKING:
case Encoder::STATUS_TRANSFERRING:
default:
$this->setWorker_ppid(getmypid());
$this->setWorker_pid(null);
Expand Down Expand Up @@ -562,7 +562,7 @@ public static function downloadFile($queue_id)
return $obj;
}

$q->setStatus(Encoder::$STATUS_DOWNLOADING);
$q->setStatus(Encoder::STATUS_DOWNLOADING);
$q->save();

_error_log("downloadFile: start queue_id = {$queue_id} url = {$url} pathFileName = {$obj->pathFileName}");
Expand Down Expand Up @@ -640,7 +640,7 @@ private static function setDownloaded($queue_id, $filePath)
$encoder = new Encoder($queue_id);
$msg = "Original filesize is " . humanFileSize(filesize($filePath));
_error_log($msg);
$encoder->setStatus(Encoder::$STATUS_DOWNLOADED);
$encoder->setStatus(Encoder::STATUS_DOWNLOADED);
$encoder->setStatus_obs($msg);
return $encoder->save();
}
Expand Down Expand Up @@ -791,31 +791,31 @@ public static function getVideoFile($videoURL, $queue_id, $downloadedFile, $dest
public static function areDownloading($status = array())
{
if (empty($status)) {
$status = array(Encoder::$STATUS_DOWNLOADED, Encoder::$STATUS_DOWNLOADING);
$status = array(Encoder::STATUS_DOWNLOADED, Encoder::STATUS_DOWNLOADING);
}
return self::getQueue($status);
}

public static function areEncoding()
{
//return self::getQueue($status = array(Encoder::$STATUS_ENCODING, Encoder::$STATUS_DOWNLOADING));
return self::getQueue($status = array(Encoder::$STATUS_ENCODING));
//return self::getQueue($status = array(Encoder::STATUS_ENCODING, Encoder::STATUS_DOWNLOADING));
return self::getQueue($status = array(Encoder::STATUS_ENCODING));
}

public static function areDownloaded()
{
return self::getQueue($status = array(Encoder::$STATUS_DOWNLOADED));
return self::getQueue($status = array(Encoder::STATUS_DOWNLOADED));
}
public static function areTransferring()
{
return self::getQueue($status = array(Encoder::$STATUS_TRANSFERRING));
return self::getQueue($status = array(Encoder::STATUS_TRANSFERRING));
}

public static function getQueue($status = array(), $streamers_id = 0)
{
global $global;
if (empty($status)) {
$status = array(Encoder::$STATUS_ENCODING, Encoder::$STATUS_DOWNLOADING);
$status = array(Encoder::STATUS_ENCODING, Encoder::STATUS_DOWNLOADING);
}

$statusIn = implode("', '", $status);
Expand Down Expand Up @@ -887,11 +887,11 @@ public static function getAllQueue()
global $global;
$sql = "SELECT f.*, e.* FROM " . static::getTableName() . " e "
. " LEFT JOIN {$global['tablesPrefix']}formats f ON f.id = formats_id WHERE "
. "(status = '" . Encoder::$STATUS_ENCODING . "' OR "
. "status = '" . Encoder::$STATUS_DOWNLOADING . "' OR "
. "status = '" . Encoder::$STATUS_DOWNLOADED . "' OR "
. "status = '" . Encoder::$STATUS_QUEUE . "' OR "
. "status = '" . Encoder::$STATUS_ERROR . "') ";
. "(status = '" . Encoder::STATUS_ENCODING . "' OR "
. "status = '" . Encoder::STATUS_DOWNLOADING . "' OR "
. "status = '" . Encoder::STATUS_DOWNLOADED . "' OR "
. "status = '" . Encoder::STATUS_QUEUE . "' OR "
. "status = '" . Encoder::STATUS_ERROR . "') ";

$sql .= " ORDER BY priority ASC, e.id ASC ";
//_error_log($sql);
Expand Down Expand Up @@ -986,7 +986,7 @@ private static function setStatusError($queue_id, $msg, $notifyIsDone = false)
global $global;
_error_log("setStatusError($queue_id, $msg, $notifyIsDone) " . json_encode(debug_backtrace()));
$q = new Encoder($queue_id);
$q->setStatus(Encoder::$STATUS_ERROR);
$q->setStatus(Encoder::STATUS_ERROR);
$q->setStatus_obs($msg);
$saved = $q->save();

Expand Down Expand Up @@ -1132,7 +1132,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 ");
unlink($lockFile); // Remove the lock file before returning
return false;
Expand Down Expand Up @@ -1165,15 +1165,15 @@ public static function run($try = 0)
if (!self::canDownloadNow()) {
$msg = "Encoder::run: There is something downloading now " . json_encode($objFile);
_error_log($msg);
$encoder->setStatus(Encoder::$STATUS_QUEUE);
$encoder->setStatus(Encoder::STATUS_QUEUE);
$encoder->setStatus_obs($msg);
$encoder->save();
unlink($lockFile); // Remove the lock file before returning
return false;
} else if ($try <= $maxTries) {
$msg = "Encoder::run: Trying again: [$try] => Could not download the file " . json_encode($objFile);
_error_log($msg);
$encoder->setStatus(Encoder::$STATUS_QUEUE);
$encoder->setStatus(Encoder::STATUS_QUEUE);
$encoder->setStatus_obs($msg);
$encoder->save();
unlink($lockFile); // Remove the lock file before returning
Expand All @@ -1187,7 +1187,7 @@ public static function run($try = 0)
return false;
}
} elseif (!$objFile->error && !empty($return_vars->videos_id)) {
$encoder->setStatus(Encoder::$STATUS_ENCODING);
$encoder->setStatus(Encoder::STATUS_ENCODING);
$encoder->save();
self::run(0);
self::sendImages($objFile->pathFileName, $return_vars, $encoder);
Expand All @@ -1204,7 +1204,7 @@ public static function run($try = 0)
} else if ($try < 4) {
$msg = "Encoder::run: Trying again: [$try] => Execute code error 1 " . json_encode($resp->msg) . " \n Code: {$resp->code}";
_error_log($msg);
$encoder->setStatus(Encoder::$STATUS_QUEUE);
$encoder->setStatus(Encoder::STATUS_QUEUE);
$encoder->setStatus_obs($msg);
$encoder->save();
unlink($lockFile); // Remove the lock file before returning
Expand All @@ -1224,7 +1224,7 @@ public static function run($try = 0)
$obj->msg = $resp->code;
$response = $encoder->send();
if (!$response->error) {
$encoder->setStatus(Encoder::$STATUS_DONE);
$encoder->setStatus(Encoder::STATUS_DONE);
$config = new Configuration();
if (!empty($config->getAutodelete())) {
$encoder->delete();
Expand Down Expand Up @@ -1433,7 +1433,7 @@ public function send()
$return->original_videos_id = $videos_id;
$return->videos_id = 0;

$this->setStatus(Encoder::$STATUS_TRANSFERRING);
$this->setStatus(Encoder::STATUS_TRANSFERRING);
$this->save();
_error_log("Encoder::send() order_id=$order_id");
/**
Expand Down Expand Up @@ -1510,7 +1510,7 @@ public function send()
}
$return->sends[] = $r;
}
$this->setStatus(Encoder::$STATUS_DONE);
$this->setStatus(Encoder::STATUS_DONE);
// check if autodelete is enabled
$config = new Configuration();
if (!empty($config->getAutodelete())) {
Expand Down Expand Up @@ -1675,7 +1675,7 @@ public static function sendFile($file, $return_vars, $format, Encoder $encoder =
$obj->file = $file;

if (isset($u) && $u !== false && $obj->error == false) {
$u->setStatus(Encoder::$STATUS_DONE);
$u->setStatus(Encoder::STATUS_DONE);
$u->save();
} elseif ($obj->error) {
_error_log("AVideo-Streamer sendFile error: " . json_encode($postFields) . ' <=>' . json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)));
Expand Down Expand Up @@ -2775,6 +2775,7 @@ public static function getYouTubeDLCommand($addOauthFromProvider = '', $streamer
$ytdl .= " --add-header \"Authorization: Bearer {$accessToken}\" ";
}
}
_error_log("getYouTubeDLCommand($addOauthFromProvider, $streamers_id, $forceYoutubeDL)");
return $ytdl;
}

Expand Down
6 changes: 3 additions & 3 deletions objects/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ private static function preProcessDynamicHLS($pathFileName, $destinationFile) {
private static function posProcessHLS($destinationFile, $encoder_queue_id) {
// zip the directory
$encoder = new Encoder($encoder_queue_id);
$encoder->setStatus(Encoder::$STATUS_PACKING);
$encoder->setStatus(Encoder::STATUS_PACKING);
$encoder->save();
_error_log("posProcessHLS: ZIP start {$destinationFile}");
$zipPath = zipDirectory($destinationFile);
Expand All @@ -721,7 +721,7 @@ private static function posProcessHLS($destinationFile, $encoder_queue_id) {
private static function fixFile($pathFileName, $encoder_queue_id) {
// zip the directory
$encoder = new Encoder($encoder_queue_id);
$encoder->setStatus(Encoder::$STATUS_FIXING);
$encoder->setStatus(Encoder::STATUS_FIXING);
$encoder->save();
_error_log("fixFile: start {$pathFileName}" . humanFileSize(filesize($pathFileName)));
// try to fix the file in case you want to try again
Expand Down Expand Up @@ -789,7 +789,7 @@ private static function exec($format_id, $pathFileName, $destinationFile, $encod
} else {
$msg = json_encode($output);
_error_log("AVideo-Encoder Format::exec " . $msg . ' ' . json_encode(debug_backtrace()));
$encoder->setStatus(Encoder::$STATUS_ERROR);
$encoder->setStatus(Encoder::STATUS_ERROR);
$encoder->setStatus_obs($msg);
$encoder->save();
}
Expand Down
2 changes: 1 addition & 1 deletion objects/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static function create($encoders_id, $file)
$u->setResolution($resolution);
$u->setFormat($format);
$u->setVideos_id($return_vars->videos_id);
$u->setStatus(Encoder::$STATUS_QUEUE);
$u->setStatus(Encoder::STATUS_QUEUE);
$u->save();

$sent = Encoder::sendFile($file, $return_vars, $format, $e, $resolution);
Expand Down
2 changes: 1 addition & 1 deletion objects/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ function addVideo($link, $streamers_id, $title = "") {
$e->setFileURI($link);
$e->setVideoDownloadedLink($link);
$e->setFilename($filename);
$e->setStatus(Encoder::$STATUS_QUEUE);
$e->setStatus(Encoder::STATUS_QUEUE);
$e->setPriority($s->getPriority());
//$e->setNotifyURL($global['AVideoURL'] . "aVideoEncoder.json");

Expand Down
2 changes: 1 addition & 1 deletion view/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
$id = $e->save();
error_log("queue: save done [$id]");
} else {
$e->setStatus(Encoder::$STATUS_QUEUE);
$e->setStatus(Encoder::STATUS_QUEUE);
$id = $e->save();

$obj = Encoder::getVideosId($id);
Expand Down
2 changes: 1 addition & 1 deletion view/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
$e->setTitle($path_parts['filename']);
$e->setFileURI($destinationFileURI);
$e->setFilename($filename);
$e->setStatus(Encoder::$STATUS_QUEUE);
$e->setStatus(Encoder::STATUS_QUEUE);
$e->setPriority($s->getPriority());
//$e->setNotifyURL($global['AVideoURL'] . "aVideoEncoder.json");
//error_log("Upload.php will set format");
Expand Down

0 comments on commit 9ab7a18

Please sign in to comment.