Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SponsorBlock Viewed API #31

Merged
merged 4 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Ability to clear search history from web app
- WebSocket server for realtime events
- SponsorBlock tracking

### Changed
- The License has changed from MIT to AGPL
Expand Down
12 changes: 12 additions & 0 deletions src/components/VideoPlayer/SponsorBlockTrackingTask.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "pkg:/source/services/SponsorBlock.bs"

function Init()
m.top.functionName = "TaskMain"
end function

function TaskMain()
input = m.top.getField("input")
segmentId = input.segmentId

SponsorBlock.PostSegmentViewed(segmentId)
end function
8 changes: 8 additions & 0 deletions src/components/VideoPlayer/SponsorBlockTrackingTask.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<component name="SponsorBlockTrackingTask" extends="Task">
<interface>
<field id="input" type="assocarray" />
<field id="output" type="assocarray" />
</interface>
</component>
7 changes: 7 additions & 0 deletions src/components/VideoPlayer/VideoPlayerSponsorBlock.bs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function OnPositionChangeSkipSponsorBlockSections() as void
' TODO: if segmentEnd is at the end of the video, close video
m.top.seek = segmentEnd
print("Skiping section:" + segment["category"])
SendSkippedSectionEvent(segment.UUID)
return
end if
end if
Expand All @@ -141,3 +142,9 @@ function OnPositionChangeSkipSponsorBlockSections() as void
m.top.mute = shouldMute
end if
end function

function SendSkippedSectionEvent(segmentId as string)
task = createObject("roSGNode", "SponsorBlockTrackingTask")
task.input = { segmentId: segmentId }
task.control = "RUN"
end function
7 changes: 7 additions & 0 deletions src/source/services/SponsorBlock.bs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "pkg:/source/utils/Crypto.bs"
namespace SponsorBlock
const API_URL = "https://sponsor.ajay.app"
const SKIP_SEGMENT_ENDPOINT = "/api/skipSegments"
const VIEWED_SEGMENT_ENDPOINT = "/api/viewedVideoSponsorTime"

function SegmentColor(category as string) as integer
map = m.SponsorBlockColors
Expand Down Expand Up @@ -75,6 +76,12 @@ namespace SponsorBlock
return invalid
end function

function PostSegmentViewed(segmentId as string) as boolean
url = `${SponsorBlock.API_URL}${SponsorBlock.VIEWED_SEGMENT_ENDPOINT}?UUID=${segmentId}`
response = Requests().post(url)
return response.statuscode = 200
end function

function GenerateProgressBarBackground(segments as object, path as string)
bar = CreateObject("roBitmap", { width: 1000, height: 20, AlphaEnable: true })
bar.Clear(&hFFFFFF80)
Expand Down