SponsorBlock Fix

This commit is contained in:
Brahim Hadriche committed 2026-10-09 14:29:52 -04:00
1 parent 810ef60770
commit c581a4767a
14 files changed
+746 -191

No files matched your search

+1
View File
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Small security fixes
- SponsorBlock skip looping back to the start of a segment on some devices, and overlapping segments
### Changed
+1 -1
View File
@@ -70,7 +70,7 @@ async function snap(label: string): Promise<Record<string, unknown>> {
await ecp.sendKeypress(Key.Home);
process.exit(1);
}
await ecp.sleep(2500); // let OnPosition fire a few times -> stash manualSkipSegment + show the notice
await ecp.sleep(2500); // let OnPosition fire a few times -> arm the manual segment + show the notice
const posBefore = await odcN('#VideoPlayer.position');
console.log(` position before OK=${posBefore}s`);
@@ -1,5 +1,6 @@
import "pkg:/components/Services/SponsorBlock/SponsorBlockConfig.bs"
import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs"
import "pkg:/components/Services/SponsorBlock/SponsorBlockTimeline.bs"
import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs"
import "pkg:/source/utils/Types.bs"
@@ -20,6 +21,7 @@ function ExecuteJob() as void
skipSegments = ProcessSkipSegments(skipSegments, showNotifications, categories, config)
barPath = invalid
timeline = invalid
if skipSegments <> invalid
barDir = "tmp:/sponsorblock"
fs = CreateObject("roFileSystem")
@@ -27,8 +29,7 @@ function ExecuteJob() as void
fs.CreateDirectory(barDir)
' path contains video id to avoid texture cache reuse
barPath = `${barDir}/${videoId}.png`
service.GenerateProgressBarBackground(skipSegments, lengthSeconds, barPath)
end if
service.GenerateProgressBarBackground(skipSegments, SponsorBlock.BuildTimeline(skipSegments), lengthSeconds, barPath)
' Usually segment.start and segment.end are equal for poi_highlight
' We pad the duration for poi_highlight segments so that the chapter label
@@ -36,15 +37,13 @@ function ExecuteJob() as void
' Padding poi_highlight is done after generating the progress bar, so that the
' highlight is not too long in the bar.
skipSegments = PadHightlightSegment(skipSegments, lengthSeconds)
' Sort the segments by start time, so we can binary search them later.
if skipSegments <> invalid
skipSegments.SortBy("start")
timeline = SponsorBlock.BuildTimeline(skipSegments)
end if
JobSuccessData({
videoId: videoId
skipSegments: skipSegments
timeline: timeline
barPath: barPath
})
end function
@@ -1,4 +1,5 @@
import "pkg:/components/Services/SponsorBlock/SponsorBlockConfig.bs"
import "pkg:/components/Services/SponsorBlock/SponsorBlockTimeline.types.bs"
import "pkg:/source/services/HttpClient.bs"
import "pkg:/source/utils/CryptoUtils.bs"
@@ -64,13 +65,28 @@ namespace SponsorBlock
HttpClient.Post(url, "").Cancellation(cancellation).Await()
end function
function GenerateProgressBarBackground(segments as object, lengthSeconds as integer, path as string)
function GenerateProgressBarBackground(segments as object, timeline as SponsorBlockTimeline, lengthSeconds as integer, path as string)
' 1144 = trackbar width, so the bar renders 1:1 without horizontal scaling
bar = CreateObject("roBitmap", { width: 1144, height: 20, AlphaEnable: true })
bar.Clear(&hFFFFFF80)
width = bar.GetWidth()
height = bar.GetHeight()
starts = timeline.starts
ends = timeline.ends
segmentIndexes = timeline.segmentIndexes
for i = 0 to starts.Count() - 1
m.DrawSegment(bar, segments[segmentIndexes[i]], starts[i], ends[i], lengthSeconds)
end for
' a zero-length segment (a highlight) owns no interval: draw it on top.
for each segment in segments
if segment.start = segment.end
m.DrawSegment(bar, segment, segment.start, segment.end, lengthSeconds)
end if
end for
bar.Finish()
buffer = bar.GetPng(0, 0, bar.GetWidth(), bar.GetHeight())
buffer.WriteFile(path)
end function
function DrawSegment(bar as object, segment as object, startSeconds as float, endSeconds as float, lengthSeconds as integer) as void
videoDuration = lengthSeconds
if videoDuration = 0 or videoDuration = invalid
' We should ignore segment.videoDuration https://github.com/iBicha/playlet/pull/23#issuecomment-1431520676
@@ -78,22 +94,19 @@ namespace SponsorBlock
videoDuration = segment.videoDuration
end if
if videoDuration = 0 or videoDuration = invalid
continue for
return
end if
pixelStart = (segment.start / videoDuration) * width
pixelEnd = (segment.end / videoDuration) * width
color = m.config.SegmentColor(segment.category)
' integer edges, so adjacent intervals meet without a truncation seam.
width = bar.GetWidth()
pixelStart = Int((startSeconds / videoDuration) * width)
pixelEnd = Int((endSeconds / videoDuration) * width)
' highlight's duration is zero, so it is not visble on the bar.
' Add a few pixels to see it
if pixelStart = pixelEnd
if startSeconds = endSeconds
pixelEnd += 5
end if
bar.DrawRect(pixelStart, 0, pixelEnd - pixelStart, height, color)
end for
bar.Finish()
buffer = bar.GetPng(0, 0, width, height)
buffer.WriteFile(path)
bar.DrawRect(pixelStart, 0, pixelEnd - pixelStart, bar.GetHeight(), m.config.SegmentColor(segment.category))
end function
end class
end namespace
@@ -0,0 +1,107 @@
import "pkg:/components/Services/SponsorBlock/SponsorBlockTimeline.types.bs"
import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs"
namespace SponsorBlock
' Flatten (possibly overlapping) segments into disjoint intervals, each owned by one segment: auto-skip,
' then manual-skip with a prompt, then the rest; a tie goes to the segment ending later, then to the first.
function BuildTimeline(segments as object) as SponsorBlockTimeline
starts = []
ends = []
segmentIndexes = []
points = []
for each segment in segments
points.Push(segment.start)
points.Push(segment.end)
end for
points.Sort()
segmentCount = segments.Count()
for i = 0 to points.Count() - 2
intervalStart = points[i]
intervalEnd = points[i + 1]
if intervalEnd <= intervalStart
continue for
end if
middle = (intervalStart + intervalEnd) / 2
owner = -1
for j = 0 to segmentCount - 1
segment = segments[j]
if segment.start <= middle and middle <= segment.end
if owner = -1 or SponsorBlock.Outranks(segment, segments[owner])
owner = j
end if
end if
end for
if owner = -1
continue for
end if
last = segmentIndexes.Count() - 1
if last >= 0 and segmentIndexes[last] = owner and ends[last] = intervalStart
ends[last] = intervalEnd
else
starts.Push(intervalStart)
ends.Push(intervalEnd)
segmentIndexes.Push(owner)
end if
end for
return {
starts: starts
ends: ends
segmentIndexes: segmentIndexes
}
end function
' The index of the segment owning `time` (seconds), or -1.
function FindTimelineSegmentIndex(timeline as SponsorBlockTimeline, time as dynamic) as integer
starts = timeline.starts
low = 0
high = starts.Count() - 1
found = -1
while low <= high
middle = (low + high) \ 2
if starts[middle] <= time
found = middle
low = middle + 1
else
high = middle - 1
end if
end while
if found = -1 or time > timeline.ends[found]
return -1
end if
return timeline.segmentIndexes[found]
end function
function Outranks(segment as object, other as object) as boolean
rank = SponsorBlock.TimelineRank(segment)
otherRank = SponsorBlock.TimelineRank(other)
if rank <> otherRank
return rank > otherRank
end if
return segment.end > other.end
end function
function TimelineRank(segment as object) as integer
if segment.option = SponsorBlock.SegmentAction.AutoSkip
return 2
end if
if SponsorBlock.IsSkippable(segment)
return 1
end if
return 0
end function
' Auto-skip, or manual-skip with its prompt: the prompt is the only way to skip a manual segment.
function IsSkippable(segment as object) as boolean
if segment.option = SponsorBlock.SegmentAction.AutoSkip
return true
end if
return segment.option = SponsorBlock.SegmentAction.ManualSkip and segment.showNotification
end function
end namespace
@@ -0,0 +1,6 @@
' Disjoint intervals in time order (seconds), interval i owned by segments[segmentIndexes[i]].
interface SponsorBlockTimeline
starts as object
ends as object
segmentIndexes as object
end interface
@@ -1,6 +1,7 @@
import "pkg:/components/JobSystem/Jobs.bs"
import "pkg:/components/JobSystem/JobSystem.bs"
import "pkg:/components/Services/SponsorBlock/Notifications/SponsorBlockNotificationUtils.bs"
import "pkg:/components/Services/SponsorBlock/SponsorBlockTimeline.bs"
import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/Types.bs"
@@ -15,9 +16,15 @@ namespace SponsorBlockController
' Bar fill tint (semi-transparent black over the red fill) pushed onto the trickplay bar when segments arrive.
const BAR_FILL_BLEND = &hFF000080
' TrySkip returns this for "the segment is at the video end -> finish" (vs a seek ms).
' OnPosition/TrySkip return a seek target (ms), or one of these.
const NO_SKIP = -1
' the segment runs to the video end: finish playback instead of seeking.
const FINISH_SENTINEL = -2
' Video.seek and Video.position are single-precision: on a long video the tick echoing a seek target can read
' a few ms past it.
const SEEK_ECHO_SLACK_MS = 100
class Controller
' deps the coordinator owns; top = the Video node (seekMode + duration).
private jobQueue as object = invalid
@@ -27,11 +34,19 @@ namespace SponsorBlockController
' segment state — stays here, never copied onto a field.
private segments as object = invalid
private timeline as SponsorBlockTimeline = invalid
private enabled as boolean = false
private manualSkipSegment as object = invalid
' a manual notice the user dismissed with Back: don't re-arm/re-show it while still inside this segment.
private dismissedSegmentId as string = ""
private sponsorSkipEventJob as object = invalid
' the manual segment whose prompt is armed for the next OK (index into segments, -1 = none).
private manualSkipIndex as integer = -1
' the manual segment dismissed with Back (index into segments, -1 = none): its prompt stays down until the
' position leaves the segment's range.
private dismissedIndex as integer = -1
' after a skip, no segment acts until the position passes this ms or the user seeks (-1 = none). Without
' accurate seek the player lands on the sync frame BEFORE the target — inside the skipped segment,
' before a short one's start, or in an earlier one — and re-arming there loops the skip.
private quietUntilMs as integer = -1
' UUIDs already reported to the service: one report per segment per viewing.
private reportedSegmentIds as object = {}
function new(deps as object)
m.jobQueue = deps.jobQueue
@@ -73,92 +88,129 @@ namespace SponsorBlockController
return
end if
m.segments = segments
m.timeline = info.data.timeline
if m.top <> invalid
m.top.seekMode = "accurate"
end if
LogDebug("segments ready:", segments.Count())
end function
' The real position (ms) while idle. Returns { skipSeekMs } (auto-skip), { finish: true } (segment at
' the video end), or invalid. A manual segment only shows the notification + stashes for the next OK
' (TrySkip). Reports the skip to the service on an actual auto-skip.
function OnPosition(positionMs as integer) as object
' The real position (ms) while idle. Returns the auto-skip target (ms), FINISH_SENTINEL (segment at the
' video end), or NO_SKIP. A manual segment only shows the notification + arms it for the next OK
' (TrySkip), and withdraws it once OK can no longer skip. Reports the skip to the service on an actual
' auto-skip.
function OnPosition(positionMs as integer) as integer
if not m.enabled or m.segments = invalid
return invalid
return SponsorBlockController.NO_SKIP
end if
if m.quietUntilMs >= 0
' inclusive: the first tick after a seek echoes the target before reporting the actual landing.
if positionMs <= m.quietUntilMs + SponsorBlockController.SEEK_ECHO_SLACK_MS
return SponsorBlockController.NO_SKIP
end if
m.quietUntilMs = -1
end if
positionS = positionMs / 1000.0
segment = SponsorBlockController.FindSegmentByTime(m.segments, positionS)
if segment = invalid
' left the segment: a Back-dismissal only suppresses the current pass — re-entering later re-arms.
m.dismissedSegmentId = ""
return invalid
if m.dismissedIndex <> -1
dismissed = m.segments[m.dismissedIndex]
if positionS < dismissed.start or positionS > dismissed.end
m.dismissedIndex = -1
end if
end if
if segment.showNotification and Abs(segment.end - positionS) >= 1 and segment.UUID <> m.dismissedSegmentId
index = SponsorBlock.FindTimelineSegmentIndex(m.timeline, positionS)
segment = invalid
targetMs = SponsorBlockController.NO_SKIP
if index <> -1 and index <> m.dismissedIndex
segment = m.segments[index]
if SponsorBlock.IsSkippable(segment)
targetMs = SponsorBlockController.SkipTargetMs(segment, positionS, m.Duration())
end if
end if
if m.manualSkipIndex <> -1 and (targetMs = SponsorBlockController.NO_SKIP or m.manualSkipIndex <> index)
m.WithdrawManual()
end if
if targetMs = SponsorBlockController.NO_SKIP
return targetMs
end if
if segment.showNotification
SponsorBlock.ShowNotifcation(m.notifications, segment)
end if
if segment.option = SponsorBlock.SegmentAction.ManualSkip
m.manualSkipSegment = segment
return invalid
m.manualSkipIndex = index
return SponsorBlockController.NO_SKIP
end if
end if
if segment.option = SponsorBlock.SegmentAction.AutoSkip
result = SponsorBlockController.SkipTargetForSegment(segment, positionS, m.Duration())
if result <> invalid
m.SendSegmentViewed(segment.UUID)
end if
return result
end if
return invalid
m.OnSkipped(segment, targetMs)
return targetMs
end function
' The OK routing calls this first. Returns the seek target (ms) for the stashed manual segment if the
' position is still inside it (FINISH_SENTINEL at the video end), else -1. Reports the skip on success.
' The coordinator applied a seek. Any seek but our own skip wakes the segments a skip quieted.
function OnSeek(seekMs as integer) as void
if seekMs <> m.quietUntilMs
m.quietUntilMs = -1
end if
end function
' The OK routing calls this first. Returns the seek target (ms) for the armed manual segment if the
' position is still inside it (FINISH_SENTINEL at the video end), else NO_SKIP. Reports the skip on success.
function TrySkip(positionMs as integer) as integer
segment = m.manualSkipSegment
if segment = invalid
return -1
end if
m.manualSkipSegment = invalid
notification = SponsorBlock.GetCurrentNotification(m.notifications)
if notification = invalid or notification.segmentId <> segment.UUID
return -1
index = m.manualSkipIndex
m.manualSkipIndex = -1
if not m.IsManualPromptShowing(index)
return SponsorBlockController.NO_SKIP
end if
segment = m.segments[index]
positionS = positionMs / 1000.0
if positionS < segment.start or segment.end < positionS
return -1
return SponsorBlockController.NO_SKIP
end if
result = SponsorBlockController.SkipTargetForSegment(segment, positionS, m.Duration())
targetMs = SponsorBlockController.SkipTargetMs(segment, positionS, m.Duration())
SponsorBlock.RemoveNotifcation(m.notifications)
if result = invalid
return -1
if targetMs <> SponsorBlockController.NO_SKIP
m.OnSkipped(segment, targetMs)
end if
m.SendSegmentViewed(segment.UUID)
if result.finish = true
return SponsorBlockController.FINISH_SENTINEL
end if
return result.skipSeekMs
return targetMs
end function
' Back while the manual-skip notice is up: dismiss the notice without skipping (and without it
' re-arming until the position leaves the segment). Returns true if a notice was dismissed — the
' caller then swallows the Back instead of acting on the player.
' re-arming until the position leaves the segment). Returns true if a notice was dismissed — the caller
' then swallows the Back instead of acting on the player.
function DismissManual() as boolean
segment = m.manualSkipSegment
if segment = invalid
index = m.manualSkipIndex
if not m.IsManualPromptShowing(index)
return false
end if
m.manualSkipIndex = -1
m.dismissedIndex = index
SponsorBlock.RemoveNotifcation(m.notifications)
return true
end function
function OnSkipped(segment as object, targetMs as integer) as void
if targetMs <> SponsorBlockController.FINISH_SENTINEL
m.quietUntilMs = targetMs
end if
m.SendSegmentViewed(segment.UUID)
end function
function WithdrawManual() as void
if m.IsManualPromptShowing(m.manualSkipIndex)
SponsorBlock.RemoveNotifcation(m.notifications)
end if
m.manualSkipIndex = -1
end function
function IsManualPromptShowing(index as integer) as boolean
if index = -1
return false
end if
notification = SponsorBlock.GetCurrentNotification(m.notifications)
if notification = invalid or notification.segmentId <> segment.UUID
return false
end if
m.manualSkipSegment = invalid
m.dismissedSegmentId = ValidString(segment.UUID)
SponsorBlock.RemoveNotifcation(m.notifications)
return true
return notification <> invalid and notification.segmentId = m.segments[index].UUID
end function
' The chapter label text for a cursor (ms): the segment title inside a segment, else "".
@@ -166,11 +218,11 @@ namespace SponsorBlockController
if not m.enabled or m.segments = invalid
return ""
end if
segment = SponsorBlockController.FindSegmentByTime(m.segments, cursorMs / 1000.0)
if segment = invalid
index = SponsorBlock.FindTimelineSegmentIndex(m.timeline, cursorMs / 1000.0)
if index = -1
return ""
end if
return ValidString(segment.title)
return ValidString(m.segments[index].title)
end function
function HasSegments() as boolean
@@ -184,38 +236,24 @@ namespace SponsorBlockController
end if
end function
' Reset on close / new content.
function Clear() as void
' Take the notice down and drop every held node ref on close so the controller — and the player node it
' points at — can free.
function Dispose() as void
if m.notifications <> invalid
SponsorBlock.RemoveNotifcation(m.notifications)
end if
m.segments = invalid
m.manualSkipSegment = invalid
m.dismissedSegmentId = ""
m.enabled = false
end function
' Drop every held node ref on close so the controller — and the player node it points at — can free.
function Dispose() as void
m.Clear()
' a skip can fire just before close and must still report — release the ref, don't cancel the in-flight job.
m.sponsorSkipEventJob = invalid
m.top = invalid
m.jobQueue = invalid
m.preferences = invalid
m.notifications = invalid
end function
' Report a skipped segment to the SponsorBlock service (fire-and-forget).
function SendSegmentViewed(segmentId as string) as void
if m.jobQueue = invalid
if m.jobQueue = invalid or m.reportedSegmentIds.DoesExist(segmentId)
return
end if
if m.sponsorSkipEventJob <> invalid
m.sponsorSkipEventJob.cancel = true
end if
m.sponsorSkipEventJob = JobSystem.CreateCallback()
JobSystem.QueueJob(m.jobQueue, Jobs.SponsorBlockSegmentViewedJob, { segmentId: segmentId }, m.sponsorSkipEventJob)
m.reportedSegmentIds[segmentId] = true
JobSystem.QueueJob(m.jobQueue, Jobs.SponsorBlockSegmentViewedJob, { segmentId: segmentId })
end function
function Duration() as float
@@ -227,40 +265,21 @@ namespace SponsorBlockController
end class
' Binary search for the segment containing `time` (seconds); segments are sorted by start. May miss
' overlapping segments (acceptable — they are rare).
function FindSegmentByTime(segments as object, time as dynamic) as dynamic
low = 0
high = segments.Count() - 1
while low <= high
middle = (low + high) \ 2
segment = segments[middle]
if time < segment.start
high = middle - 1
else if time > segment.end
low = middle + 1
else
return segment
end if
end while
return invalid
end function
' The seek decision for a segment at `positionS` (seconds): { skipSeekMs } | { finish: true } (segment at
' the video end) | invalid (too short — a skip would just rebuffer). `duration` clamps a segment end past
' the video end.
function SkipTargetForSegment(segment as object, positionS as dynamic, duration as dynamic) as object
' The seek decision for a segment at `positionS` (seconds): the target (ms), FINISH_SENTINEL (segment at the
' video end), or NO_SKIP (too short — a skip would just rebuffer). `duration` clamps a segment end past the
' video end.
function SkipTargetMs(segment as object, positionS as dynamic, duration as dynamic) as integer
segmentEnd = segment.end
if duration > 0 and segmentEnd > duration
segmentEnd = duration
end if
if Abs(segmentEnd - positionS) < 2
return invalid
return SponsorBlockController.NO_SKIP
end if
if duration > 0 and Abs(segmentEnd - duration) < 2
return { finish: true }
return SponsorBlockController.FINISH_SENTINEL
end if
return { skipSeekMs: Int(segmentEnd * 1000) }
return Int(segmentEnd * 1000)
end function
end namespace
@@ -92,7 +92,7 @@ namespace TransportController
const REPLAY_BACK_MS = 20000
' A VOD commit landing within this of the duration means "watched to the end" -> finish (PlayNext/close),
' not a seek into the last instants (which just re-buffers and fights the device's EOF auto-resume).
' Matches the SponsorBlock finish rule (SkipTargetForSegment).
' Matches the SponsorBlock finish rule (SponsorBlockController.SkipTargetMs).
const FINISH_EPSILON_MS = 2000
const REPLAY_TOAST_MS = 700 ' how long the transient InstantReplay icon stays before it self-clears
' "● LIVE" shows while the offset is within this jitter band of the inherent latency; beyond it the bar
@@ -313,6 +313,7 @@ end function
' Apply a seek (ms): the one writer of the device's `seek`. The live "jump to edge" sentinel maps to the
' live-end seek the OS understands.
function ApplySeek(seekMs as integer) as void
m.sponsorblock.OnSeek(seekMs)
if TransportController.IsLiveEdgeSentinelMs(seekMs)
m.top.seek = 999999
return
@@ -406,7 +407,7 @@ end function
' on-screen "Press OK to skip" must win over the button/bar focus tiers.
function TrySponsorBlockSkip() as boolean
skip = m.sponsorblock.TrySkip(Int(m.top.position * 1000))
if skip = -1
if skip = SponsorBlockController.NO_SKIP
return false
end if
LogDebug("OK skip resolved=", skip, " (FINISH=", SponsorBlockController.FINISH_SENTINEL, ") posS=", m.top.position, " mode=", m.transport.transportMode)
@@ -887,15 +888,13 @@ function OnPosition(event as object) as void
end if
' SponsorBlock auto-skip off the real position (the controller decides; we apply the seek / finish).
sb = m.sponsorblock.OnPosition(posMs)
if sb <> invalid
if sb.finish = true
skipMs = m.sponsorblock.OnPosition(posMs)
if skipMs = SponsorBlockController.FINISH_SENTINEL
OnPlaybackFinished()
else
m.transport.ForceIdleSeek(sb.skipSeekMs, true) ' through the module (no out-of-band seek); keep playing
else if skipMs <> SponsorBlockController.NO_SKIP
m.transport.ForceIdleSeek(skipMs, true) ' through the module (no out-of-band seek); keep playing
ApplyTransport()
end if
end if
' report watch progress to the account in 20-second steps.
if m.reportWatchTime and m.markVideoWatchedJob <> invalid
@@ -36,9 +36,12 @@ function TestSetup() as void
container.fullscreen = true
m.top.container = container
' swallows the jobs the coordinator queues (JobSystem.QueueJob writes request) without running them
' swallows the jobs the coordinator queues (JobSystem.QueueJob writes request) without running them,
' counting the SponsorBlock viewed-segment reports (alwaysNotify: a repeated identical report must count).
jobQueue = createObject("roSGNode", "Node")
jobQueue.addField("request", "assocarray", false)
jobQueue.addField("request", "assocarray", true)
m.top.sponsorViewedCount = 0
jobQueue.observeFieldScoped("request", FuncName(OnTestJobRequest))
m.top.jobQueue = jobQueue
m.top.notifications = createObject("roSGNode", "Node")
m.top.preferences = createObject("roSGNode", "Node")
@@ -95,6 +98,12 @@ function OnTestNudge() as void
m.top.nudgeCount += 1
end function
function OnTestJobRequest(event as object) as void
if event.getData().jobName = Jobs.SponsorBlockSegmentViewedJob
m.top.sponsorViewedCount += 1
end if
end function
' TestKey — drive a remote key through the REAL OnKeyEvent (scrub/scan/commit/etc).
function TestKey(key as string, down as boolean) as boolean
return OnKeyEvent(key, down)
@@ -126,6 +135,7 @@ end function
function TestSeedSponsorBlock(segments as object) as void
m.sponsorblock.enabled = true
m.sponsorblock.segments = segments
m.sponsorblock.timeline = SponsorBlock.BuildTimeline(segments)
end function
' TestSeekToInitialPosition — the content-load seek (live edge / resume timestamp / percent watched), minus the
@@ -46,6 +46,8 @@
<field id="setSeek" type="float" alwaysNotify="true" />
<!-- test-only probe: how many times the coordinator pulsed ButtonRow.nudge (TestSetup observes it). -->
<field id="nudgeCount" type="integer" />
<!-- test-only probe: how many SponsorBlock viewed-segment reports the coordinator queued. -->
<field id="sponsorViewedCount" type="integer" />
<!-- the Video-only method Initialize calls, plus the spec's drivers (callFunc reaches only interface funcs). -->
<function name="getHttpAgent" />
<function name="TestSetup" />
@@ -627,6 +627,110 @@ namespace Tests
m.assertTrue(m.top.videoQueue.closePlayer, "no next video -> the finish closed the player")
end function
' =========================================================================================
' SponsorBlock skip — the device lands a seek on the sync frame BEFORE its target when it can't seek
' accurately (measured 3.3-6.7s short); the position ticks then echo the target before the landing.
' =========================================================================================
function AutoSegment(startS as float, endS as float) as object
return [{ start: startS, end: endS, option: "auto_skip", title: "Sponsor", shortTitle: "Sponsor", actionText: "Skipped", showNotification: false, UUID: "seg-auto", category: "sponsor" }]
end function
' -1 = the coordinator wrote no seek since the spec armed the probe.
function ArmSeekProbe() as void
m.top.seek = -1
end function
function AssertSeekedTo(targetS as float, message as string) as void
m.assertTrue(Abs(m.top.seek - targetS) < 0.01, message + " (seek=" + m.top.seek.ToStr() + ")")
end function
@it("an auto-skip seeks once: the target echo and a landing short of it inside the segment don't re-seek")
function _()
m.top.duration = 300
m.top.callFunc("TestSeedSponsorBlock", m.AutoSegment(60.0, 75.3))
m.top.position = 60.0
m.AssertSeekedTo(75.3, "entering the segment skips to its end")
m.ArmSeekProbe()
for each positionS in [75.3, 72.0, 73.0, 74.0, 75.0, 76.0]
m.top.position = positionS
end for
m.assertEqual(m.top.seek, -1.0, "the skip loop: a landing inside the segment re-armed it")
m.assertEqual(m.top.sponsorViewedCount, 1)
end function
@it("a landing before a short segment's start doesn't re-seek when playback re-enters it")
function _()
m.top.duration = 300
m.top.callFunc("TestSeedSponsorBlock", m.AutoSegment(131.5, 137.7))
m.top.position = 132.0
m.AssertSeekedTo(137.7, "entering the segment skips to its end")
m.ArmSeekProbe()
for each positionS in [137.7, 131.0, 132.0, 133.0, 137.0, 138.0]
m.top.position = positionS
end for
m.assertEqual(m.top.seek, -1.0, "the skip loop: re-entering the segment from the landing re-armed it")
end function
@it("a user seek back into a skipped segment skips it again, and reports it once")
function _()
m.top.duration = 300
m.top.callFunc("TestSeedSponsorBlock", m.AutoSegment(60.0, 100.0))
m.top.position = 60.0
m.top.position = 100.0
m.top.position = 95.0
m.top.callFunc("TestKey", RemoteKeys.Replay, true) ' InstantReplay: 95s - 20s
m.AssertSeekedTo(75.0, "the replay seek")
m.top.position = 75.0
m.AssertSeekedTo(100.0, "the user's seek woke the segment: it skips again")
m.assertEqual(m.top.sponsorViewedCount, 1, "a segment is reported once per viewing")
end function
@it("a setSeek back into a skipped segment skips it again")
function _()
m.top.duration = 300
m.top.callFunc("TestSeedSponsorBlock", m.AutoSegment(60.0, 100.0))
m.top.position = 60.0
m.top.position = 100.0
m.top.position = 95.0
m.top.setSeek = 70.0
m.AssertSeekedTo(70.0, "the external seek")
m.top.position = 70.0
m.AssertSeekedTo(100.0, "the external seek woke the segment: it skips again")
end function
@it("an OK skip landing short inside the segment doesn't re-arm the notice")
function _()
m.top.duration = 100
m.top.callFunc("TestSeedSponsorBlock", m.ManualSegment(10.0, 40.0))
m.top.position = 12.0
m.top.callFunc("TestKey", RemoteKeys.Ok, true)
m.AssertSeekedTo(40.0, "OK skips to the segment end")
m.top.position = 40.0
m.top.position = 34.0
m.top.position = 35.0
m.assertFalse(m.Snap().sponsorNoticeShown, "the landing re-armed the notice")
end function
@it("the manual notice comes down once OK can no longer skip")
function _()
m.top.duration = 100
m.top.callFunc("TestSeedSponsorBlock", m.ManualSegment(10.0, 40.0))
m.top.position = 12.0
m.assertTrue(m.Snap().sponsorNoticeShown)
m.top.position = 38.5 ' within 2s of the end: a skip is no longer worth a rebuffer
m.assertFalse(m.Snap().sponsorNoticeShown)
seekBefore = m.top.seek
m.top.callFunc("TestKey", RemoteKeys.Ok, true)
m.assertEqual(m.top.seek, seekBefore, "OK no longer skips")
end function
@it("the non-transport keys act on the key-DOWN edge only")
function _()
' Back goes first: only from the start state does its DOWN edge close the player.
@@ -0,0 +1,135 @@
import "pkg:/components/Services/SponsorBlock/SponsorBlockTimeline.bs"
namespace Tests
@suite
class SponsorBlockTimelineTests extends Rooibos.BaseTestSuite
function Auto(startS as float, endS as float) as object
return { start: startS, end: endS, option: "auto_skip", showNotification: false }
end function
function Manual(startS as float, endS as float) as object
return { start: startS, end: endS, option: "manual_skip", showNotification: true }
end function
function Seekbar(startS as float, endS as float) as object
return { start: startS, end: endS, option: "show_in_seekbar", showNotification: false }
end function
function AssertTimeline(timeline as object, starts as object, ends as object, segmentIndexes as object) as void
m.assertEqual(timeline.starts, starts)
m.assertEqual(timeline.ends, ends)
m.assertEqual(timeline.segmentIndexes, segmentIndexes)
end function
@describe("SponsorBlock.BuildTimeline")
@it("keeps disjoint segments as they are, in time order")
function _()
timeline = SponsorBlock.BuildTimeline([m.Auto(100, 110), m.Manual(0, 21.5)])
m.AssertTimeline(timeline, [0.0, 100.0], [21.5, 110.0], [1, 0])
end function
@it("gives the part an auto-skip segment covers to it, inside a seekbar-only one")
function _()
timeline = SponsorBlock.BuildTimeline([m.Seekbar(90, 300), m.Auto(100, 130)])
m.AssertTimeline(timeline, [90.0, 100.0, 130.0], [100.0, 130.0, 300.0], [0, 1, 0])
end function
@it("ranks auto-skip over a prompting manual segment over the rest")
function _()
timeline = SponsorBlock.BuildTimeline([m.Seekbar(0, 30), m.Manual(0, 20), m.Auto(0, 10)])
m.AssertTimeline(timeline, [0.0, 10.0, 20.0], [10.0, 20.0, 30.0], [2, 1, 0])
end function
@it("ranks a manual segment without a prompt with the seekbar-only ones")
function _()
silent = m.Manual(0, 20)
silent.showNotification = false
timeline = SponsorBlock.BuildTimeline([silent, m.Seekbar(0, 30)])
m.AssertTimeline(timeline, [0.0], [30.0], [1])
end function
@it("gives an overlap between equal ranks to the segment ending later")
function _()
timeline = SponsorBlock.BuildTimeline([m.Auto(100, 130), m.Auto(120, 150)])
m.AssertTimeline(timeline, [100.0, 120.0], [120.0, 150.0], [0, 1])
end function
@it("gives a full tie to the first segment")
function _()
timeline = SponsorBlock.BuildTimeline([m.Auto(100, 130), m.Auto(110, 130)])
m.AssertTimeline(timeline, [100.0], [130.0], [0])
end function
@it("orders integer and float bounds numerically, as the API's JSON mixes them")
function _()
timeline = SponsorBlock.BuildTimeline([
{ start: 0, end: 21.808, option: "manual_skip", showNotification: true }
{ start: 10, end: 15.5, option: "auto_skip", showNotification: false }
])
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 5.0), 0)
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 12.0), 1)
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 18.0), 0)
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 22.0), -1)
end function
@it("lets a containing segment of equal rank own a nested one")
function _()
timeline = SponsorBlock.BuildTimeline([m.Auto(100, 200), m.Auto(120, 130), m.Auto(300, 310)])
m.AssertTimeline(timeline, [100.0, 300.0], [200.0, 310.0], [0, 2])
end function
@it("gives a zero-length segment no interval")
function _()
timeline = SponsorBlock.BuildTimeline([m.Seekbar(50, 50), m.Auto(100, 110)])
m.AssertTimeline(timeline, [100.0], [110.0], [1])
end function
@it("returns an empty timeline for no segments")
function _()
m.AssertTimeline(SponsorBlock.BuildTimeline([]), [], [], [])
end function
@describe("SponsorBlock.FindTimelineSegmentIndex")
@it("finds the owner inside an interval and -1 in a gap")
function _()
timeline = SponsorBlock.BuildTimeline([m.Manual(0, 21.5), m.Auto(100, 110), m.Manual(249, 281)])
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 12.0), 0)
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 105.0), 1)
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 260.0), 2)
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 50.0), -1)
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 300.0), -1)
end function
@it("includes both interval ends")
function _()
timeline = SponsorBlock.BuildTimeline([m.Manual(0, 21.5)])
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 0.0), 0)
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 21.5), 0)
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 21.6), -1)
end function
@it("gives a point two intervals share to the later one")
function _()
timeline = SponsorBlock.BuildTimeline([m.Auto(100, 110), m.Manual(110, 120)])
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 110.0), 1)
end function
@it("finds a containing segment past a later-starting nested one")
function _()
timeline = SponsorBlock.BuildTimeline([m.Seekbar(100, 200), m.Auto(120, 130), m.Seekbar(300, 310)])
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 150.0), 0)
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(timeline, 125.0), 1)
end function
@it("returns -1 on an empty timeline")
function _()
m.assertEqual(SponsorBlock.FindTimelineSegmentIndex(SponsorBlock.BuildTimeline([]), 10.0), -1)
end function
end class
end namespace
@@ -1,5 +1,5 @@
' SponsorBlockController unit suite — the pure SponsorBlock decision logic in isolation. No real job: seed the
' segments array directly + a fake `top` (for duration) and assert the find/skip/chapter decisions. The
' segments + their timeline directly + a fake `top` (for duration) and assert the skip/chapter decisions. The
' notification + job plumbing live in the coordinator; manual-skip is tested via the stash + position guard.
import "pkg:/components/VideoPlayerDev/SponsorBlockController.bs"
@@ -19,37 +19,20 @@ namespace Tests
top: m.fakeTop
})
' Despacito-like segments: music_offtopic [0,21.808] manual, sponsor [100,110] auto, music_offtopic
' [249.38,281.521] manual. Sorted by start.
' [249.38,281.521] manual.
m.segments = [
{ start: 0.0, end: 21.808, option: "manual_skip", title: "Music: Non-Music Section", shortTitle: "Non-Music", showNotification: true, UUID: "seg-a", category: "music_offtopic" }
{ start: 100.0, end: 110.0, option: "auto_skip", title: "Sponsor", shortTitle: "Sponsor", showNotification: false, UUID: "seg-b", category: "sponsor" }
{ start: 249.38, end: 281.521, option: "manual_skip", title: "Music: Non-Music Section", shortTitle: "Non-Music", showNotification: true, UUID: "seg-c", category: "music_offtopic" }
]
' seed the controller as if the job had returned (the enable gate + stored segments).
m.Seed(m.segments)
end function
' seed the controller as if the job had returned (the enable gate + stored segments + their timeline).
function Seed(segments as object) as void
m.sb.enabled = true
m.sb.segments = m.segments
end function
@describe("find segment by time")
@it("finds the segment containing the time")
function _()
seg = SponsorBlockController.FindSegmentByTime(m.segments, 12.0)
m.assertEqual(seg.UUID, "seg-a")
seg = SponsorBlockController.FindSegmentByTime(m.segments, 105.0)
m.assertEqual(seg.UUID, "seg-b")
end function
@it("returns invalid between segments")
function _()
m.assertInvalid(SponsorBlockController.FindSegmentByTime(m.segments, 50.0))
m.assertInvalid(SponsorBlockController.FindSegmentByTime(m.segments, 200.0))
end function
@it("includes the segment boundaries")
function _()
m.assertEqual(SponsorBlockController.FindSegmentByTime(m.segments, 0.0).UUID, "seg-a")
m.assertEqual(SponsorBlockController.FindSegmentByTime(m.segments, 21.808).UUID, "seg-a")
m.sb.segments = segments
m.sb.timeline = SponsorBlock.BuildTimeline(segments)
end function
@describe("skip target")
@@ -57,31 +40,31 @@ namespace Tests
@it("returns the segment end (ms) as the seek target")
function _()
seg = m.segments[1] ' [100,110] auto
result = SponsorBlockController.SkipTargetForSegment(seg, 102.0, m.fakeTop.duration)
m.assertEqual(result.skipSeekMs, 110000)
result = SponsorBlockController.SkipTargetMs(seg, 102.0, m.fakeTop.duration)
m.assertEqual(result, 110000)
end function
@it("returns finish when the segment ends within 2s of the video end")
function _()
' [249.38,281.521], duration 282 -> end within 2s of duration -> finish.
seg = m.segments[2]
result = SponsorBlockController.SkipTargetForSegment(seg, 250.0, m.fakeTop.duration)
m.assertTrue(result.finish = true)
result = SponsorBlockController.SkipTargetMs(seg, 250.0, m.fakeTop.duration)
m.assertEqual(result, SponsorBlockController.FINISH_SENTINEL)
end function
@it("returns invalid when the skip distance is under 2s")
@it("returns NO_SKIP when the skip distance is under 2s")
function _()
seg = m.segments[1] ' [100,110]
result = SponsorBlockController.SkipTargetForSegment(seg, 109.0, m.fakeTop.duration)
m.assertInvalid(result)
result = SponsorBlockController.SkipTargetMs(seg, 109.0, m.fakeTop.duration)
m.assertEqual(result, SponsorBlockController.NO_SKIP)
end function
@it("clamps the segment end to the video duration")
function _()
m.fakeTop.duration = 105.0
seg = m.segments[1] ' [100,110] -> clamped to 105 == duration -> within 2s -> finish
result = SponsorBlockController.SkipTargetForSegment(seg, 101.0, m.fakeTop.duration)
m.assertTrue(result.finish = true)
result = SponsorBlockController.SkipTargetMs(seg, 101.0, m.fakeTop.duration)
m.assertEqual(result, SponsorBlockController.FINISH_SENTINEL)
end function
@describe("OnPosition auto-skip")
@@ -89,18 +72,18 @@ namespace Tests
@it("returns a skip seek target while inside an auto-skip segment")
function _()
result = m.sb.OnPosition(105000) ' 105s, inside [100,110] auto
m.assertEqual(result.skipSeekMs, 110000)
m.assertEqual(result, 110000)
end function
@it("returns invalid inside a manual-skip segment + stashes it for OK")
@it("returns NO_SKIP inside a manual-skip segment + arms it for OK")
function _()
m.sb.notifications = CreateObject("roSGNode", "Group")
result = m.sb.OnPosition(5000) ' inside [0,21.808] manual
m.assertInvalid(result)
m.assertEqual(m.sb.manualSkipSegment.UUID, "seg-a")
m.assertEqual(result, SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.manualSkipIndex, 0)
end function
@it("TrySkip returns the stashed manual segment's end while still inside it")
@it("TrySkip returns the armed manual segment's end while still inside it")
function _()
m.sb.notifications = CreateObject("roSGNode", "Group")
m.sb.OnPosition(5000) ' stash [0,21.808]
@@ -108,20 +91,148 @@ namespace Tests
m.assertEqual(target, 21808)
end function
@it("TrySkip returns -1 with nothing stashed")
@it("does not re-arm the manual notice when the OK skip lands back inside the segment")
function _()
m.assertEqual(m.sb.TrySkip(6000), -1)
m.sb.notifications = CreateObject("roSGNode", "Group")
m.sb.OnPosition(5000)
m.assertEqual(m.sb.TrySkip(6000), 21808)
m.sb.OnSeek(21808)
m.assertEqual(m.sb.OnPosition(18000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.manualSkipIndex, -1)
m.assertEqual(m.sb.notifications.getChildCount(), 0)
end function
@it("returns invalid outside any segment")
@it("withdraws the manual notice once OK can no longer skip")
function _()
m.assertInvalid(m.sb.OnPosition(50000))
m.sb.notifications = CreateObject("roSGNode", "Group")
m.sb.OnPosition(5000)
m.assertEqual(m.sb.notifications.getChildCount(), 1)
m.sb.OnPosition(20500) ' within 2s of the end [0,21.808]
m.assertEqual(m.sb.manualSkipIndex, -1)
m.assertEqual(m.sb.notifications.getChildCount(), 0)
end function
@it("returns invalid when disabled")
@it("withdraws the manual notice when the position leaves the segment")
function _()
m.sb.notifications = CreateObject("roSGNode", "Group")
m.sb.OnPosition(5000)
m.sb.OnPosition(50000)
m.assertEqual(m.sb.manualSkipIndex, -1)
m.assertEqual(m.sb.notifications.getChildCount(), 0)
m.assertFalse(m.sb.DismissManual())
end function
@it("TrySkip returns NO_SKIP with nothing armed")
function _()
m.assertEqual(m.sb.TrySkip(6000), SponsorBlockController.NO_SKIP)
end function
@it("returns NO_SKIP outside any segment")
function _()
m.assertEqual(m.sb.OnPosition(50000), SponsorBlockController.NO_SKIP)
end function
@it("does not re-skip when an inexact seek lands back inside the skipped segment")
function _()
m.assertEqual(m.sb.OnPosition(100000), 110000)
m.sb.OnSeek(110000)
' the player reports the target, then the sync frame it actually landed on, short of the end.
m.assertEqual(m.sb.OnPosition(110000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(106700), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(108000), SponsorBlockController.NO_SKIP)
end function
@it("stays quiet on a target echo that single precision reads a few ms past the target")
function _()
m.assertEqual(m.sb.OnPosition(100000), 110000)
m.sb.OnSeek(110000)
m.assertEqual(m.sb.OnPosition(110004), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(106700), SponsorBlockController.NO_SKIP)
end function
@it("does not re-skip a short segment when the seek lands before its start")
function _()
m.Seed([
{ start: 111.0, end: 114.0, option: "auto_skip", showNotification: false, UUID: "seg-x" }
])
m.assertEqual(m.sb.OnPosition(111000), 114000)
m.sb.OnSeek(114000)
m.assertEqual(m.sb.OnPosition(114000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(106700), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(111000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(113000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(115000), SponsorBlockController.NO_SKIP)
end function
@it("does not skip an earlier segment the seek lands in")
function _()
m.Seed([
{ start: 100.0, end: 110.0, option: "auto_skip", showNotification: false, UUID: "seg-x" }
{ start: 111.0, end: 114.0, option: "auto_skip", showNotification: false, UUID: "seg-y" }
])
m.assertEqual(m.sb.OnPosition(111000), 114000)
m.sb.OnSeek(114000)
m.assertEqual(m.sb.OnPosition(114000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(106700), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(110000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(112000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(115000), SponsorBlockController.NO_SKIP)
end function
@it("skips again after a user seek back into the skipped segment")
function _()
m.sb.OnPosition(100000)
m.sb.OnSeek(110000)
m.sb.OnPosition(106700)
m.sb.OnSeek(102000)
m.assertEqual(m.sb.OnPosition(102000), 110000)
end function
@it("skips an adjacent segment entered straight from the skipped one")
function _()
m.Seed([
{ start: 100.0, end: 110.0, option: "auto_skip", showNotification: false, UUID: "seg-x" }
{ start: 110.0, end: 120.0, option: "auto_skip", showNotification: false, UUID: "seg-y" }
])
m.sb.OnPosition(100000)
m.assertEqual(m.sb.OnPosition(107000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(110500), 120000)
end function
@it("skips an auto-skip segment nested in a seekbar-only one")
function _()
m.Seed([
{ start: 0.0, end: 250.0, option: "show_in_seekbar", showNotification: false, UUID: "seg-x", title: "Filler" }
{ start: 100.0, end: 130.0, option: "auto_skip", showNotification: false, UUID: "seg-y", title: "Sponsor" }
])
m.assertEqual(m.sb.OnPosition(101000), 130000)
m.assertEqual(m.sb.ChapterTextForCursor(101000), "Sponsor")
m.assertEqual(m.sb.ChapterTextForCursor(140000), "Filler")
end function
@it("reports a segment once per viewing, however often it is skipped")
function _()
m.sb.jobQueue = { request: invalid }
m.sb.OnPosition(100000)
m.assertNotInvalid(m.sb.jobQueue.request)
m.sb.jobQueue.request = invalid
m.sb.OnSeek(102000)
m.assertEqual(m.sb.OnPosition(102000), 110000)
m.assertInvalid(m.sb.jobQueue.request)
end function
@it("shows no auto-skip notice when the segment is too close to its end to skip")
function _()
m.sb.notifications = CreateObject("roSGNode", "Group")
m.segments[1].showNotification = true
m.assertEqual(m.sb.OnPosition(109000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.notifications.getChildCount(), 0)
end function
@it("returns NO_SKIP when disabled")
function _()
m.sb.enabled = false
m.assertInvalid(m.sb.OnPosition(105000))
m.assertEqual(m.sb.OnPosition(105000), SponsorBlockController.NO_SKIP)
end function
@describe("manual notice dismissal (Back)")
@@ -131,11 +242,47 @@ namespace Tests
m.sb.notifications = CreateObject("roSGNode", "Group")
m.sb.OnPosition(5000) ' arm + show the manual notice for [0,21.808]
m.assertTrue(m.sb.DismissManual())
m.assertInvalid(m.sb.manualSkipSegment)
m.assertEqual(m.sb.manualSkipIndex, -1)
' still inside the segment: the notice must NOT re-arm/re-show on the next position ticks.
m.assertInvalid(m.sb.OnPosition(6000))
m.assertInvalid(m.sb.manualSkipSegment)
m.assertEqual(m.sb.TrySkip(7000), -1)
m.assertEqual(m.sb.OnPosition(6000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.manualSkipIndex, -1)
m.assertEqual(m.sb.TrySkip(7000), SponsorBlockController.NO_SKIP)
end function
@it("withdraws a manual notice for a nested auto-skip segment and re-arms it after the skip lands")
function _()
m.sb.notifications = CreateObject("roSGNode", "Group")
m.Seed([
{ start: 90.0, end: 200.0, option: "manual_skip", showNotification: true, UUID: "seg-x" }
{ start: 100.0, end: 130.0, option: "auto_skip", showNotification: false, UUID: "seg-y" }
])
m.sb.OnPosition(95000)
m.assertEqual(m.sb.manualSkipIndex, 0)
m.assertEqual(m.sb.OnPosition(101000), 130000)
m.assertEqual(m.sb.manualSkipIndex, -1)
m.assertEqual(m.sb.notifications.getChildCount(), 0)
m.sb.OnSeek(130000)
m.assertEqual(m.sb.OnPosition(126000), SponsorBlockController.NO_SKIP)
m.sb.OnPosition(131000)
m.assertEqual(m.sb.manualSkipIndex, 0)
m.assertEqual(m.sb.TrySkip(132000), 200000)
end function
@it("a dismissed segment stays quiet around an auto-skip segment nested in it")
function _()
m.sb.notifications = CreateObject("roSGNode", "Group")
m.Seed([
{ start: 90.0, end: 200.0, option: "manual_skip", showNotification: true, UUID: "seg-x" }
{ start: 100.0, end: 130.0, option: "auto_skip", showNotification: false, UUID: "seg-y" }
])
m.sb.OnPosition(95000)
m.assertTrue(m.sb.DismissManual())
m.assertEqual(m.sb.OnPosition(101000), 130000)
m.sb.OnSeek(130000)
m.assertEqual(m.sb.OnPosition(126000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(131000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.manualSkipIndex, -1)
m.assertEqual(m.sb.notifications.getChildCount(), 0)
end function
@it("DismissManual is a no-op without an armed notice")
@@ -149,9 +296,22 @@ namespace Tests
m.sb.notifications = CreateObject("roSGNode", "Group")
m.sb.OnPosition(5000)
m.assertTrue(m.sb.DismissManual())
m.sb.OnPosition(50000) ' outside any segment -> the dismissal is forgotten
m.sb.OnPosition(7000) ' back inside -> armed again
m.assertEqual(m.sb.manualSkipSegment.UUID, "seg-a")
m.sb.OnPosition(50000)
m.sb.OnPosition(7000)
m.assertEqual(m.sb.manualSkipIndex, 0)
end function
@it("a dismissal leaves the next segment active")
function _()
m.sb.notifications = CreateObject("roSGNode", "Group")
m.Seed([
{ start: 100.0, end: 110.0, option: "manual_skip", showNotification: true, UUID: "seg-x" }
{ start: 110.0, end: 120.0, option: "auto_skip", showNotification: false, UUID: "seg-y" }
])
m.sb.OnPosition(101000)
m.assertTrue(m.sb.DismissManual())
m.assertEqual(m.sb.OnPosition(105000), SponsorBlockController.NO_SKIP)
m.assertEqual(m.sb.OnPosition(110500), 120000)
end function
@describe("chapter text")