From d66e5af28999540997388110b5d09231f301d4ba Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Tue, 28 Apr 2026 04:20:53 +0200 Subject: [PATCH] fix(livetv): fall back to legacy channels endpoint when cloud guide errors --- lib/services/plex_client.dart | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/services/plex_client.dart b/lib/services/plex_client.dart index 84b80f46..d2e3364c 100644 --- a/lib/services/plex_client.dart +++ b/lib/services/plex_client.dart @@ -2513,20 +2513,29 @@ class PlexClient { final allChannels = []; for (final provider in _providerEpg) { final isCloudGuide = provider.identifier.startsWith('tv.plex.providers.epg'); - final primaryEndpoint = isCloudGuide ? '/lineups/plex/channels' : '/${provider.identifier}/lineups/dvr/channels'; - try { - final response = await _getWithFailover(primaryEndpoint); - final parsed = parseChannels(response); - if (parsed.isEmpty && isCloudGuide) { - // Fallback: the prefix matched but this server doesn't expose the - // cloud endpoint. Retry with the legacy DVR endpoint. - final fallback = await _getWithFailover('/${provider.identifier}/lineups/dvr/channels'); - allChannels.addAll(parseChannels(fallback)); - } else { - allChannels.addAll(parsed); + final legacyEndpoint = '/${provider.identifier}/lineups/dvr/channels'; + + if (isCloudGuide) { + try { + final response = await _getWithFailover('/lineups/plex/channels'); + final parsed = parseChannels(response); + if (parsed.isNotEmpty) { + allChannels.addAll(parsed); + continue; + } + } catch (e) { + appLogger.d( + 'Cloud channel endpoint /lineups/plex/channels unavailable, falling back to $legacyEndpoint', + error: e, + ); } + } + + try { + final response = await _getWithFailover(legacyEndpoint); + allChannels.addAll(parseChannels(response)); } catch (e) { - appLogger.e('Failed to get EPG channels from ${provider.identifier} via $primaryEndpoint', error: e); + appLogger.e('Failed to get EPG channels from ${provider.identifier} via $legacyEndpoint', error: e); } } return allChannels;