From 7ab98024c169bb07254204a6d9b5dd531edd9b4e Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sun, 1 Jun 2025 16:43:51 -0400 Subject: [PATCH] [skip ci] tweak sponsorblock notification timing --- .../src/components/VideoPlayer/SponsorBlock.bs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/playlet-lib/src/components/VideoPlayer/SponsorBlock.bs b/playlet-lib/src/components/VideoPlayer/SponsorBlock.bs index 2367c48e..c758f68a 100644 --- a/playlet-lib/src/components/VideoPlayer/SponsorBlock.bs +++ b/playlet-lib/src/components/VideoPlayer/SponsorBlock.bs @@ -99,7 +99,7 @@ namespace SponsorBlock function UpdateSponsorBlockChapter(time as double) as void segments = m.skipSegments - segment = FindSegmentByTime(segments, time, 0) + segment = FindSegmentByTime(segments, time) if segment = invalid m.top.chapter = "" return @@ -107,7 +107,7 @@ namespace SponsorBlock m.top.chapter = segment.title end function - function FindSegmentByTime(segments as object, time as dynamic, endOffset as integer) as dynamic + function FindSegmentByTime(segments as object, time as dynamic) as dynamic ' Binary search for the segment that contains the time. ' This search sometimes fails if the segments overlap. ' For most cases, this is acceptable, since it is not common for segments to overlap. @@ -118,7 +118,7 @@ namespace SponsorBlock segment = segments[middle] if time < segment.start high = middle - 1 - else if time > (segment.end + endOffset) + else if time > segment.end low = middle + 1 else return segment @@ -131,18 +131,17 @@ namespace SponsorBlock segments = m.skipSegments position = m.top.position - ' We add a small offset to the end position of the segment. - ' This is so that when we skip a segment, we don't get - ' another notification to skip it. - ' Seeking accuracy is not perfect, so we need to account for that. - segment = FindSegmentByTime(segments, position, -1) + segment = FindSegmentByTime(segments, position) if segment = invalid return end if action = segment.option - if segment.showNotification + ' If we're close to the end of the segment, we don't want to show + ' a notification, since it is possible this is where we skipped to. + ' Seeking is not super accurate. + if segment.showNotification and Abs(segment.end - position) >= 1 SponsorBlock.ShowNotifcation(m.notifications, segment, action) if action = SegmentAction.ManualSkip