All in GraphQL #34

Merged
timw4mail merged 87 commits from develop into master 2020-12-01 10:07:49 -05:00
3 changed files with 58 additions and 5 deletions
Showing only changes of commit e2e845b9c0 - Show all commits

View File

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

View File

@ -94,8 +94,20 @@ query ($slug: String!) {
}
}
status
streamingLinks {
nodes {
dubs
subs
regions
streamer {
id
siteName
}
url
}
}
subtype
synopsis
description
titles {
alternatives
canonical

View File

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