Joyn: Behebe Serien mit chronologischer Staffelreihenfolge
This commit is contained in:
@@ -65,15 +65,19 @@ class JoynBridge extends BridgeAbstract {
|
|||||||
|
|
||||||
$path = '/serien/' . $series_id;
|
$path = '/serien/' . $series_id;
|
||||||
|
|
||||||
// First GraphQL request: Get number of seasons and episodes
|
// First GraphQL request: Get all seasons to find highest available number
|
||||||
$seasonQuery = '
|
$checkQuery = '
|
||||||
query ($path: String!) {
|
query ($path: String!) {
|
||||||
page(path: $path) {
|
page(path: $path) {
|
||||||
... on SeriesPage {
|
... on SeriesPage {
|
||||||
series {
|
series {
|
||||||
numberOfSeasons
|
numberOfSeasons
|
||||||
seasons {
|
seasons {
|
||||||
|
number
|
||||||
numberOfEpisodes
|
numberOfEpisodes
|
||||||
|
episodes(first: 1) {
|
||||||
|
number
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,12 +85,12 @@ class JoynBridge extends BridgeAbstract {
|
|||||||
}
|
}
|
||||||
';
|
';
|
||||||
|
|
||||||
$seasonData = $this->makeGraphQLRequest($seasonQuery, ['path' => $path]);
|
$checkData = $this->makeGraphQLRequest($checkQuery, ['path' => $path]);
|
||||||
if (!$seasonData || !isset($seasonData['page']['series'])) {
|
if (!$checkData || !isset($checkData['page']['series'])) {
|
||||||
returnServerError('Could not fetch series information');
|
returnServerError('Could not fetch series information');
|
||||||
}
|
}
|
||||||
|
|
||||||
$series = $seasonData['page']['series'];
|
$series = $checkData['page']['series'];
|
||||||
$numberOfSeasons = $series['numberOfSeasons'] ?? 0;
|
$numberOfSeasons = $series['numberOfSeasons'] ?? 0;
|
||||||
$seasons = $series['seasons'] ?? [];
|
$seasons = $series['seasons'] ?? [];
|
||||||
|
|
||||||
@@ -94,23 +98,41 @@ class JoynBridge extends BridgeAbstract {
|
|||||||
returnServerError('No seasons found for this series');
|
returnServerError('No seasons found for this series');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the last season (index: numberOfSeasons - 1)
|
// Find the highest available season number (delisted seasons create gaps)
|
||||||
$lastSeasonIndex = $numberOfSeasons - 1;
|
$seasonNumbers = array_map(function($season) {
|
||||||
$lastSeason = $seasons[$lastSeasonIndex] ?? null;
|
return $season['number'] ?? 0;
|
||||||
|
}, $seasons);
|
||||||
|
$highestSeasonNumber = max($seasonNumbers);
|
||||||
|
|
||||||
if (!$lastSeason) {
|
// Find first and last seasons by their actual position in the array
|
||||||
returnServerError('Could not find last season');
|
$firstSeason = $seasons[0] ?? null;
|
||||||
|
$lastSeason = $seasons[count($seasons) - 1] ?? null;
|
||||||
|
|
||||||
|
if (!$firstSeason || !$lastSeason) {
|
||||||
|
returnServerError('Could not find seasons');
|
||||||
}
|
}
|
||||||
|
|
||||||
$numberOfEpisodesInLastSeason = $lastSeason['numberOfEpisodes'] ?? 0;
|
$firstSeasonNumber = $firstSeason['number'] ?? 1;
|
||||||
|
$lastSeasonNumber = $lastSeason['number'] ?? 1;
|
||||||
|
$firstEpisodes = $firstSeason['episodes'] ?? [];
|
||||||
|
$firstEpisodeNumber = !empty($firstEpisodes) ? ($firstEpisodes[0]['number'] ?? 1) : 1;
|
||||||
|
|
||||||
if ($numberOfEpisodesInLastSeason === 0) {
|
// Check if series is chronologically sorted (newest first)
|
||||||
returnServerError('No episodes found in last season');
|
// If first season has higher number than last season, it's sorted newest first
|
||||||
|
$isChronological = $firstSeasonNumber > $lastSeasonNumber;
|
||||||
|
|
||||||
|
$seasonOffset = 0;
|
||||||
|
$episodeOffset = 0;
|
||||||
|
$seasonLimit = 1;
|
||||||
|
$episodeLimit = 10;
|
||||||
|
|
||||||
|
if (!$isChronological) {
|
||||||
|
// Series is sorted oldest first, use offset to get latest (last season in array)
|
||||||
|
$seasonOffset = count($seasons) - 1;
|
||||||
|
$numberOfEpisodesInLastSeason = $lastSeason['numberOfEpisodes'] ?? 0;
|
||||||
|
$episodeOffset = max(0, $numberOfEpisodesInLastSeason - 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate offset to get last 10 episodes (or all if less than 10)
|
|
||||||
$episodeOffset = max(0, $numberOfEpisodesInLastSeason - 10);
|
|
||||||
|
|
||||||
// Second GraphQL request: Get the latest episodes
|
// Second GraphQL request: Get the latest episodes
|
||||||
$episodeQuery = '
|
$episodeQuery = '
|
||||||
query ($path: String!) {
|
query ($path: String!) {
|
||||||
@@ -121,12 +143,12 @@ class JoynBridge extends BridgeAbstract {
|
|||||||
title
|
title
|
||||||
description
|
description
|
||||||
numberOfSeasons
|
numberOfSeasons
|
||||||
seasons(offset: ' . $lastSeasonIndex . ') {
|
seasons(' . ($seasonOffset > 0 ? 'offset: ' . $seasonOffset : 'first: ' . $seasonLimit) . ') {
|
||||||
id
|
id
|
||||||
title
|
title
|
||||||
number
|
number
|
||||||
numberOfEpisodes
|
numberOfEpisodes
|
||||||
episodes(offset: ' . $episodeOffset . ') {
|
episodes(' . ($episodeOffset > 0 ? 'offset: ' . $episodeOffset : 'first: ' . $episodeLimit) . ') {
|
||||||
id
|
id
|
||||||
number
|
number
|
||||||
airdate
|
airdate
|
||||||
@@ -161,8 +183,10 @@ class JoynBridge extends BridgeAbstract {
|
|||||||
$seasonNumber = $season['number'] ?? 1;
|
$seasonNumber = $season['number'] ?? 1;
|
||||||
$episodes = $season['episodes'] ?? [];
|
$episodes = $season['episodes'] ?? [];
|
||||||
|
|
||||||
// Reverse episodes array to show newest first
|
// Reverse episodes array only if series is sorted oldest first
|
||||||
$episodes = array_reverse($episodes);
|
if (!$isChronological) {
|
||||||
|
$episodes = array_reverse($episodes);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($episodes as $episode) {
|
foreach ($episodes as $episode) {
|
||||||
$episodeId = $episode['id'] ?? '';
|
$episodeId = $episode['id'] ?? '';
|
||||||
|
Reference in New Issue
Block a user