Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
4 changed files with 11 additions and 124 deletions
Showing only changes of commit f0e3aa6fd7 - Show all commits

View File

@ -22,9 +22,9 @@ use Aviat\Ion\Enum;
* Possible values for watching status for the current anime
*/
final class Kitsu extends Enum {
public const WATCHING = 'current';
public const PLAN_TO_WATCH = 'planned';
public const ON_HOLD = 'on_hold';
public const DROPPED = 'dropped';
public const COMPLETED = 'completed';
public const WATCHING = 'CURRENT';
public const PLAN_TO_WATCH = 'PLANNED';
public const ON_HOLD = 'ON_HOLD';
public const DROPPED = 'DROPPED';
public const COMPLETED = 'COMPLETED';
}

View File

@ -42,8 +42,8 @@ final class Kitsu {
/**
* Determine whether an anime is airing, finished airing, or has not yet aired
*
* @param string $startDate
* @param string $endDate
* @param string|null $startDate
* @param string|null $endDate
* @return string
*/
public static function getAiringStatus(string $startDate = NULL, string $endDate = NULL): string
@ -158,50 +158,6 @@ final class Kitsu {
return $output;
}
/**
* Reorganize streaming links
*
* @param array $included
* @return array
*/
public static function oldParseStreamingLinks(array $included): array
{
if (
( ! array_key_exists('streamingLinks', $included)) ||
count($included['streamingLinks']) === 0
)
{
return [];
}
$links = [];
foreach ($included['streamingLinks'] 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
*
@ -243,49 +199,6 @@ final class Kitsu {
return $links;
}
/**
* Reorganize streaming links for the current list item
*
* @param array $included
* @param string $animeId
* @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)
{
return static::oldParseStreamingLinks($anime['relationships']);
}
return $links;
}
return [];
}
/**
* Get the list of titles
*
* @param array $data
* @return array
*/
public static function oldGetTitles(array $data): array
{
$raw = array_unique([
$data['canonicalTitle'],
...array_values($data['titles']),
...array_values($data['abbreviatedTitles'] ?? []),
]);
return array_diff($raw,[$data['canonicalTitle']]);
}
/**
* Get the list of titles
*
@ -297,37 +210,11 @@ final class Kitsu {
$raw = array_unique([
$titles['canonical'],
...array_values($titles['localized']),
// ...array_values($data['abbreviatedTitles'] ?? []),
]);
return array_diff($raw,[$titles['canonical']]);
}
/**
* Filter out duplicate and very similar names from
*
* @param array $data The 'attributes' section of the api data response
* @return array List of alternate titles
*/
public static function filterTitles(array $data): array
{
// The 'canonical' title is always returned
$valid = [$data['canonicalTitle']];
if (array_key_exists('titles', $data) && is_array($data['titles']))
{
foreach($data['titles'] as $alternateTitle)
{
if (self::titleIsUnique($alternateTitle, $valid))
{
$valid[] = $alternateTitle;
}
}
}
return $valid;
}
/**
* Filter out duplicate and very similar titles from a GraphQL response
*

View File

@ -42,7 +42,7 @@ class Anime extends API {
* @param string $status
* @return array
*/
public function getList($status): array
public function getList(string $status): array
{
$data = $this->kitsuModel->getAnimeList($status);
$this->sortByName($data, 'anime');

View File

@ -38,7 +38,7 @@ class Manga extends API {
* @param string $status
* @return array
*/
public function getList($status): array
public function getList(string $status): array
{
if ($status === 'All')
{
@ -63,7 +63,7 @@ class Manga extends API {
* @param string $manga_id
* @return MangaPage
*/
public function getManga($manga_id): MangaPage
public function getManga(string $manga_id): MangaPage
{
return $this->kitsuModel->getManga($manga_id);
}
@ -105,7 +105,7 @@ class Manga extends API {
Title::COMPLETED => [],
];
foreach ($data as &$entry) {
foreach ($data as $entry) {
$statusMap = MangaReadingStatus::KITSU_TO_TITLE;
$key = $statusMap[$entry['reading_status']];
$output[$key][] = $entry;