Update nzb and nfo import

This commit is contained in:
DariusIII
2026-07-14 20:18:04 +02:00
parent 567a614a02
commit de005d3e7e
13 changed files with 1082 additions and 216 deletions
+69
View File
@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use App\Services\Nzb\NfoImportService;
use App\Services\Nzb\NzbUploadManifestService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Throwable;
final class ImportNfos extends Command
{
protected $signature = 'nntmux:import-nfos
{--folder= : Import folder path}
{--delete : Delete NFO files after import}
{--delete-failed : Delete NFO files after terminal or failed imports}';
protected $description = 'Import paired NFO files for previously imported NZB releases';
public function handle(NzbUploadManifestService $manifests, NfoImportService $importer): int
{
$folderOption = $this->option('folder');
if (! is_string($folderOption) || trim($folderOption) === '') {
$this->error('Folder path must not be empty');
return self::FAILURE;
}
$folder = rtrim($folderOption, '/\\');
if (! File::isDirectory($folder)) {
$this->error('Folder path does not exist: '.$folder);
return self::FAILURE;
}
try {
$manifestPaths = $manifests->findManifests($folder);
} catch (Throwable $exception) {
$this->error($exception->getMessage());
return self::FAILURE;
}
$imported = $skipped = $failed = 0;
foreach ($manifestPaths as $manifestPath) {
$result = $importer->importManifest(
$manifestPath,
(bool) $this->option('delete'),
(bool) $this->option('delete-failed'),
);
match ($result['status']) {
'imported' => $imported++,
'failed' => $failed++,
default => $skipped++,
};
if ($result['status'] === 'failed') {
$this->warn(basename(dirname($manifestPath)).': '.$result['message']);
}
}
$this->info("Processed {$imported} NFOs, skipped {$skipped}, failed {$failed}.");
return $failed === 0 ? self::SUCCESS : self::FAILURE;
}
}
+58 -50
View File
@@ -4,10 +4,14 @@ declare(strict_types=1);
namespace App\Console\Commands;
use App\Enums\NzbImportStatus;
use App\Services\Nzb\NzbImportService;
use App\Services\Nzb\NzbUploadManifestService;
use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use SplFileInfo;
use Throwable;
class ImportNzbs extends Command
{
@@ -33,57 +37,61 @@ class ImportNzbs extends Command
/**
* Execute the console command.
*/
public function handle(): void
public function handle(NzbUploadManifestService $manifests): void
{
if ($this->option('folder')) {
if ($this->option('filename')) {
$useNzbName = true;
} else {
$useNzbName = false;
}
if ($this->option('delete')) {
$deleteNZB = true;
} else {
$deleteNZB = false;
}
if ($this->option('delete-failed')) {
$deleteFailedNZB = true;
} else {
$deleteFailedNZB = false;
}
if ($this->option('source')) {
$source = (int) $this->option('source');
} else {
$source = 1;
}
$importFolder = $this->option('folder');
$folders = File::directories($importFolder);
if (empty($folders)) {
$this->info('Importing NZB files from '.$importFolder);
$files = File::allFiles($importFolder);
$NZBImport = new NzbImportService;
try {
$NZBImport->beginImport($files, $useNzbName, $deleteNZB, $deleteFailedNZB, $source);
} catch (FileNotFoundException $e) {
$this->error($e->getMessage());
}
} else {
foreach ($folders as $folder) {
$this->info('Importing NZB files from '.$folder);
$files = File::allFiles($folder);
$NZBImport = new NzbImportService;
try {
$NZBImport->beginImport($files, $useNzbName, $deleteNZB, $deleteFailedNZB, $source);
} catch (FileNotFoundException $e) {
$this->error($e->getMessage());
}
}
}
} else {
$folderOption = $this->option('folder');
if (! is_string($folderOption) || trim($folderOption) === '') {
$this->error('Folder path must not be empty');
exit();
return;
}
$importFolder = rtrim($folderOption, '/\\');
if (! File::isDirectory($importFolder)) {
$this->error('Folder path does not exist: '.$importFolder);
return;
}
$useNzbName = (bool) $this->option('filename');
$deleteNZB = (bool) $this->option('delete');
$deleteFailedNZB = (bool) $this->option('delete-failed');
$source = $this->option('source') ? (int) $this->option('source') : 1;
try {
$files = array_values(array_filter(
File::allFiles($importFolder),
static function (SplFileInfo $file) use ($manifests): bool {
$path = $file->getPathname();
if (! Str::endsWith(strtolower($path), ['.nzb', '.nzb.gz'])) {
return true;
}
return $manifests->shouldImportNzb($path);
}
));
$this->info('Importing NZB files from '.$importFolder);
$importer = new NzbImportService;
$importer->beginImport(
$files,
$useNzbName,
$deleteNZB,
$deleteFailedNZB,
$source,
static function (array $result) use ($manifests): void {
/** @var NzbImportStatus $status */
$status = $result['status'];
$manifests->recordNzbOutcome(
$result['path'],
$status,
$result['release_id'],
$result['release_guid'],
);
}
);
} catch (Throwable $exception) {
$this->error($exception->getMessage());
}
}
}