From 79d9d61592949a0ecb60809c942ff32ff24c4813 Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Tue, 17 Mar 2026 23:16:11 -0500 Subject: [PATCH] fix: includes year in media directory name --- src/Base/Service/MediaFiles.php | 18 ++++++++++++++---- src/Download/Downloader/ProcessDownloader.php | 16 ++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Base/Service/MediaFiles.php b/src/Base/Service/MediaFiles.php index a99eca5..cd2ddac 100644 --- a/src/Base/Service/MediaFiles.php +++ b/src/Base/Service/MediaFiles.php @@ -113,9 +113,14 @@ class MediaFiles return Map::from($results); } - public function createMovieDirectory(string $path): string + public function createMovieDirectory(string $title, string|int $year): string { - $path = $this->moviesPath . DIRECTORY_SEPARATOR . $path; + $path = sprintf( + '%s' . DIRECTORY_SEPARATOR . '%s (%s)', + $this->moviesPath, + $title, + $year + ); if (false === $this->filesystem->exists($path)) { $this->filesystem->mkdir($path); @@ -124,9 +129,14 @@ class MediaFiles return $path; } - public function createTvShowDirectory(string $path): string + public function createTvShowDirectory(string $title, string|int $year): string { - $path = $this->tvShowsPath . DIRECTORY_SEPARATOR . $path; + $path = sprintf( + '%s' . DIRECTORY_SEPARATOR . '%s (%s)', + $this->tvShowsPath, + $title, + $year + ); if (false === $this->filesystem->exists($path)) { $this->filesystem->mkdir($path); diff --git a/src/Download/Downloader/ProcessDownloader.php b/src/Download/Downloader/ProcessDownloader.php index 99641e1..a7ea995 100644 --- a/src/Download/Downloader/ProcessDownloader.php +++ b/src/Download/Downloader/ProcessDownloader.php @@ -7,6 +7,8 @@ use App\Base\Service\MediaFiles; use App\Download\DownloadEvents; use App\Download\Framework\Entity\Download; use App\EventLog\Action\Command\AddEventLogCommand; +use App\Search\Action\Command\GetMediaInfoCommand; +use App\Search\Action\Handler\GetMediaInfoHandler; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Cache\Adapter\RedisAdapter; use Symfony\Component\Messenger\MessageBusInterface; @@ -25,6 +27,7 @@ class ProcessDownloader implements DownloaderInterface private MediaFiles $mediaFiles, private CacheInterface $cache, private readonly Broadcaster $broadcaster, + private readonly GetMediaInfoHandler $getMediaInfoHandler, ) {} /** @@ -37,7 +40,7 @@ class ProcessDownloader implements DownloaderInterface $this->entityManager->flush(); $downloadPreferences = $downloadEntity->getUser()->getDownloadPreferences(); - $path = $this->getDownloadPath($mediaType, $title, $downloadPreferences); + $path = $this->getDownloadPath($mediaType, $title, $downloadEntity->getImdbId(), $downloadPreferences); $processArgs = ['wget', '-O', $downloadEntity->getFilename(), $url]; @@ -103,17 +106,22 @@ class ProcessDownloader implements DownloaderInterface $this->entityManager->flush(); } - public function getDownloadPath(string $mediaType, string $title, array $downloadPreferences): string + public function getDownloadPath(string $mediaType, string $title, string $imdbId, array $downloadPreferences): string { + $mediaInfo = $this->getMediaInfoHandler->handle(new GetMediaInfoCommand( + $imdbId, + $mediaType, + )); + if ($mediaType === 'movies') { if ((bool) $downloadPreferences['movie_folder']->getPreferenceValue() === true) { - return $this->mediaFiles->createMovieDirectory($title); + return $this->mediaFiles->createMovieDirectory($title, $mediaInfo->media->year); } return $this->mediaFiles->getMoviesPath(); } if ($mediaType === 'tvshows') { - return $this->mediaFiles->createTvShowDirectory($title); + return $this->mediaFiles->createTvShowDirectory($title, $mediaInfo->media->year); } throw new \Exception("There is no download path for media type: $mediaType");