Fix display of streaming links in cover and list views

This commit is contained in:
Timothy Warren 2017-01-25 13:37:39 -05:00
parent 1818bf105d
commit b8f75e14ec
5 changed files with 41 additions and 6 deletions

View File

@ -54,7 +54,7 @@
<?php foreach($item['anime']['streaming_links'] as $link): ?> <?php foreach($item['anime']['streaming_links'] as $link): ?>
<div class="cover_streaming_link"> <div class="cover_streaming_link">
<?php if($link['meta']['link']): ?> <?php if($link['meta']['link']): ?>
<a href="<?= $link['link']?>"> <a href="<?= $link['link']?>" title="Stream '<?= $item['anime']['title'] ?>' on <?= $link['meta']['name'] ?>">
<?= $link['meta']['logo'] ?> <?= $link['meta']['logo'] ?>
</a> </a>
<?php else: ?> <?php else: ?>

View File

@ -162,6 +162,39 @@ class Kitsu {
return $links; return $links;
} }
/**
* Reorganize streaming links for the current list item
*
* @param array $included
* @return array
*/
public static function parseListItemStreamingLinks(array $included, string $animeId): array
{
// Anime lists have a different structure to search through
if (array_key_exists('anime', $included) && ! array_key_exists('streamingLinks', $included))
{
$links = [];
$anime = $included['anime'][$animeId];
if (count($anime['relationships']['streamingLinks']) > 0)
{
foreach ($anime['relationships']['streamingLinks'] as $streamingLink)
{
$host = parse_url($streamingLink['url'], \PHP_URL_HOST);
$links[] = [
'meta' => static::getServiceMetaData($host),
'link' => $streamingLink['url'],
'subs' => $streamingLink['subs'],
'dubs' => $streamingLink['dubs']
];
}
}
return $links;
}
}
/** /**
* Filter out duplicate and very similar names from * Filter out duplicate and very similar names from
* *

View File

@ -175,7 +175,7 @@ class KitsuModel {
'include' => 'media,media.genres,media.mappings,anime.streamingLinks', 'include' => 'media,media.genres,media.mappings,anime.streamingLinks',
'page' => [ 'page' => [
'offset' => 0, 'offset' => 0,
'limit' => 500 'limit' => 600
] ]
] ]
]; ];

View File

@ -61,6 +61,8 @@ class AnimeListTransformer extends AbstractTransformer {
} }
} }
$streamingLinks = Kitsu::parseListItemStreamingLinks($included, $animeId);
return [ return [
'id' => $item['id'], 'id' => $item['id'],
'mal_id' => $MALid, 'mal_id' => $MALid,
@ -78,12 +80,13 @@ class AnimeListTransformer extends AbstractTransformer {
], ],
'anime' => [ 'anime' => [
'age_rating' => $anime['ageRating'], 'age_rating' => $anime['ageRating'],
'title' => $anime['canonicalTitle'],
'titles' => Kitsu::filterTitles($anime), 'titles' => Kitsu::filterTitles($anime),
'slug' => $anime['slug'], 'slug' => $anime['slug'],
'type' => $this->string($anime['showType'])->upperCaseFirst()->__toString(), 'type' => $this->string($anime['showType'])->upperCaseFirst()->__toString(),
'image' => $anime['posterImage']['small'], 'image' => $anime['posterImage']['small'],
'genres' => $genres, 'genres' => $genres,
'streaming_links' => Kitsu::parseStreamingLinks($included), 'streaming_links' => $streamingLinks,
], ],
'watching_status' => $item['attributes']['status'], 'watching_status' => $item['attributes']['status'],
'notes' => $item['attributes']['notes'], 'notes' => $item['attributes']['notes'],

View File

@ -34,7 +34,7 @@ class API extends Model {
/** /**
* Cache manager * Cache manager
* @var \Aviat\Ion\Cache\CacheInterface * @var \Psr\Cache\CacheItemPoolInterface
*/ */
protected $cache; protected $cache;
@ -56,7 +56,7 @@ class API extends Model {
} }
/** /**
* Sort the manga entries by their title * Sort the list entries by their title
* *
* @codeCoverageIgnore * @codeCoverageIgnore
* @param array $array * @param array $array
@ -75,4 +75,3 @@ class API extends Model {
array_multisort($sort, SORT_ASC, $array); array_multisort($sort, SORT_ASC, $array);
} }
} }
// End of BaseApiModel.php