Export films

This commit is contained in:
Dan Jones 2023-10-08 23:01:28 -05:00
commit dfc11d7a7f
5 changed files with 71 additions and 14 deletions

View file

@ -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();

View file

@ -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');

View file

@ -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;
}