From ab36a43892f6cee8d841c476413e9874e70a19e1 Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Mon, 2 Feb 2026 19:06:33 -0500 Subject: [PATCH] another --- allstarr/Controllers/JellyfinController.cs | 36 ++++++++-------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/allstarr/Controllers/JellyfinController.cs b/allstarr/Controllers/JellyfinController.cs index 5634470..35eb233 100644 --- a/allstarr/Controllers/JellyfinController.cs +++ b/allstarr/Controllers/JellyfinController.cs @@ -1785,28 +1785,6 @@ public class JellyfinController : ControllerBase _logger.LogInformation("📻 Playback START reported"); - // Extract device info and ensure session exists - var (deviceId, client, device, version) = ExtractDeviceInfo(Request.Headers); - if (!string.IsNullOrEmpty(deviceId)) - { - var sessionCreated = await _sessionManager.EnsureSessionAsync(deviceId, client ?? "Unknown", device ?? "Unknown", version ?? "1.0", Request.Headers); - if (sessionCreated) - { - _logger.LogInformation("✓ Session ensured for device {DeviceId}", deviceId); - - // Give Jellyfin a moment to process the session creation - await Task.Delay(100); - } - else - { - _logger.LogWarning("⚠️ Failed to ensure session for device {DeviceId}", deviceId); - } - } - else - { - _logger.LogWarning("⚠️ No device ID found in headers - session cannot be created"); - } - // Parse the body to check if it's an external track var doc = JsonDocument.Parse(body); string? itemId = null; @@ -1839,11 +1817,10 @@ public class JellyfinController : ControllerBase itemName ?? "Unknown", itemId); } - // For local tracks, forward to Jellyfin with client auth + // For local tracks, forward playback start to Jellyfin FIRST _logger.LogInformation("Forwarding playback start to Jellyfin..."); // Fetch full item details to include in playback report - // This makes the session show up properly in Jellyfin dashboard with "Now Playing" try { var (itemResult, itemStatus) = await _proxyService.GetJsonAsync($"Items/{itemId}", null, Request.Headers); @@ -1868,6 +1845,17 @@ public class JellyfinController : ControllerBase if (statusCode == 204 || statusCode == 200) { _logger.LogInformation("✓ Playback start forwarded to Jellyfin ({StatusCode})", statusCode); + + // NOW ensure session exists with capabilities (after playback is reported) + var (deviceId, client, device, version) = ExtractDeviceInfo(Request.Headers); + if (!string.IsNullOrEmpty(deviceId)) + { + var sessionCreated = await _sessionManager.EnsureSessionAsync(deviceId, client ?? "Unknown", device ?? "Unknown", version ?? "1.0", Request.Headers); + if (sessionCreated) + { + _logger.LogInformation("✓ Session ensured for device {DeviceId} after playback start", deviceId); + } + } } else {