1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00

Improve trhe deletethumbs

This commit is contained in:
Daniel 2021-12-08 18:33:06 -03:00
parent b31c9d2ceb
commit 0dd7422dd0
3 changed files with 48 additions and 6 deletions

View file

@ -7,7 +7,7 @@ require_once $global['systemRootPath'] . 'objects/video.php';
if (!isCommandLineInterface()) { if (!isCommandLineInterface()) {
return die('Command Line only'); return die('Command Line only');
} }
$checkIfIsCorrupted = intval(@$argv[1]);
$users_ids = array(); $users_ids = array();
$sql = "SELECT * FROM videos "; $sql = "SELECT * FROM videos ";
$res = sqlDAL::readSql($sql); $res = sqlDAL::readSql($sql);
@ -20,7 +20,7 @@ if ($res != false) {
foreach ($fullData as $key => $row) { foreach ($fullData as $key => $row) {
$count++; $count++;
$filename = $row['filename']; $filename = $row['filename'];
Video::deleteThumbs($filename, true); Video::deleteThumbs($filename, true, $checkIfIsCorrupted);
echo "{$total}/{$count} Thumbs deleted from {$row['title']}".PHP_EOL; echo "{$total}/{$count} Thumbs deleted from {$row['title']}".PHP_EOL;
ob_flush(); ob_flush();
} }

View file

@ -4484,9 +4484,9 @@ function isLive() {
if (!empty($global['doNotLoadPlayer'])) { if (!empty($global['doNotLoadPlayer'])) {
return false; return false;
} }
if(class_exists('LiveTransmition') && class_exists('Live')){ if (class_exists('LiveTransmition') && class_exists('Live')) {
$livet = LiveTransmition::getFromRequest(); $livet = LiveTransmition::getFromRequest();
if(!empty($livet)){ if (!empty($livet)) {
setLiveKey($livet['key'], Live::getLiveServersIdRequest(), @$_REQUEST['live_index']); setLiveKey($livet['key'], Live::getLiveServersIdRequest(), @$_REQUEST['live_index']);
$isLive = 1; $isLive = 1;
} }
@ -6552,6 +6552,7 @@ function sendSocketErrorMessageToUsers_id($msg, $users_id, $callbackJSFunction =
$newMessage->msg = $msg; $newMessage->msg = $msg;
return sendSocketMessageToUsers_id($newMessage, $users_id, $callbackJSFunction); return sendSocketMessageToUsers_id($newMessage, $users_id, $callbackJSFunction);
} }
function sendSocketSuccessMessageToUsers_id($msg, $users_id, $callbackJSFunction = "avideoResponse") { function sendSocketSuccessMessageToUsers_id($msg, $users_id, $callbackJSFunction = "avideoResponse") {
$newMessage = new stdClass(); $newMessage = new stdClass();
$newMessage->error = false; $newMessage->error = false;
@ -7579,6 +7580,43 @@ function isImage($file) {
return false; return false;
} }
function isHTMLEmpty($html_string){ function isHTMLEmpty($html_string) {
return empty(trim(strip_specific_tags($html_string, array('br', 'p')))); return empty(trim(strip_specific_tags($html_string, array('br', 'p'))));
}
function totalImageColors($image_path) {
$img = imagecreatefromjpeg($image_path);
$w = imagesx($img);
$h = imagesy($img);
// capture the raw data of the image
ob_start();
imagegd2($img, null, $w);
$data = ob_get_clean();
$totalLength = strlen($data);
// calculate the length of the actual pixel data
// from that we can derive the header size
$pixelDataLength = $w * $h * 4;
$headerLength = $totalLength - $pixelDataLength;
// use each four-byte segment as the key to a hash table
$counts = array();
for ($i = $headerLength; $i < $totalLength; $i += 4) {
$pixel = substr($data, $i, 4);
$count = & $counts[$pixel];
$count += 1;
}
$colorCount = count($counts);
return $colorCount;
}
function isImageCorrupted($image_path){
if(filesize($image_path)<10){
return true;
}
if(totalImageColors($image_path) === 1){
return true;
}
return false;
} }

View file

@ -4184,7 +4184,7 @@ if (!class_exists('Video')) {
return $r; return $r;
} }
public static function deleteThumbs($filename, $doNotDeleteSprit = false) { public static function deleteThumbs($filename, $doNotDeleteSprit = false, $checkIfIsCorrupted = false) {
if (empty($filename)) { if (empty($filename)) {
return false; return false;
} }
@ -4195,9 +4195,13 @@ if (!class_exists('Video')) {
$files = glob("{$filePath}*_thumbs*.jpg"); $files = glob("{$filePath}*_thumbs*.jpg");
foreach ($files as $file) { foreach ($files as $file) {
if (file_exists($file)) { if (file_exists($file)) {
if($checkIfIsCorrupted && !isImageCorrupted($image_path)){
continue;
}
if ($doNotDeleteSprit && strpos($file, '_thumbsSprit.jpg') !== false) { if ($doNotDeleteSprit && strpos($file, '_thumbsSprit.jpg') !== false) {
continue; continue;
} }
echo "Delete {$file}";PHP_EOL;
@unlink($file); @unlink($file);
} }
} }