From b950b5501724e2fb4067dcb268f0b1c6e50cf5ce Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sun, 26 Apr 2026 12:03:11 -0400 Subject: [PATCH] Fix some reporting of incorrect episodes (check more log history to account for short episodes; only accept positive deltas) --- src/pkjs/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pkjs/index.js b/src/pkjs/index.js index 3d33bec..69b5c38 100644 --- a/src/pkjs/index.js +++ b/src/pkjs/index.js @@ -14,13 +14,13 @@ Pebble.addEventListener("appmessage", function (dict) { // TODO report last episode as "Configure app settings!" if CLAY_API_HOST, CLAY_API_KEY, or CLAY_USER is empty // TODO use API to dynamically determine user (prompt on watch) if (cfg.CLAY_API_IS_JELLYFIN == true) { - callAPI(cfg.CLAY_API_HOST + "/System/ActivityLog/Entries?hasUserId=true&limit=50", cfg.CLAY_API_KEY, true, cfg.CLAY_USER, sleepTimestamp * 1000); + callAPI(cfg.CLAY_API_HOST + "/System/ActivityLog/Entries?hasUserId=true&limit=100", cfg.CLAY_API_KEY, true, cfg.CLAY_USER, sleepTimestamp * 1000); } else { // The official history endpoint doesn't seem to return history w/o Plex Pass. // If someone with Plex Pass wants to give it a shot, I'd be happy to accept a PR adding this as an option. // Until then, I'm using Tautulli because it's free. //callAPI(cfg.CLAY_API_HOST + "/status/sessions/history/all", cfg.CLAY_API_KEY, false, cfg.CLAY_USER, sleepTimestamp); - callAPI(cfg.CLAY_API_HOST + "/api/v2?apikey=" + cfg.CLAY_API_KEY + "&cmd=get_history&length=50", null, false, cfg.CLAY_USER, sleepTimestamp); + callAPI(cfg.CLAY_API_HOST + "/api/v2?apikey=" + cfg.CLAY_API_KEY + "&cmd=get_history&length=100", null, false, cfg.CLAY_USER, sleepTimestamp); } } }); @@ -43,8 +43,8 @@ function callAPI(fullURL, apiKey, isJellyfin, trackedUser, sleepTimestamp) { if (arr != null && arr[1] == trackedUser) { logTimestamp = Date.parse(item.Date); if (!Number.isNaN(logTimestamp)) { - delta = Math.abs(logTimestamp - sleepTimestamp); - if (delta < bestDelta) { + delta = sleepTimestamp - logTimestamp; + if (delta >= 0 && delta < bestDelta) { bestDelta = delta; lastWatched = arr[2]; } @@ -56,8 +56,8 @@ function callAPI(fullURL, apiKey, isJellyfin, trackedUser, sleepTimestamp) { if (item.user == trackedUser) { // we use "date" instead of "started" because started tracks the first // time the user watched the media, not just the start of the last session. - delta = Math.abs(item.date - sleepTimestamp); - if (delta < bestDelta) { + delta = sleepTimestamp - item.date; + if (delta >= 0 && delta < bestDelta) { bestDelta = delta; lastWatched = item.full_title; }