feat: simple related media block on results page
This commit is contained in:
@@ -19,7 +19,8 @@ class GetMediaInfoHandler implements HandlerInterface
|
||||
public function handle(CommandInterface $command): ResultInterface
|
||||
{
|
||||
$media = $this->tmdb->mediaDetails($command->imdbId, $command->mediaType);
|
||||
$relatedMedia = $this->tmdb->relatedMedia($media->tmdbId, $command->mediaType);
|
||||
|
||||
return new GetMediaInfoResult($media, $command->season, $command->episode);
|
||||
return new GetMediaInfoResult($media, $relatedMedia, $command->season, $command->episode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ class GetMediaInfoResult implements ResultInterface
|
||||
{
|
||||
public function __construct(
|
||||
public TmdbResult $media,
|
||||
public array $relatedMedia,
|
||||
public ?int $season,
|
||||
public ?int $episode,
|
||||
) {}
|
||||
|
||||
@@ -7,9 +7,6 @@ use App\Search\Action\Handler\SearchHandler;
|
||||
use App\Search\Action\Input\GetMediaInfoInput;
|
||||
use App\Search\Action\Input\SearchInput;
|
||||
use App\Search\Action\Result\RedirectToMediaResult;
|
||||
use App\Tmdb\TmdbResult;
|
||||
use App\Torrentio\Action\Command\GetMovieOptionsCommand;
|
||||
use App\Torrentio\Action\Command\GetTvShowOptionsCommand;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
@@ -247,6 +247,21 @@ class Tmdb
|
||||
return $series;
|
||||
}
|
||||
|
||||
public function relatedMedia(string $tmdbId, string $mediaType, int $maxResults = 6)
|
||||
{
|
||||
$repos = [
|
||||
'movies' => $this->movieRepository,
|
||||
'tvshows' => $this->tvRepository,
|
||||
];
|
||||
|
||||
$results = $repos[$mediaType]->getRecommendations($tmdbId);
|
||||
return Map::from(array_values($results->toArray()))
|
||||
->slice(0, 6)
|
||||
->map(function ($result) use ($mediaType) {
|
||||
return $this->parseResult($result, $mediaType);
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
public function mediaDetails(string $id, string $type)
|
||||
{
|
||||
$id = $this->find($id);
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
{% block title %}{{ results.media.title }} — Download Options — Torsearch{% endblock %}
|
||||
|
||||
{% block h2 %}Media Results{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<div class="p-4 flex flex-col grow gap-4">
|
||||
<h2 class="mb-2 text-3xl font-bold text-gray-50">Media Results</h2>
|
||||
<div class="flex flex-row w-full gap-2">
|
||||
<twig:Card title="" class="w-full" contentClass="flex flex-col gap-4 justify-between w-full text-gray-50">
|
||||
<div class="p-2 md:p-4 flex flex-col md:flex-row gap-6">
|
||||
@@ -19,7 +20,7 @@
|
||||
<div class="w-full flex flex-col">
|
||||
<div class="mb-4 flex flex-row gap-2 justify-between">
|
||||
<h3 class="text-xl font-medium leading-tight font-bold text-gray-50">
|
||||
{{ results.media.title }} ({{ results.media.year }})
|
||||
{{ results.media.title }} ({{ results.media.year|date('Y') }})
|
||||
</h3>
|
||||
|
||||
{% if results.media.mediaType == "tvshows" %}
|
||||
@@ -95,12 +96,35 @@
|
||||
{% elseif "tvshows" == results.media.mediaType %}
|
||||
<twig:TvEpisodeList
|
||||
results="results"
|
||||
:imdbId="results.media.imdbId" :season="results.season" :perPage="20" :pageNumber="1"
|
||||
:tmdbId="results.media.tmdbId" :title="results.media.title" loading="defer" :episodeNumber="results.episode"
|
||||
loading="defer"
|
||||
:imdbId="results.media.imdbId"
|
||||
:season="results.season"
|
||||
:perPage="20"
|
||||
:pageNumber="1"
|
||||
:tmdbId="results.media.tmdbId"
|
||||
:title="results.media.title"
|
||||
:episodeNumber="results.episode"
|
||||
/>
|
||||
{% endif %}
|
||||
</twig:Card>
|
||||
</div>
|
||||
|
||||
<twig:Card title="Related Media" contentClass="flex flex-col gap-4 text-white">
|
||||
<p>Results similar to "{{ results.media.title }}" that you may be interested in.</p>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4 md:flex flex-col md:flex-row justify-between w-full">
|
||||
{% for media in results.relatedMedia %}
|
||||
<twig:Poster imdbId="{{ media.imdbId }}"
|
||||
tmdbId="{{ media.tmdbId }}"
|
||||
title="{{ media.title }}"
|
||||
description="{{ media.description }}"
|
||||
image="{{ media.poster }}"
|
||||
year="{{ media.year }}"
|
||||
mediaType="{{ media.mediaType }}"
|
||||
/>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</twig:Card>
|
||||
</div>
|
||||
<style>
|
||||
html,
|
||||
|
||||
Reference in New Issue
Block a user