34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Search\Action\Handler;
|
|
|
|
use App\Base\Service\MediaFiles;
|
|
use App\Search\Action\Command\GetMediaInfoCommand;
|
|
use App\Search\Action\Result\GetMediaInfoResult;
|
|
use App\Tmdb\Tmdb;
|
|
use OneToMany\RichBundle\Contract\CommandInterface;
|
|
use OneToMany\RichBundle\Contract\HandlerInterface;
|
|
use OneToMany\RichBundle\Contract\ResultInterface;
|
|
|
|
/** @implements HandlerInterface<GetMediaInfoCommand, GetMediaInfoResult> */
|
|
class GetMediaInfoHandler implements HandlerInterface
|
|
{
|
|
public function __construct(
|
|
private readonly Tmdb $tmdb,
|
|
private readonly MediaFiles $mediaFiles
|
|
) {}
|
|
|
|
public function handle(CommandInterface $command): ResultInterface
|
|
{
|
|
$media = $this->tmdb->mediaDetails($command->imdbId, $command->mediaType);
|
|
|
|
if ("tvshows" === $command->mediaType) {
|
|
foreach ($media->episodes[$command->season] as $key => $episode) {
|
|
$media->episodes[$command->season][$key]['file'] = $this->mediaFiles->episodeExists($media->title, $command->season, $episode['episode_number']);
|
|
}
|
|
}
|
|
|
|
return new GetMediaInfoResult($media, $command->season);
|
|
}
|
|
}
|