✨ Export films
This commit is contained in:
parent
1295b03c3a
commit
dfc11d7a7f
5 changed files with 71 additions and 14 deletions
|
|
@ -1,7 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Data\DataPipes;
|
||||
|
||||
use App\Data\Enums\Type;
|
||||
use FFMpeg\FFMpeg;
|
||||
use Illuminate\Support\Collection;
|
||||
use SimpleXMLElement;
|
||||
|
|
@ -23,26 +26,49 @@ class GetSeasonEp implements DataPipe
|
|||
$nfo = "{$pi['dirname']}/{$pi['filename']}.nfo";
|
||||
if (file_exists($nfo)) {
|
||||
$properties['epNfo'] = $nfo;
|
||||
$xml = simplexml_load_file($nfo);
|
||||
$type = $xml->getName();
|
||||
|
||||
return $this->getEpFromNfo($properties, $nfo);
|
||||
if ($type === 'episodedetails') {
|
||||
return $this->getEpFromNfo($properties, $xml);
|
||||
} else if ($type === 'movie') {
|
||||
return $this->getFilmFromNfo($properties, $xml);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->getEpFromFfprobe($properties);
|
||||
}
|
||||
|
||||
protected function getEpFromNfo(Collection $properties, string $nfo): Collection
|
||||
protected function getFilmFromNfo(Collection $properties, SimpleXMLElement $xml): Collection
|
||||
{
|
||||
$xml = simplexml_load_file($nfo);
|
||||
if ($xml->season) {
|
||||
$properties['season'] = (int) $xml->season;
|
||||
}
|
||||
if ($xml->episode) {
|
||||
$properties['episode'] = (int) $xml->episode;
|
||||
$properties['type'] = Type::Movie;
|
||||
$properties['showTitle'] = $this->getProp($xml, 'title');
|
||||
$properties['movieTmdb'] = $this->getProp($xml, 'tmdbid');
|
||||
$properties['movieImdb'] = $this->getProp($xml, 'imdbid');
|
||||
if (!is_null($year = $this->getProp($xml, 'year'))) {
|
||||
$properties['movieYear'] = (int) $year;
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
protected function getEpFromNfo(Collection $properties, SimpleXMLElement $xml): Collection
|
||||
{
|
||||
if (!is_null($seas = $this->getProp($xml, 'season'))) {
|
||||
$properties['season'] = (int) $seas;
|
||||
}
|
||||
if (!is_null($ep = $this->getProp($xml, 'episode'))) {
|
||||
$properties['episode'] = (int) $ep;
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
protected function getProp(SimpleXMLElement $xml, string $prop): ?string
|
||||
{
|
||||
return $xml->$prop ? (string) $xml->$prop : null;
|
||||
}
|
||||
|
||||
protected function getEpFromFfprobe(Collection $properties): Collection
|
||||
{
|
||||
$ffmpeg = FFMpeg::create();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Data\DataPipes;
|
||||
|
||||
use App\Data\Enums\Type;
|
||||
use Illuminate\Support\Collection;
|
||||
use SimpleXMLElement;
|
||||
use Spatie\LaravelData\DataPipes\DataPipe;
|
||||
|
|
@ -28,6 +31,7 @@ class GetShowTmdb implements DataPipe
|
|||
}
|
||||
|
||||
$properties['showNfo'] = $nfo;
|
||||
$properties['type'] = Type::Episode;
|
||||
|
||||
$xml = simplexml_load_file($nfo);
|
||||
$properties['showTmdb'] = $this->getProp($xml, 'tmdbid');
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Data\DataPipes;
|
||||
|
||||
use App\Data\Enums\Type;
|
||||
use App\Data\FileData;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
|
@ -18,12 +21,19 @@ class ParseWatchFile implements DataPipe
|
|||
public function handle(mixed $payload, DataClass $class, Collection $properties): Collection
|
||||
{
|
||||
$properties['watched'] = Carbon::now();
|
||||
$properties['output'] = sprintf(
|
||||
'%s-%dx%02d.json',
|
||||
Str::slug($properties['showTitle'] ?? uniqid()),
|
||||
$properties['season'],
|
||||
$properties['episode']
|
||||
);
|
||||
$properties['output'] = match ($properties['type']) {
|
||||
Type::Movie => sprintf(
|
||||
'%s-%d.json',
|
||||
Str::slug($properties['showTitle'] ?? uniqid()),
|
||||
$properties['movieYear'],
|
||||
),
|
||||
default => sprintf(
|
||||
'%s-%dx%02d.json',
|
||||
Str::slug($properties['showTitle'] ?? uniqid()),
|
||||
$properties['season'],
|
||||
$properties['episode']
|
||||
),
|
||||
};
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
|
|
|||
11
app/Data/Enums/Type.php
Normal file
11
app/Data/Enums/Type.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Data\Enums;
|
||||
|
||||
enum Type: string {
|
||||
case Unknown = "unknown";
|
||||
case Episode = "episode";
|
||||
case Movie = "movie";
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
|
|
@ -15,10 +17,14 @@ class WatchFile extends Data
|
|||
public ?string $showTmdb = null;
|
||||
public ?string $showImdb = null;
|
||||
public ?string $showTitle = null;
|
||||
public ?string $movieTmdb = null;
|
||||
public ?string $movieImdb = null;
|
||||
public int $movieYear = 1900;
|
||||
public ?string $epNfo = null;
|
||||
public int $season = 0;
|
||||
public int $episode = 0;
|
||||
public Carbon $watched;
|
||||
public Enums\Type $type = Enums\Type::Unknown;
|
||||
|
||||
public static function fromPath(string $path): static
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue