fix: checks that season & episode properties exist on PTN

This commit is contained in:
2025-06-09 10:53:41 -05:00
parent f5ed464719
commit 51c2a1c577

View File

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