From dfc11d7a7fe79e9d2d457605205de4c18b61ed37 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 8 Oct 2023 23:01:28 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Export=20films?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Data/DataPipes/GetSeasonEp.php | 42 ++++++++++++++++++++++----- app/Data/DataPipes/GetShowTmdb.php | 4 +++ app/Data/DataPipes/ParseWatchFile.php | 22 ++++++++++---- app/Data/Enums/Type.php | 11 +++++++ app/Data/WatchFile.php | 6 ++++ 5 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 app/Data/Enums/Type.php diff --git a/app/Data/DataPipes/GetSeasonEp.php b/app/Data/DataPipes/GetSeasonEp.php index 57c713c..e62dd3f 100644 --- a/app/Data/DataPipes/GetSeasonEp.php +++ b/app/Data/DataPipes/GetSeasonEp.php @@ -1,7 +1,10 @@ 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(); diff --git a/app/Data/DataPipes/GetShowTmdb.php b/app/Data/DataPipes/GetShowTmdb.php index 192d729..154c2b1 100644 --- a/app/Data/DataPipes/GetShowTmdb.php +++ b/app/Data/DataPipes/GetShowTmdb.php @@ -1,7 +1,10 @@ getProp($xml, 'tmdbid'); diff --git a/app/Data/DataPipes/ParseWatchFile.php b/app/Data/DataPipes/ParseWatchFile.php index c625eaa..14ac0d9 100644 --- a/app/Data/DataPipes/ParseWatchFile.php +++ b/app/Data/DataPipes/ParseWatchFile.php @@ -1,7 +1,10 @@ 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; } diff --git a/app/Data/Enums/Type.php b/app/Data/Enums/Type.php new file mode 100644 index 0000000..3d2f302 --- /dev/null +++ b/app/Data/Enums/Type.php @@ -0,0 +1,11 @@ +