Add specific locale arguments to keep up with the API
Some checks failed
timw4mail/HummingBirdAnimeClient/pipeline/head There was a failure building this commit

This commit is contained in:
Timothy Warren 2023-05-18 12:55:38 -04:00
parent b13c35eaec
commit cbff386734
21 changed files with 70 additions and 49 deletions

View File

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

View File

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

View File

@ -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']);

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

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

View File

@ -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

View File

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

View File

@ -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: "*")
}
}
}

View File

@ -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: "*")
}
}
}

View File

@ -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"])
}
}
}

View File

@ -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

View File

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

View File

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

View File

@ -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: "*")
},
}
}

View File

@ -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);

View File

@ -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' => [

View File

@ -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)

View File

@ -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);
}

View File

@ -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;