From 4b3b64bd7ef677e2b7d954935a725f0eadce20ef Mon Sep 17 00:00:00 2001 From: Duncan Tourolle Date: Fri, 12 Jun 2026 20:09:36 +0200 Subject: [PATCH] json copying debugging overlay --- Jellyfin.Plugin.JRay/Models/TruthActor.cs | 1 + Jellyfin.Plugin.JRay/Models/TruthFile.cs | 1 + Jellyfin.Plugin.JRay/Web/jray-overlay.js | 36 ++++++++++++++++------- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Jellyfin.Plugin.JRay/Models/TruthActor.cs b/Jellyfin.Plugin.JRay/Models/TruthActor.cs index 2732a65..91cb1bc 100644 --- a/Jellyfin.Plugin.JRay/Models/TruthActor.cs +++ b/Jellyfin.Plugin.JRay/Models/TruthActor.cs @@ -37,5 +37,6 @@ public class TruthActor /// Gets the list of [start_sec, end_sec] windows during which the actor is on screen. /// [JsonPropertyName("scenes")] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] public Collection Scenes { get; } = new(); } diff --git a/Jellyfin.Plugin.JRay/Models/TruthFile.cs b/Jellyfin.Plugin.JRay/Models/TruthFile.cs index 5d8c79e..f893010 100644 --- a/Jellyfin.Plugin.JRay/Models/TruthFile.cs +++ b/Jellyfin.Plugin.JRay/Models/TruthFile.cs @@ -37,5 +37,6 @@ public class TruthFile /// Gets the list of actors detected in the film, each with their on-screen scene windows. /// [JsonPropertyName("actors")] + [JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)] public Collection Actors { get; } = new(); } diff --git a/Jellyfin.Plugin.JRay/Web/jray-overlay.js b/Jellyfin.Plugin.JRay/Web/jray-overlay.js index ba7b7f8..c609a5a 100644 --- a/Jellyfin.Plugin.JRay/Web/jray-overlay.js +++ b/Jellyfin.Plugin.JRay/Web/jray-overlay.js @@ -4,9 +4,23 @@ var POLL_INTERVAL_MS = 1000; var overlayEl = null; - function getItemIdFromHash() { - var match = window.location.hash.match(/[?&]id=([0-9a-fA-F-]+)/); - return match ? match[1] : null; + function getNowPlaying() { + if (!window.ApiClient) { + return Promise.reject(new Error('no ApiClient')); + } + + var url = window.ApiClient.getUrl('Sessions', { DeviceId: window.ApiClient.deviceId() }); + return window.ApiClient.ajax({ url: url, type: 'GET', dataType: 'json' }).then(function (sessions) { + var session = sessions && sessions[0]; + if (!session || !session.NowPlayingItem || !session.PlayState) { + return null; + } + + return { + itemId: session.NowPlayingItem.Id, + positionSeconds: (session.PlayState.PositionTicks || 0) / 10000000 + }; + }); } function removeOverlay() { @@ -72,14 +86,14 @@ }); } - function onPause(event) { - var video = event.target; - var itemId = getItemIdFromHash(); - if (!itemId) { - return; - } - - fetchContext(itemId, video.currentTime); + function onPause() { + getNowPlaying().then(function (info) { + if (info) { + fetchContext(info.itemId, info.positionSeconds); + } + }, function () { + // ApiClient unavailable or request error - fail silently, never break playback. + }); } function onPlay() {