Export watched show based on nfo files

Still a work in progress. But enough to get me going now.
This commit is contained in:
Dan Jones 2022-09-13 16:50:10 -05:00
commit b7534c01f5
8 changed files with 183 additions and 1 deletions

View file

@ -0,0 +1,44 @@
<?php
namespace App\Data\DataPipes;
use Illuminate\Support\Collection;
use SimpleXMLElement;
use Spatie\LaravelData\DataPipes\DataPipe;
use Spatie\LaravelData\Support\DataClass;
use function file_exists;
use function pathinfo;
use function simplexml_load_file;
class GetSeasonEp implements DataPipe
{
public function handle(mixed $payload, DataClass $class, Collection $properties): Collection
{
$path = $properties->get('path');
$pi = pathinfo($path);
$nfo = "{$pi['dirname']}/{$pi['filename']}.nfo";
if (file_exists($nfo)) {
$properties['epNfo'] = $nfo;
return $this->getEpFromNfo($properties, $nfo);
}
return $properties;
}
protected function getEpFromNfo(Collection $properties, string $nfo): Collection
{
$xml = simplexml_load_file($nfo);
if ($xml->season) {
$properties['season'] = (int) $xml->season;
}
if ($xml->episode) {
$properties['episode'] = (int) $xml->episode;
}
return $properties;
}
}