fix: episode id not being added when monitor downloads episode

This commit is contained in:
2025-07-09 18:15:55 -05:00
parent bb6dcdef30
commit d2e7650b6c
2 changed files with 30 additions and 4 deletions

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Base\Util;
class EpisodeId
{
public static function fromSeasonEpisodeNumbers(int $season, int $episode): string
{
return "S". str_pad($season, 2, "0", STR_PAD_LEFT) .
"E". str_pad($episode, 2, "0", STR_PAD_LEFT);
}
}

View File

@@ -2,8 +2,11 @@
namespace App\Monitor\Action\Handler; namespace App\Monitor\Action\Handler;
use App\Base\Util\EpisodeId;
use App\Download\Action\Command\DownloadMediaCommand; use App\Download\Action\Command\DownloadMediaCommand;
use App\Download\DownloadOptionEvaluator; use App\Download\DownloadOptionEvaluator;
use App\Download\Framework\Entity\Download;
use App\Download\Framework\Repository\DownloadRepository;
use App\Monitor\Action\Command\MonitorMovieCommand; use App\Monitor\Action\Command\MonitorMovieCommand;
use App\Monitor\Action\Result\MonitorTvEpisodeResult; use App\Monitor\Action\Result\MonitorTvEpisodeResult;
use App\Monitor\Framework\Repository\MonitorRepository; use App\Monitor\Framework\Repository\MonitorRepository;
@@ -31,6 +34,7 @@ readonly class MonitorTvEpisodeHandler implements HandlerInterface
private LoggerInterface $logger, private LoggerInterface $logger,
private MonitorRepository $monitorRepository, private MonitorRepository $monitorRepository,
private Tmdb $tmdb, private Tmdb $tmdb,
private DownloadRepository $downloadRepository,
) {} ) {}
public function handle(CommandInterface $command): ResultInterface public function handle(CommandInterface $command): ResultInterface
@@ -69,13 +73,23 @@ readonly class MonitorTvEpisodeHandler implements HandlerInterface
if (null !== $result) { if (null !== $result) {
$this->logger->info('> [MonitorTvEpisodeHandler] ...Found 1 matching result found: dispatching DownloadMediaCommand for "' . $result->title . '"'); $this->logger->info('> [MonitorTvEpisodeHandler] ...Found 1 matching result found: dispatching DownloadMediaCommand for "' . $result->title . '"');
$download = $this->downloadRepository->insert(
user: $monitor->getUser(),
url: $result->url,
title: $monitor->getTitle(),
filename: $result->filename,
imdbId: $monitor->getImdbId(),
mediaType: 'tvshows',
episodeId: EpisodeId::fromSeasonEpisodeNumbers($monitor->getSeason(), $monitor->getEpisode()),
);
$this->bus->dispatch(new DownloadMediaCommand( $this->bus->dispatch(new DownloadMediaCommand(
$result->url, $download->getUrl(),
$monitor->getTitle(), $download->getTitle(),
$result->filename, $download->getFilename(),
'tvshows', 'tvshows',
$monitor->getImdbId(), $download->getImdbId(),
$monitor->getUser()->getId(), $monitor->getUser()->getId(),
$download->getId(),
)); ));
$monitor->setStatus('Complete'); $monitor->setStatus('Complete');
$monitor->setDownloadedAt(new DateTimeImmutable()); $monitor->setDownloadedAt(new DateTimeImmutable());