Files
newznab-tmux-NNTmux/misc/testing/PostProc/updateXXXImages.php
T
2025-12-26 23:48:37 +01:00

70 lines
2.6 KiB
PHP

<?php
require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
use App\Models\XxxInfo;
use Illuminate\Support\Facades\File;
$covers = $updated = $deleted = 0;
if ($argc === 1 || $argv[1] !== 'true') {
cli()->error("\nThis script will check all images in covers/xxx and compare to db->xxxinfo.\nTo run:\nphp $argv[0] true\n");
exit();
}
$path2covers = storage_path('covers/xxx/');
$itr = File::allFiles($path2covers);
foreach ($itr as $filePath) {
if (is_file($filePath->getPathname()) && preg_match('/-cover\.jpg$/', $filePath->getPathname())) {
preg_match('/(\d+)-cover\.jpg$/', $filePath->getPathname(), $hit);
if (isset($hit[1])) {
$run = XxxInfo::query()->where('cover', '=', 0)->where('id', $hit[1])->update(['cover' => 1]);
if ($run >= 1) {
$covers++;
} else {
$run = XxxInfo::query()->where('id', $hit[1])->select(['id'])->get();
if ($run->count() === 0) {
cli()->info($filePath->getPathname().' not found in db.');
}
}
}
}
if (is_file($filePath->getPathname()) && preg_match('/-backdrop\.jpg$/', $filePath->getPathname())) {
preg_match('/(\d+)-backdrop\.jpg$/', $filePath->getPathname(), $match1);
if (isset($match1[1])) {
$run = XxxInfo::query()->where(['backdrop' => 0, 'id' => $match1[1]])->update(['backdrop' => 1]);
if ($run >= 1) {
$updated++;
} else {
$run = XxxInfo::query()->where('id', $match1[1])->select(['id'])->get();
if ($run->count() === 0) {
cli()->info($filePath->getPathname().' not found in db.');
}
}
}
}
}
$qry = XxxInfo::query()->where('cover', '=', 1)->select(['id'])->get();
foreach ($qry as $rows) {
if (! is_file($path2covers.$rows['id'].'-cover.jpg')) {
XxxInfo::query()->where(['cover' => 1, 'id' => $rows['id']])->update(['cover' => 0]);
cli()->info($path2covers.$rows['id'].'-cover.jpg does not exist.');
$deleted++;
}
}
$qry1 = XxxInfo::query()->where('backdrop', '=', 1)->select(['id'])->get();
foreach ($qry1 as $rows) {
if (! is_file($path2covers.$rows['id'].'-backdrop.jpg')) {
XxxInfo::query()->where(['backdrop' => 1, 'id' => $rows['id']])->update(['backdrop' => 0]);
cli()->info($path2covers.$rows['id'].'-backdrop.jpg does not exist.');
$deleted++;
}
}
cli()->header($covers.' covers set.');
cli()->header($updated.' backdrops set.');
cli()->header($deleted.' movies unset.');