fix: includes year in media directory name
This commit is contained in:
@@ -113,9 +113,14 @@ class MediaFiles
|
|||||||
return Map::from($results);
|
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)) {
|
if (false === $this->filesystem->exists($path)) {
|
||||||
$this->filesystem->mkdir($path);
|
$this->filesystem->mkdir($path);
|
||||||
@@ -124,9 +129,14 @@ class MediaFiles
|
|||||||
return $path;
|
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)) {
|
if (false === $this->filesystem->exists($path)) {
|
||||||
$this->filesystem->mkdir($path);
|
$this->filesystem->mkdir($path);
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ use App\Base\Service\MediaFiles;
|
|||||||
use App\Download\DownloadEvents;
|
use App\Download\DownloadEvents;
|
||||||
use App\Download\Framework\Entity\Download;
|
use App\Download\Framework\Entity\Download;
|
||||||
use App\EventLog\Action\Command\AddEventLogCommand;
|
use App\EventLog\Action\Command\AddEventLogCommand;
|
||||||
|
use App\Search\Action\Command\GetMediaInfoCommand;
|
||||||
|
use App\Search\Action\Handler\GetMediaInfoHandler;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\Cache\Adapter\RedisAdapter;
|
use Symfony\Component\Cache\Adapter\RedisAdapter;
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
@@ -25,6 +27,7 @@ class ProcessDownloader implements DownloaderInterface
|
|||||||
private MediaFiles $mediaFiles,
|
private MediaFiles $mediaFiles,
|
||||||
private CacheInterface $cache,
|
private CacheInterface $cache,
|
||||||
private readonly Broadcaster $broadcaster,
|
private readonly Broadcaster $broadcaster,
|
||||||
|
private readonly GetMediaInfoHandler $getMediaInfoHandler,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +40,7 @@ class ProcessDownloader implements DownloaderInterface
|
|||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
$downloadPreferences = $downloadEntity->getUser()->getDownloadPreferences();
|
$downloadPreferences = $downloadEntity->getUser()->getDownloadPreferences();
|
||||||
$path = $this->getDownloadPath($mediaType, $title, $downloadPreferences);
|
$path = $this->getDownloadPath($mediaType, $title, $downloadEntity->getImdbId(), $downloadPreferences);
|
||||||
|
|
||||||
$processArgs = ['wget', '-O', $downloadEntity->getFilename(), $url];
|
$processArgs = ['wget', '-O', $downloadEntity->getFilename(), $url];
|
||||||
|
|
||||||
@@ -103,17 +106,22 @@ class ProcessDownloader implements DownloaderInterface
|
|||||||
$this->entityManager->flush();
|
$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 ($mediaType === 'movies') {
|
||||||
if ((bool) $downloadPreferences['movie_folder']->getPreferenceValue() === true) {
|
if ((bool) $downloadPreferences['movie_folder']->getPreferenceValue() === true) {
|
||||||
return $this->mediaFiles->createMovieDirectory($title);
|
return $this->mediaFiles->createMovieDirectory($title, $mediaInfo->media->year);
|
||||||
}
|
}
|
||||||
return $this->mediaFiles->getMoviesPath();
|
return $this->mediaFiles->getMoviesPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mediaType === 'tvshows') {
|
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");
|
throw new \Exception("There is no download path for media type: $mediaType");
|
||||||
|
|||||||
Reference in New Issue
Block a user