Skip to content

Commit e1416e6

Browse files
authored
Merge pull request #598 from Aldione/patch-14
Fix: preserve alias credentials on failover
2 parents afeaad6 + a1b2fdf commit e1416e6

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

app/Services/M3uProxyService.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Services;
44

55
use App\Facades\ProxyFacade;
6+
use App\Facades\PlaylistFacade;
67
use App\Models\Channel;
78
use App\Models\CustomPlaylist;
89
use App\Models\Episode;
@@ -670,19 +671,15 @@ public function getChannelUrl($playlist, $channel, ?Request $request = null, ?St
670671
// See if channel has any failovers
671672
// Return bool if using resolver, else array of failover URLs (legacy mode)
672673
$failovers = $this->usingResolver()
673-
? $channel->failoverChannels()->count() > 0
674-
: $channel->failoverChannels()
675-
->select(['channels.id', 'channels.url', 'channels.url_custom', 'channels.playlist_id', 'channels.custom_playlist_id'])->get()
676-
->map(function ($ch) {
677-
$playlist = $ch->getEffectivePlaylist();
678-
if (! $playlist) {
679-
return null;
680-
}
681-
return PlaylistUrlService::getChannelUrl($ch, $playlist);
682-
})
683-
->filter()
684-
->values()
685-
->toArray();
674+
? $channel->failoverChannels()->count() > 0
675+
: $channel->failoverChannels()
676+
->select(['channels.id', 'channels.url', 'channels.url_custom', 'channels.playlist_id', 'channels.custom_playlist_id'])->get()
677+
->map(function ($ch) use ($playlist) {
678+
return PlaylistUrlService::getChannelUrl($ch, $playlist);
679+
})
680+
->filter()
681+
->values()
682+
->toArray();
686683

687684
// Use appropriate endpoint based on whether transcoding profile is provided
688685
if ($profile) {
@@ -1429,6 +1426,8 @@ public function resolveFailoverUrl(int $channelId, string $playlistUuid, string
14291426
// Get the original channel to access its failover relationships
14301427
$channel = Channel::findOrFail($channelId);
14311428
$nextUrl = null;
1429+
// Resolve the original stream context by UUID (Playlist / MergedPlaylist / CustomPlaylist / PlaylistAlias)
1430+
$contextPlaylist = !empty($playlistUuid) ? PlaylistFacade::resolvePlaylistByUuid($playlistUuid) : null;
14321431

14331432
// Get all failover channels with their relationships
14341433
$failoverChannels = $channel->failoverChannels()
@@ -1459,7 +1458,7 @@ public function resolveFailoverUrl(int $channelId, string $playlistUuid, string
14591458
}
14601459

14611460
// Get the url
1462-
$url = PlaylistUrlService::getChannelUrl($failoverChannel, $failoverPlaylist);
1461+
$url = PlaylistUrlService::getChannelUrl($failoverChannel, $contextPlaylist ?? $failoverPlaylist);
14631462

14641463
// Check if the url is the current URL (skip it)
14651464
if ($url === $currentUrl) {

0 commit comments

Comments
 (0)