From 9a631aab51311144a35052901d44a289a1bc412f Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Fri, 19 May 2023 18:19:26 -0400 Subject: [PATCH] SponsorBlock categories (#70) * SponsorBlock categories * Remove faulty animation check * Changelog --- CHANGELOG.md | 4 ++ .../SponsorBlockNotification.bs | 25 ++++------ .../SponsorBlockNotification.xml | 1 + .../SponsorBlockNotificationManager.bs | 3 +- .../VideoPlayer/VideoPlayerSponsorBlock.bs | 47 +++++++++---------- 5 files changed, 37 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8a6416f..622cc173 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased +### Changed +- SponsorBlock segments are not skipped by default, except for sponsor segments + ## [0.9.0] - 2023-04-21 ### Added - Add watched videos to Invidious watch history diff --git a/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.bs b/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.bs index 68174498..5704cb82 100644 --- a/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.bs +++ b/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.bs @@ -11,10 +11,16 @@ function Init() m.animationTimer.observeField("fire", "OnAnimationTimer") end function -function OnSegmentSet() +function OnActionSet() + action = m.top.action category = m.top.segment.category categoryTitle = SponsorBlock.SegmentShortTitle(category) - m.categoryLabel.text = "Skipped" + chr(10) + categoryTitle + if action = "AutoSkip" + m.categoryLabel.text = "Skipped" + chr(10) + categoryTitle + else + m.categoryLabel.text = categoryTitle + end if + AnimateIn() end function @@ -37,23 +43,10 @@ end function function Animate(reverse as boolean) as void ' We are already animating in the requested direction - if m.translationAnimationInterpolator.reverse = reverse and m.translationAnimation.state = "running" + if m.translationAnimationInterpolator.reverse = reverse and m.translationAnimation.control <> "none" return end if - ' Check if we are already at the destination - if m.translationAnimation.state = "stopped" - if reverse - destination = m.translationAnimationInterpolator.keyValue[0][0] - else - destination = m.translationAnimationInterpolator.keyValue[1][0] - end if - current = m.top.translation[0] - if current = destination - return - end if - end if - m.translationAnimationInterpolator.reverse = reverse m.translationAnimation.control = "start" end function diff --git a/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.xml b/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.xml index f619f436..d531805c 100644 --- a/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.xml +++ b/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.xml @@ -3,6 +3,7 @@ + currentPosition) - ' TODO: if segmentEnd is at the end of the video, close video + segmentRange = segment["segment"] + segmentStart = segmentRange[0] + segmentEnd = segmentRange[1] + currentPosition = m.top.position + if (segmentStart < currentPosition) and ((segmentEnd - 1) > currentPosition) + action = GetActionForSegment(segment) + ShowSponsorBlockNotifcation(segment, action) + + if action = "AutoSkip" m.top.seek = segmentEnd print("Skipping section:" + segment["category"]) - ShowSponsorBlockNotifcation(segment) SendSkippedSectionEvent(segment.UUID) return end if end if - - if segment["actionType"] = "mute" - segmentRange = segment["segment"] - segmentStart = segmentRange[0] - segmentEnd = segmentRange[1] - currentPosition = m.top.position - if (segmentStart < currentPosition) and (segmentEnd > currentPosition) - shouldMute = true - muteCategory = segment["category"] - exit for - end if - end if end for +end function - if m.top.mute <> shouldMute - print(`Muting section: ${muteCategory} - ${shouldMute}`) - m.top.mute = shouldMute +function GetActionForSegment(segment as object) as dynamic + category = segment["category"] + if category = "sponsor" + return "AutoSkip" + else if category = "poi_highlight" + return "ManualSkip" + else if category = "exclusive_access" + return "ShowOverlay" + else if category = "chapter" + return "ShowOverlay" end if + return "" end function function SendSkippedSectionEvent(segmentId as string)