feat: tv episode results
This commit is contained in:
@@ -27,6 +27,7 @@ use Tmdb\Model\Search\SearchQuery\MovieSearchQuery;
|
||||
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;
|
||||
@@ -139,7 +140,14 @@ class Tmdb
|
||||
$client = new TvRepository($this->client);
|
||||
$details = $client->getApi()->getTvshow($id, ['append_to_response' => 'external_ids,seasons']);
|
||||
$details = $this->getEpisodesFromSeries($details);
|
||||
return $this->parseResult($details, "tv");
|
||||
return $this->parseResult($details, "tvshow");
|
||||
}
|
||||
|
||||
public function episodeDetails(string $id, string $season, string $episode)
|
||||
{
|
||||
$client = new TvEpisodeRepository($this->client);
|
||||
$result = $client->getApi()->getEpisode($id, $season, $episode, ['append_to_response' => 'external_ids']);
|
||||
return $this->parseResult($result, "episode");
|
||||
}
|
||||
|
||||
public function getEpisodesFromSeries(array $series)
|
||||
@@ -192,6 +200,19 @@ class Tmdb
|
||||
);
|
||||
}
|
||||
|
||||
function parseEpisode(array $data, string $posterBasePath): TmdbResult {
|
||||
return new TmdbResult(
|
||||
imdbId: $data['external_ids']['imdb_id'],
|
||||
tmdbId: $data['id'],
|
||||
title: $data['name'],
|
||||
poster: $posterBasePath . $data['still_path'],
|
||||
description: $data['overview'],
|
||||
year: (new \DateTime($data['air_date']))->format('Y'),
|
||||
mediaType: "tvshows",
|
||||
episodes: null,
|
||||
);
|
||||
}
|
||||
|
||||
function parseMovie(array $data, string $posterBasePath): TmdbResult {
|
||||
return new TmdbResult(
|
||||
imdbId: $data['external_ids']['imdb_id'],
|
||||
@@ -204,8 +225,13 @@ class Tmdb
|
||||
);
|
||||
}
|
||||
|
||||
$posterBasePath = self::POSTER_IMG_PATH;
|
||||
$result = ("movie" === $mediaType) ? parseMovie($data, $posterBasePath) : parseTvShow($data, $posterBasePath);
|
||||
if ($mediaType === 'movie') {
|
||||
$result = parseMovie($data, self::POSTER_IMG_PATH);
|
||||
} elseif ($mediaType === 'tvshow') {
|
||||
$result = parseTvShow($data, self::POSTER_IMG_PATH);
|
||||
} elseif ($mediaType === 'episode') {
|
||||
$result = parseEpisode($data, self::POSTER_IMG_PATH);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user