1
0

Joyn: Behebe Serien mit chronologischer Staffelreihenfolge

This commit is contained in:
2025-07-18 22:57:02 +02:00
parent 7f10c92e74
commit cd04d1fd0c

View File

@@ -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,23 +98,41 @@ 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');
}
$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) {
returnServerError('No episodes found in last season');
// 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;
$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
$episodeQuery = '
query ($path: String!) {
@@ -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
$episodes = array_reverse($episodes);
// Reverse episodes array only if series is sorted oldest first
if (!$isChronological) {
$episodes = array_reverse($episodes);
}
foreach ($episodes as $episode) {
$episodeId = $episode['id'] ?? '';