diff --git a/CHANGELOG.md b/CHANGELOG.md
index 89810c53..bbad93d2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,9 @@ 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]
+### Added
+- SponsorBlock notification
+
### Fixed
- Crash in case GetLocalIpAddress() returns invalid
diff --git a/package-lock.json b/package-lock.json
index 027bf003..05f8976a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "playlet",
- "version": "0.6.0",
+ "version": "0.7.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "playlet",
- "version": "0.6.0",
+ "version": "0.7.0",
"hasInstallScript": true,
"dependencies": {
"bslib": "npm:@rokucommunity/bslib@^0.1.1",
diff --git a/package.json b/package.json
index 87333d60..8fd64304 100644
--- a/package.json
+++ b/package.json
@@ -55,6 +55,7 @@
"sign-package": "node tools/sign-package.js",
"screenshot": "node tools/screenshot.js",
"profile-sync": "node tools/profile-sync.js",
+ "generate-sponsorblock-config": "node tools/generate-sponsorblock-config.js",
"postinstall": "npx ropm copy && cd playlet-web && npm install"
}
-}
+}
\ No newline at end of file
diff --git a/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.bs b/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.bs
new file mode 100644
index 00000000..68174498
--- /dev/null
+++ b/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.bs
@@ -0,0 +1,65 @@
+import "pkg:/source/services/SponsorBlock.bs"
+
+function Init()
+ m.categoryLabel = m.top.findNode("categoryLabel")
+ m.translationAnimation = m.top.findNode("translationAnimation")
+ m.translationAnimationInterpolator = m.top.findNode("translationAnimationInterpolator")
+ m.animationTimer = m.top.findNode("animationTimer")
+
+ m.top.translation = [1280, 20]
+ m.translationAnimation.observeField("state", "OnAnimationState")
+ m.animationTimer.observeField("fire", "OnAnimationTimer")
+end function
+
+function OnSegmentSet()
+ category = m.top.segment.category
+ categoryTitle = SponsorBlock.SegmentShortTitle(category)
+ m.categoryLabel.text = "Skipped" + chr(10) + categoryTitle
+ AnimateIn()
+end function
+
+function OnAnimationTimer()
+ AnimateOut()
+end function
+
+function AnimateIn()
+ m.translationAnimation.unobserveField("state")
+ m.animationTimer.control = "stop"
+ m.animationTimer.control = "start"
+ m.translationAnimation.observeField("state", "OnAnimationState")
+
+ Animate(false)
+end function
+
+function AnimateOut()
+ Animate(true)
+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"
+ 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
+
+function OnAnimationState()
+ if m.translationAnimation.state = "stopped" and m.translationAnimationInterpolator.reverse = true
+ m.top.getParent().removeChild(m.top)
+ end if
+end function
diff --git a/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.xml b/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.xml
new file mode 100644
index 00000000..f619f436
--- /dev/null
+++ b/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotification.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotificationManager.bs b/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotificationManager.bs
new file mode 100644
index 00000000..625ea8da
--- /dev/null
+++ b/playlet-lib/src/components/SponsorBlockNotification/SponsorBlockNotificationManager.bs
@@ -0,0 +1,27 @@
+import "pkg:/components/VideoPlayer/Video.bs"
+
+function ShowSponsorBlockNotifcation(segment as object)
+ videoContainer = GetVideoContainer()
+ notification = videoContainer.findNode("sponsorBlockNotification")
+ if notification = invalid
+ notification = videoContainer.createChild("SponsorBlockNotification")
+ notification.id = "sponsorBlockNotification"
+ end if
+ notification.segment = segment
+end function
+
+function RemoveSponsorBlockNotifcation()
+ videoContainer = GetVideoContainer()
+ notification = videoContainer.findNode("sponsorBlockNotification")
+ if notification <> invalid
+ videoContainer.RemoveChild(notification)
+ end if
+end function
+
+function SponsorBlockNotifcationSetVisible(visible as boolean)
+ videoContainer = GetVideoContainer()
+ notification = videoContainer.findNode("sponsorBlockNotification")
+ if notification <> invalid
+ notification.visible = visible
+ end if
+end function
diff --git a/playlet-lib/src/components/VideoPlayer/Video.bs b/playlet-lib/src/components/VideoPlayer/Video.bs
index 26988b29..fff546ef 100644
--- a/playlet-lib/src/components/VideoPlayer/Video.bs
+++ b/playlet-lib/src/components/VideoPlayer/Video.bs
@@ -1,5 +1,6 @@
import "pkg:/source/services/Invidious.bs"
import "pkg:/components/Dialog/DialogUtils.bs"
+import "pkg:/components/SponsorBlockNotification/SponsorBlockNotificationManager.bs"
function PlayVideo(videoId as string, args = invalid as object)
sender = args?.sender
@@ -23,6 +24,7 @@ function PlayVideo(videoId as string, args = invalid as object)
videoContainer.sender = sender
end if
videoContainer.videoPlayer = videoContainer.createChild("VideoPlayer")
+ videoContainer.insertChild(videoContainer.videoPlayer, 0)
videoContainer.videoPlayer.id = "VideoPlayer"
videoContainer.videoPlayer.metadata = metadata
videoContainer.videoPlayer.videoId = videoId
@@ -49,6 +51,7 @@ function CloseVideo(setFocus = true as boolean)
videoContainer.sender.SetFocus(true)
end if
end if
+ SponsorBlockNotifcationSetVisible(false)
end function
function ToggleVideoPictureInPicture(sender = invalid as object) as boolean
diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
index 979a6e73..56883160 100644
--- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
+++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
@@ -4,6 +4,8 @@ import "pkg:/components/VideoPlayer/Video.bs"
import "pkg:/components/VideoPlayer/VideoDetailsTask.bs"
function Init()
+ m.videoContainer = GetVideoContainer()
+
SetupSponsorBlock()
SetupAnimation()
SetupBusySpinner()
@@ -12,7 +14,6 @@ function Init()
m.top.bufferingBar.filledBarBlendColor = "0xFF0000FF"
m.top.retrievingBar.filledBarBlendColor = "0xFF0000FF"
- m.videoContainer = GetVideoContainer()
m.top.enableUI = m.videoContainer.fullscreen
m.videoContainer.observeFieldScoped("fullscreen", "OnFullScreenChange")
@@ -335,4 +336,5 @@ function OnFullScreenChange()
m.translationAnimation.control = "start"
m.top.enableUI = m.videoContainer.fullscreen
+ SponsorBlockNotifcationSetVisible(m.videoContainer.fullscreen)
end function
diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayerSponsorBlock.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayerSponsorBlock.bs
index 1e7d5667..7f6d6cec 100644
--- a/playlet-lib/src/components/VideoPlayer/VideoPlayerSponsorBlock.bs
+++ b/playlet-lib/src/components/VideoPlayer/VideoPlayerSponsorBlock.bs
@@ -1,9 +1,13 @@
import "pkg:/source/asyncTask/asyncTask.bs"
import "pkg:/components/VideoPlayer/SponsorBlockTask.bs"
import "pkg:/components/VideoPlayer/SponsorBlockTrackingTask.bs"
+import "pkg:/components/SponsorBlockNotification/SponsorBlockNotificationManager.bs"
function SetupSponsorBlock()
PositionChapterLabel()
+
+ SponsorBlockNotifcationSetVisible(m.videoContainer.fullscreen)
+
m.timeLabel = FindTimeLabel()
m.top.trickPlayBar.observeField("visible", "OnTrickPlayBarVisible")
m.chapterLabelTimer = m.top.findNode("chapterLabelTimer")
@@ -123,6 +127,7 @@ function OnPositionChangeSkipSponsorBlockSections() as void
' TODO: if segmentEnd is at the end of the video, close video
m.top.seek = segmentEnd
print("Skipping section:" + segment["category"])
+ ShowSponsorBlockNotifcation(segment)
SendSkippedSectionEvent(segment.UUID)
return
end if
diff --git a/playlet-lib/src/components/WebServer/Task/WebServerTask.bs b/playlet-lib/src/components/WebServer/Task/WebServerTask.bs
index 306b7b99..efa9b61d 100644
--- a/playlet-lib/src/components/WebServer/Task/WebServerTask.bs
+++ b/playlet-lib/src/components/WebServer/Task/WebServerTask.bs
@@ -43,11 +43,12 @@ function WebServerLoop()
return true
end function)
- if IsDebugMode()
+ #if DEBUG
allowedOrigin = "*"
- else
+ #else
allowedOrigin = `http://${GetLocalIpAddress()}:8888`
- end if
+ #end if
+
m.server.UseRouter(new Http.CorsMiddleware(allowedOrigin))
#if WEB_SOCKETS
m.server.UseRouter(new Http.WebSocketMiddleware())
@@ -58,13 +59,13 @@ function WebServerLoop()
m.server.UseRouter(new Http.StateApiRouter())
m.server.UseRouter(new Http.InvidiousRouter())
m.server.UseRouter(new Http.HttpStaticFilesRouter("/", m.settings.WwwRoot, false, false, false))
- if IsDebugMode()
+ #if DEBUG
m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/libpkg", "libpkg:/", true, true, false))
m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/pkg", "pkg:/", true, true))
m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/tmp", "tmp:/", true, true))
m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/cachefs", "cachefs:/", true, true))
m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/common", "common:/", true, true))
- end if
+ #end if
#if WEB_SERVER_BASIC_AUTH
m.server.UseRouter(new Http.BasicAuthMiddleware())
#end if
diff --git a/playlet-lib/src/components/WebServer/Task/WebServerTask.xml b/playlet-lib/src/components/WebServer/Task/WebServerTask.xml
index df185c42..af65b7ea 100644
--- a/playlet-lib/src/components/WebServer/Task/WebServerTask.xml
+++ b/playlet-lib/src/components/WebServer/Task/WebServerTask.xml
@@ -5,5 +5,4 @@
-
diff --git a/playlet-lib/src/config/sponsorblock_config.json b/playlet-lib/src/config/sponsorblock_config.json
new file mode 100644
index 00000000..90dfd11c
--- /dev/null
+++ b/playlet-lib/src/config/sponsorblock_config.json
@@ -0,0 +1,115 @@
+{
+ "serverAddress": "https://sponsor.ajay.app",
+ "categoryList": [
+ "sponsor",
+ "selfpromo",
+ "exclusive_access",
+ "interaction",
+ "poi_highlight",
+ "intro",
+ "outro",
+ "preview",
+ "filler",
+ "chapter",
+ "music_offtopic"
+ ],
+ "categories": {
+ "sponsor": {
+ "title": "Sponsor",
+ "short_title": "Sponsor",
+ "categorySupport": [
+ "skip",
+ "mute",
+ "full"
+ ],
+ "color": "#00d400B3"
+ },
+ "selfpromo": {
+ "title": "Unpaid/Self Promotion",
+ "short_title": "Unpaid/Self Promotion",
+ "categorySupport": [
+ "skip",
+ "mute",
+ "full"
+ ],
+ "color": "#ffff00B3"
+ },
+ "exclusive_access": {
+ "title": "Exclusive Access",
+ "short_title": "Exclusive Access",
+ "categorySupport": [
+ "full"
+ ],
+ "color": "#008a5cB3"
+ },
+ "interaction": {
+ "title": "Interaction Reminder (Subscribe)",
+ "short_title": "Interaction Reminder",
+ "categorySupport": [
+ "skip",
+ "mute"
+ ],
+ "color": "#cc00ffB3"
+ },
+ "poi_highlight": {
+ "title": "Highlight",
+ "short_title": "Highlight",
+ "categorySupport": [
+ "poi"
+ ],
+ "color": "#ff1684B3"
+ },
+ "intro": {
+ "title": "Intermission/Intro Animation",
+ "short_title": "Intermission",
+ "categorySupport": [
+ "skip",
+ "mute"
+ ],
+ "color": "#00ffffB3"
+ },
+ "outro": {
+ "title": "Endcards/Credits",
+ "short_title": "Endcards/Credits",
+ "categorySupport": [
+ "skip",
+ "mute"
+ ],
+ "color": "#0202edB3"
+ },
+ "preview": {
+ "title": "Preview/Recap",
+ "short_title": "Preview/Recap",
+ "categorySupport": [
+ "skip",
+ "mute"
+ ],
+ "color": "#008fd6B3"
+ },
+ "filler": {
+ "title": "Filler Tangent/Jokes",
+ "short_title": "Filler",
+ "categorySupport": [
+ "skip",
+ "mute"
+ ],
+ "color": "#7300FFE6"
+ },
+ "chapter": {
+ "title": "Chapter",
+ "short_title": "Chapter",
+ "categorySupport": [
+ "chapter"
+ ],
+ "color": "#FFFFFFC8"
+ },
+ "music_offtopic": {
+ "title": "Music: Non-Music Section",
+ "short_title": "Non-Music",
+ "categorySupport": [
+ "skip"
+ ],
+ "color": "#ff9900B3"
+ }
+ }
+}
\ No newline at end of file
diff --git a/playlet-lib/src/images/LogoSponsorBlockSimple256px.png b/playlet-lib/src/images/LogoSponsorBlockSimple256px.png
new file mode 100644
index 00000000..7f8cd795
Binary files /dev/null and b/playlet-lib/src/images/LogoSponsorBlockSimple256px.png differ
diff --git a/playlet-lib/src/source/services/SponsorBlock.bs b/playlet-lib/src/source/services/SponsorBlock.bs
index 05e693ba..dd3222b3 100644
--- a/playlet-lib/src/source/services/SponsorBlock.bs
+++ b/playlet-lib/src/source/services/SponsorBlock.bs
@@ -1,54 +1,53 @@
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
import "pkg:/source/utils/WebUtils.bs"
import "pkg:/source/utils/Crypto.bs"
+import "pkg:/source/utils/ColorUtils.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
- if map = invalid
- map = {
- sponsor: &h00D400FF,
- selfpromo: &hFFFF00FF,
- exclusive_access: &h008A5CFF,
- interaction: &hCC00FFFF,
- poi_highlight: &hFF1684FF,
- intro: &h00FFFFFF,
- outro: &h0202EDFF,
- preview: &h008FD6FF,
- filler: &h7300FFFF,
- music_offtopic: &hFF9900FF
- }
- m.SponsorBlockColors = map
+ function GetSponsorBlockConfig() as object
+ if m.sponsorBlockConfig = invalid
+ m.sponsorBlockConfig = ParseJson(ReadAsciiFile("libpkg:/config/sponsorblock_config.json"))
end if
- if map.doesexist(category)
- return map[category]
+ return m.sponsorBlockConfig
+ end function
+
+ function SegmentColor(category as string) as integer
+ config = SponsorBlock.GetSponsorBlockConfig()
+ if config = invalid
+ return 0
+ end if
+
+ if config.categories.doesexist(category)
+ color = config.categories[category].color
+ return ColorUtils.HexToInt(color)
end if
return 0
end function
function SegmentTitle(category as string) as string
- map = m.SponsorBlockTitles
- if map = invalid
- map = {
- sponsor: "Sponsor",
- selfpromo: "Unpaid/Self Promotion",
- exclusive_access: "Exclusive Access",
- interaction: "Interaction Reminder (Subscribe)",
- poi_highlight: "Highlight",
- intro: "Intermission/Intro Animation",
- outro: "Endcards/Credits",
- preview: "Preview/Recap",
- filler: "Filler Tangent/Jokes",
- music_offtopic: "Non-Music Section"
- }
- m.SponsorBlockTitles = map
+ config = SponsorBlock.GetSponsorBlockConfig()
+ if config = invalid
+ return ""
end if
- if map.doesexist(category)
- return map[category]
+
+ if config.categories.doesexist(category)
+ return config.categories[category].title
+ end if
+ return ""
+ end function
+
+ function SegmentShortTitle(category as string) as string
+ config = SponsorBlock.GetSponsorBlockConfig()
+ if config = invalid
+ return ""
+ end if
+
+ if config.categories.doesexist(category)
+ return config.categories[category].short_title
end if
return ""
end function
diff --git a/playlet-lib/src/source/utils/ColorUtils.bs b/playlet-lib/src/source/utils/ColorUtils.bs
new file mode 100644
index 00000000..01d3a014
--- /dev/null
+++ b/playlet-lib/src/source/utils/ColorUtils.bs
@@ -0,0 +1,19 @@
+namespace ColorUtils
+ function HexToInt(color as dynamic) as integer
+ if color = invalid
+ return 0
+ end if
+ if color.left(1) = "#"
+ color = color.mid(1)
+ end if
+
+ value = Val(color.mid(0, 2), 16) * 16777216 + Val(color.mid(2, 2), 16) * 65536 + Val(color.mid(4, 2), 16) * 256
+ if color.Len() = 6
+ value += 255
+ else if color.Len() = 8
+ value += Val(color.mid(6, 2), 16)
+ end if
+
+ return value
+ end function
+end namespace
diff --git a/playlet-lib/src/source/utils/Debug.bs b/playlet-lib/src/source/utils/Debug.bs
deleted file mode 100644
index 13ce179a..00000000
--- a/playlet-lib/src/source/utils/Debug.bs
+++ /dev/null
@@ -1,17 +0,0 @@
-function IsDebugMode() as boolean
- appInfo = CreateObject("roAppInfo")
- bsConst = appInfo.GetValue("bs_const")
- symbols = bsConst.Tokenize(";")
-
- for each symbol in symbols
- keyValuePair = symbol.Tokenize("=")
- if keyValuePair.Count() <> 2
- continue for
- end if
- if UCase(keyValuePair[0]) = "DEBUG"
- return UCase(keyValuePair[1]) = "TRUE"
- end if
- end for
-
- return false
-end function
diff --git a/tools/generate-sponsorblock-config.js b/tools/generate-sponsorblock-config.js
new file mode 100644
index 00000000..eb707d34
--- /dev/null
+++ b/tools/generate-sponsorblock-config.js
@@ -0,0 +1,129 @@
+const fs = require('fs');
+const path = require('path');
+
+if (process.argv.length !== 3) {
+ console.error("Invalid usage! usage: npm run generate-sponsorblock-config -- sponsorblock_root");
+ exit(-1);
+}
+
+const PLAYLEY_CONFIG_PATH = "./playlet-lib/src/config/sponsorblock_config.json"
+
+const sponsorblockRoot = process.argv[2];
+
+const configExamplePath = path.join(sponsorblockRoot, "config.json.example")
+const englishLocalePath = path.join(sponsorblockRoot, "public/_locales/en/messages.json")
+
+let configExample = JSON.parse(fs.readFileSync(configExamplePath, { encoding: 'utf8', flag: 'r' }))
+let englishLocale = JSON.parse(fs.readFileSync(englishLocalePath, { encoding: 'utf8', flag: 'r' }))
+
+// https://github.com/ajayyy/SponsorBlock/blob/f4d80d88438ff31bc067ff480fd94112d972718d/src/config.ts#L251
+const barTypes = {
+ "preview-chooseACategory": {
+ color: "#ffffff",
+ opacity: "0.7"
+ },
+ "sponsor": {
+ color: "#00d400",
+ opacity: "0.7"
+ },
+ "preview-sponsor": {
+ color: "#007800",
+ opacity: "0.7"
+ },
+ "selfpromo": {
+ color: "#ffff00",
+ opacity: "0.7"
+ },
+ "preview-selfpromo": {
+ color: "#bfbf35",
+ opacity: "0.7"
+ },
+ "exclusive_access": {
+ color: "#008a5c",
+ opacity: "0.7"
+ },
+ "interaction": {
+ color: "#cc00ff",
+ opacity: "0.7"
+ },
+ "preview-interaction": {
+ color: "#6c0087",
+ opacity: "0.7"
+ },
+ "intro": {
+ color: "#00ffff",
+ opacity: "0.7"
+ },
+ "preview-intro": {
+ color: "#008080",
+ opacity: "0.7"
+ },
+ "outro": {
+ color: "#0202ed",
+ opacity: "0.7"
+ },
+ "preview-outro": {
+ color: "#000070",
+ opacity: "0.7"
+ },
+ "preview": {
+ color: "#008fd6",
+ opacity: "0.7"
+ },
+ "preview-preview": {
+ color: "#005799",
+ opacity: "0.7"
+ },
+ "music_offtopic": {
+ color: "#ff9900",
+ opacity: "0.7"
+ },
+ "preview-music_offtopic": {
+ color: "#a6634a",
+ opacity: "0.7"
+ },
+ "poi_highlight": {
+ color: "#ff1684",
+ opacity: "0.7"
+ },
+ "preview-poi_highlight": {
+ color: "#9b044c",
+ opacity: "0.7"
+ },
+ "filler": {
+ color: "#7300FF",
+ opacity: "0.9"
+ },
+ "preview-filler": {
+ color: "#2E0066",
+ opacity: "0.7"
+ }
+}
+
+function getColor(obj) {
+ if (!obj) {
+ return "#FFFFFFC8"
+ }
+
+ const opacity = (Math.round(parseFloat(obj.opacity) * 255)).toString(16).toUpperCase().padStart(2, "0")
+ return obj.color + opacity;
+}
+
+let playletConfig = {
+ serverAddress: configExample.serverAddress,
+ categoryList: configExample.categoryList,
+ categories: {}
+}
+
+playletConfig.categoryList.forEach(categoryId => {
+ const category = {}
+
+ category.title = englishLocale[`category_${categoryId}`].message
+ category.short_title = englishLocale[`category_${categoryId}_short`]?.message ?? category.title;
+ category.categorySupport = configExample.categorySupport[categoryId];
+ category.color = getColor(barTypes[categoryId]);
+
+ playletConfig.categories[categoryId] = category;
+});
+
+fs.writeFileSync(PLAYLEY_CONFIG_PATH, JSON.stringify(playletConfig, null, 4));