Skip to content

Commit 9f16dfa

Browse files
author
Daniel Neto
committed
Refactor Encoder class for improved status handling and logging; enhance UI updates in index view for better user experience
1 parent c8eadf7 commit 9f16dfa

File tree

7 files changed

+254
-52
lines changed

7 files changed

+254
-52
lines changed

objects/Encoder.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ public function save()
196196
$this->worker_pid = intval($this->worker_pid);
197197

198198
_error_log("Encoder::save id=(" . $this->getId() . ") title=(" . $this->getTitle() . ") streamers_id={$this->streamers_id} status_obs={$this->status_obs} ");
199-
return parent::save();
199+
$id = parent::save();
200+
$this->id = $id;
201+
_error_log("Encoder::save id=(" . $this->getId() . ")". ' <=>' . json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)));
202+
return $id;
200203
}
201204

202205
public static function getAll($onlyMine = false, $errorOnly = false)
@@ -1158,8 +1161,12 @@ public function isWorkerRunning()
11581161
private static function setStatusError($queue_id, $msg, $notifyIsDone = false)
11591162
{
11601163
global $global;
1161-
_error_log("setStatusError($queue_id, $msg, $notifyIsDone) " . json_encode(debug_backtrace()));
11621164
$q = new Encoder($queue_id);
1165+
_error_log("setStatusError($queue_id, $msg, $notifyIsDone) isUploadLimitMsg status_obs=" . $q->getStatus_obs() . ' <=>' . json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)));
1166+
if (self::isUploadLimitMsg($q->getStatus_obs())) {
1167+
return false;
1168+
}
1169+
11631170
$q->setStatus(Encoder::STATUS_ERROR);
11641171
$q->setStatus_obs($msg);
11651172
$saved = $q->save();
@@ -1302,13 +1309,16 @@ public static function run($try = 0)
13021309

13031310
// Create the lock file with the current time
13041311
file_put_contents($lockFile, time());
1312+
_error_log("Encoder::run: Lock file created $lockFile");
13051313

13061314
if ($try > $maxTries) {
1315+
_error_log("Encoder::run: Lock file deleted maxTries $lockFile");
13071316
unlink($lockFile); // Remove the lock file before returning
13081317
return false;
13091318
}
13101319

13111320
if (self::areDownloading(array(Encoder::STATUS_DOWNLOADING))) {
1321+
_error_log("Encoder::run: Lock file deleted areDownloading $lockFile");
13121322
//_error_log("You have a video downloading now, please wait ");
13131323
unlink($lockFile); // Remove the lock file before returning
13141324
return false;
@@ -1419,7 +1429,9 @@ public static function run($try = 0)
14191429
} else {
14201430
$msg = "Encoder::run: Send message error = " . $response->msg;
14211431
_error_log($msg);
1422-
self::setStatusError($encoder->getId(), $msg, 1);
1432+
if (!self::isUploadLimitMsg($encoder->getStatus_obs())) {
1433+
self::setStatusError($encoder->getId(), $msg, 1);
1434+
}
14231435
unlink($lockFile); // Remove the lock file before returning
14241436
return false;
14251437
}
@@ -1438,6 +1450,7 @@ public static function run($try = 0)
14381450
if (empty($obj->videos_id)) {
14391451
$errorMsg[] = 'We could not get videos_id check the streamer logs';
14401452
self::setStatusError($encoder->getId(), "We could not get videos_id check the streamer logs", 1);
1453+
_error_log("Encoder::run: Lock file deleted getVideosId $lockFile");
14411454
unlink($lockFile); // Remove the lock file before returning
14421455
return false;
14431456
}
@@ -1460,6 +1473,7 @@ public static function run($try = 0)
14601473
if ($setError) {
14611474
self::setStatusError($encoder->getId(), "try [{$try}] ", 1);
14621475
}
1476+
_error_log("Encoder::run: Lock file deleted setError $lockFile");
14631477
unlink($lockFile); // Remove the lock file before returning
14641478
return false;
14651479
}
@@ -1486,7 +1500,7 @@ public static function run($try = 0)
14861500
$msg .= (count($rows) == 1) ? " is encoding" : " are encoding";
14871501
$obj->msg = $msg;
14881502
}
1489-
1503+
_error_log("Encoder::run: Lock file deleted $lockFile");
14901504
// Remove the lock file before returning
14911505
unlink($lockFile);
14921506
return $obj;
@@ -1865,14 +1879,19 @@ public static function sendFile($file, $return_vars, $format, Encoder $encoder =
18651879
$encoder->setStatus(Encoder::STATUS_ERROR);
18661880
$encoder->setStatus_obs($obj->response->msg);
18671881
$savedId = $encoder->save();
1868-
_error_log("AVideo-Streamer sendFile error: ". ' '. json_encode($obj->response->msg) . ' savedId=' . $savedId);
1882+
_error_log("AVideo-Streamer sendFile error: ". json_encode($obj->response->msg) . ' savedId=' . $savedId . ' <=>' . json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)));
18691883
}else{
18701884
_error_log("AVideo-Streamer sendFile error error: " . json_encode($postFields) . ' <=>' . json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)). ' '. json_encode($obj) );
18711885
}
18721886
}
18731887
return $obj;
18741888
}
18751889

1890+
private static function isUploadLimitMsg($text)
1891+
{
1892+
return stripos($text, 'upload limit reached') !== false;
1893+
}
1894+
18761895
public static function sendFileChunk($file, $return_vars, $format, $encoder = null, $resolution = "", $try = 0)
18771896
{
18781897

@@ -2200,6 +2219,7 @@ public static function sendToStreamer($target, $postFields, $return_vars = false
22002219
return $obj;
22012220
}else{
22022221
_error_log("sendToStreamer it is the spectrum (mp3 to hls) mp4 file will be sent");
2222+
$postFields['forceIndex'] = 1;
22032223
}
22042224
}
22052225
$f = new Format($encoder->getFormats_id());
@@ -2287,7 +2307,12 @@ public static function sendToStreamer($target, $postFields, $return_vars = false
22872307
}
22882308
} else {
22892309
if (is_object($obj->response)) {
2290-
$obj->error = $obj->response->error;
2310+
if (isset($obj->response->error)) {
2311+
$obj->error = $obj->response->error;
2312+
}
2313+
if (isset($obj->response->code)) {
2314+
$obj->code = $obj->response->code;
2315+
}
22912316
if (!empty($obj->response->msg)) {
22922317
$obj->msg = $obj->response->msg;
22932318
}

objects/Format.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ public function run($pathFileName, $encoder_queue_id)
126126
$path_parts = pathinfo($pathFileName);
127127
if (!file_exists($pathFileName)) {
128128
_error_log("AVideo-Encoder Format::run($pathFileName, $encoder_queue_id) ERROR File not found");
129-
$obj->msg = 'file not found';
129+
$obj->msg = "file not found $pathFileName";
130130
$obj->addInQueueAgain = true;
131-
131+
$obj->code = 404;
132132
return $obj;
133133
}
134134
/**
@@ -920,6 +920,7 @@ private static function exec($format_id, $pathFileName, $destinationFile, $encod
920920
}
921921
$code = '';
922922
eval('$code ="' . addcslashes($fc, '"') . '";');
923+
923924
$code = replaceFFMPEG($code);
924925
$code = removeUserAgentIfNotURL($code);
925926
if (empty($code)) {

objects/Object.php

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
<?php
22

3-
interface ObjectInterface {
3+
interface ObjectInterface
4+
{
45

56
public static function getTableName();
67

78
public static function getSearchFieldsNames();
89
}
910

10-
abstract class ObjectYPT implements ObjectInterface {
11+
abstract class ObjectYPT implements ObjectInterface
12+
{
1113

1214
private $fieldsName = [];
15+
protected $id;
1316

14-
protected function load($id) {
17+
protected function load($id)
18+
{
1519
$user = self::getFromDb($id);
1620
if (empty($user)) {
1721
return false;
@@ -22,17 +26,19 @@ protected function load($id) {
2226
return true;
2327
}
2428

25-
public function __construct($id) {
29+
public function __construct($id)
30+
{
2631
if (!empty($id)) {
2732
// get data from id
2833
$this->load($id);
2934
}
3035
}
3136

32-
protected static function getFromDb($id) {
37+
protected static function getFromDb($id)
38+
{
3339
global $global;
3440
$id = intval($id);
35-
$sql = "SELECT * FROM " . static::getTableName() . " WHERE id = $id LIMIT 1";
41+
$sql = "SELECT SQL_NO_CACHE * FROM " . static::getTableName() . " WHERE id = $id LIMIT 1";
3642
$global['lastQuery'] = $sql;
3743
/**
3844
* @var array $global
@@ -41,7 +47,9 @@ protected static function getFromDb($id) {
4147
return $res ? $res->fetch_assoc() : false;
4248
}
4349

44-
public static function getAll() {
50+
51+
public static function getAll()
52+
{
4553
global $global;
4654
$sql = "SELECT * FROM " . static::getTableName() . " WHERE 1=1 ";
4755

@@ -63,7 +71,8 @@ public static function getAll() {
6371
return $rows;
6472
}
6573

66-
public static function getTotal() {
74+
public static function getTotal()
75+
{
6776
//will receive
6877
//current=1&rowCount=10&sort[sender]=asc&searchPhrase=
6978
global $global;
@@ -80,7 +89,8 @@ public static function getTotal() {
8089
return $res->num_rows;
8190
}
8291

83-
public static function getSqlFromPost() {
92+
public static function getSqlFromPost()
93+
{
8494

8595
global $global;
8696
$sql = self::getSqlSearchFromPost();
@@ -113,7 +123,8 @@ public static function getSqlFromPost() {
113123
return $sql;
114124
}
115125

116-
public static function getSqlSearchFromPost() {
126+
public static function getSqlSearchFromPost()
127+
{
117128
$sql = "";
118129
if (!empty($_POST['searchPhrase'])) {
119130
$_GET['q'] = $_POST['searchPhrase'];
@@ -137,7 +148,8 @@ public static function getSqlSearchFromPost() {
137148
return $sql;
138149
}
139150

140-
public function save() {
151+
public function save()
152+
{
141153
global $global;
142154
$fieldsName = $this->getAllFields();
143155
if (!empty($this->id)) {
@@ -167,14 +179,14 @@ public function save() {
167179
} elseif (!isset($this->$value)) {
168180
$fields[] = " NULL ";
169181
} else {
170-
if(preg_match('/_id$/', $value)){
182+
if (preg_match('/_id$/', $value)) {
171183
$id = intval($this->$value);
172-
if(empty($id)){
184+
if (empty($id)) {
173185
$fields[] = " NULL ";
174-
}else{
186+
} else {
175187
$fields[] = " {$id} ";
176188
}
177-
}else{
189+
} else {
178190
$escapedValue = $global['mysqli']->real_escape_string($this->$value);
179191
$fields[] = " '{$escapedValue}' ";
180192
}
@@ -187,7 +199,7 @@ public function save() {
187199
/**
188200
* @var array $global
189201
*/
190-
202+
191203
//error_log($sql);
192204
$insert_row = $global['mysqli']->query($sql);
193205

@@ -204,7 +216,8 @@ public function save() {
204216
}
205217
}
206218

207-
private function getAllFields() {
219+
private function getAllFields()
220+
{
208221
global $global, $mysqlHost, $mysqlUser, $mysqlPass, $mysqlDatabase;
209222
$sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{$mysqlDatabase}' AND TABLE_NAME = '" . static::getTableName() . "'";
210223
$global['lastQuery'] = $sql;
@@ -237,7 +250,8 @@ private function getAllFields() {
237250
}
238251
}
239252

240-
public function delete() {
253+
public function delete()
254+
{
241255
global $global;
242256
if (!empty($this->id)) {
243257
$sql = "DELETE FROM " . static::getTableName() . " ";
@@ -252,5 +266,4 @@ public function delete() {
252266
error_log("Id for table " . static::getTableName() . " not defined for deletion");
253267
return false;
254268
}
255-
256269
}

objects/functions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ function getFFmpegScaleToForceOriginalAspectRatio($width, $height)
4545
function replaceFFMPEG($cmd)
4646
{
4747
$cmd = removeUserAgentIfNotURL($cmd);
48+
// has to be twice because of the double slashes
49+
$cmd = str_replace("\\'", "'", $cmd);
4850
$cmd = str_replace("\\'", "'", $cmd);
4951
if (preg_match('/-user_agent/', $cmd)) {
5052
return $cmd;

view/css/style.css

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020

2121
.progress>.progress-type {
22-
color: #FFF;
22+
color: #FFF;
2323
text-shadow: 0px 0px 5px #000;
2424
padding: 3px 10px 2px !important;
2525
white-space: nowrap; /* Prevents the text from wrapping */
@@ -33,7 +33,7 @@
3333
font-weight: 800;
3434
padding: 3px 10px 2px !important;
3535
text-align: right;
36-
color: #000;
36+
color: #000;
3737
text-shadow: 0px 0px 5px #FFF;
3838
}
3939

@@ -118,6 +118,7 @@
118118
.downloadProgress {
119119
border-top-left-radius: 0;
120120
border-top-right-radius: 0;
121+
margin-bottom: 2px;
121122
}
122123

123124
#config .checkboxes label {
@@ -162,3 +163,49 @@ body {
162163
overflow: hidden; /* Hide overflow text */
163164
text-overflow: ellipsis; /* Show ellipsis for overflow text */
164165
}
166+
167+
.label-priority {
168+
background-color: #777;
169+
color: white;
170+
margin-left: 10px;
171+
}
172+
173+
.label-status {
174+
margin-left: 10px;
175+
}
176+
177+
.label-status-error {
178+
background-color: #d9534f;
179+
}
180+
181+
.label-status-done {
182+
background-color: #5cb85c;
183+
}
184+
185+
.label-status-queue {
186+
background-color: #337ab7;
187+
}
188+
189+
.label-status-encoding {
190+
background-color: #5bc0de;
191+
}
192+
193+
.label-status-downloading {
194+
background-color: #f0ad4e;
195+
}
196+
197+
.label-status-downloaded {
198+
background-color: #f7b731;
199+
}
200+
201+
.label-status-transferring {
202+
background-color: #8e44ad;
203+
}
204+
205+
.label-status-packing {
206+
background-color: #e67e22;
207+
}
208+
209+
.label-status-fixing {
210+
background-color: #16a085;
211+
}

0 commit comments

Comments
 (0)