1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +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 <?php
//streamer config //streamer config
require_once '../videos/configuration.php'; require_once '../videos/configuration.php';
require_once $global['systemRootPath'] . 'objects/video.php';
if (!isCommandLineInterface()) { if (!isCommandLineInterface()) {
return die('Command Line only'); 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'; ob_end_flush();
$path = getVideosDir(); $sql = "SELECT * FROM videos where status in ('".implode("', '", $arrayStatusToDelete)."') ";
$files = array_diff(scandir($path), ['.', '..']); $res = sqlDAL::readSql($sql);
echo "*** Total filenames " . count($files) . "\n"; $fullData = sqlDAL::fetchAllAssoc($res);
foreach ($files as $key => $value) { $total = count($fullData);
$dir = "{$path}{$value}"; sqlDAL::close($res);
if (!is_dir($dir)) { $rows = [];
$bname = basename($dir); if ($res != false) {
if (in_array($bname, $doNotDeleteFilesList) || preg_match('/configuration\./i', $bname)) { $count = 0;
unset($files[$key]); foreach ($fullData as $key => $row) {
} else { $count++;
$filename = Video::getCleanFilenameFromFile($dir); if(!in_array($row['status'], $arrayStatusToDelete)){
$video = Video::getVideoFromFileName($filename, true); echo "{$total}/{$count} Deleteuseless skip status={$row['status']} title={$row['title']}".PHP_EOL;
if (!empty($video)) { continue;
//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;
}
} }
continue; $v = new Video('', '', $row['id']);
} if ($v->delete(true)) {
$file = "{$dir}" . DIRECTORY_SEPARATOR . "{$lockFilename}"; echo "{$total}/{$count} Deleteuseless deleted from status={$row['status']} title={$row['title']}".PHP_EOL;
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]);
} else { } else {
$files[$key] = [$value, $dir]; echo "{$total}/{$count} Deleteuseless ERROR status={$row['status']} title={$row['title']}".PHP_EOL;
//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";
} }
} }
} }