Add streaming links back to anime description pages, see #27
Some checks failed
timw4mail/HummingBirdAnimeClient/pipeline/head There was a failure building this commit

This commit is contained in:
Timothy Warren 2020-08-17 10:45:17 -04:00
parent 24def28cda
commit e2e845b9c0
3 changed files with 58 additions and 5 deletions

View File

@ -97,7 +97,7 @@ final class Kitsu {
* @param array $included * @param array $included
* @return array * @return array
*/ */
public static function parseStreamingLinks(array $included): array public static function oldParseStreamingLinks(array $included): array
{ {
if ( if (
( ! array_key_exists('streamingLinks', $included)) || ( ! array_key_exists('streamingLinks', $included)) ||
@ -135,6 +135,47 @@ final class Kitsu {
return $links; 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 * Reorganize streaming links for the current list item
* *
@ -152,7 +193,7 @@ final class Kitsu {
if (count($anime['relationships']['streamingLinks']) > 0) if (count($anime['relationships']['streamingLinks']) > 0)
{ {
return static::parseStreamingLinks($anime['relationships']); return static::oldParseStreamingLinks($anime['relationships']);
} }
return $links; return $links;

View File

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

View File

@ -116,8 +116,8 @@ final class AnimeTransformer extends AbstractTransformer {
'staff' => $staff, 'staff' => $staff,
'show_type' => $base['subtype'], 'show_type' => $base['subtype'],
'status' => Kitsu::getAiringStatus($base['startDate'], $base['endDate']), 'status' => Kitsu::getAiringStatus($base['startDate'], $base['endDate']),
'streaming_links' => [], // Kitsu::parseStreamingLinks($item['included']), 'streaming_links' => Kitsu::parseStreamingLinks($base['streamingLinks']['nodes']),
'synopsis' => $base['synopsis']['en'], 'synopsis' => $base['description']['en'],
'title' => $title, 'title' => $title,
'titles' => $titles, 'titles' => $titles,
'titles_more' => $titles_more, 'titles_more' => $titles_more,