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