1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
This commit is contained in:
Daniel Neto 2023-09-28 10:55:46 -03:00
parent 5641c011ec
commit ee16ae2bc4

View file

@ -1,83 +1,40 @@
<?php
//streamer config
require_once '../videos/configuration.php';
require_once $global['systemRootPath'] . 'objects/video.php';
if (!isCommandLineInterface()) {
return die('Command Line only');
}
$doNotDeleteFilesList = ['configuration.php', 'favicon.ico', 'favicon.png', 'avideo.log', 'PayPal.log', 'socketPID.log', 'logo.png', 'logoOverlay.png'];
$arrayStatusToDelete = array(
Video::$statusBrokenMissingFiles,
Video::$statusDownloading,
Video::$statusEncoding,
Video::$statusEncodingError,
Video::$statusTranfering,
);
$lockFilename = '.move_v1.lock';
$path = getVideosDir();
$files = array_diff(scandir($path), ['.', '..']);
echo "*** Total filenames " . count($files) . "\n";
foreach ($files as $key => $value) {
$dir = "{$path}{$value}";
if (!is_dir($dir)) {
$bname = basename($dir);
if (in_array($bname, $doNotDeleteFilesList) || preg_match('/configuration\./i', $bname)) {
unset($files[$key]);
} else {
$filename = Video::getCleanFilenameFromFile($dir);
$video = Video::getVideoFromFileName($filename, true);
if (!empty($video)) {
//echo "+++ Video FOUND for filename {$filename} ".PHP_EOL;
unset($files[$key]);
} else {
$files[$key] = [$value, $dir];
//echo "*** Video NOT found for filename {$filename} ".PHP_EOL;
}
ob_end_flush();
$sql = "SELECT * FROM videos where status in ('".implode("', '", $arrayStatusToDelete)."') ";
$res = sqlDAL::readSql($sql);
$fullData = sqlDAL::fetchAllAssoc($res);
$total = count($fullData);
sqlDAL::close($res);
$rows = [];
if ($res != false) {
$count = 0;
foreach ($fullData as $key => $row) {
$count++;
if(!in_array($row['status'], $arrayStatusToDelete)){
echo "{$total}/{$count} Deleteuseless skip status={$row['status']} title={$row['title']}".PHP_EOL;
continue;
}
continue;
}
$file = "{$dir}" . DIRECTORY_SEPARATOR . "{$lockFilename}";
if (file_exists($file)) {
$filename = Video::getCleanFilenameFromFile($dir);
$video = Video::getVideoFromFileName($filename, true);
if (!empty($video)) {
//echo "+++ Video FOUND for filename {$filename} ".PHP_EOL;
unset($files[$key]);
$v = new Video('', '', $row['id']);
if ($v->delete(true)) {
echo "{$total}/{$count} Deleteuseless deleted from status={$row['status']} title={$row['title']}".PHP_EOL;
} else {
$files[$key] = [$value, $dir];
//echo "*** Video NOT found for filename {$filename} ".PHP_EOL;
}
} else {
//echo "*** Lock file does not exists {$file} ".PHP_EOL;
unset($files[$key]);
}
}
$total = count($files);
echo "*** Total filenames " . $total . " Will be deleted\n";
if (empty($total)) {
exit;
}
$totalSize = 0;
foreach ($files as $key => $value) {
$size = getDirSize($value[1]);
$totalSize += $size;
echo "{$value[0]} => $value[1] " . (humanFileSize($size)) . " \n";
}
echo "*** Confirm Delete Them (" . humanFileSize($totalSize) . ")? y/n: ";
ob_flush();
$confirm = trim(readline(""));
if (!empty($confirm) && strtolower($confirm) === 'y') {
foreach ($files as $key => $value) {
if (is_dir($value[1])) {
rrmdir($value[1]);
if (is_dir($value[1])) {
echo "$value[1] Directory Deleted \n";
} else {
echo "$value[1] Directory Could Not be Deleted \n";
}
} elseif (unlink($value[1])) {
echo "$value[1] Deleted \n";
} else {
echo "$value[1] Could Not be Deleted \n";
echo "{$total}/{$count} Deleteuseless ERROR status={$row['status']} title={$row['title']}".PHP_EOL;
}
}
}
}