Fix SponsorBlock segments where video duration is not provided (#102)
* Fix SponsorBlock segments where video duration is not provided * add another null check
This commit is contained in:
1 parent
936eefeeb9
commit
a224b86fca
5 files changed
+28
-21
No files matched your search
@@ -3,26 +3,14 @@ import "pkg:/source/services/SponsorBlock.bs"
|
||||
@asynctask
|
||||
function SponsorBlockTask(input as object) as object
|
||||
videoId = input.videoId
|
||||
lengthSeconds = input.metadata.lengthSeconds
|
||||
|
||||
sponsorBlockResponse = SponsorBlock.GetSkipSegmentsForVideo(videoId)
|
||||
skipSegments = SponsorBlock.GetSkipSegmentsForVideo(videoId)
|
||||
barPath = invalid
|
||||
|
||||
skipSegments = []
|
||||
if sponsorBlockResponse <> invalid
|
||||
for each segment in sponsorBlockResponse
|
||||
if segment.videoDuration > 0
|
||||
skipSegments.push(segment)
|
||||
end if
|
||||
end for
|
||||
end if
|
||||
|
||||
if skipSegments.Count() = 0
|
||||
skipSegments = invalid
|
||||
end if
|
||||
|
||||
if skipSegments <> invalid
|
||||
barPath = `tmp:/sponsorblock_bar_${videoId}.png`
|
||||
SponsorBlock.GenerateProgressBarBackground(skipSegments, barPath)
|
||||
SponsorBlock.GenerateProgressBarBackground(skipSegments, lengthSeconds, barPath)
|
||||
end if
|
||||
|
||||
return {
|
||||
|
||||
@@ -153,6 +153,8 @@ function OnVideoDetailsTaskResults(output as object) as void
|
||||
m.top.control = "play"
|
||||
|
||||
m.videoContainer@.watchedVideosAdd(videoId)
|
||||
|
||||
StartSponsorBlockTask()
|
||||
end function
|
||||
|
||||
function AddDashUrls(playletStreamUrls as object, metadata as object, settings as object) as void
|
||||
|
||||
@@ -18,7 +18,6 @@ function SetupSponsorBlock() as void
|
||||
m.top.trickPlayBar.observeField("visible", "OnTrickPlayBarVisible")
|
||||
m.chapterLabelTimer = m.top.findNode("chapterLabelTimer")
|
||||
m.chapterLabelTimer.observeField("fire", "OnChapterLabelTimer")
|
||||
m.top.observeField("videoId", "StartSponsorBlockTask")
|
||||
end function
|
||||
|
||||
function LoadSponsorBlockSettings() as void
|
||||
@@ -103,12 +102,19 @@ function UpdateSponsorBlockChapter(time as integer) as void
|
||||
m.top.chapter = ""
|
||||
end function
|
||||
|
||||
function StartSponsorBlockTask()
|
||||
function StartSponsorBlockTask() as void
|
||||
if not m.sponsorBlockEnabled = true
|
||||
return
|
||||
end if
|
||||
|
||||
if m.sponsorBlockTask <> invalid
|
||||
m.sponsorBlockTask.control = "stop"
|
||||
end if
|
||||
|
||||
m.sponsorBlockTask = StartAsyncTask(SponsorBlockTask, { videoId: m.top.videoId }, OnSponsorBlockTaskResults)
|
||||
m.sponsorBlockTask = StartAsyncTask(SponsorBlockTask, {
|
||||
videoId: m.top.videoId,
|
||||
metadata: m.top.content.metadata
|
||||
}, OnSponsorBlockTaskResults)
|
||||
end function
|
||||
|
||||
function OnSponsorBlockTaskResults(output as object)
|
||||
|
||||
Reference in new issue
Block a user