diff --git a/Jellyfin.Plugin.SRFPlay/Controllers/StreamProxyController.cs b/Jellyfin.Plugin.SRFPlay/Controllers/StreamProxyController.cs index 2033143..fc7fed0 100644 --- a/Jellyfin.Plugin.SRFPlay/Controllers/StreamProxyController.cs +++ b/Jellyfin.Plugin.SRFPlay/Controllers/StreamProxyController.cs @@ -292,9 +292,23 @@ public class StreamProxyController : ControllerBase _logger.LogDebug("Streamed segment {SegmentPath} ({ContentType})", segmentPath, contentType); return new EmptyResult(); } + catch (OperationCanceledException) + { + // Client disconnected during streaming (e.g., FFmpeg stopped, player seeked). + // This is expected behavior, not an error. + _logger.LogDebug("Segment streaming canceled - ItemId: {ItemId}, Path: {SegmentPath}", itemId, segmentPath); + return new EmptyResult(); + } catch (Exception ex) { _logger.LogError(ex, "Error proxying segment - ItemId: {ItemId}, Path: {SegmentPath}", itemId, segmentPath); + + // If we already started streaming data to the client, we can't change the status code + if (Response.HasStarted) + { + return new EmptyResult(); + } + return StatusCode(StatusCodes.Status500InternalServerError); } } diff --git a/Jellyfin.Plugin.SRFPlay/Services/ContentExpirationService.cs b/Jellyfin.Plugin.SRFPlay/Services/ContentExpirationService.cs index bb62daf..f51e778 100644 --- a/Jellyfin.Plugin.SRFPlay/Services/ContentExpirationService.cs +++ b/Jellyfin.Plugin.SRFPlay/Services/ContentExpirationService.cs @@ -120,9 +120,10 @@ public class ContentExpirationService : IContentExpirationService if (mediaComposition?.HasChapters != true) { - // If we can't fetch the content, consider it expired - _logger.LogWarning("Could not fetch media composition for URN: {Urn}, treating as expired", urn); - return true; + // Don't treat API failures as expired - the content may still be available + // and a transient error (network issue, 403, API outage) shouldn't delete library items + _logger.LogWarning("Could not fetch media composition for URN: {Urn}, skipping (not treating as expired)", urn); + return false; } var chapter = mediaComposition.ChapterList[0]; diff --git a/Jellyfin.Plugin.SRFPlay/Services/StreamProxyService.cs b/Jellyfin.Plugin.SRFPlay/Services/StreamProxyService.cs index b531089..fc00cd7 100644 --- a/Jellyfin.Plugin.SRFPlay/Services/StreamProxyService.cs +++ b/Jellyfin.Plugin.SRFPlay/Services/StreamProxyService.cs @@ -373,6 +373,15 @@ public class StreamProxyService : IStreamProxyService return refreshedUrl; } + if (streamInfo.IsLiveStream) + { + // For livestreams, keep the mapping and flag for re-authentication + // rather than removing it — the next request will trigger a fresh auth + _logger.LogWarning("Failed to refresh token for livestream {ItemId}, will re-authenticate on next request", itemId); + streamInfo.NeedsAuthentication = true; + return streamInfo.AuthenticatedUrl; + } + _logger.LogWarning("Failed to refresh token for item {ItemId}, removing mapping", itemId); _streamMappings.TryRemove(itemId, out _); return null; @@ -979,8 +988,9 @@ public class StreamProxyService : IStreamProxyService _logger.LogDebug("Marking item {ItemId} for cleanup (old registration)", kvp.Key); } - // Remove if token has expired - if (kvp.Value.TokenExpiresAt.HasValue && kvp.Value.TokenExpiresAt.Value <= now) + // Remove if token has expired — but skip livestreams since their CDN tokens + // expire every ~30s and get refreshed on-demand during playback + if (kvp.Value.TokenExpiresAt.HasValue && kvp.Value.TokenExpiresAt.Value <= now && !kvp.Value.IsLiveStream) { shouldRemove = true; _logger.LogDebug("Marking item {ItemId} for cleanup (expired token)", kvp.Key);