wip: mostly working tmdb client
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
namespace App\Tmdb\Framework\Controller;
|
||||
|
||||
use App\Base\Util\ImdbMatcher;
|
||||
use App\Tmdb\Tmdb;
|
||||
use App\Tmdb\TmdbClient;
|
||||
use App\Tmdb\TmdbResult;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -23,7 +22,7 @@ class ApiController extends AbstractController
|
||||
|
||||
if (null !== $term) {
|
||||
if (ImdbMatcher::isMatch($term)) {
|
||||
$tmdbResult = $tmdb->findByImdbId($term);
|
||||
$tmdbResult = $tmdb->search($term);
|
||||
$results = [
|
||||
[
|
||||
'data' => $tmdbResult,
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tmdb;
|
||||
|
||||
use Tmdb\Event\HydrationEvent;
|
||||
|
||||
class HydrationListener extends \Tmdb\Event\Listener\HydrationListener
|
||||
{
|
||||
public function hydrateSubject(HydrationEvent $event)
|
||||
{
|
||||
dump($event);
|
||||
dd('hre');
|
||||
}
|
||||
}
|
||||
@@ -8,23 +8,19 @@ use App\Base\Util\ImdbMatcher;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\ObjectMapper\ObjectMapper;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
use Tmdb\Api\Find;
|
||||
use Tmdb\Client;
|
||||
use Tmdb\Event\BeforeRequestEvent;
|
||||
use Tmdb\Event\HydrationEvent;
|
||||
use Tmdb\Event\Listener\Psr6CachedRequestListener;
|
||||
use Tmdb\Event\Listener\Request\AcceptJsonRequestListener;
|
||||
use Tmdb\Event\Listener\Request\ApiTokenRequestListener;
|
||||
use Tmdb\Event\Listener\Request\ContentTypeJsonRequestListener;
|
||||
use Tmdb\Event\Listener\Request\UserAgentRequestListener;
|
||||
use Tmdb\Event\RequestEvent;
|
||||
use Tmdb\Model\Movie;
|
||||
use Tmdb\Model\Tv;
|
||||
use Tmdb\Repository\MovieRepository;
|
||||
use Tmdb\Repository\SearchRepository;
|
||||
use Tmdb\Repository\TvEpisodeRepository;
|
||||
use Tmdb\Repository\TvRepository;
|
||||
use Tmdb\Repository\TvSeasonRepository;
|
||||
use Tmdb\Token\Api\ApiToken;
|
||||
@@ -38,6 +34,7 @@ class TmdbClient
|
||||
protected MovieRepository $movieRepository;
|
||||
protected TvRepository $tvRepository;
|
||||
protected TvSeasonRepository $tvSeasonRepository;
|
||||
protected TvEpisodeRepository $tvEpisodeRepository;
|
||||
protected SearchRepository $searchRepository;
|
||||
|
||||
public function __construct(
|
||||
@@ -97,6 +94,7 @@ class TmdbClient
|
||||
$this->movieRepository = new MovieRepository($this->client);
|
||||
$this->tvRepository = new TvRepository($this->client);
|
||||
$this->tvSeasonRepository = new TvSeasonRepository($this->client);
|
||||
$this->tvEpisodeRepository = new TvEpisodeRepository($this->client);
|
||||
$this->searchRepository = new SearchRepository($this->client);
|
||||
}
|
||||
|
||||
@@ -136,6 +134,8 @@ class TmdbClient
|
||||
strtolower($data['name']) !== 'specials';
|
||||
})->map(function ($data) use ($media) {
|
||||
return $this->tvSeasonDetails($media['id'], $data['season_number'])['episodes'];
|
||||
})->rekey(function ($data) {
|
||||
return $data[1]['season_number'];
|
||||
})->toArray();
|
||||
|
||||
return $this->parseResult(
|
||||
@@ -152,10 +152,20 @@ class TmdbClient
|
||||
$data['still_path'] = self::POSTER_IMG_PATH . $data['still_path'];
|
||||
$data['poster'] = $data['still_path'];
|
||||
return $data;
|
||||
})->toArray();
|
||||
})->rekey(fn ($data) => $data['episode_number'])->toArray();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function tvEpisodeDetails(string $tmdbId, int $season, int $episode): ?TmdbResult
|
||||
{
|
||||
$result = $this->tvEpisodeRepository->getApi()->getEpisode($tmdbId, $season, $episode, ['append_to_response' => 'external_ids']);
|
||||
return $this->parseResult(
|
||||
$result,
|
||||
MediaType::TvEpisode->value,
|
||||
$result['external_ids']['imdb_id']
|
||||
);
|
||||
}
|
||||
|
||||
public function relatedMedia(string $tmdbId, string $mediaType, int $resultCount = 6): Map
|
||||
{
|
||||
$repos = [
|
||||
|
||||
@@ -28,7 +28,7 @@ class TmdbResultDenormalizer implements DenormalizerInterface
|
||||
MediaType::TvShow->value => 'parseTvShow',
|
||||
'movie' => 'parseMovie',
|
||||
'tv' => 'parseTvShow',
|
||||
'tvepisodes' => 'parseEpisode',
|
||||
'tvepisode' => 'parseEpisode',
|
||||
];
|
||||
|
||||
$denormalized = $this->normalizer->denormalize($data, TmdbResult::class, $format, $context);
|
||||
@@ -79,7 +79,7 @@ class TmdbResultDenormalizer implements DenormalizerInterface
|
||||
}
|
||||
|
||||
$result->premiereDate = $airDate;
|
||||
$result->episodeAirDate = $airDate;
|
||||
$result->episodeAirDate = $airDate->format('m/d/Y');
|
||||
$result->poster = (null !== $data['still_path']) ? self::POSTER_IMG_PATH . $data['still_path'] : null;
|
||||
$result->year = (null !== $airDate) ? $airDate->format('Y') : null;
|
||||
$result->mediaType = "tvshows";
|
||||
|
||||
Reference in New Issue
Block a user