✨ Export watched show based on nfo files
Still a work in progress. But enough to get me going now.
This commit is contained in:
parent
a4aab55616
commit
b7534c01f5
8 changed files with 183 additions and 1 deletions
44
app/Data/DataPipes/GetShowTmdb.php
Normal file
44
app/Data/DataPipes/GetShowTmdb.php
Normal 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 dirname;
|
||||
use function file_exists;
|
||||
use function simplexml_load_file;
|
||||
|
||||
class GetShowTmdb implements DataPipe
|
||||
{
|
||||
public function handle(mixed $payload, DataClass $class, Collection $properties): Collection
|
||||
{
|
||||
$path = $properties->get('path');
|
||||
|
||||
$dir = dirname($path);
|
||||
do {
|
||||
$nfo = "$dir/tvshow.nfo";
|
||||
$dir = dirname($dir);
|
||||
} while (!file_exists($nfo) && $dir !== '/');
|
||||
|
||||
if (!file_exists($nfo)) {
|
||||
return $properties;
|
||||
}
|
||||
|
||||
$properties['showNfo'] = $nfo;
|
||||
|
||||
$xml = simplexml_load_file($nfo);
|
||||
$properties['showTmdb'] = $this->getProp($xml, 'tmdbid');
|
||||
$properties['showImdb'] = $this->getProp($xml, 'imdb_id');
|
||||
$properties['showTitle'] = $this->getProp($xml, 'title');
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
protected function getProp(SimpleXMLElement $xml, string $prop): ?string
|
||||
{
|
||||
return $xml->$prop ? (string) $xml->$prop : null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue