Skip to content

Commit 21f6406

Browse files
committed
Update XtreamApiController.php
1 parent 7709cdb commit 21f6406

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

app/Http/Controllers/XtreamApiController.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,17 +1538,27 @@ public function handle(Request $request)
15381538
return response()->json(['epg_listings' => []]);
15391539
}
15401540

1541-
// Get programmes for today
1542-
$today = Carbon::now()->format('Y-m-d');
1543-
$programmes = $cacheService->getCachedProgrammes($epg, $today, [$channel->epgChannel->channel_id]);
1541+
// Get programmes for several days to ensure we have enough data
1542+
// Start from 3 days ago to cover past programmes as well
1543+
// We fetch 7 days total (3 past, today, 3 future)
1544+
$daysToFetch = 7;
1545+
$allProgrammes = [];
1546+
$threeDaysAgo = Carbon::now()->subDays(3);
1547+
foreach (range(0, $daysToFetch - 1) as $dayOffset) {
1548+
$date = $threeDaysAgo->clone()->addDays($dayOffset)->format('Y-m-d');
1549+
$programmes = $cacheService->getCachedProgrammes($epg, $date, [$channel->epgChannel->channel_id]);
1550+
if (isset($programmes[$channel->epgChannel->channel_id])) {
1551+
$allProgrammes = array_merge($allProgrammes, $programmes[$channel->epgChannel->channel_id]);
1552+
}
1553+
}
15441554

15451555
$epgListings = [];
1546-
if (isset($programmes[$channel->epgChannel->channel_id])) {
1556+
if (! empty($allProgrammes)) {
15471557
// Check if channel is currently playing
15481558
$isNowPlaying = $proxyEnabled ? M3uProxyService::isChannelActive($channel) : false;
15491559

15501560
$now = Carbon::now();
1551-
foreach ($programmes[$channel->epgChannel->channel_id] as $index => $programme) {
1561+
foreach ($allProgrammes as $index => $programme) {
15521562
$startTime = Carbon::parse($programme['start']);
15531563
$endTime = Carbon::parse($programme['stop']);
15541564
$isCurrentProgramme = $startTime->lte($now) && $endTime->gt($now);

0 commit comments

Comments
 (0)