Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
21 changed files with 70 additions and 49 deletions
Showing only changes of commit cbff386734 - Show all commits

View File

@ -26,7 +26,7 @@ use Aviat\AnimeClient\Kitsu;
<br /> <br />
<hr /> <hr />
<div class="description"> <div class="description">
<p><?= str_replace("\n", '</p><p>', $data['description']) ?></p> <p><?= nl2br($data['description']) ?></p>
</div> </div>
</div> </div>
</section> </section>

View File

@ -8,6 +8,9 @@
<?php foreach ($data['names'] as $name): ?> <?php foreach ($data['names'] as $name): ?>
<h3><?= $name ?></h3> <h3><?= $name ?></h3>
<?php endforeach ?> <?php endforeach ?>
<?php if ( ! empty($data['birthday'])): ?>
<h4><?= $data['birthday'] ?></h4>
<?php endif ?>
<br /> <br />
<hr /> <hr />
<div class="description"> <div class="description">

View File

@ -535,14 +535,14 @@ final class Model
* Get the data for a specific list item, generally for editing * Get the data for a specific list item, generally for editing
* *
* @param string $listId - The unique identifier of that list item * @param string $listId - The unique identifier of that list item
* @return mixed
*/ */
public function getListItem(string $listId) public function getListItem(string $listId): AnimeListItem|MangaListItem|array
{ {
$baseData = $this->listItem->get($listId); $baseData = $this->listItem->get($listId);
if ( ! isset($baseData['data']['findLibraryEntryById'])) if ( ! isset($baseData['data']['findLibraryEntryById']))
{ {
return []; // We need to get the errors...
return $baseData;
} }
return (new LibraryEntryTransformer())->transform($baseData['data']['findLibraryEntryById']); return (new LibraryEntryTransformer())->transform($baseData['data']['findLibraryEntryById']);

View File

@ -19,7 +19,7 @@ query ($slug: String!) {
} }
categories(first: 100) { categories(first: 100) {
nodes { nodes {
title title(locales: "en")
} }
} }
characters(first: 100) { characters(first: 100) {
@ -29,7 +29,7 @@ query ($slug: String!) {
names { names {
alternatives alternatives
canonical canonical
localized localized(locales: "*")
} }
image { image {
original { original {
@ -50,7 +50,7 @@ query ($slug: String!) {
startCursor startCursor
} }
} }
description description(locales: "en")
startDate startDate
endDate endDate
episodeCount episodeCount
@ -87,7 +87,7 @@ query ($slug: String!) {
names { names {
alternatives alternatives
canonical canonical
localized localized(locales: "*")
} }
slug slug
} }
@ -118,7 +118,7 @@ query ($slug: String!) {
alternatives alternatives
canonical canonical
canonicalLocale canonicalLocale
localized localized(locales: ["en", "en-t-ja", "ja", "ja-jp"])
} }
totalLength totalLength
youtubeTrailerVideoId youtubeTrailerVideoId

View File

@ -19,7 +19,7 @@ query ($id: ID!) {
} }
categories(first: 100) { categories(first: 100) {
nodes { nodes {
title title(locales: "en")
} }
} }
characters(first: 100) { characters(first: 100) {
@ -29,7 +29,7 @@ query ($id: ID!) {
names { names {
alternatives alternatives
canonical canonical
localized localized(locales: "*")
} }
image { image {
original { original {
@ -50,7 +50,7 @@ query ($id: ID!) {
startCursor startCursor
} }
} }
description description(locales: "en")
startDate startDate
endDate endDate
episodeCount episodeCount
@ -87,7 +87,7 @@ query ($id: ID!) {
names { names {
alternatives alternatives
canonical canonical
localized localized(locales: "*")
} }
slug slug
} }
@ -118,7 +118,7 @@ query ($id: ID!) {
alternatives alternatives
canonical canonical
canonicalLocale canonicalLocale
localized localized(locales: ["en", "en-t-ja", "ja", "ja-jp"])
} }
totalLength totalLength
youtubeTrailerVideoId youtubeTrailerVideoId

View File

@ -6,12 +6,12 @@ query ($slug: String!) {
url url
} }
} }
description description(locales: "en")
names { names {
alternatives alternatives
canonical canonical
canonicalLocale canonicalLocale
localized localized(locales: "*")
}, },
media(first: 100) { media(first: 100) {
nodes { nodes {
@ -22,7 +22,7 @@ query ($slug: String!) {
alternatives alternatives
canonical canonical
canonicalLocale canonicalLocale
localized localized(locales: ["en", "en-t-ja", "ja", "ja-jp"])
} }
posterImage { posterImage {
original { original {
@ -41,7 +41,7 @@ query ($slug: String!) {
type type
} }
role role
voices(first: 10) { voices(first: 10, locale:"*", sort:{direction:ASCENDING, on: UPDATED_AT}) {
nodes { nodes {
id id
locale locale
@ -53,7 +53,7 @@ query ($slug: String!) {
alternatives alternatives
canonical canonical
canonicalLocale canonicalLocale
localized localized(locales: "*")
} }
image { image {
original { original {
@ -70,4 +70,4 @@ query ($slug: String!) {
} }
slug slug
} }
} }

View File

@ -57,7 +57,7 @@ query (
type type
titles { titles {
canonical canonical
localized localized(locales: "*")
alternatives alternatives
} }
...on Anime { ...on Anime {

View File

@ -16,7 +16,7 @@ query($id: ID!) {
ageRating ageRating
categories(first: 100) { categories(first: 100) {
nodes { nodes {
title title(locales: "*")
} }
} }
mappings(first: 10) { mappings(first: 10) {
@ -41,7 +41,7 @@ query($id: ID!) {
endDate endDate
titles { titles {
canonical canonical
localized localized(locales: "*")
canonicalLocale canonicalLocale
} }
type type

View File

@ -33,7 +33,7 @@ query ($slug: String!) {
titles { titles {
alternatives alternatives
canonical canonical
localized localized(locales: "*")
} }
...on Anime { ...on Anime {
episodeCount episodeCount

View File

@ -19,7 +19,7 @@ query ($slug: String!) {
} }
categories(first: 100) { categories(first: 100) {
nodes { nodes {
title title(locales: "*")
} }
} }
chapterCount chapterCount
@ -116,7 +116,7 @@ query ($slug: String!) {
titles { titles {
canonical canonical
canonicalLocale canonicalLocale
localized localized(locales: "*")
} }
} }
} }

View File

@ -19,7 +19,7 @@ query ($id: ID!) {
} }
categories(first: 100) { categories(first: 100) {
nodes { nodes {
title title(locales: "*")
} }
} }
chapterCount chapterCount
@ -116,7 +116,7 @@ query ($id: ID!) {
titles { titles {
canonical canonical
canonicalLocale canonicalLocale
localized localized(locales: "*")
} }
} }
} }

View File

@ -1,7 +1,7 @@
query ($slug: String!) { query ($slug: String!) {
findPersonBySlug(slug: $slug) { findPersonBySlug(slug: $slug) {
id id
description description(locales: "en")
birthday birthday
image { image {
original { original {
@ -20,7 +20,7 @@ query ($slug: String!) {
names { names {
alternatives alternatives
canonical canonical
localized localized(locales: "*")
} }
mediaStaff(first: 100) { mediaStaff(first: 100) {
nodes { nodes {
@ -47,7 +47,7 @@ query ($slug: String!) {
titles { titles {
alternatives alternatives
canonical canonical
localized localized(locales: ["en", "en-t-ja", "ja", "ja-jp"])
} }
} }
} }
@ -91,7 +91,7 @@ query ($slug: String!) {
} }
titles { titles {
canonical canonical
localized localized(locales: ["en", "en-t-ja", "ja", "ja-jp"])
} }
} }
} }

View File

@ -26,7 +26,7 @@ query ($type: MediaTypeEnum!) {
} }
categories(first: 100) { categories(first: 100) {
nodes { nodes {
title title(locales: "*")
} }
} }
characters(first: 100) { characters(first: 100) {
@ -36,7 +36,7 @@ query ($type: MediaTypeEnum!) {
names { names {
alternatives alternatives
canonical canonical
localized localized(locales: "*")
} }
image { image {
original { original {
@ -90,7 +90,7 @@ query ($type: MediaTypeEnum!) {
names { names {
alternatives alternatives
canonical canonical
localized localized(locales: "*")
} }
slug slug
} }
@ -108,7 +108,7 @@ query ($type: MediaTypeEnum!) {
alternatives alternatives
canonical canonical
canonicalLocale canonicalLocale
localized localized(locales: "*")
} }
...on Anime { ...on Anime {
episodeCount episodeCount

View File

@ -19,7 +19,7 @@ query ($query: String!) {
slug slug
titles { titles {
canonical canonical
localized localized(locales: ["en", "en-t-ja", "ja", "ja-jp"])
alternatives alternatives
} }
myLibraryEntry { myLibraryEntry {

View File

@ -19,7 +19,7 @@ query ($query: String!) {
slug slug
titles { titles {
canonical canonical
localized localized(locales: ["en", "en-t-ja", "ja", "ja-jp"])
alternatives alternatives
} }
myLibraryEntry { myLibraryEntry {

View File

@ -52,7 +52,7 @@ query ($slug: String!) {
} }
titles { titles {
canonical canonical
localized localized(locales: ["en", "en-t-ja", "ja", "ja-jp"])
} }
} }
...on Manga { ...on Manga {
@ -72,7 +72,7 @@ query ($slug: String!) {
} }
titles { titles {
canonical canonical
localized localized(locales: ["en", "en-t-ja", "ja", "ja-jp"])
} }
} }
...on Person { ...on Person {
@ -88,11 +88,12 @@ query ($slug: String!) {
width width
} }
} }
name,
names { names {
alternatives alternatives
canonical canonical
canonicalLocale canonicalLocale
localized localized(locales: "*")
}, },
} }
...on Character { ...on Character {
@ -107,12 +108,12 @@ query ($slug: String!) {
height height
width width
} }
} },
names { names {
alternatives alternatives
canonical canonical
canonicalLocale canonicalLocale
localized localized(locales: "*")
}, },
} }
} }

View File

@ -36,7 +36,8 @@ final class AnimeTransformer extends AbstractTransformer
$characters = []; $characters = [];
$links = []; $links = [];
$staff = []; $staff = [];
$genres = array_map(static fn ($genre) => $genre['title']['en'], $base['categories']['nodes']); $rawGenres = array_filter($base['categories']['nodes'], static fn ($c) => $c !== null);
$genres = array_map(static fn ($genre) => $genre['title']['en'], $rawGenres);
sort($genres); sort($genres);

View File

@ -35,6 +35,7 @@ final class PersonTransformer extends AbstractTransformer
return Person::from([ return Person::from([
'id' => $data['id'], 'id' => $data['id'],
'name' => $canonicalName, 'name' => $canonicalName,
'birthday' => $data['birthday'],
'image' => $data['image']['original']['url'], 'image' => $data['image']['original']['url'],
'names' => array_diff($data['names']['localized'], [$canonicalName]), 'names' => array_diff($data['names']['localized'], [$canonicalName]),
'description' => $data['description']['en'] ?? '', 'description' => $data['description']['en'] ?? '',
@ -97,7 +98,12 @@ final class PersonTransformer extends AbstractTransformer
{ {
foreach ($data['voices']['nodes'] as $voicing) foreach ($data['voices']['nodes'] as $voicing)
{ {
$character = $voicing['mediaCharacter']['character']; if ($voicing === null)
{
continue;
}
$character = $voicing['mediaCharacter']['character'] ?? [];
$charId = $character['id']; $charId = $character['id'];
$rawMedia = $voicing['mediaCharacter']['media']; $rawMedia = $voicing['mediaCharacter']['media'];
$role = strtolower($voicing['mediaCharacter']['role']); $role = strtolower($voicing['mediaCharacter']['role']);
@ -123,7 +129,7 @@ final class PersonTransformer extends AbstractTransformer
'character' => [ 'character' => [
'id' => $character['id'], 'id' => $character['id'],
'slug' => $character['slug'], 'slug' => $character['slug'],
'image' => $character['image']['original']['url'], 'image' => $character['image']['original']['url'] ?? '',
'canonicalName' => $character['names']['canonical'], 'canonicalName' => $character['names']['canonical'],
], ],
'media' => [ 'media' => [

View File

@ -305,7 +305,16 @@ final class Kitsu
{ {
// Really don't care about languages that aren't english // Really don't care about languages that aren't english
// or Japanese for titles // or Japanese for titles
if ( ! in_array($locale, ['en', 'en_us', 'en_jp', 'ja_jp'], TRUE)) if ( ! in_array($locale, [
'en',
'en-jp',
'en-us',
'en_jp',
'en_us',
'ja-jp',
'ja_jp',
'jp',
], TRUE))
{ {
continue; continue;
} }
@ -486,7 +495,7 @@ final class Kitsu
foreach ($existingTitles as $existing) foreach ($existingTitles as $existing)
{ {
$isSubset = mb_substr_count($existing, $title) > 0; $isSubset = mb_substr_count(mb_strtolower($existing), mb_strtolower($title)) > 0;
$diff = levenshtein(mb_strtolower($existing), mb_strtolower($title)); $diff = levenshtein(mb_strtolower($existing), mb_strtolower($title));
if ($diff <= 4 || $isSubset || mb_strlen($title) > 45 || mb_strlen($existing) > 50) if ($diff <= 4 || $isSubset || mb_strlen($title) > 45 || mb_strlen($existing) > 50)

View File

@ -74,7 +74,7 @@ trait MediaTrait
* Get information about a specific list item * Get information about a specific list item
* for editing/updating that item * for editing/updating that item
*/ */
public function getItem(string $itemId): AnimeListItem|MangaListItem public function getItem(string $itemId): AnimeListItem|MangaListItem|array
{ {
return $this->kitsuModel->getListItem($itemId); return $this->kitsuModel->getListItem($itemId);
} }

View File

@ -21,6 +21,7 @@ final class Person extends AbstractType
{ {
public string $id; public string $id;
public ?string $name; public ?string $name;
public ?string $birthday;
public string $image; public string $image;
public array $names = []; public array $names = [];
public ?string $description; public ?string $description;