Add streaming links back to anime description pages, see #27
This commit is contained in:
parent
56f7d5142d
commit
79aee53524
@ -97,7 +97,7 @@ final class Kitsu {
|
||||
* @param array $included
|
||||
* @return array
|
||||
*/
|
||||
public static function parseStreamingLinks(array $included): array
|
||||
public static function oldParseStreamingLinks(array $included): array
|
||||
{
|
||||
if (
|
||||
( ! array_key_exists('streamingLinks', $included)) ||
|
||||
@ -135,6 +135,47 @@ final class Kitsu {
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorganize streaming links
|
||||
*
|
||||
* @param array $included
|
||||
* @return array
|
||||
*/
|
||||
public static function parseStreamingLinks(array $nodes): array
|
||||
{
|
||||
if (count($nodes) === 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$links = [];
|
||||
|
||||
foreach ($nodes as $streamingLink)
|
||||
{
|
||||
$url = $streamingLink['url'];
|
||||
|
||||
// 'Fix' links that start with the hostname,
|
||||
// rather than a protocol
|
||||
if (strpos($url, '//') === FALSE)
|
||||
{
|
||||
$url = '//' . $url;
|
||||
}
|
||||
|
||||
$host = parse_url($url, \PHP_URL_HOST);
|
||||
|
||||
$links[] = [
|
||||
'meta' => static::getServiceMetaData($host),
|
||||
'link' => $streamingLink['url'],
|
||||
'subs' => $streamingLink['subs'],
|
||||
'dubs' => $streamingLink['dubs']
|
||||
];
|
||||
}
|
||||
|
||||
usort($links, fn ($a, $b) => $a['meta']['name'] <=> $b['meta']['name']);
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorganize streaming links for the current list item
|
||||
*
|
||||
@ -152,7 +193,7 @@ final class Kitsu {
|
||||
|
||||
if (count($anime['relationships']['streamingLinks']) > 0)
|
||||
{
|
||||
return static::parseStreamingLinks($anime['relationships']);
|
||||
return static::oldParseStreamingLinks($anime['relationships']);
|
||||
}
|
||||
|
||||
return $links;
|
||||
|
@ -94,8 +94,20 @@ query ($slug: String!) {
|
||||
}
|
||||
}
|
||||
status
|
||||
streamingLinks {
|
||||
nodes {
|
||||
dubs
|
||||
subs
|
||||
regions
|
||||
streamer {
|
||||
id
|
||||
siteName
|
||||
}
|
||||
url
|
||||
}
|
||||
}
|
||||
subtype
|
||||
synopsis
|
||||
description
|
||||
titles {
|
||||
alternatives
|
||||
canonical
|
||||
|
@ -116,8 +116,8 @@ final class AnimeTransformer extends AbstractTransformer {
|
||||
'staff' => $staff,
|
||||
'show_type' => $base['subtype'],
|
||||
'status' => Kitsu::getAiringStatus($base['startDate'], $base['endDate']),
|
||||
'streaming_links' => [], // Kitsu::parseStreamingLinks($item['included']),
|
||||
'synopsis' => $base['synopsis']['en'],
|
||||
'streaming_links' => Kitsu::parseStreamingLinks($base['streamingLinks']['nodes']),
|
||||
'synopsis' => $base['description']['en'],
|
||||
'title' => $title,
|
||||
'titles' => $titles,
|
||||
'titles_more' => $titles_more,
|
||||
|
Loading…
Reference in New Issue
Block a user