fix: checks that season & episode properties exist on PTN
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Monitor\Service;
|
namespace App\Monitor\Service;
|
||||||
|
|
||||||
use Aimeos\Map;
|
use Aimeos\Map;
|
||||||
|
use App\Download\Framework\Entity\Download;
|
||||||
use Nihilarr\PTN;
|
use Nihilarr\PTN;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
@@ -151,6 +152,10 @@ class MediaFiles
|
|||||||
foreach ($existingEpisodes as $episode) {
|
foreach ($existingEpisodes as $episode) {
|
||||||
$ptn = (object) (new PTN())->parse($episode->getFilename());
|
$ptn = (object) (new PTN())->parse($episode->getFilename());
|
||||||
|
|
||||||
|
if (!property_exists($episode, 'season') || !property_exists($episode, 'episode')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($ptn->season === $seasonNumber && $ptn->episode === $episodeNumber) {
|
if ($ptn->season === $seasonNumber && $ptn->episode === $episodeNumber) {
|
||||||
return $episode;
|
return $episode;
|
||||||
}
|
}
|
||||||
@@ -183,4 +188,36 @@ class MediaFiles
|
|||||||
|
|
||||||
return false;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user