sb fix
This commit is contained in:
1 parent
fd86e6c7b5
commit
8599e275ab
9 files changed
+113
-91
No files matched your search
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Wrong SponsorBlock in the trackbar due to image caching
|
||||
|
||||
### Changed
|
||||
|
||||
- Video Player HUD now focuses initially on the trackbar, instead of the pause button
|
||||
|
||||
+6
-6
@@ -1,7 +1,7 @@
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
import "pkg:/components/Navigation/Navigation.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:/source/utils/Logging.bs"
|
||||
import "pkg:/source/utils/RemoteKeys.bs"
|
||||
@@ -10,7 +10,7 @@ import "pkg:/source/utils/Types.bs"
|
||||
function Init()
|
||||
m.categoryList = m.top.findNode("categoryList")
|
||||
m.categoryList.ObserveField("itemSelected", FuncName(OnCategorySelected))
|
||||
m.service = new SponsorBlock.SponsorBlockService()
|
||||
m.config = new SponsorBlock.SponsorBlockConfig()
|
||||
|
||||
optionTitles = {}
|
||||
optionTitles[SponsorBlock.SegmentAction.Disable] = Tr(Locale.SponsorBlock.Disable)
|
||||
@@ -36,7 +36,7 @@ function Init()
|
||||
end function
|
||||
|
||||
function SetupCategoriesUi() as void
|
||||
categories = m.service.GetCategories()
|
||||
categories = m.config.GetCategories()
|
||||
if categories.Count() = 0
|
||||
return
|
||||
end if
|
||||
@@ -47,11 +47,11 @@ function SetupCategoriesUi() as void
|
||||
for each category in categories
|
||||
categoryNode = CreateObject("roSGNode", "SponsorBlockCategoryContent")
|
||||
categoryNode.category = category
|
||||
categoryNode.categoryTitle = Tr(m.service.SegmentTitle(category))
|
||||
categoryNode.categoryTitle = Tr(m.config.SegmentTitle(category))
|
||||
categoryNode.selectedOption = SponsorBlock.SegmentAction.Disable
|
||||
categoryNode.options = m.service.GetOptionsForCategory(category)
|
||||
categoryNode.options = m.config.GetOptionsForCategory(category)
|
||||
categoryNode.optionTitles = m.optionTitles
|
||||
categoryNode.color = m.service.SegmentColor(category)
|
||||
categoryNode.color = m.config.SegmentColor(category)
|
||||
categoryContentNodes.push(categoryNode)
|
||||
end for
|
||||
|
||||
|
||||
+1
-3
@@ -1,5 +1,5 @@
|
||||
import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs"
|
||||
import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.categoryLabel = m.top.findNode("categoryLabel")
|
||||
@@ -10,8 +10,6 @@ function Init()
|
||||
m.top.translation = [1280, 20]
|
||||
m.translationAnimation.observeField("state", FuncName(OnAnimationState))
|
||||
m.animationTimer.observeField("fire", FuncName(OnAnimationTimer))
|
||||
|
||||
m.service = SponsorBlock.SponsorBlockService()
|
||||
end function
|
||||
|
||||
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"
|
||||
|
||||
@job("SponsorBlockSegmentViewedJob")
|
||||
@@ -5,7 +6,7 @@ function ExecuteJob()
|
||||
input = JobGetInput()
|
||||
|
||||
segmentId = input.segmentId
|
||||
service = new SponsorBlock.SponsorBlockService()
|
||||
service = new SponsorBlock.SponsorBlockService(new SponsorBlock.SponsorBlockConfig())
|
||||
|
||||
service.PostSegmentViewed(segmentId, m.top.cancellation)
|
||||
end function
|
||||
@@ -1,3 +1,4 @@
|
||||
import "pkg:/components/Services/SponsorBlock/SponsorBlockConfig.bs"
|
||||
import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs"
|
||||
import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
@@ -11,15 +12,21 @@ function ExecuteJob() as void
|
||||
showNotifications = input.showNotifications
|
||||
categories = input.categories
|
||||
|
||||
service = new SponsorBlock.SponsorBlockService()
|
||||
config = new SponsorBlock.SponsorBlockConfig()
|
||||
service = new SponsorBlock.SponsorBlockService(config)
|
||||
cancellation = JobGetCancellation()
|
||||
skipSegments = service.GetSkipSegmentsForVideo(videoId, cancellation)
|
||||
|
||||
skipSegments = ProcessSkipSegments(skipSegments, showNotifications, categories, service)
|
||||
skipSegments = ProcessSkipSegments(skipSegments, showNotifications, categories, config)
|
||||
|
||||
barPath = 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)
|
||||
end if
|
||||
|
||||
@@ -42,7 +49,7 @@ function ExecuteJob() as void
|
||||
})
|
||||
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
|
||||
return invalid
|
||||
end if
|
||||
@@ -80,8 +87,8 @@ function ProcessSkipSegments(skipSegments as object, showNotifications as boolea
|
||||
segment.start = segmentStart
|
||||
segment.end = segmentEnd
|
||||
|
||||
segment.title = Tr(ValidString(service.SegmentTitle(segment.category)))
|
||||
segment.shortTitle = Tr(ValidString(service.SegmentShortTitle(segment.category)))
|
||||
segment.title = Tr(ValidString(config.SegmentTitle(segment.category)))
|
||||
segment.shortTitle = Tr(ValidString(config.SegmentShortTitle(segment.category)))
|
||||
|
||||
processedSegments.push(segment)
|
||||
end for
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import "pkg:/components/Services/SponsorBlock/SponsorBlockConfig.bs"
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
import "pkg:/source/utils/ColorUtils.bs"
|
||||
import "pkg:/source/utils/CryptoUtils.bs"
|
||||
|
||||
namespace SponsorBlock
|
||||
@@ -7,70 +7,13 @@ namespace SponsorBlock
|
||||
const VIEWED_SEGMENT_ENDPOINT = "/api/viewedVideoSponsorTime"
|
||||
|
||||
class SponsorBlockService
|
||||
function new()
|
||||
' TODO:P2 this is being read and parsed on every skipped segment. It should be cached.
|
||||
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
|
||||
function new(config as SponsorBlock.SponsorBlockConfig)
|
||||
m.config = config
|
||||
end function
|
||||
|
||||
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
|
||||
end if
|
||||
|
||||
@@ -84,7 +27,7 @@ namespace SponsorBlock
|
||||
|
||||
' From SponsorBlock docs: It should be the first 4 - 32 characters (4 is recommended).
|
||||
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()
|
||||
if not response.IsSuccess()
|
||||
if response.IsCancelled()
|
||||
@@ -112,16 +55,18 @@ namespace SponsorBlock
|
||||
end function
|
||||
|
||||
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
|
||||
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()
|
||||
end function
|
||||
|
||||
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)
|
||||
width = bar.GetWidth()
|
||||
height = bar.GetHeight()
|
||||
@@ -138,7 +83,7 @@ namespace SponsorBlock
|
||||
|
||||
pixelStart = (segment.start / 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.
|
||||
' Add a few pixels to see it
|
||||
if pixelStart = pixelEnd
|
||||
@@ -150,6 +95,5 @@ namespace SponsorBlock
|
||||
buffer = bar.GetPng(0, 0, width, height)
|
||||
buffer.WriteFile(path)
|
||||
end function
|
||||
|
||||
end class
|
||||
end namespace
|
||||
@@ -1,7 +1,6 @@
|
||||
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/SponsorBlockService.bs"
|
||||
import "SponsorBlockSegmentAction.bs"
|
||||
import "VideoPlayer.bs"
|
||||
|
||||
@@ -12,7 +11,6 @@ namespace SponsorBlock
|
||||
return
|
||||
end if
|
||||
|
||||
m.sponsorBlockService = new SponsorBlock.SponsorBlockService()
|
||||
SponsorBlock.SetVisible(m.notifications, m.container.fullscreen)
|
||||
end function
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@ function Repaint() as void
|
||||
end if
|
||||
end function
|
||||
|
||||
' --- VOD ------------------------------------------------------------------------------------------------
|
||||
function RenderVodBar() as void
|
||||
transportActive = (m.top.transportMode <> TransportController.Mode.Idle)
|
||||
if transportActive
|
||||
@@ -78,7 +77,6 @@ function RenderVodBar() as void
|
||||
m.liveLabel.visible = false
|
||||
end function
|
||||
|
||||
' --- LIVE -----------------------------------------------------------------------------------------------
|
||||
function RenderLiveBar() as void
|
||||
transportActive = (m.top.transportMode = TransportController.Mode.LiveDvr)
|
||||
|
||||
@@ -160,7 +158,6 @@ function OnFocusChange() as void
|
||||
m.playheadFocus.control = "start"
|
||||
end function
|
||||
|
||||
' --- glyph swap (handle child) --------------------------------------------------------------------------
|
||||
function OnGlyph() as void
|
||||
name = GlyphAssetName(m.top.glyph)
|
||||
if name = ""
|
||||
@@ -194,7 +191,6 @@ function GlyphAssetName(glyph as integer) as string
|
||||
return ""
|
||||
end function
|
||||
|
||||
' --- SponsorBlock fill tint -----------------------------------------------------------------------------
|
||||
' A SponsorBlock tint overrides the red fill; an empty (fully transparent) value keeps the red.
|
||||
function OnSbFillBlend() as void
|
||||
blend = m.top.sbFillBlend
|
||||
@@ -203,7 +199,6 @@ function OnSbFillBlend() as void
|
||||
end if
|
||||
end function
|
||||
|
||||
' --- time format ----------------------------------------------------------------------------------------
|
||||
' under 1min -> "0:SS"; else "MM:SS"; "H:MM:SS" when >= 1hr.
|
||||
function FormatBarTime(seconds as dynamic) as string
|
||||
if seconds = invalid
|
||||
|
||||
Reference in new issue
Block a user