All in GraphQL #34

Merged
timw4mail merged 87 commits from develop into master 2020-12-01 10:07:49 -05:00
4 changed files with 147 additions and 7 deletions
Showing only changes of commit 766e3cd71c - Show all commits

View File

@ -141,7 +141,7 @@ final class Kitsu {
* @param array $data
* @return array
*/
public static function getTitles(array $data): array
public static function oldGetTitles(array $data): array
{
$raw = array_unique([
$data['canonicalTitle'],
@ -152,6 +152,23 @@ final class Kitsu {
return array_diff($raw,[$data['canonicalTitle']]);
}
/**
* Get the list of titles
*
* @param array $titles
* @return array
*/
public static function getTitles(array $titles): array
{
$raw = array_unique([
$titles['canonical'],
...array_values($titles['localized']),
// ...array_values($data['abbreviatedTitles'] ?? []),
]);
return array_diff($raw,[$titles['canonical']]);
}
/**
* Filter out duplicate and very similar names from
*

View File

@ -0,0 +1,117 @@
query ($id: ID!) {
findAnimeById(id: $id) {
id
ageRating
ageRatingGuide
posterImage {
original {
height
name
url
width
}
views {
height
name
url
width
}
}
categories {
nodes {
title
}
}
characters {
nodes {
character {
id
names {
canonical
alternatives
}
image {
original {
height
name
url
width
}
}
slug
}
role
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
startDate
endDate
episodeCount
episodeLength
totalLength
posterImage {
original {
height
name
url
width
}
views {
height
name
url
width
}
}
season
sfw
slug
staff {
nodes {
person {
id
birthday
image {
original {
height
name
url
width
}
views {
height
name
url
width
}
}
names {
alternatives
canonical
localized
}
}
role
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
status
synopsis
titles {
canonical
localized
}
totalLength
youtubeTrailerVideoId
}
}

View File

@ -63,7 +63,6 @@ trait KitsuAnimeTrait {
$baseData = $this->requestBuilder->runQuery('AnimeDetails', [
'slug' => $slug
]);
// $baseData = $this->getRawMediaData('anime', $slug);
if (empty($baseData))
{
@ -109,7 +108,10 @@ trait KitsuAnimeTrait {
*/
public function getAnimeById(string $animeId): Anime
{
$baseData = $this->getRawMediaDataById('anime', $animeId);
$baseData = $this->requestBuilder->runQuery('AnimeDetailsById', [
'id' => $animeId,
]);
// $baseData = $this->getRawMediaDataById('anime', $animeId);
return $this->animeTransformer->transform($baseData);
}

View File

@ -34,7 +34,9 @@ final class AnimeTransformer extends AbstractTransformer {
*/
public function transform($item): AnimePage
{
$base = $item['data']['findAnimeBySlug'];
$base = array_key_exists('findAnimeBySlug', $item['data'])
? $item['data']['findAnimeBySlug']
: $item['data']['findAnimeById'];
$characters = [];
$staff = [];
$genres = array_map(fn ($genre) => $genre['title']['en'], $base['categories']['nodes']);
@ -42,7 +44,8 @@ final class AnimeTransformer extends AbstractTransformer {
sort($genres);
$title = $base['titles']['canonical'];
$titles = Kitsu::filterLocalizedTitles($base['titles']);
$titles = Kitsu::getTitles($base['titles']);
$titles_more = Kitsu::filterLocalizedTitles($base['titles']);
if (count($base['characters']['nodes']) > 0)
{
@ -103,12 +106,13 @@ final class AnimeTransformer extends AbstractTransformer {
'id' => $base['id'],
'slug' => $base['slug'],
'staff' => $staff,
'show_type' => 'TV', // TODO: get show type
'status' => Kitsu::getAiringStatus($base['startDate'], $base['endDate']),
'streaming_links' => [], // Kitsu::parseStreamingLinks($item['included']),
'synopsis' => $base['synopsis']['en'],
'title' => $title,
'titles' => [],
'titles_more' => $titles,
'titles' => $titles,
'titles_more' => $titles_more,
'total_length' => $base['totalLength'],
'trailer_id' => $base['youtubeTrailerVideoId'],
'url' => "https://kitsu.io/anime/{$base['slug']}",