44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Torrentio\Action\Handler;
|
|
|
|
use App\Base\Service\MediaFiles;
|
|
use App\Library\Dto\MediaFileDto;
|
|
use App\Tmdb\Tmdb;
|
|
use App\Torrentio\Action\Command\GetTvShowOptionsCommand;
|
|
use App\Torrentio\Action\Result\GetTvShowOptionsResult;
|
|
use App\Torrentio\Client\Torrentio;
|
|
use OneToMany\RichBundle\Contract\CommandInterface;
|
|
use OneToMany\RichBundle\Contract\HandlerInterface;
|
|
use OneToMany\RichBundle\Contract\ResultInterface;
|
|
|
|
/** @implements HandlerInterface<GetTvShowOptionsCommand, GetTvShowOptionsResult> */
|
|
class GetTvShowOptionsHandler implements HandlerInterface
|
|
{
|
|
public function __construct(
|
|
private readonly Tmdb $tmdb,
|
|
private readonly Torrentio $torrentio,
|
|
private readonly MediaFiles $mediaFiles,
|
|
) {}
|
|
|
|
public function handle(CommandInterface $command): ResultInterface
|
|
{
|
|
$media = $this->tmdb->episodeDetails($command->tmdbId, $command->season, $command->episode);
|
|
$parentShow = $this->tmdb->mediaDetails($command->imdbId, 'tvshows');
|
|
$file = $this->mediaFiles->episodeExists($parentShow->title, $command->season, $command->episode);
|
|
|
|
return new GetTvShowOptionsResult(
|
|
parentShow: $parentShow,
|
|
media: $media,
|
|
file: MediaFileDto::fromSplFileInfo($file),
|
|
season: $command->season,
|
|
episode: $command->episode,
|
|
results: $this->torrentio->fetchEpisodeResults(
|
|
$command->imdbId,
|
|
$command->season,
|
|
$command->episode,
|
|
)
|
|
);
|
|
}
|
|
}
|