Use images directly from Kitsu for the rest of the views
Some checks failed
timw4mail/HummingBirdAnimeClient/pipeline/head There was a failure building this commit

This commit is contained in:
Timothy Warren 2022-01-17 09:59:27 -05:00
parent f210b157ff
commit 5a5421cee9
14 changed files with 28 additions and 39 deletions

View File

@ -1,7 +1,6 @@
<?php <?php
use Aviat\AnimeClient\Kitsu; use Aviat\AnimeClient\Kitsu;
use function Aviat\AnimeClient\getLocalImg;
?> ?>
<main class="details fixed"> <main class="details fixed">
@ -162,14 +161,14 @@ use function Aviat\AnimeClient\getLocalImg;
use ($component, $url, $helper) { use ($component, $url, $helper) {
$rendered = []; $rendered = [];
foreach ($characterList as $id => $character): foreach ($characterList as $id => $character):
if (empty($character['image']['original'])) if (empty($character['image']))
{ {
continue; continue;
} }
$rendered[] = $component->character( $rendered[] = $component->character(
$character['name'], $character['name'],
$url->generate('character', ['slug' => $character['slug']]), $url->generate('character', ['slug' => $character['slug']]),
$helper->picture("images/characters/{$id}.webp"), $helper->img($character['image']),
(strtolower($role) !== 'main') ? 'small-character' : 'character' (strtolower($role) !== 'main') ? 'small-character' : 'character'
); );
endforeach; endforeach;
@ -187,14 +186,14 @@ use function Aviat\AnimeClient\getLocalImg;
use ($component, $url, $helper) { use ($component, $url, $helper) {
$rendered = []; $rendered = [];
foreach ($staffList as $id => $person): foreach ($staffList as $id => $person):
if (empty($person['image']['original'])) if (empty($person['image']))
{ {
continue; continue;
} }
$rendered[] = $component->character( $rendered[] = $component->character(
$person['name'], $person['name'],
$url->generate('person', ['slug' => $person['slug']]), $url->generate('person', ['slug' => $person['slug']]),
$helper->picture(getLocalImg($person['image']['original'] ?? NULL)), $helper->img($person['image']),
'character small-person', 'character small-person',
); );
endforeach; endforeach;

View File

@ -16,7 +16,7 @@
<tbody> <tbody>
<tr> <tr>
<td rowspan="9"> <td rowspan="9">
<?= $helper->img($item['anime']['cover_image'], ["width" => "390"]) ?> <?= $helper->img($item['anime']['cover_image']) ?>
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@ -41,7 +41,7 @@ use Aviat\AnimeClient\Kitsu;
$rendered[] = $component->media( $rendered[] = $component->media(
array_merge([$item['title']], $item['titles']), array_merge([$item['title']], $item['titles']),
$url->generate("{$mediaType}.details", ['id' => $item['slug']]), $url->generate("{$mediaType}.details", ['id' => $item['slug']]),
$helper->picture("images/{$mediaType}/{$item['id']}.webp") $helper->img(Kitsu::getPosterImage($item), ['width' => 220, 'loading' => 'lazy']),
); );
} }
@ -75,7 +75,7 @@ use Aviat\AnimeClient\Kitsu;
$link = $url->generate('person', ['id' => $c['person']['id']]); $link = $url->generate('person', ['id' => $c['person']['id']]);
?> ?>
<a href="<?= $link ?>"> <a href="<?= $link ?>">
<?= $helper->picture(getLocalImg($c['person']['image'], TRUE)) ?> <?= $helper->img($c['person']['image']) ?>
<div class="name"> <div class="name">
<?= $c['person']['name'] ?> <?= $c['person']['name'] ?>
</div> </div>
@ -91,7 +91,7 @@ use Aviat\AnimeClient\Kitsu;
$titles = Kitsu::filterTitles($series['attributes']); $titles = Kitsu::filterTitles($series['attributes']);
?> ?>
<a href="<?= $link ?>"> <a href="<?= $link ?>">
<?= $helper->picture(getLocalImg($series['attributes']['posterImage']['small'], TRUE)) ?> <?= $helper->img(Kitsu::getPosterImage($series['attributes'])) ?>
</a> </a>
<div class="name"> <div class="name">
<a href="<?= $link ?>"> <a href="<?= $link ?>">
@ -121,12 +121,12 @@ use Aviat\AnimeClient\Kitsu;
$person = $component->character( $person = $component->character(
$c['person']['name'], $c['person']['name'],
$url->generate('person', ['slug' => $c['person']['slug']]), $url->generate('person', ['slug' => $c['person']['slug']]),
$helper->picture(getLocalImg($c['person']['image'])) $helper->img($c['person']['image']['original']['url']),
); );
$medias = array_map(fn ($series) => $component->media( $medias = array_map(fn ($series) => $component->media(
array_merge([$series['title']], $series['titles']), array_merge([$series['title']], $series['titles']),
$url->generate('anime.details', ['id' => $series['slug']]), $url->generate('anime.details', ['id' => $series['slug']]),
$helper->picture(getLocalImg($series['posterImage'], TRUE)) $helper->img(Kitsu::getPosterImage($series)),
), $c['series']); ), $c['series']);
$media = implode('', array_map('mb_trim', $medias)); $media = implode('', array_map('mb_trim', $medias));

View File

@ -7,11 +7,9 @@
<article class="flex flex-no-wrap flex-justify-start"> <article class="flex flex-no-wrap flex-justify-start">
<section class="flex-self-center history-img"> <section class="flex-self-center history-img">
<a href="<?= $item['url'] ?>"> <a href="<?= $item['url'] ?>">
<?= $helper->picture( <?= $helper->img(
$item['coverImg'], $item['coverImg'],
'jpg',
['width' => '110px', 'height' => '156px'], ['width' => '110px', 'height' => '156px'],
['width' => '110px', 'height' => '156px']
) ?> ) ?>
</a> </a>
</section> </section>

View File

@ -79,7 +79,7 @@
$rendered[] = $component->character( $rendered[] = $component->character(
$char['name'], $char['name'],
$url->generate('character', ['slug' => $char['slug']]), $url->generate('character', ['slug' => $char['slug']]),
$helper->picture("images/characters/{$id}.webp"), $helper->img($char['image'], ['loading' => 'lazy']),
($role !== 'main') ? 'small-character' : 'character' ($role !== 'main') ? 'small-character' : 'character'
); );
} }
@ -96,7 +96,7 @@
fn ($person) => $component->character( fn ($person) => $component->character(
$person['name'], $person['name'],
$url->generate('person', ['slug' => $person['slug']]), $url->generate('person', ['slug' => $person['slug']]),
$helper->picture("images/people/{$person['id']}.webp") $helper->img($person['image']),
), ),
$people $people
)) ))

View File

@ -18,7 +18,7 @@
<tbody> <tbody>
<tr> <tr>
<td rowspan="9"> <td rowspan="9">
<?= $helper->image($item['manga']['image'], ["width" => "390"]) ?> <?= $helper->img($item['manga']['image']) ?>
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@ -1,6 +1,3 @@
<?php
use function Aviat\AnimeClient\getLocalImg;
?>
<main class="details fixed"> <main class="details fixed">
<section class="flex flex-no-wrap"> <section class="flex flex-no-wrap">
<div> <div>
@ -40,7 +37,7 @@ use function Aviat\AnimeClient\getLocalImg;
<?= $component->media( <?= $component->media(
$series['titles'], $series['titles'],
$url->generate("{$mediaType}.details", ['id' => $series['slug']]), $url->generate("{$mediaType}.details", ['id' => $series['slug']]),
$helper->img($series['image'], ['width' => 220]) $helper->img($series['image'], ['width' => 220, 'loading' => 'lazy'])
) ?> ) ?>
<?php endforeach; ?> <?php endforeach; ?>
</section> </section>
@ -61,7 +58,7 @@ use function Aviat\AnimeClient\getLocalImg;
$character = $component->character( $character = $component->character(
$item['character']['canonicalName'], $item['character']['canonicalName'],
$url->generate('character', ['slug' => $item['character']['slug']]), $url->generate('character', ['slug' => $item['character']['slug']]),
$helper->picture(getLocalImg($item['character']['image']['original'] ?? null)) $helper->img($item['character']['image'], ['loading' => 'lazy']),
); );
$medias = []; $medias = [];
foreach ($item['media'] as $sid => $series) foreach ($item['media'] as $sid => $series)
@ -69,7 +66,7 @@ use function Aviat\AnimeClient\getLocalImg;
$medias[] = $component->media( $medias[] = $component->media(
$series['titles'], $series['titles'],
$url->generate('anime.details', ['id' => $series['slug']]), $url->generate('anime.details', ['id' => $series['slug']]),
$helper->img($series['image'], ['width' => 220]) $helper->img($series['image'], ['width' => 220, 'loading' => 'lazy'])
); );
} }
$media = implode('', array_map('mb_trim', $medias)); $media = implode('', array_map('mb_trim', $medias));

View File

@ -40,12 +40,10 @@ query ($slug: String!) {
} }
type type
} }
voices(first: 100) { role
voices(first: 10) {
nodes { nodes {
id id
licensor {
name
}
locale locale
person { person {
id id

View File

@ -52,7 +52,7 @@ query ($slug: String!) {
} }
} }
} }
voices(first: 100) { voices(first: 500) {
nodes { nodes {
locale locale
mediaCharacter { mediaCharacter {

View File

@ -59,7 +59,7 @@ final class AnimeTransformer extends AbstractTransformer {
$details = $rawCharacter['character']; $details = $rawCharacter['character'];
$characters[$type][$details['id']] = [ $characters[$type][$details['id']] = [
'image' => $details['image'], 'image' => $details['image']['original']['url'] ?? '',
'name' => $details['names']['canonical'], 'name' => $details['names']['canonical'],
'slug' => $details['slug'], 'slug' => $details['slug'],
]; ];
@ -103,9 +103,7 @@ final class AnimeTransformer extends AbstractTransformer {
$staff[$role][$person['id']] = [ $staff[$role][$person['id']] = [
'id' => $person['id'], 'id' => $person['id'],
'name' => $name, 'name' => $name,
'image' => [ 'image' => $person['image']['original']['url'],
'original' => $person['image']['original']['url'] ?? '',
],
'slug' => $person['slug'], 'slug' => $person['slug'],
]; ];

View File

@ -148,7 +148,7 @@ final class CharacterTransformer extends AbstractTransformer {
'slug' => $voiceMap['media']['slug'], 'slug' => $voiceMap['media']['slug'],
'title' => $voiceMap['media']['titles']['canonical'], 'title' => $voiceMap['media']['titles']['canonical'],
'titles' => Kitsu::getFilteredTitles($voiceMap['media']['titles']), 'titles' => Kitsu::getFilteredTitles($voiceMap['media']['titles']),
'posterImage' => $voiceMap['media']['posterImage']['views'][1]['url'], 'posterImage' => Kitsu::getPosterImage($voiceMap['media']),
]; ];
uasort($castings['Voice Actor'][$lang][$id]['series'], $titleSort); uasort($castings['Voice Actor'][$lang][$id]['series'], $titleSort);

View File

@ -58,7 +58,7 @@ final class MangaTransformer extends AbstractTransformer {
$details = $rawCharacter['character']; $details = $rawCharacter['character'];
$characters[$type][$details['id']] = [ $characters[$type][$details['id']] = [
'image' => $details['image'], 'image' => $details['image']['original']['url'],
'name' => $details['names']['canonical'], 'name' => $details['names']['canonical'],
'slug' => $details['slug'], 'slug' => $details['slug'],
]; ];
@ -103,9 +103,7 @@ final class MangaTransformer extends AbstractTransformer {
'id' => $person['id'], 'id' => $person['id'],
'slug' => $person['slug'], 'slug' => $person['slug'],
'name' => $name, 'name' => $name,
'image' => [ 'image' => $person['image']['original']['url'],
'original' => $person['image']['original']['url'] ?? '',
],
]; ];
usort($staff[$role], fn ($a, $b) => $a['name'] <=> $b['name']); usort($staff[$role], fn ($a, $b) => $a['name'] <=> $b['name']);

View File

@ -106,6 +106,7 @@ final class PersonTransformer extends AbstractTransformer {
$media = [ $media = [
'id' => $rawMedia['id'], 'id' => $rawMedia['id'],
'slug' => $rawMedia['slug'], 'slug' => $rawMedia['slug'],
'image' => Kitsu::getPosterImage($rawMedia),
'titles' => array_merge( 'titles' => array_merge(
[$rawMedia['titles']['canonical']], [$rawMedia['titles']['canonical']],
Kitsu::getFilteredTitles($rawMedia['titles']), Kitsu::getFilteredTitles($rawMedia['titles']),
@ -123,7 +124,7 @@ final class PersonTransformer extends AbstractTransformer {
'character' => [ 'character' => [
'id' => $character['id'], 'id' => $character['id'],
'slug' => $character['slug'], 'slug' => $character['slug'],
'image' => Kitsu::getPosterImage($character), 'image' => $character['image']['original']['url'],
'canonicalName' => $character['names']['canonical'], 'canonicalName' => $character['names']['canonical'],
], ],
'media' => [ 'media' => [

View File

@ -343,7 +343,7 @@ final class Kitsu {
* @param int $size * @param int $size
* @return string * @return string
*/ */
public static function getPosterImage(array $base, int $size = 2): string public static function getPosterImage(array $base, int $size = 1): string
{ {
$rawUrl = $base['posterImage']['views'][$size]['url'] $rawUrl = $base['posterImage']['views'][$size]['url']
?? $base['posterImage']['original']['url'] ?? $base['posterImage']['original']['url']