From e875e4a6cca8b92b35528d5d57ca19aae71850df Mon Sep 17 00:00:00 2001 From: Sattva <74269253+Sattva-108@users.noreply.github.com> Date: Tue, 20 May 2025 09:14:19 +0300 Subject: [PATCH] media-random: also remember tracks that have duration < 15 sec not really necessary now, but good for future --- Leatrix_Plus.lua | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/Leatrix_Plus.lua b/Leatrix_Plus.lua index 80e46af..7a6f7e2 100644 --- a/Leatrix_Plus.lua +++ b/Leatrix_Plus.lua @@ -15564,12 +15564,35 @@ function LeaPlusLC:RunOnce() local function MarkCurrentTrackListened() if LastFolder == L["Random"] and LastPlayed and trackStartTime and trackStartTime > 0 then local elapsed = GetTime() - trackStartTime - if elapsed >= 15 then - local id = GetTrackIDFromPath(LastPlayed) - if id and id ~= "" then - LeaPlusDB["ListenedTracks"][id] = true - --LeaPlusLC:Print("Added track to listened: " .. id) + local id = GetTrackIDFromPath(LastPlayed) -- Get ID early + + if not id or id == "" then return end -- No valid ID, nothing to do + + -- Extract total duration of the track + local totalDurationStr = string.match(LastPlayed, "#(%d+)") + local totalDurationNum + + if totalDurationStr then + totalDurationNum = tonumber(totalDurationStr) + end + + local shouldMarkListened = false + + if totalDurationNum and totalDurationNum < 15 then + -- For short tracks: if it has played at all (elapsed > 0, to avoid issues if trackStartTime was just set) + if elapsed > 5 then -- Or a very small threshold like elapsed >= 0.1 if needed + shouldMarkListened = true end + else + -- For longer tracks: original 15-second rule + if elapsed >= 15 then + shouldMarkListened = true + end + end + + if shouldMarkListened then + LeaPlusDB["ListenedTracks"][id] = true + --LeaPlusLC:Print("Added track to listened: " .. id) end end end