This commit is contained in:
Brahim Hadriche committed 2026-07-07 11:00:06 -04:00
1 parent fd86e6c7b5
commit 8599e275ab
9 files changed
+113 -91

No files matched your search

+4
View File
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Fixed
- Wrong SponsorBlock in the trackbar due to image caching
### Changed ### Changed
- Video Player HUD now focuses initially on the trackbar, instead of the pause button - Video Player HUD now focuses initially on the trackbar, instead of the pause button
@@ -1,7 +1,7 @@
import "pkg:/components/Dialog/DialogUtils.bs" import "pkg:/components/Dialog/DialogUtils.bs"
import "pkg:/components/Navigation/Navigation.bs" import "pkg:/components/Navigation/Navigation.bs"
import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs" import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs"
import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs" import "pkg:/components/Services/SponsorBlock/SponsorBlockConfig.bs"
import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs" import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs"
import "pkg:/source/utils/Logging.bs" import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/RemoteKeys.bs" import "pkg:/source/utils/RemoteKeys.bs"
@@ -10,7 +10,7 @@ import "pkg:/source/utils/Types.bs"
function Init() function Init()
m.categoryList = m.top.findNode("categoryList") m.categoryList = m.top.findNode("categoryList")
m.categoryList.ObserveField("itemSelected", FuncName(OnCategorySelected)) m.categoryList.ObserveField("itemSelected", FuncName(OnCategorySelected))
m.service = new SponsorBlock.SponsorBlockService() m.config = new SponsorBlock.SponsorBlockConfig()
optionTitles = {} optionTitles = {}
optionTitles[SponsorBlock.SegmentAction.Disable] = Tr(Locale.SponsorBlock.Disable) optionTitles[SponsorBlock.SegmentAction.Disable] = Tr(Locale.SponsorBlock.Disable)
@@ -36,7 +36,7 @@ function Init()
end function end function
function SetupCategoriesUi() as void function SetupCategoriesUi() as void
categories = m.service.GetCategories() categories = m.config.GetCategories()
if categories.Count() = 0 if categories.Count() = 0
return return
end if end if
@@ -47,11 +47,11 @@ function SetupCategoriesUi() as void
for each category in categories for each category in categories
categoryNode = CreateObject("roSGNode", "SponsorBlockCategoryContent") categoryNode = CreateObject("roSGNode", "SponsorBlockCategoryContent")
categoryNode.category = category categoryNode.category = category
categoryNode.categoryTitle = Tr(m.service.SegmentTitle(category)) categoryNode.categoryTitle = Tr(m.config.SegmentTitle(category))
categoryNode.selectedOption = SponsorBlock.SegmentAction.Disable categoryNode.selectedOption = SponsorBlock.SegmentAction.Disable
categoryNode.options = m.service.GetOptionsForCategory(category) categoryNode.options = m.config.GetOptionsForCategory(category)
categoryNode.optionTitles = m.optionTitles categoryNode.optionTitles = m.optionTitles
categoryNode.color = m.service.SegmentColor(category) categoryNode.color = m.config.SegmentColor(category)
categoryContentNodes.push(categoryNode) categoryContentNodes.push(categoryNode)
end for end for
@@ -1,5 +1,5 @@
import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs"
import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs" import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs"
import "pkg:/source/utils/Types.bs"
function Init() function Init()
m.categoryLabel = m.top.findNode("categoryLabel") m.categoryLabel = m.top.findNode("categoryLabel")
@@ -10,8 +10,6 @@ function Init()
m.top.translation = [1280, 20] m.top.translation = [1280, 20]
m.translationAnimation.observeField("state", FuncName(OnAnimationState)) m.translationAnimation.observeField("state", FuncName(OnAnimationState))
m.animationTimer.observeField("fire", FuncName(OnAnimationTimer)) m.animationTimer.observeField("fire", FuncName(OnAnimationTimer))
m.service = SponsorBlock.SponsorBlockService()
end function end function
function OnDoShow() as void function OnDoShow() as void
@@ -0,0 +1,75 @@
import "pkg:/source/utils/ColorUtils.bs"
namespace SponsorBlock
class SponsorBlockConfig
function new()
' TODO:P2 this is being read and parsed on every skipped segment. It should be cached.
m.config = StringUtils.ParseJsonSafe(ReadAsciiFile("libpkg:/config/sponsorblock_config.json5"))
end function
function GetServerAddress() as string
if m.config = invalid
return ""
end if
return ValidString(m.config.serverAddress)
end function
function GetCategories() as object
if m.config = invalid
return []
end if
return ValidArray(m.config.categoryList)
end function
function GetOptionsForCategory(category as string) as object
if m.config = invalid
return []
end if
if not m.config.categories.doesexist(category)
return []
end if
return ValidArray(m.config.categories[category].options)
end function
function SegmentColor(category as string) as integer
if m.config = invalid
return 0
end if
if not m.config.categories.doesexist(category)
return 0
end if
color = m.config.categories[category].color
return ColorUtils.HexToInt(color)
end function
function SegmentTitle(category as string) as string
if m.config = invalid
return category
end if
if not m.config.categories.doesexist(category)
return category
end if
return m.config.categories[category].title
end function
function SegmentShortTitle(category as string) as string
if m.config = invalid
return category
end if
if not m.config.categories.doesexist(category)
return category
end if
return m.config.categories[category].short_title
end function
end class
end namespace
@@ -1,3 +1,4 @@
import "pkg:/components/Services/SponsorBlock/SponsorBlockConfig.bs"
import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs" import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs"
@job("SponsorBlockSegmentViewedJob") @job("SponsorBlockSegmentViewedJob")
@@ -5,7 +6,7 @@ function ExecuteJob()
input = JobGetInput() input = JobGetInput()
segmentId = input.segmentId segmentId = input.segmentId
service = new SponsorBlock.SponsorBlockService() service = new SponsorBlock.SponsorBlockService(new SponsorBlock.SponsorBlockConfig())
service.PostSegmentViewed(segmentId, m.top.cancellation) service.PostSegmentViewed(segmentId, m.top.cancellation)
end function end function
@@ -1,3 +1,4 @@
import "pkg:/components/Services/SponsorBlock/SponsorBlockConfig.bs"
import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs" import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs"
import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs" import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs"
import "pkg:/source/utils/Types.bs" import "pkg:/source/utils/Types.bs"
@@ -11,15 +12,21 @@ function ExecuteJob() as void
showNotifications = input.showNotifications showNotifications = input.showNotifications
categories = input.categories categories = input.categories
service = new SponsorBlock.SponsorBlockService() config = new SponsorBlock.SponsorBlockConfig()
service = new SponsorBlock.SponsorBlockService(config)
cancellation = JobGetCancellation() cancellation = JobGetCancellation()
skipSegments = service.GetSkipSegmentsForVideo(videoId, cancellation) skipSegments = service.GetSkipSegmentsForVideo(videoId, cancellation)
skipSegments = ProcessSkipSegments(skipSegments, showNotifications, categories, service) skipSegments = ProcessSkipSegments(skipSegments, showNotifications, categories, config)
barPath = invalid barPath = invalid
if skipSegments <> invalid if skipSegments <> invalid
barPath = `tmp:/sponsorblock_bar.png` barDir = "tmp:/sponsorblock"
fs = CreateObject("roFileSystem")
fs.Delete(barDir)
fs.CreateDirectory(barDir)
' path contains video id to avoid texture cache reuse
barPath = `${barDir}/${videoId}.png`
service.GenerateProgressBarBackground(skipSegments, lengthSeconds, barPath) service.GenerateProgressBarBackground(skipSegments, lengthSeconds, barPath)
end if end if
@@ -42,7 +49,7 @@ function ExecuteJob() as void
}) })
end function end function
function ProcessSkipSegments(skipSegments as object, showNotifications as boolean, categories as object, service as SponsorBlock.SponsorBlockService) as object function ProcessSkipSegments(skipSegments as object, showNotifications as boolean, categories as object, config as SponsorBlock.SponsorBlockConfig) as object
if skipSegments = invalid if skipSegments = invalid
return invalid return invalid
end if end if
@@ -80,8 +87,8 @@ function ProcessSkipSegments(skipSegments as object, showNotifications as boolea
segment.start = segmentStart segment.start = segmentStart
segment.end = segmentEnd segment.end = segmentEnd
segment.title = Tr(ValidString(service.SegmentTitle(segment.category))) segment.title = Tr(ValidString(config.SegmentTitle(segment.category)))
segment.shortTitle = Tr(ValidString(service.SegmentShortTitle(segment.category))) segment.shortTitle = Tr(ValidString(config.SegmentShortTitle(segment.category)))
processedSegments.push(segment) processedSegments.push(segment)
end for end for
@@ -1,5 +1,5 @@
import "pkg:/components/Services/SponsorBlock/SponsorBlockConfig.bs"
import "pkg:/source/services/HttpClient.bs" import "pkg:/source/services/HttpClient.bs"
import "pkg:/source/utils/ColorUtils.bs"
import "pkg:/source/utils/CryptoUtils.bs" import "pkg:/source/utils/CryptoUtils.bs"
namespace SponsorBlock namespace SponsorBlock
@@ -7,70 +7,13 @@ namespace SponsorBlock
const VIEWED_SEGMENT_ENDPOINT = "/api/viewedVideoSponsorTime" const VIEWED_SEGMENT_ENDPOINT = "/api/viewedVideoSponsorTime"
class SponsorBlockService class SponsorBlockService
function new() function new(config as SponsorBlock.SponsorBlockConfig)
' TODO:P2 this is being read and parsed on every skipped segment. It should be cached. m.config = config
m.sponsorBlockConfig = StringUtils.ParseJsonSafe(ReadAsciiFile("libpkg:/config/sponsorblock_config.json5"))
end function
function GetCategories() as object
if m.sponsorBlockConfig = invalid
return []
end if
return ValidArray(m.sponsorBlockConfig.categoryList)
end function
function GetOptionsForCategory(category as string) as object
if m.sponsorBlockConfig = invalid
return []
end if
if not m.sponsorBlockConfig.categories.doesexist(category)
return []
end if
return ValidArray(m.sponsorBlockConfig.categories[category].options)
end function
function SegmentColor(category as string) as integer
if m.sponsorBlockConfig = invalid
return 0
end if
if not m.sponsorBlockConfig.categories.doesexist(category)
return 0
end if
color = m.sponsorBlockConfig.categories[category].color
return ColorUtils.HexToInt(color)
end function
function SegmentTitle(category as string) as string
if m.sponsorBlockConfig = invalid
return category
end if
if not m.sponsorBlockConfig.categories.doesexist(category)
return category
end if
return m.sponsorBlockConfig.categories[category].title
end function
function SegmentShortTitle(category as string) as string
if m.sponsorBlockConfig = invalid
return category
end if
if not m.sponsorBlockConfig.categories.doesexist(category)
return category
end if
return m.sponsorBlockConfig.categories[category].short_title
end function end function
function GetSkipSegmentsForVideo(videoId as string, cancellation = invalid as dynamic) as object function GetSkipSegmentsForVideo(videoId as string, cancellation = invalid as dynamic) as object
if m.sponsorBlockConfig = invalid or StringUtils.IsNullOrEmpty(m.sponsorBlockConfig.serverAddress) serverAddress = m.config.GetServerAddress()
if StringUtils.IsNullOrEmpty(serverAddress)
return invalid return invalid
end if end if
@@ -84,7 +27,7 @@ namespace SponsorBlock
' From SponsorBlock docs: It should be the first 4 - 32 characters (4 is recommended). ' From SponsorBlock docs: It should be the first 4 - 32 characters (4 is recommended).
hashPrefix = CryptoUtils.GetSha256(videoId).Left(4) hashPrefix = CryptoUtils.GetSha256(videoId).Left(4)
url = `${m.sponsorBlockConfig.serverAddress}${SponsorBlock.SKIP_SEGMENT_ENDPOINT}/${hashPrefix}?categories=${categoriesJson}&actionTypes=${actionTypesJson}` url = `${serverAddress}${SponsorBlock.SKIP_SEGMENT_ENDPOINT}/${hashPrefix}?categories=${categoriesJson}&actionTypes=${actionTypesJson}`
response = HttpClient.Get(url).Cancellation(cancellation).Await() response = HttpClient.Get(url).Cancellation(cancellation).Await()
if not response.IsSuccess() if not response.IsSuccess()
if response.IsCancelled() if response.IsCancelled()
@@ -112,16 +55,18 @@ namespace SponsorBlock
end function end function
function PostSegmentViewed(segmentId as string, cancellation = invalid as object) as void function PostSegmentViewed(segmentId as string, cancellation = invalid as object) as void
if m.sponsorBlockConfig = invalid or StringUtils.IsNullOrEmpty(m.sponsorBlockConfig.serverAddress) serverAddress = m.config.GetServerAddress()
if StringUtils.IsNullOrEmpty(serverAddress)
return return
end if end if
url = `${m.sponsorBlockConfig.serverAddress}${SponsorBlock.VIEWED_SEGMENT_ENDPOINT}?UUID=${segmentId}` url = `${serverAddress}${SponsorBlock.VIEWED_SEGMENT_ENDPOINT}?UUID=${segmentId}`
HttpClient.Post(url, "").Cancellation(cancellation).Await() HttpClient.Post(url, "").Cancellation(cancellation).Await()
end function end function
function GenerateProgressBarBackground(segments as object, lengthSeconds as integer, path as string) function GenerateProgressBarBackground(segments as object, lengthSeconds as integer, path as string)
bar = CreateObject("roBitmap", { width: 1000, height: 20, AlphaEnable: true }) ' 1144 = trackbar width, so the bar renders 1:1 without horizontal scaling
bar = CreateObject("roBitmap", { width: 1144, height: 20, AlphaEnable: true })
bar.Clear(&hFFFFFF80) bar.Clear(&hFFFFFF80)
width = bar.GetWidth() width = bar.GetWidth()
height = bar.GetHeight() height = bar.GetHeight()
@@ -138,7 +83,7 @@ namespace SponsorBlock
pixelStart = (segment.start / videoDuration) * width pixelStart = (segment.start / videoDuration) * width
pixelEnd = (segment.end / videoDuration) * width pixelEnd = (segment.end / videoDuration) * width
color = m.SegmentColor(segment.category) color = m.config.SegmentColor(segment.category)
' highlight's duration is zero, so it is not visble on the bar. ' highlight's duration is zero, so it is not visble on the bar.
' Add a few pixels to see it ' Add a few pixels to see it
if pixelStart = pixelEnd if pixelStart = pixelEnd
@@ -150,6 +95,5 @@ namespace SponsorBlock
buffer = bar.GetPng(0, 0, width, height) buffer = bar.GetPng(0, 0, width, height)
buffer.WriteFile(path) buffer.WriteFile(path)
end function end function
end class end class
end namespace end namespace
@@ -1,7 +1,6 @@
import "pkg:/components/JobSystem/Jobs.bs" import "pkg:/components/JobSystem/Jobs.bs"
import "pkg:/components/JobSystem/JobSystem.bs" import "pkg:/components/JobSystem/JobSystem.bs"
import "pkg:/components/Services/SponsorBlock/Notifications/SponsorBlockNotificationUtils.bs" import "pkg:/components/Services/SponsorBlock/Notifications/SponsorBlockNotificationUtils.bs"
import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs"
import "SponsorBlockSegmentAction.bs" import "SponsorBlockSegmentAction.bs"
import "VideoPlayer.bs" import "VideoPlayer.bs"
@@ -12,7 +11,6 @@ namespace SponsorBlock
return return
end if end if
m.sponsorBlockService = new SponsorBlock.SponsorBlockService()
SponsorBlock.SetVisible(m.notifications, m.container.fullscreen) SponsorBlock.SetVisible(m.notifications, m.container.fullscreen)
end function end function
@@ -44,7 +44,6 @@ function Repaint() as void
end if end if
end function end function
' --- VOD ------------------------------------------------------------------------------------------------
function RenderVodBar() as void function RenderVodBar() as void
transportActive = (m.top.transportMode <> TransportController.Mode.Idle) transportActive = (m.top.transportMode <> TransportController.Mode.Idle)
if transportActive if transportActive
@@ -78,7 +77,6 @@ function RenderVodBar() as void
m.liveLabel.visible = false m.liveLabel.visible = false
end function end function
' --- LIVE -----------------------------------------------------------------------------------------------
function RenderLiveBar() as void function RenderLiveBar() as void
transportActive = (m.top.transportMode = TransportController.Mode.LiveDvr) transportActive = (m.top.transportMode = TransportController.Mode.LiveDvr)
@@ -160,7 +158,6 @@ function OnFocusChange() as void
m.playheadFocus.control = "start" m.playheadFocus.control = "start"
end function end function
' --- glyph swap (handle child) --------------------------------------------------------------------------
function OnGlyph() as void function OnGlyph() as void
name = GlyphAssetName(m.top.glyph) name = GlyphAssetName(m.top.glyph)
if name = "" if name = ""
@@ -194,7 +191,6 @@ function GlyphAssetName(glyph as integer) as string
return "" return ""
end function end function
' --- SponsorBlock fill tint -----------------------------------------------------------------------------
' A SponsorBlock tint overrides the red fill; an empty (fully transparent) value keeps the red. ' A SponsorBlock tint overrides the red fill; an empty (fully transparent) value keeps the red.
function OnSbFillBlend() as void function OnSbFillBlend() as void
blend = m.top.sbFillBlend blend = m.top.sbFillBlend
@@ -203,7 +199,6 @@ function OnSbFillBlend() as void
end if end if
end function end function
' --- time format ----------------------------------------------------------------------------------------
' under 1min -> "0:SS"; else "MM:SS"; "H:MM:SS" when >= 1hr. ' under 1min -> "0:SS"; else "MM:SS"; "H:MM:SS" when >= 1hr.
function FormatBarTime(seconds as dynamic) as string function FormatBarTime(seconds as dynamic) as string
if seconds = invalid if seconds = invalid