From 51c2a1c5772bf55532aeff27f7e540472b6405ba Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Mon, 9 Jun 2025 10:53:41 -0500 Subject: [PATCH] fix: checks that season & episode properties exist on PTN --- src/Monitor/Service/MediaFiles.php | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Monitor/Service/MediaFiles.php b/src/Monitor/Service/MediaFiles.php index 53e2f43..e81ef1d 100644 --- a/src/Monitor/Service/MediaFiles.php +++ b/src/Monitor/Service/MediaFiles.php @@ -3,6 +3,7 @@ namespace App\Monitor\Service; use Aimeos\Map; +use App\Download\Framework\Entity\Download; use Nihilarr\PTN; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Filesystem\Filesystem; @@ -151,6 +152,10 @@ class MediaFiles foreach ($existingEpisodes as $episode) { $ptn = (object) (new PTN())->parse($episode->getFilename()); + if (!property_exists($episode, 'season') || !property_exists($episode, 'episode')) { + continue; + } + if ($ptn->season === $seasonNumber && $ptn->episode === $episodeNumber) { return $episode; } @@ -183,4 +188,36 @@ class MediaFiles return false; } + + public function getDownloadPath(Download $download): string + { + $basePath = $this->getBasePath(); + + if ($download->getMediaType() === 'movies') { + $basePath = $this->getMoviesPath(); + if ($download->getUser()->hasUserPreference('movie_folder')) { + $basePath .= DIRECTORY_SEPARATOR . $download->getTitle(); + } + } elseif ($download->getMediaType() === 'tvshows') { + $basePath = $this->getTvShowsPath() . DIRECTORY_SEPARATOR . $download->getTitle(); + } + + $filepath = $basePath . DIRECTORY_SEPARATOR . $download->getFilename(); + + if (false === $this->filesystem->exists($filepath)) { + throw new \Exception(sprintf('File %s does not exist.', $filepath)); + } + + return $filepath; + } + + public function renameFile(string $oldFile, string $newFile) + { + $this->filesystem->rename($oldFile, $newFile); + } + + public function setFilePermissions(string $filepath, int $permissions) + { + $this->filesystem->chmod($filepath, $permissions); + } }