Compare commits

...

3 Commits

11 changed files with 52 additions and 14 deletions

View File

@@ -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', [

View File

@@ -3,8 +3,11 @@
namespace App\Download\Framework\Entity;
use App\Download\Framework\Repository\DownloadRepository;
use App\Torrentio\Result\ResultFactory;
use App\Torrentio\Result\TorrentioResult;
use App\User\Framework\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use Nihilarr\PTN;
use Symfony\UX\Turbo\Attribute\Broadcast;
#[ORM\Entity(repositoryClass: DownloadRepository::class)]
@@ -162,4 +165,16 @@ class Download
return $this;
}
public function getPtn(): object
{
$ptn = (object) (new PTN())->parse($this->filename);
if ($this->mediaType === "tvshows") {
$ptn->season = str_pad($ptn->season, 2, "0", STR_PAD_LEFT);
$ptn->episode = str_pad($ptn->episode, 2, "0", STR_PAD_LEFT);
}
return $ptn;
}
}

View File

@@ -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,
) {}
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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,16 @@ 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]['id'];
} elseif (count($result['tv_results']) > 0) {
return $result['tv_results'][0]['id'];
} elseif (count($result['tv_episode_results']) > 0) {
return $result['tv_episode_results'][0]['show_id'];
}
throw new \Exception("No results found for $id");
}
public function movieDetails(string $id)
@@ -183,6 +195,8 @@ class Tmdb
public function mediaDetails(string $id, string $type)
{
$id = $this->find($id);
if ($type === "movies") {
return $this->movieDetails($id);
} else {

View File

@@ -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'),
);
}

View File

@@ -1,6 +1,14 @@
<tr{{ attributes }} id="ad_download_{{ download.id }}">
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-stone-800 truncate">
{{ download.title }}
<a href="{{ path('app_search_result', {imdbId: download.imdbId, mediaType: download.mediaType}) }}"
class="hover:underline mr-1"
>
{{ download.title }}
</a>
{% if download.mediaType == "tvshows" %}
&mdash; <span class="ml-1">(S{{ download.ptn.season }}E{{ download.ptn.episode }})</span>
{% endif %}
</td>
{% if isWidget == false %}

View File

@@ -1,13 +1,13 @@
<div{{ attributes }}>
<a href="{{ path('app_search_result', {
mediaType: mediaType,
tmdbId: tmdbId
imdbId: imdbId
}) }}">
<img src="{{ image }}" class="w-40 rounded-md" />
</a>
<a href="{{ path('app_search_result', {
mediaType: mediaType,
tmdbId: tmdbId
imdbId: imdbId
}) }}">
<h3 class="text-center text-gray-50 max-w-[16ch] text-extrabold">{{ title }}</h3>
</a>

View File

@@ -17,7 +17,7 @@
</p>
</div>
<a class="h-9 rounded-md py-1 px-2 bg-green-600 text-gray-50"
href="{{ path('app_search_result', {mediaType: mediaType, tmdbId: tmdbId}) }}"
href="{{ path('app_search_result', {mediaType: mediaType, imdbId: imdbId}) }}"
>choose</a>
</div>
</div>

View File

@@ -22,7 +22,7 @@
<div class="flex flex-col gap-4">
<twig:Card title="Popular Movies" contentClass="flex flex-row justify-between w-full">
{% for movie in popular_movies %}
<twig:Poster imdbId=""
<twig:Poster imdbId="{{ movie.imdbId }}"
tmdbId="{{ movie.tmdbId }}"
title="{{ movie.title }}"
description="{{ movie.description }}"
@@ -34,7 +34,7 @@
</twig:Card>
<twig:Card title="Popular TV Shows" contentClass="flex flex-row justify-between w-full">
{% for movie in popular_tvshows %}
<twig:Poster imdbId=""
<twig:Poster imdbId="{{ movie.imdbId }}"
tmdbId="{{ movie.tmdbId }}"
title="{{ movie.title }}"
description="{{ movie.description }}"