diff --git a/Leatrix_Plus.lua b/Leatrix_Plus.lua index 86bd6d9..6db07d2 100644 --- a/Leatrix_Plus.lua +++ b/Leatrix_Plus.lua @@ -15493,15 +15493,12 @@ function LeaPlusLC:RunOnce() local function MarkCurrentTrackListened() if LastFolder == L["Random"] and LastPlayed and trackStartTime and trackStartTime > 0 then - print("last folder ok") local elapsed = GetTime() - trackStartTime - if elapsed >= 30 then - print("time ok (" .. math.floor(elapsed) .. "s)") + if elapsed >= 15 then local id = GetTrackIDFromPath(LastPlayed) if id and id ~= "" then - print("id ok") LeaPlusDB["ListenedTracks"][id] = true - LeaPlusLC:Print("Added track to listened: " .. id) + --LeaPlusLC:Print("Added track to listened: " .. id) end end end @@ -15552,7 +15549,7 @@ function LeaPlusLC:RunOnce() -- Function to play a track and show the static highlight bar local function PlayTrack() - -- Зафиксировать предыдущий трек, если слушали >=30 сек + -- On Click new track - mark previous MarkCurrentTrackListened() -- Остановить текущее воспроизведение (если было) StopMusic() @@ -15593,7 +15590,7 @@ function LeaPlusLC:RunOnce() end if trackTime then LeaPlusLC.TrackTimer = LibCompat.NewTimer(trackTime + 1, function() - -- По окончании: фиксируем текущий трек и переходим к следующему + -- Automatic mark track after listened fully MarkCurrentTrackListened() StopMusic() if tracknumber > #playlist then @@ -15827,6 +15824,8 @@ function LeaPlusLC:RunOnce() ListData[4] = "|cffffd800" .. L["Selection of music tracks"] -- Must be lower case |c -- Populate list data until it contains desired number of tracks local attempt = 0 + -- локальный set, чтобы за один проход random не добавлял один и тот же trackID снова + local randHash = {} while #ListData < 50 and attempt < 2000 do attempt = attempt + 1 -- Get random category @@ -15835,22 +15834,32 @@ function LeaPlusLC:RunOnce() local rZone = random(1, #ZoneList[rCategory]) -- Get random track within zone local rTrack = ZoneList[rCategory][rZone].tracks[random(1, #ZoneList[rCategory][rZone].tracks)] - -- Only allow tracks that are real mp3 (exclude SoundKit/non-file) + + + -- гарантируем, что подтаблица существует + LeaPlusDB["ListenedTracks"] = LeaPlusDB["ListenedTracks"] or {} + if rTrack and rTrack ~= "" and strfind(rTrack, "#") and strfind(rTrack:lower(), ".mp3") then local trackID = GetTrackIDFromPath(rTrack) - -- гарантируем, что подтаблица существует (на всякий случай) - if not LeaPlusDB["ListenedTracks"] then - LeaPlusDB["ListenedTracks"] = {} - end - -- база инициализирована заранее, используем квадратные скобки - if not LeaPlusDB["ListenedTracks"][trackID] then + + -- пропускаем, если уже слушали или уже попал в текущий random + if not LeaPlusDB["ListenedTracks"][trackID] and not randHash[trackID] then local zoneLabel = "|Cffffffaa" .. ZoneList[rCategory][rZone].zone .. " |r" .. rTrack - if not tContains(ListData, zoneLabel) - and not tContains(randomBannedList, L[ZoneList[rCategory][rZone].zone]) + if not tContains(randomBannedList, L[ZoneList[rCategory][rZone].zone]) and not tContains(randomBannedList, rTrack) then - tinsert(ListData, zoneLabel) + if not tContains(ListData, zoneLabel) then + tinsert(ListData, zoneLabel) + randHash[trackID] = true -- фиксируем, чтобы не повторить в этой же подборке + end end + else + ---- Печать причины пропуска + --if LeaPlusDB["ListenedTracks"][trackID] then + -- print("skipped (already listened):", trackID) + --elseif randHash[trackID] then + -- print("skipped (already added in this random):", trackID) + --end end end end @@ -15858,6 +15867,7 @@ function LeaPlusLC:RunOnce() if #ListData <= 4 then tinsert(ListData, "|cff999999(You have listened it all!)|r") end + print("Final random count:", #ListData - 4) -- вычитаем заголовки -- Refresh the track listing UpdateList() -- Set track listing to top