From cbff3867343c10bcfc13b187308a406d71bed4d6 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 18 May 2023 12:55:38 -0400 Subject: [PATCH] Add specific locale arguments to keep up with the API --- app/views/character/details.php | 2 +- app/views/person/details.php | 3 +++ src/AnimeClient/API/Kitsu/Model.php | 6 +++--- .../API/Kitsu/Queries/AnimeDetails.graphql | 10 +++++----- .../API/Kitsu/Queries/AnimeDetailsById.graphql | 10 +++++----- .../API/Kitsu/Queries/CharacterDetails.graphql | 12 ++++++------ .../API/Kitsu/Queries/GetLibrary.graphql | 2 +- .../API/Kitsu/Queries/GetLibraryItem.graphql | 4 ++-- .../API/Kitsu/Queries/GetUserHistory.graphql | 2 +- .../API/Kitsu/Queries/MangaDetails.graphql | 4 ++-- .../API/Kitsu/Queries/MangaDetailsById.graphql | 4 ++-- .../API/Kitsu/Queries/PersonDetails.graphql | 8 ++++---- .../API/Kitsu/Queries/RandomMedia.graphql | 8 ++++---- .../API/Kitsu/Queries/SearchAnime.graphql | 2 +- .../API/Kitsu/Queries/SearchManga.graphql | 2 +- .../API/Kitsu/Queries/UserDetails.graphql | 11 ++++++----- .../API/Kitsu/Transformer/AnimeTransformer.php | 3 ++- .../API/Kitsu/Transformer/PersonTransformer.php | 10 ++++++++-- src/AnimeClient/Kitsu.php | 13 +++++++++++-- src/AnimeClient/Model/MediaTrait.php | 2 +- src/AnimeClient/Types/Person.php | 1 + 21 files changed, 70 insertions(+), 49 deletions(-) diff --git a/app/views/character/details.php b/app/views/character/details.php index 0a0977a7..9e0baa34 100644 --- a/app/views/character/details.php +++ b/app/views/character/details.php @@ -26,7 +26,7 @@ use Aviat\AnimeClient\Kitsu;

-

', $data['description']) ?>

+

diff --git a/app/views/person/details.php b/app/views/person/details.php index b3c362c6..eb06775a 100644 --- a/app/views/person/details.php +++ b/app/views/person/details.php @@ -8,6 +8,9 @@

+ +

+

diff --git a/src/AnimeClient/API/Kitsu/Model.php b/src/AnimeClient/API/Kitsu/Model.php index b4cf554f..018aea92 100644 --- a/src/AnimeClient/API/Kitsu/Model.php +++ b/src/AnimeClient/API/Kitsu/Model.php @@ -535,14 +535,14 @@ final class Model * Get the data for a specific list item, generally for editing * * @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); if ( ! isset($baseData['data']['findLibraryEntryById'])) { - return []; + // We need to get the errors... + return $baseData; } return (new LibraryEntryTransformer())->transform($baseData['data']['findLibraryEntryById']); diff --git a/src/AnimeClient/API/Kitsu/Queries/AnimeDetails.graphql b/src/AnimeClient/API/Kitsu/Queries/AnimeDetails.graphql index 793028d7..ea57178c 100644 --- a/src/AnimeClient/API/Kitsu/Queries/AnimeDetails.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/AnimeDetails.graphql @@ -19,7 +19,7 @@ query ($slug: String!) { } categories(first: 100) { nodes { - title + title(locales: "en") } } characters(first: 100) { @@ -29,7 +29,7 @@ query ($slug: String!) { names { alternatives canonical - localized + localized(locales: "*") } image { original { @@ -50,7 +50,7 @@ query ($slug: String!) { startCursor } } - description + description(locales: "en") startDate endDate episodeCount @@ -87,7 +87,7 @@ query ($slug: String!) { names { alternatives canonical - localized + localized(locales: "*") } slug } @@ -118,7 +118,7 @@ query ($slug: String!) { alternatives canonical canonicalLocale - localized + localized(locales: ["en", "en-t-ja", "ja", "ja-jp"]) } totalLength youtubeTrailerVideoId diff --git a/src/AnimeClient/API/Kitsu/Queries/AnimeDetailsById.graphql b/src/AnimeClient/API/Kitsu/Queries/AnimeDetailsById.graphql index a3b2bc0d..e39e9a6d 100644 --- a/src/AnimeClient/API/Kitsu/Queries/AnimeDetailsById.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/AnimeDetailsById.graphql @@ -19,7 +19,7 @@ query ($id: ID!) { } categories(first: 100) { nodes { - title + title(locales: "en") } } characters(first: 100) { @@ -29,7 +29,7 @@ query ($id: ID!) { names { alternatives canonical - localized + localized(locales: "*") } image { original { @@ -50,7 +50,7 @@ query ($id: ID!) { startCursor } } - description + description(locales: "en") startDate endDate episodeCount @@ -87,7 +87,7 @@ query ($id: ID!) { names { alternatives canonical - localized + localized(locales: "*") } slug } @@ -118,7 +118,7 @@ query ($id: ID!) { alternatives canonical canonicalLocale - localized + localized(locales: ["en", "en-t-ja", "ja", "ja-jp"]) } totalLength youtubeTrailerVideoId diff --git a/src/AnimeClient/API/Kitsu/Queries/CharacterDetails.graphql b/src/AnimeClient/API/Kitsu/Queries/CharacterDetails.graphql index 587ae3c8..54768910 100644 --- a/src/AnimeClient/API/Kitsu/Queries/CharacterDetails.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/CharacterDetails.graphql @@ -6,12 +6,12 @@ query ($slug: String!) { url } } - description + description(locales: "en") names { alternatives canonical canonicalLocale - localized + localized(locales: "*") }, media(first: 100) { nodes { @@ -22,7 +22,7 @@ query ($slug: String!) { alternatives canonical canonicalLocale - localized + localized(locales: ["en", "en-t-ja", "ja", "ja-jp"]) } posterImage { original { @@ -41,7 +41,7 @@ query ($slug: String!) { type } role - voices(first: 10) { + voices(first: 10, locale:"*", sort:{direction:ASCENDING, on: UPDATED_AT}) { nodes { id locale @@ -53,7 +53,7 @@ query ($slug: String!) { alternatives canonical canonicalLocale - localized + localized(locales: "*") } image { original { @@ -70,4 +70,4 @@ query ($slug: String!) { } slug } -} \ No newline at end of file +} diff --git a/src/AnimeClient/API/Kitsu/Queries/GetLibrary.graphql b/src/AnimeClient/API/Kitsu/Queries/GetLibrary.graphql index f2dd3bdd..8d34ccb1 100644 --- a/src/AnimeClient/API/Kitsu/Queries/GetLibrary.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/GetLibrary.graphql @@ -57,7 +57,7 @@ query ( type titles { canonical - localized + localized(locales: "*") alternatives } ...on Anime { diff --git a/src/AnimeClient/API/Kitsu/Queries/GetLibraryItem.graphql b/src/AnimeClient/API/Kitsu/Queries/GetLibraryItem.graphql index e970eeb5..0d96fb56 100644 --- a/src/AnimeClient/API/Kitsu/Queries/GetLibraryItem.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/GetLibraryItem.graphql @@ -16,7 +16,7 @@ query($id: ID!) { ageRating categories(first: 100) { nodes { - title + title(locales: "*") } } mappings(first: 10) { @@ -41,7 +41,7 @@ query($id: ID!) { endDate titles { canonical - localized + localized(locales: "*") canonicalLocale } type diff --git a/src/AnimeClient/API/Kitsu/Queries/GetUserHistory.graphql b/src/AnimeClient/API/Kitsu/Queries/GetUserHistory.graphql index 78eca809..9418c22a 100644 --- a/src/AnimeClient/API/Kitsu/Queries/GetUserHistory.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/GetUserHistory.graphql @@ -33,7 +33,7 @@ query ($slug: String!) { titles { alternatives canonical - localized + localized(locales: "*") } ...on Anime { episodeCount diff --git a/src/AnimeClient/API/Kitsu/Queries/MangaDetails.graphql b/src/AnimeClient/API/Kitsu/Queries/MangaDetails.graphql index 9393aeff..7422c360 100644 --- a/src/AnimeClient/API/Kitsu/Queries/MangaDetails.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/MangaDetails.graphql @@ -19,7 +19,7 @@ query ($slug: String!) { } categories(first: 100) { nodes { - title + title(locales: "*") } } chapterCount @@ -116,7 +116,7 @@ query ($slug: String!) { titles { canonical canonicalLocale - localized + localized(locales: "*") } } } diff --git a/src/AnimeClient/API/Kitsu/Queries/MangaDetailsById.graphql b/src/AnimeClient/API/Kitsu/Queries/MangaDetailsById.graphql index 09a3aab6..6b8b129b 100644 --- a/src/AnimeClient/API/Kitsu/Queries/MangaDetailsById.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/MangaDetailsById.graphql @@ -19,7 +19,7 @@ query ($id: ID!) { } categories(first: 100) { nodes { - title + title(locales: "*") } } chapterCount @@ -116,7 +116,7 @@ query ($id: ID!) { titles { canonical canonicalLocale - localized + localized(locales: "*") } } } diff --git a/src/AnimeClient/API/Kitsu/Queries/PersonDetails.graphql b/src/AnimeClient/API/Kitsu/Queries/PersonDetails.graphql index 9830a947..9cd02d4b 100644 --- a/src/AnimeClient/API/Kitsu/Queries/PersonDetails.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/PersonDetails.graphql @@ -1,7 +1,7 @@ query ($slug: String!) { findPersonBySlug(slug: $slug) { id - description + description(locales: "en") birthday image { original { @@ -20,7 +20,7 @@ query ($slug: String!) { names { alternatives canonical - localized + localized(locales: "*") } mediaStaff(first: 100) { nodes { @@ -47,7 +47,7 @@ query ($slug: String!) { titles { alternatives canonical - localized + localized(locales: ["en", "en-t-ja", "ja", "ja-jp"]) } } } @@ -91,7 +91,7 @@ query ($slug: String!) { } titles { canonical - localized + localized(locales: ["en", "en-t-ja", "ja", "ja-jp"]) } } } diff --git a/src/AnimeClient/API/Kitsu/Queries/RandomMedia.graphql b/src/AnimeClient/API/Kitsu/Queries/RandomMedia.graphql index 63e19476..c0194711 100644 --- a/src/AnimeClient/API/Kitsu/Queries/RandomMedia.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/RandomMedia.graphql @@ -26,7 +26,7 @@ query ($type: MediaTypeEnum!) { } categories(first: 100) { nodes { - title + title(locales: "*") } } characters(first: 100) { @@ -36,7 +36,7 @@ query ($type: MediaTypeEnum!) { names { alternatives canonical - localized + localized(locales: "*") } image { original { @@ -90,7 +90,7 @@ query ($type: MediaTypeEnum!) { names { alternatives canonical - localized + localized(locales: "*") } slug } @@ -108,7 +108,7 @@ query ($type: MediaTypeEnum!) { alternatives canonical canonicalLocale - localized + localized(locales: "*") } ...on Anime { episodeCount diff --git a/src/AnimeClient/API/Kitsu/Queries/SearchAnime.graphql b/src/AnimeClient/API/Kitsu/Queries/SearchAnime.graphql index a91b6c6f..eda7a3d0 100644 --- a/src/AnimeClient/API/Kitsu/Queries/SearchAnime.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/SearchAnime.graphql @@ -19,7 +19,7 @@ query ($query: String!) { slug titles { canonical - localized + localized(locales: ["en", "en-t-ja", "ja", "ja-jp"]) alternatives } myLibraryEntry { diff --git a/src/AnimeClient/API/Kitsu/Queries/SearchManga.graphql b/src/AnimeClient/API/Kitsu/Queries/SearchManga.graphql index 0e4bb4c6..687b78c1 100644 --- a/src/AnimeClient/API/Kitsu/Queries/SearchManga.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/SearchManga.graphql @@ -19,7 +19,7 @@ query ($query: String!) { slug titles { canonical - localized + localized(locales: ["en", "en-t-ja", "ja", "ja-jp"]) alternatives } myLibraryEntry { diff --git a/src/AnimeClient/API/Kitsu/Queries/UserDetails.graphql b/src/AnimeClient/API/Kitsu/Queries/UserDetails.graphql index 492cb6a6..401cc12b 100644 --- a/src/AnimeClient/API/Kitsu/Queries/UserDetails.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/UserDetails.graphql @@ -52,7 +52,7 @@ query ($slug: String!) { } titles { canonical - localized + localized(locales: ["en", "en-t-ja", "ja", "ja-jp"]) } } ...on Manga { @@ -72,7 +72,7 @@ query ($slug: String!) { } titles { canonical - localized + localized(locales: ["en", "en-t-ja", "ja", "ja-jp"]) } } ...on Person { @@ -88,11 +88,12 @@ query ($slug: String!) { width } } + name, names { alternatives canonical canonicalLocale - localized + localized(locales: "*") }, } ...on Character { @@ -107,12 +108,12 @@ query ($slug: String!) { height width } - } + }, names { alternatives canonical canonicalLocale - localized + localized(locales: "*") }, } } diff --git a/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php b/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php index 24baa11a..6bfa2e91 100644 --- a/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php +++ b/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php @@ -36,7 +36,8 @@ final class AnimeTransformer extends AbstractTransformer $characters = []; $links = []; $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); diff --git a/src/AnimeClient/API/Kitsu/Transformer/PersonTransformer.php b/src/AnimeClient/API/Kitsu/Transformer/PersonTransformer.php index ae966ebe..e8c8eadb 100644 --- a/src/AnimeClient/API/Kitsu/Transformer/PersonTransformer.php +++ b/src/AnimeClient/API/Kitsu/Transformer/PersonTransformer.php @@ -35,6 +35,7 @@ final class PersonTransformer extends AbstractTransformer return Person::from([ 'id' => $data['id'], 'name' => $canonicalName, + 'birthday' => $data['birthday'], 'image' => $data['image']['original']['url'], 'names' => array_diff($data['names']['localized'], [$canonicalName]), 'description' => $data['description']['en'] ?? '', @@ -97,7 +98,12 @@ final class PersonTransformer extends AbstractTransformer { foreach ($data['voices']['nodes'] as $voicing) { - $character = $voicing['mediaCharacter']['character']; + if ($voicing === null) + { + continue; + } + + $character = $voicing['mediaCharacter']['character'] ?? []; $charId = $character['id']; $rawMedia = $voicing['mediaCharacter']['media']; $role = strtolower($voicing['mediaCharacter']['role']); @@ -123,7 +129,7 @@ final class PersonTransformer extends AbstractTransformer 'character' => [ 'id' => $character['id'], 'slug' => $character['slug'], - 'image' => $character['image']['original']['url'], + 'image' => $character['image']['original']['url'] ?? '', 'canonicalName' => $character['names']['canonical'], ], 'media' => [ diff --git a/src/AnimeClient/Kitsu.php b/src/AnimeClient/Kitsu.php index e249c68e..b3525936 100644 --- a/src/AnimeClient/Kitsu.php +++ b/src/AnimeClient/Kitsu.php @@ -305,7 +305,16 @@ final class Kitsu { // Really don't care about languages that aren't english // 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; } @@ -486,7 +495,7 @@ final class Kitsu 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)); if ($diff <= 4 || $isSubset || mb_strlen($title) > 45 || mb_strlen($existing) > 50) diff --git a/src/AnimeClient/Model/MediaTrait.php b/src/AnimeClient/Model/MediaTrait.php index 8e0d3177..cd2f8579 100644 --- a/src/AnimeClient/Model/MediaTrait.php +++ b/src/AnimeClient/Model/MediaTrait.php @@ -74,7 +74,7 @@ trait MediaTrait * Get information about a specific list 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); } diff --git a/src/AnimeClient/Types/Person.php b/src/AnimeClient/Types/Person.php index 0b4f39a6..6038894f 100644 --- a/src/AnimeClient/Types/Person.php +++ b/src/AnimeClient/Types/Person.php @@ -21,6 +21,7 @@ final class Person extends AbstractType { public string $id; public ?string $name; + public ?string $birthday; public string $image; public array $names = []; public ?string $description;