diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index 8ab5a4f..de95c04 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -33,11 +33,12 @@ final class SearchController extends AbstractController ]); } - #[Route('/result/{mediaType}/{tmdbId}', name: 'app_search_result')] + #[Route('/result/{mediaType}/{imdbId}', name: 'app_search_result')] public function result( GetMediaInfoInput $input, ): Response { $result = $this->getMediaInfoHandler->handle($input->toCommand()); + $this->warmDownloadOptionCache($result->media); return $this->render('search/result.html.twig', [ diff --git a/src/Search/Action/Command/GetMediaInfoCommand.php b/src/Search/Action/Command/GetMediaInfoCommand.php index 05490a5..22b489d 100644 --- a/src/Search/Action/Command/GetMediaInfoCommand.php +++ b/src/Search/Action/Command/GetMediaInfoCommand.php @@ -8,7 +8,7 @@ use OneToMany\RichBundle\Contract\CommandInterface; class GetMediaInfoCommand implements CommandInterface { public function __construct( - public string $tmdbId, + public string $imdbId, public string $mediaType, ) {} } \ No newline at end of file diff --git a/src/Search/Action/Handler/GetMediaInfoHandler.php b/src/Search/Action/Handler/GetMediaInfoHandler.php index 7c36350..77ac9ed 100644 --- a/src/Search/Action/Handler/GetMediaInfoHandler.php +++ b/src/Search/Action/Handler/GetMediaInfoHandler.php @@ -18,7 +18,7 @@ class GetMediaInfoHandler implements HandlerInterface public function handle(CommandInterface $command): ResultInterface { - $media = $this->tmdb->mediaDetails($command->tmdbId, $command->mediaType); + $media = $this->tmdb->mediaDetails($command->imdbId, $command->mediaType); return new GetMediaInfoResult($media); } diff --git a/src/Search/Action/Input/GetMediaInfoInput.php b/src/Search/Action/Input/GetMediaInfoInput.php index 3f49a32..58eca1f 100644 --- a/src/Search/Action/Input/GetMediaInfoInput.php +++ b/src/Search/Action/Input/GetMediaInfoInput.php @@ -12,8 +12,8 @@ use OneToMany\RichBundle\Contract\InputInterface; class GetMediaInfoInput implements InputInterface { public function __construct( - #[SourceRoute('tmdbId')] - public string $tmdbId, + #[SourceRoute('imdbId')] + public string $imdbId, #[SourceRoute('mediaType')] public string $mediaType, @@ -21,6 +21,6 @@ class GetMediaInfoInput implements InputInterface public function toCommand(): CommandInterface { - return new GetMediaInfoCommand($this->tmdbId, $this->mediaType); + return new GetMediaInfoCommand($this->imdbId, $this->mediaType); } } \ No newline at end of file diff --git a/src/Tmdb/Tmdb.php b/src/Tmdb/Tmdb.php index 1caa706..4366f99 100644 --- a/src/Tmdb/Tmdb.php +++ b/src/Tmdb/Tmdb.php @@ -133,9 +133,12 @@ class Tmdb if (!$result instanceof Movie && !$result instanceof Tv) { continue; } + $results[] = $this->parseResult($result); } + $results = array_filter($results, fn ($result) => null !== $result->imdbId); + return $results; } @@ -143,7 +146,14 @@ class Tmdb { $finder = new Find($this->client); $result = $finder->findBy($id, ['external_source' => 'imdb_id']); - return $this->parseResult($result); + + if (count($result['movie_results']) > 0) { + return $result['movie_results'][0]; + } elseif (count($result['tv_results']) > 0) { + return $result['tv_results'][0]; + } + + throw new \Exception("No results found for $id"); } public function movieDetails(string $id) @@ -183,6 +193,8 @@ class Tmdb public function mediaDetails(string $id, string $type) { + $id = $this->find($id)['id']; + if ($type === "movies") { return $this->movieDetails($id); } else { diff --git a/src/Torrentio/Action/Handler/GetMovieOptionsHandler.php b/src/Torrentio/Action/Handler/GetMovieOptionsHandler.php index f9e6ea8..942628c 100644 --- a/src/Torrentio/Action/Handler/GetMovieOptionsHandler.php +++ b/src/Torrentio/Action/Handler/GetMovieOptionsHandler.php @@ -19,7 +19,7 @@ class GetMovieOptionsHandler implements HandlerInterface public function handle(CommandInterface $command): ResultInterface { return new GetMovieOptionsResult( - media: $this->tmdb->mediaDetails($command->tmdbId, 'movies'), + media: $this->tmdb->mediaDetails($command->imdbId, 'movies'), results: $this->torrentio->search($command->imdbId, 'movies'), ); } diff --git a/templates/components/Poster.html.twig b/templates/components/Poster.html.twig index 806cd21..f1529d1 100644 --- a/templates/components/Poster.html.twig +++ b/templates/components/Poster.html.twig @@ -1,13 +1,13 @@

{{ title }}

diff --git a/templates/components/SearchResult.html.twig b/templates/components/SearchResult.html.twig index 2d3fa24..0d3bead 100644 --- a/templates/components/SearchResult.html.twig +++ b/templates/components/SearchResult.html.twig @@ -17,7 +17,7 @@

choose diff --git a/templates/index/index.html.twig b/templates/index/index.html.twig index dc4ef22..8d3403d 100644 --- a/templates/index/index.html.twig +++ b/templates/index/index.html.twig @@ -22,7 +22,7 @@
{% for movie in popular_movies %} - {% for movie in popular_tvshows %} -