diff --git a/CHANGELOG.md b/CHANGELOG.md index ae4a5458..bac60984 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - German translations - Support for multi-accounts, such as brand accounts +- Support for manual skip in SponsorBlock +- Customize SponsorBlock categories from the settings ### Fixed diff --git a/package.json b/package.json index e67259d1..4f9cf88b 100644 --- a/package.json +++ b/package.json @@ -47,8 +47,8 @@ "build:lib:dev": "cd playlet-lib && npm run build:dev", "build:lib:prod": "cd playlet-lib && npm run build:prod", "build:web": "cd playlet-web && npm run build", - "lint": "cd playlet-lib && npm run lint && cd ../playlet-app && npm run lint", - "lint:fix": "cd playlet-lib && npm run lint:fix && cd ../playlet-app && npm run lint:fix", + "lint": "cd playlet-lib && npm run lint && cd ../playlet-app && npm run lint && cd ../playlet-web && npm run lint", + "lint:fix": "cd playlet-lib && npm run lint:fix && cd ../playlet-app && npm run lint:fix && cd ../playlet-web && npm run lint", "format": "cd playlet-lib && npm run format && cd ../playlet-app && npm run format", "format:fix": "cd playlet-lib && npm run format:fix && cd ../playlet-app && npm run format:fix", "test": "npm run test:lib && npm run test:app", @@ -62,7 +62,6 @@ "manifest-git-hash": "node tools/update-manifest-git-hash.js", "sign-released-package": "node tools/sign-released-package.js", "screenshot": "node tools/screenshot.js", - "generate-sponsorblock-config": "node tools/generate-sponsorblock-config.js", "convert-images": "node tools/convert-images.js", "update-rale-component": "cd tools/RALE && rm TrackerTask.xml && curl -o TrackerTask.zip https://devtools.web.roku.com/roku-advanced-layout-editor/app/TrackerTask.zip && unzip TrackerTask.zip && rm TrackerTask.zip", "postinstall": "cd playlet-lib && npm install && cd ../playlet-app && npm install && cd ../playlet-web && npm install", diff --git a/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousInstanceTesting/InvidiousInstanceTestingTask.bs b/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousInstanceTesting/InvidiousInstanceTestingTask.bs index 8a0df504..af69d02c 100644 --- a/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousInstanceTesting/InvidiousInstanceTestingTask.bs +++ b/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousInstanceTesting/InvidiousInstanceTestingTask.bs @@ -24,8 +24,6 @@ end function function PrepareTests() as object content = CreateObject("roSGNode", "ContentNode") - ' TODO:P2 test if video data is reachable (head?) - ' TODO:P2 test if video data is reachable in proxy mode (local=true) content.AppendChild(CreateTestNode(Tr(Locale.InvidiousTesting.ValidUrl), IsValidUrl)) content.AppendChild(CreateTestNode(Tr(Locale.InvidiousTesting.InstanceReachable), IsReachable)) content.AppendChild(CreateTestNode(Tr(Locale.InvidiousTesting.FetchVideoDetails), CanFetchVideoDetails)) diff --git a/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoriesControl.bs b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoriesControl.bs new file mode 100644 index 00000000..96e61546 --- /dev/null +++ b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoriesControl.bs @@ -0,0 +1,79 @@ +import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs" +import "pkg:/source/utils/FocusManagement.bs" +import "pkg:/source/utils/Locale.bs" +import "pkg:/source/utils/StringUtils.bs" +import "pkg:/source/utils/Types.bs" + +function Init() + m.top.focusable = true + m.top.itemSpacings = [8] + + m.button = m.top.findNode("button") + m.button.observeField("buttonSelected", FuncName(OpenSponsorBlockCategories)) + AdjustButtonLabel(m.button) +end function + +function OnFocusChange() as void + if not m.top.focus + return + end if + + NodeSetFocus(m.button, true) +end function + +function AdjustButtonLabel(button as object) as void + children = button.getChildren(-1, 0) + for each child in children + if child.isSubtype("Label") and child.hasField("horizAlign") + child.observeField("horizAlign", FuncName(OnButtonLabelHorizAlignChanged)) + child.horizAlign = "left" + return + end if + end for +end function + +function OnButtonLabelHorizAlignChanged(event as object) + label = event.getRoSGNode() + if label.horizAlign <> "left" + label.horizAlign = "left" + end if +end function + +function BindPreference(preferences as object, key as string) + if m.preferences <> invalid and m.key <> invalid + m.preferences.unobserveFieldScoped(m.key) + end if + + m.preferences = preferences + m.key = key + + if preferences <> invalid and key <> invalid + preferences.observeFieldScoped(key, FuncName(OnPreferenceChange)) + OnPreferenceChange() + end if +end function + +function OpenSponsorBlockCategories() + categoriesPrefs = CreateObject("roSGNode", "SponsorBlockCategoriesPreferences") + m.appController@.PushScreen(categoriesPrefs) + categoriesPrefs@.BindNode() + categoriesPrefs.value = m.top.value + categoriesPrefs.observeField("save", FuncName(OnSaveCategoriesPreferences)) +end function + +function OnSaveCategoriesPreferences(event as object) + categoriesPrefs = event.GetRoSGNode() + m.top.value = categoriesPrefs.value +end function + +function OnPreferenceChange() + m.top.value = m.preferences[m.key] +end function + +function OnValueChange() as void + if m.preferences = invalid or m.key = invalid + return + end if + + m.preferences[m.key] = m.top.value +end function diff --git a/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoriesControl.xml b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoriesControl.xml new file mode 100644 index 00000000..527f266e --- /dev/null +++ b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoriesControl.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoriesPreferences.bs b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoriesPreferences.bs new file mode 100644 index 00000000..c705ae16 --- /dev/null +++ b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoriesPreferences.bs @@ -0,0 +1,181 @@ +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/VideoPlayer/SponsorBlockSegmentAction.bs" +import "pkg:/source/utils/Logging.bs" +import "pkg:/source/utils/RemoteKeys.bs" +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() + + optionTitles = {} + optionTitles[SponsorBlock.SegmentAction.Disable] = Tr(Locale.SponsorBlock.Disable) + optionTitles[SponsorBlock.SegmentAction.AutoSkip] = Tr(Locale.SponsorBlock.AutoSkip) + optionTitles[SponsorBlock.SegmentAction.ManualSkip] = Tr(Locale.SponsorBlock.ManualSkip) + optionTitles[SponsorBlock.SegmentAction.ShowInSeekbar] = Tr(Locale.SponsorBlock.ShowInSeekbar) + m.optionTitles = optionTitles + + SetupCategoriesUi() + + m.closeButton = m.top.findNode("closeButton") + m.saveButton = m.top.findNode("saveButton") + SetButtonPositions() + + SetNavigation(m.saveButton, RemoteKeys.Right, m.closeButton) + SetNavigation(m.closeButton, RemoteKeys.Left, m.saveButton) + SetNavigation(m.saveButton, RemoteKeys.Up, m.categoryList) + SetNavigation(m.closeButton, RemoteKeys.Up, m.categoryList) + SetNavigation(m.categoryList, RemoteKeys.Down, m.saveButton) + + m.saveButton.observeField("buttonSelected", FuncName(OnSaveButtonSelected)) + m.closeButton.observeField("buttonSelected", FuncName(Close)) +end function + +function SetupCategoriesUi() as void + categories = m.service.GetCategories() + if categories.Count() = 0 + return + end if + + content = CreateObject("roSGNode", "ContentNode") + categoryContentNodes = [] + + for each category in categories + categoryNode = CreateObject("roSGNode", "SponsorBlockCategoryContent") + categoryNode.category = category + categoryNode.categoryTitle = Tr(m.service.SegmentTitle(category)) + categoryNode.selectedOption = SponsorBlock.SegmentAction.Disable + categoryNode.options = m.service.GetOptionsForCategory(category) + categoryNode.optionTitles = m.optionTitles + categoryNode.color = m.service.SegmentColor(category) + categoryContentNodes.push(categoryNode) + end for + + content.appendChildren(categoryContentNodes) + m.categoryList.content = content +end function + +function SetButtonPositions() + saveButtonWidth = m.saveButton.width + closeButtonWidth = m.closeButton.width + buttonsWith = closeButtonWidth + saveButtonWidth + 20 + m.saveButton.translation = [720 / 2 - buttonsWith / 2, m.saveButton.translation[1]] + m.closeButton.translation = [720 / 2 + buttonsWith / 2 - closeButtonWidth, m.closeButton.translation[1]] +end function + +function OnFocusChange() as void + if not m.top.focus + return + end if + + NodeSetFocus(m.categoryList, true) +end function + +function OnKeyEvent(key as string, press as boolean) as boolean + if NavigationKeyHandler(key, press).handled + return true + end if + + if key = RemoteKeys.Options or key = RemoteKeys.Play or key = RemoteKeys.Pause or key = RemoteKeys.PlayOnly + ' A pass-through to the app controller, so it can toggle picture-in-picture and pause/play + return false + end if + + if key = RemoteKeys.Back and press + Close() + return true + end if + + return true +end function + +function OnValueChange() as void + content = m.categoryList.content + if content = invalid + return + end if + + value = m.top.value + if not IsAssociativeArray(value) + return + end if + + categoryContentNodes = content.getChildren(-1, 0) + categoryNodeMap = {} + for each categoryContentNode in categoryContentNodes + categoryNodeMap[categoryContentNode.category] = categoryContentNode + end for + + for each category in value + if not categoryNodeMap.DoesExist(category) + continue for + end if + categoryNode = categoryNodeMap[category] + if categoryNode = invalid + continue for + end if + categoryNode.selectedOption = value[category].option + end for +end function + +function OnSaveButtonSelected() + m.top.save = true + Close() +end function + +function Close() + m.appController@.PopScreen() +end function + +function OnCategorySelected(event as object) as void + itemSelected = m.categoryList.itemSelected + itemNode = m.categoryList.content.GetChild(itemSelected) + if itemNode = invalid + LogError("Invalid item selected:", itemSelected) + return + end if + + options = itemNode.options + optionTitles = itemNode.optionTitles + optionTitlesArray = [] + for each option in options + optionTitlesArray.push(optionTitles[option]) + end for + + dialog = DialogUtils.ShowDialogEx({ + title: itemNode.categoryTitle + message: Tr(Locale.Settings.SelectOptionFor).Replace("%1", itemNode.categoryTitle) + buttons: optionTitlesArray + }) + if dialog = invalid + return + end if + dialog.addFields({ + "categoryContentNode": itemNode + "options": options + }) + dialog.observeField("buttonSelected", FuncName(OnCategoryDialogResult), ["buttonSelected"]) +end function + +function OnCategoryDialogResult(event as object) as void + dialog = event.getRoSGNode() + options = dialog.options + buttonIndex = event.GetData() + + if not IsInt(buttonIndex) or buttonIndex < 0 or buttonIndex >= options.Count() + return + end if + + selectedOption = options[buttonIndex] + category = dialog.categoryContentNode.category + + value = m.top.value + value[category].option = selectedOption + m.top.value = value + + LogInfo("SponsorBlock category", category, "set to", selectedOption) +end function diff --git a/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoriesPreferences.xml b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoriesPreferences.xml new file mode 100644 index 00000000..de3bfda2 --- /dev/null +++ b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoriesPreferences.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoryContent.xml b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoryContent.xml new file mode 100644 index 00000000..88761dbb --- /dev/null +++ b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoryContent.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoryListItem.bs b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoryListItem.bs new file mode 100644 index 00000000..0c50ff60 --- /dev/null +++ b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoryListItem.bs @@ -0,0 +1,11 @@ +function OnContentSet() as void + content = m.top.itemContent + if content = invalid + return + end if + + m.top.categoryTitle = content.categoryTitle + optionTitles = content.optionTitles + m.top.optionTitle = optionTitles[content.selectedOption] + m.top.color = content.color +end function diff --git a/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoryListItem.xml b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoryListItem.xml new file mode 100644 index 00000000..1debe975 --- /dev/null +++ b/playlet-lib/src/components/Screens/SettingsScreen/SponsorBlockCategories/SponsorBlockCategoryListItem.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/Services/Preferences/Preferences.bs b/playlet-lib/src/components/Services/Preferences/Preferences.bs index 23fb043c..7c773fcc 100644 --- a/playlet-lib/src/components/Services/Preferences/Preferences.bs +++ b/playlet-lib/src/components/Services/Preferences/Preferences.bs @@ -9,6 +9,7 @@ function Init() "number": "integer" "radio": "string" "array": "array" + "assocarray": "assocarray" } m.disableSavingToRegistry = false diff --git a/playlet-lib/src/components/Services/SponsorBlock/Notifications/SponsorBlockNotification.bs b/playlet-lib/src/components/Services/SponsorBlock/Notifications/SponsorBlockNotification.bs index 0ffc61d4..472f2459 100644 --- a/playlet-lib/src/components/Services/SponsorBlock/Notifications/SponsorBlockNotification.bs +++ b/playlet-lib/src/components/Services/SponsorBlock/Notifications/SponsorBlockNotification.bs @@ -1,4 +1,5 @@ import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs" +import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs" function Init() m.categoryLabel = m.top.findNode("categoryLabel") @@ -13,16 +14,7 @@ function Init() m.service = SponsorBlock.SponsorBlockService() end function -function OnActionSet() - action = m.top.action - category = m.top.segment.category - categoryTitle = Tr(ValidString(m.service.SegmentShortTitle(category))) - if action = "AutoSkip" - m.categoryLabel.text = Tr(Locale.SponsorBlock.Skipped) + `\n` + categoryTitle - else - m.categoryLabel.text = categoryTitle - end if - +function OnDoShow() as void AnimateIn() end function diff --git a/playlet-lib/src/components/Services/SponsorBlock/Notifications/SponsorBlockNotification.xml b/playlet-lib/src/components/Services/SponsorBlock/Notifications/SponsorBlockNotification.xml index 6f6e00ba..676c3e7c 100644 --- a/playlet-lib/src/components/Services/SponsorBlock/Notifications/SponsorBlockNotification.xml +++ b/playlet-lib/src/components/Services/SponsorBlock/Notifications/SponsorBlockNotification.xml @@ -1,7 +1,9 @@ - - + + + + - - - + + + + + + invalid notifications.RemoveChild(notification) end if end function function SetVisible(notifications as object, visible as boolean) - notification = notifications.findNode(NOTIFICATION_NODE_ID) + notification = GetCurrentNotification(notifications) if notification <> invalid notification.visible = visible end if diff --git a/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockSegmentViewedTask.bs b/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockSegmentViewedTask.bs index bcd0882e..097cc29f 100644 --- a/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockSegmentViewedTask.bs +++ b/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockSegmentViewedTask.bs @@ -5,5 +5,5 @@ function SponsorBlockSegmentViewedTask(input as object) segmentId = input.segmentId service = new SponsorBlock.SponsorBlockService() - service.PostSegmentViewed(segmentId) + service.PostSegmentViewed(segmentId, m.top.cancellation) end function diff --git a/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockService.bs b/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockService.bs index 1fb28ee4..8e56eb9f 100644 --- a/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockService.bs +++ b/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockService.bs @@ -12,6 +12,26 @@ namespace SponsorBlock m.sponsorBlockConfig = ParseJson(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 @@ -54,8 +74,10 @@ namespace SponsorBlock return invalid end if - categories = ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "poi_highlight", "filler", "exclusive_access"] - actionTypes = ["skip", "mute", "chapter", "full", "poi"] + ' categories = ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "poi_highlight", "filler", "exclusive_access"] + categories = ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "poi_highlight", "filler"] + ' actionTypes = ["skip", "mute", "chapter", "full", "poi"] + actionTypes = ["skip", "mute", "poi"] categoriesJson = FormatJson(categories).EncodeUriComponent() actionTypesJson = FormatJson(actionTypes).EncodeUriComponent() @@ -64,6 +86,11 @@ namespace SponsorBlock hashPrefix = CryptoUtils.GetSha256(videoId).Left(4) url = `${m.sponsorBlockConfig.serverAddress}${SponsorBlock.SKIP_SEGMENT_ENDPOINT}/${hashPrefix}?categories=${categoriesJson}&actionTypes=${actionTypesJson}` response = HttpClient.Get(url).Await() + if not response.IsSuccess() + LogError("SponsorBlockService: GetSkipSegmentsForVideo failed", response.ErrorMessage()) + return invalid + end if + json = response.Json() if json = invalid return invalid @@ -78,13 +105,13 @@ namespace SponsorBlock return invalid end function - function PostSegmentViewed(segmentId as string) as void + function PostSegmentViewed(segmentId as string, cancellation = invalid as object) as void if m.sponsorBlockConfig = invalid or StringUtils.IsNullOrEmpty(m.sponsorBlockConfig.serverAddress) return end if url = `${m.sponsorBlockConfig.serverAddress}${SponsorBlock.VIEWED_SEGMENT_ENDPOINT}?UUID=${segmentId}` - HttpClient.Post(url, "").Await() + HttpClient.Post(url, "").Cancellation(cancellation).Await() end function function GenerateProgressBarBackground(segments as object, lengthSeconds as integer, path as string) @@ -103,8 +130,8 @@ namespace SponsorBlock continue for end if - pixelStart = (segment.segment[0] / videoDuration) * width - pixelEnd = (segment.segment[1] / videoDuration) * width + pixelStart = (segment.start / videoDuration) * width + pixelEnd = (segment.end / videoDuration) * width color = m.SegmentColor(segment.category) ' highlight's duration is zero, so it is not visble on the bar. ' Add a few pixels to see it diff --git a/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockTask.bs b/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockTask.bs index 7eec9d50..bed802c4 100644 --- a/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockTask.bs +++ b/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockTask.bs @@ -1,22 +1,135 @@ import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs" +import "pkg:/components/VideoPlayer/SponsorBlockSegmentAction.bs" +import "pkg:/source/utils/Types.bs" @asynctask function SponsorBlockTask(input as object) as object videoId = input.metadata.videoId lengthSeconds = input.metadata.lengthSeconds + showNotifications = input.showNotifications + categories = input.categories service = new SponsorBlock.SponsorBlockService() skipSegments = service.GetSkipSegmentsForVideo(videoId) - barPath = invalid + skipSegments = ProcessSkipSegments(skipSegments, showNotifications, categories, service) + + barPath = invalid if skipSegments <> invalid barPath = `tmp:/sponsorblock_bar.png` service.GenerateProgressBarBackground(skipSegments, lengthSeconds, barPath) end if + ' Usually segment.start and segment.end are equal for poi_highlight + ' We pad the duration for poi_highlight segments so that the chapter label + ' can be visible when seeking in trickplay. + ' Padding poi_highlight is done after generating the progress bar, so that the + ' highlight is not too long in the bar. + skipSegments = PadHightlightSegment(skipSegments, lengthSeconds) + + ' Sort the segments by start time, so we can binary search them later. + if skipSegments <> invalid + skipSegments.SortBy("start") + end if + return { videoId: videoId skipSegments: skipSegments barPath: barPath } end function + +function ProcessSkipSegments(skipSegments as object, showNotifications as boolean, categories as object, service as SponsorBlock.SponsorBlockService) as object + if skipSegments = invalid + return invalid + end if + + processedSegments = [] + for each segment in skipSegments + ' When a submission reaches the score of -2 or lower, it gets removed and will not appear anymore for users + ' https://wiki.sponsor.ajay.app/w/FAQ#How_does_voting_work_and_what_do_certain_amounts_of_votes_mean? + if ValidInt(segment.votes) < -1 + continue for + end if + + option = GetOptionForSegment(segment, categories) + if option = SponsorBlock.SegmentAction.Disable + continue for + end if + + segment.option = option + + segment.showNotification = showNotifications and ShouldShowNotification(segment, categories) + if segment.showNotification + if option = SponsorBlock.SegmentAction.AutoSkip + segment.actionText = Tr(Locale.SponsorBlock.Skipped) + else if option = SponsorBlock.SegmentAction.ManualSkip + segment.actionText = Tr(Locale.SponsorBlock.PressOkToSkip) + else + segment.actionText = "" + end if + end if + + segmentRange = segment["segment"] + segmentStart = segmentRange[0] + segmentEnd = segmentRange[1] + segment.Delete("segment") + segment.start = segmentStart + segment.end = segmentEnd + + segment.title = Tr(ValidString(service.SegmentTitle(segment.category))) + segment.shortTitle = Tr(ValidString(service.SegmentShortTitle(segment.category))) + + processedSegments.push(segment) + end for + + return processedSegments +end function + +function GetOptionForSegment(segment as object, categories as object) as string + category = categories[segment.category] + if not IsAssociativeArray(category) + return false + end if + + option = category.option + if StringUtils.IsNullOrEmpty(option) + option = SponsorBlock.SegmentAction.Disable + end if + + return option +end function + +function ShouldShowNotification(segment as object, categories as object) as boolean + option = GetOptionForSegment(segment, categories) + return option = SponsorBlock.SegmentAction.AutoSkip or option = SponsorBlock.SegmentAction.ManualSkip +end function + +function PadHightlightSegment(segments as object, lengthSeconds as integer) as object + for each segment in segments + if not segment.category = "poi_highlight" + continue for + end if + + segmentPaddedDuration = 5 + + if lengthSeconds > 0 + if lengthSeconds < 120 + segmentPaddedDuration = 1 + else if lengthSeconds < 300 + segmentPaddedDuration = 2 + else if lengthSeconds < 900 + segmentPaddedDuration = 5 + else + segmentPaddedDuration = 10 + end if + end if + + segmentDuration = Abs(segment.end - segment.start) + padding = Abs(segmentPaddedDuration - segmentDuration) / 2 + segment.start = segment.start - padding + segment.end = segment.end + padding + end for + + return segments +end function diff --git a/playlet-lib/src/components/VideoPlayer/SponsorBlock.bs b/playlet-lib/src/components/VideoPlayer/SponsorBlock.bs index 2ea7bd05..2367c48e 100644 --- a/playlet-lib/src/components/VideoPlayer/SponsorBlock.bs +++ b/playlet-lib/src/components/VideoPlayer/SponsorBlock.bs @@ -2,6 +2,7 @@ import "pkg:/components/Services/SponsorBlock/Notifications/SponsorBlockNotifica import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs" import "pkg:/source/AsyncTask/AsyncTask.bs" import "pkg:/source/AsyncTask/Tasks.bs" +import "SponsorBlockSegmentAction.bs" import "VideoPlayer.bs" namespace SponsorBlock @@ -12,18 +13,62 @@ namespace SponsorBlock end if m.sponsorBlockService = new SponsorBlock.SponsorBlockService() - - PositionChapterLabel() - m.top.trickPlayBar.observeField("visible", FuncName(OnTrickPlayBarVisible)) - m.chapterLabelTimer = m.top.findNode("chapterLabelTimer") - m.chapterLabelTimer.observeField("fire", FuncName(OnChapterLabelTimer)) - m._sponsorBlockLastTime = 0.0# - - ' TODO:P1 more precision on when notifications should be visible - ' Should notifcations be visible when the video is not fullscreen? SponsorBlock.SetVisible(m.notifications, m.container.fullscreen) end function + function FetchSponsorBlock(metadata as object) as void + if not m.preferences["sponsorblock.enabled"] + return + end if + + if m.sponsorBlockTask <> invalid + m.sponsorBlockTask.cancel = true + end if + + m.sponsorBlockTask = AsyncTask.Start(Tasks.SponsorBlockTask, { + metadata: metadata + showNotifications: m.preferences["sponsorblock.show_notifications"] + categories: m.preferences["sponsorblock.categories"] + }, OnSponsorBlockTaskResults) + end function + + function OnSponsorBlockTaskResults(output as object) as void + m.sponsorBlockTask = invalid + if output.cancelled or m.onCloseCalled = true + return + end if + + if not output.success + error = ErrorUtils.Format(output.error) + LogError(error) + return + end if + + skipSegments = output.result.skipSegments + if skipSegments = invalid or skipSegments.Count() = 0 + return + end if + + m.skipSegments = skipSegments + m.top.seekMode = "accurate" + + barPath = output.result.barPath + if barPath <> invalid + m.top.trickPlayBar.trackImageUri = barPath + m.top.trickPlayBar.filledBarBlendColor = "#FF000080" + end if + + m.top.ObserveFieldScoped("position", FuncName(OnPositionChangeSkipSponsorBlockSections)) + + if m.top.hasField("trickPlayPosition") + PositionChapterLabel() + m.chapterLabelTimer = m.top.findNode("chapterLabelTimer") + m.chapterLabelTimer.observeField("fire", FuncName(OnChapterLabelTimer)) + m._sponsorBlockLastTimeChapterUpdated = 0.0# + m.top.trickPlayBar.observeField("visible", FuncName(OnTrickPlayBarVisible)) + end if + end function + function PositionChapterLabel() m.chapterLabel = m.top.findNode("chapterLabel") ' We move the chapter label under m.top.trickPlayBar @@ -43,162 +88,137 @@ namespace SponsorBlock end function function OnChapterLabelTimer() as void - if m.skipSegments = invalid + trickPlayPosition = m.top.trickPlayPosition + if m._sponsorBlockLastTimeChapterUpdated = trickPlayPosition return end if - ' trickPlayPosition is not documented on Roku website, this is why we're checking - if not IsDouble(m.top.trickPlayPosition) - return - end if - - if m._sponsorBlockLastTime = m.top.trickPlayPosition - return - end if - - m._sponsorBlockLastTime = m.top.trickPlayPosition - - UpdateSponsorBlockChapter(m._sponsorBlockLastTime) + m._sponsorBlockLastTimeChapterUpdated = trickPlayPosition + UpdateSponsorBlockChapter(trickPlayPosition) end function function UpdateSponsorBlockChapter(time as double) as void segments = m.skipSegments - for each segment in segments - category = segment["category"] - segmentRange = segment["segment"] - segmentStart = segmentRange[0] - segmentEnd = segmentRange[1] - - ' Usually segmentStart and segmentEnd are equal for poi_highlight - ' We pad the duration for poi_highlight segments so that the chapter label - ' can be visible when seeking in trickplay - if category = "poi_highlight" - segmentPaddedDuration = 5 - - duration = m.top.duration - if duration > 0 - if duration < 120 - segmentPaddedDuration = 1 - else if duration < 300 - segmentPaddedDuration = 2 - else if duration < 900 - segmentPaddedDuration = 5 - else - segmentPaddedDuration = 10 - end if - end if - - segmentDuration = Abs(segmentEnd - segmentStart) - padding = Abs(segmentPaddedDuration - segmentDuration) / 2 - segmentStart = segmentStart - padding - segmentEnd = segmentEnd + padding - end if - - if (segmentStart <= time) and (segmentEnd >= time) - m.top.chapter = Tr(ValidString(m.sponsorBlockService.SegmentTitle(category))) - return - end if - end for - m.top.chapter = "" + segment = FindSegmentByTime(segments, time, 0) + if segment = invalid + m.top.chapter = "" + return + end if + m.top.chapter = segment.title end function - function FetchSponsorBlock(metadata as object) as void - if not m.preferences["sponsorblock.enabled"] - return - end if - - if m.sponsorBlockTask <> invalid - m.sponsorBlockTask.cancel = true - end if - - m.sponsorBlockTask = AsyncTask.Start(Tasks.SponsorBlockTask, { metadata: metadata }, OnSponsorBlockTaskResults) - end function - - function OnSponsorBlockTaskResults(output as object) as void - m.sponsorBlockTask = invalid - if output.cancelled or m.onCloseCalled = true - return - end if - - if not output.success - error = ErrorUtils.Format(output.error) - LogError(error) - return - end if - - skipSegments = output.result.skipSegments - if skipSegments = invalid - return - end if - - m.skipSegments = skipSegments - m.top.seekMode = "accurate" - - barPath = output.result.barPath - if barPath <> invalid - m.top.trickPlayBar.trackImageUri = barPath - m.top.trickPlayBar.filledBarBlendColor = "#FF000080" - end if - - m.top.ObserveFieldScoped("position", FuncName(OnPositionChangeSkipSponsorBlockSections)) + function FindSegmentByTime(segments as object, time as dynamic, endOffset as integer) as dynamic + ' Binary search for the segment that contains the time. + ' This search sometimes fails if the segments overlap. + ' For most cases, this is acceptable, since it is not common for segments to overlap. + low = 0 + high = segments.Count() - 1 + while low <= high + middle = (low + high) \ 2 + segment = segments[middle] + if time < segment.start + high = middle - 1 + else if time > (segment.end + endOffset) + low = middle + 1 + else + return segment + end if + end while + return invalid end function function OnPositionChangeSkipSponsorBlockSections() as void segments = m.skipSegments - if segments = invalid + position = m.top.position + + ' We add a small offset to the end position of the segment. + ' This is so that when we skip a segment, we don't get + ' another notification to skip it. + ' Seeking accuracy is not perfect, so we need to account for that. + segment = FindSegmentByTime(segments, position, -1) + if segment = invalid return end if - for each segment in segments - segmentRange = segment["segment"] - segmentStart = segmentRange[0] - segmentEnd = segmentRange[1] - currentPosition = m.top.position - if (segmentStart < currentPosition) and ((segmentEnd - 1) > currentPosition) - action = GetActionForSegment(segment) - if m.preferences["sponsorblock.show_notifications"] = true - SponsorBlock.ShowNotifcation(m.notifications, segment, action) - end if + action = segment.option - if action = "AutoSkip" - duration = m.top.duration - ' Sometimes segmentEnd is greater than duration - if duration > 0 and segmentEnd > duration - segmentEnd = duration - end if - ' If the segment is at the end of the video, skip the video instead of seeking - if duration > 0 and Abs(segmentEnd - duration) < 2 - LogInfo("Skipping section:", segment["category"], "at end of video") - SendSkippedSectionEvent(segment.UUID) - OnVideoFinished() - return - else - LogInfo("Skipping section:", segment["category"]) - SendSkippedSectionEvent(segment.UUID) - m.top.seek = segmentEnd - return - end if - end if + if segment.showNotification + SponsorBlock.ShowNotifcation(m.notifications, segment, action) + + if action = SegmentAction.ManualSkip + ' We'll save the segment here, and handle it in case the user + ' presses the OK button on the notification. + m.manualSkipSegment = segment + return end if - end for + end if + + if action = SegmentAction.AutoSkip + SkipSegment(segment, position) + end if end function - function GetActionForSegment(segment as object) as dynamic - category = segment["category"] - if category = "sponsor" - return "AutoSkip" - else if category = "poi_highlight" - return "ManualSkip" - else if category = "exclusive_access" - return "ShowOverlay" - else if category = "chapter" - return "ShowOverlay" + function SkipSegment(segment as object, position as dynamic) as void + segmentEnd = segment.end + + duration = m.top.duration + ' Sometimes segmentEnd is greater than duration + if duration > 0 and segmentEnd > duration + segmentEnd = duration end if - return "" + + ' If we're skipping a very short distance, it's not worth it + ' since we can cause rebuffering + if Abs(segmentEnd - position) < 2 + LogInfo("Skip position is within 2 seconds of segment end, not skipping") + return + end if + + ' If the segment is at the end of the video, skip the video instead of seeking + if duration > 0 and Abs(segmentEnd - duration) < 2 + LogInfo("Skipping section:", segment.category, "at end of video") + OnVideoFinished() + else + LogInfo("Skipping section:", segment.category) + m.top.seek = segmentEnd + end if + SendSkippedSectionEvent(segment.UUID) + end function + + function ManualSkipSegment() as boolean + segment = m.manualSkipSegment + if segment = invalid + return false + end if + + m.manualSkipSegment = invalid + + notification = SponsorBlock.GetCurrentNotification(m.notifications) + if notification = invalid + return false + end if + + notificationSegmentId = notification.segmentId + if notificationSegmentId <> segment.UUID + return false + end if + + position = m.top.position + if (position < segment.start) or (segment.end < position) + return false + end if + + SkipSegment(segment, position) + SponsorBlock.RemoveNotifcation(m.notifications) + return true end function function SendSkippedSectionEvent(segmentId as string) - AsyncTask.Start(Tasks.SponsorBlockSegmentViewedTask, { segmentId: segmentId }) + if m.sponsorSkipEventTask <> invalid + m.sponsorSkipEventTask.cancel = true + end if + + m.sponsorSkipEventTask = AsyncTask.Start(Tasks.SponsorBlockSegmentViewedTask, { segmentId: segmentId }) end function end namespace diff --git a/playlet-lib/src/components/VideoPlayer/SponsorBlockSegmentAction.bs b/playlet-lib/src/components/VideoPlayer/SponsorBlockSegmentAction.bs new file mode 100644 index 00000000..7aaa066e --- /dev/null +++ b/playlet-lib/src/components/VideoPlayer/SponsorBlockSegmentAction.bs @@ -0,0 +1,16 @@ +namespace SponsorBlock + + enum SegmentAction + ' Disable: we do not care about this segment. + Disable = "disable" + ' AutoSkip: we want to skip this segment automatically. + AutoSkip = "auto_skip" + ' ManualSkip: we want to skip this segment manually, by showing a notification. + ' The user would have to press the skip button on the notification. + ManualSkip = "manual_skip" + ' ShowInSeekbar: we want to show this segment in the seekbar, but not skip it. + ' No notification will be shown + ShowInSeekbar = "show_in_seekbar" + end enum + +end namespace diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs index cb39a7ab..f5eee09b 100644 --- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs +++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs @@ -518,6 +518,10 @@ function HideUIAndStopTimer() end function function HandleOKPress() as boolean + if SponsorBlock.ManualSkipSegment() + return false + end if + if not m.showUIEnabled return false end if diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml b/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml index 1530be11..9ff0b8b9 100644 --- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml +++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml @@ -19,7 +19,7 @@ - + diff --git a/playlet-lib/src/config/preferences.json5 b/playlet-lib/src/config/preferences.json5 index 06ad11ef..4b574b84 100644 --- a/playlet-lib/src/config/preferences.json5 +++ b/playlet-lib/src/config/preferences.json5 @@ -128,6 +128,52 @@ type: "boolean", defaultValue: true, }, + { + displayText: "Categories", + key: "sponsorblock.categories", + description: "Configure which segments to skip", + type: "assocarray", + visibility: "tv", + rokuComponent: "SponsorBlockCategoriesControl", + defaultValue: { + // TODO:P1 support for exclusive_access and chapter + // TODO:P1 support for manual skip for poi_highlight + sponsor: { + option: "auto_skip", + }, + selfpromo: { + option: "manual_skip", + }, + interaction: { + option: "manual_skip", + }, + poi_highlight: { + option: "show_in_seekbar", + }, + intro: { + option: "manual_skip", + }, + outro: { + option: "manual_skip", + }, + preview: { + option: "manual_skip", + }, + filler: { + option: "manual_skip", + }, + music_offtopic: { + option: "manual_skip", + }, + }, + }, + { + displayText: "Categories", + key: "sponsorblock.categories", + description: "Configure which segments to skip", + visibility: "web", + svelteComponent: "SponsorBlockCategoriesControl", + }, ], }, { diff --git a/playlet-lib/src/config/sponsorblock_config.json5 b/playlet-lib/src/config/sponsorblock_config.json5 index dada5834..6a723425 100644 --- a/playlet-lib/src/config/sponsorblock_config.json5 +++ b/playlet-lib/src/config/sponsorblock_config.json5 @@ -1,116 +1,70 @@ { - serverAddress: 'https://sponsor.ajay.app', + serverAddress: "https://sponsor.ajay.app", categoryList: [ - 'sponsor', - 'selfpromo', - 'exclusive_access', - 'interaction', - 'poi_highlight', - 'intro', - 'outro', - 'preview', - 'filler', - 'chapter', - 'music_offtopic', + "sponsor", + "selfpromo", + "interaction", + "poi_highlight", + "intro", + "outro", + "preview", + "filler", + "music_offtopic", ], categories: { sponsor: { - title: 'Sponsor', - short_title: 'Sponsor', - categorySupport: [ - 'skip', - 'mute', - 'full', - ], - color: '#00D400B3', + title: "Sponsor", + short_title: "Sponsor", + options: ["auto_skip", "manual_skip", "show_in_seekbar", "disable"], + 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', + title: "Unpaid/Self Promotion", + short_title: "Unpaid/Self Promotion", + options: ["auto_skip", "manual_skip", "show_in_seekbar", "disable"], + color: "#FFFF00B3", }, interaction: { - title: 'Interaction Reminder (Subscribe)', - short_title: 'Interaction Reminder', - categorySupport: [ - 'skip', - 'mute', - ], - color: '#CC00FFB3', + title: "Interaction Reminder (Subscribe)", + short_title: "Interaction Reminder", + options: ["auto_skip", "manual_skip", "show_in_seekbar", "disable"], + color: "#CC00FFB3", }, poi_highlight: { - title: 'Highlight', - short_title: 'Highlight', - categorySupport: [ - 'poi', - ], - color: '#FF1684B3', + title: "Highlight", + short_title: "Highlight", + options: ["show_in_seekbar", "disable"], + color: "#FF1684B3", }, intro: { - title: 'Intermission/Intro Animation', - short_title: 'Intermission', - categorySupport: [ - 'skip', - 'mute', - ], - color: '#00FFFFB3', + title: "Intermission/Intro Animation", + short_title: "Intermission", + options: ["auto_skip", "manual_skip", "show_in_seekbar", "disable"], + color: "#00FFFFB3", }, outro: { - title: 'Endcards/Credits', - short_title: 'Endcards/Credits', - categorySupport: [ - 'skip', - 'mute', - ], - color: '#0202EDB3', + title: "Endcards/Credits", + short_title: "Endcards/Credits", + options: ["auto_skip", "manual_skip", "show_in_seekbar", "disable"], + color: "#0202EDB3", }, preview: { - title: 'Preview/Recap/Hook', - // Note: short title renamed from "Preview/Recap/Hook" to "Preview/Recap" to fit in the UI - short_title: 'Preview/Recap', - categorySupport: [ - 'skip', - 'mute', - ], - color: '#008FD6B3', + title: "Preview/Recap/Hook", + short_title: "Preview/Recap", + options: ["auto_skip", "manual_skip", "show_in_seekbar", "disable"], + 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', + title: "Filler Tangent/Jokes", + short_title: "Filler", + options: ["auto_skip", "manual_skip", "show_in_seekbar", "disable"], + color: "#7300FFE6", }, music_offtopic: { - title: 'Music: Non-Music Section', - short_title: 'Non-Music', - categorySupport: [ - 'skip', - ], - color: '#FF9900B3', + title: "Music: Non-Music Section", + short_title: "Non-Music", + options: ["auto_skip", "manual_skip", "show_in_seekbar", "disable"], + color: "#FF9900B3", }, }, -} \ No newline at end of file +} diff --git a/playlet-lib/src/locale/en_US/translations.ts b/playlet-lib/src/locale/en_US/translations.ts index b587c1de..876c0527 100644 --- a/playlet-lib/src/locale/en_US/translations.ts +++ b/playlet-lib/src/locale/en_US/translations.ts @@ -884,6 +884,18 @@ Show notifications when a segment is skipped Show notifications when a segment is skipped + + Categories + Categories + + + Configure which segments to skip + Configure which segments to skip + + + Select option for %1 + Select option for %1 + Search History Search History @@ -1004,6 +1016,26 @@ Skipped Skipped + + Press OK to skip + Press OK to skip + + + Disable + Disable + + + Auto Skip + Auto Skip + + + Manual Skip + Manual Skip + + + Show in Seekbar + Show in Seekbar + Sponsor Sponsor diff --git a/playlet-lib/src/source/utils/Locale.bs b/playlet-lib/src/source/utils/Locale.bs index bebfa401..e2fe71f4 100644 --- a/playlet-lib/src/source/utils/Locale.bs +++ b/playlet-lib/src/source/utils/Locale.bs @@ -285,6 +285,9 @@ namespace Locale EnabledDescription = "Enable SponsorBlock" ShowNotifications = "Show notifications" ShowNotificationsDescription = "Show notifications when a segment is skipped" + Categories = "Categories" + CategoriesDescription = "Configure which segments to skip" + SelectOptionFor = "Select option for %1" SearchHistory = "Search History" SearchHistoryPreferences = "Search history preferences" @@ -333,6 +336,12 @@ namespace Locale @locale enum SponsorBlock Skipped = "Skipped" + PressOkToSkip = "Press OK to skip" + + Disable = "Disable" + AutoSkip = "Auto Skip" + ManualSkip = "Manual Skip" + ShowInSeekbar = "Show in Seekbar" SponsorTitle = "Sponsor" SelfPromoTitle = "Unpaid/Self Promotion" diff --git a/playlet-web/package.json b/playlet-web/package.json index 1bc76bcf..9e31aa89 100644 --- a/playlet-web/package.json +++ b/playlet-web/package.json @@ -6,7 +6,7 @@ "dev": "vite", "build": "vite build", "preview": "vite preview", - "check": "svelte-check --tsconfig ./tsconfig.json" + "lint": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings" }, "devDependencies": { "@sveltejs/vite-plugin-svelte": "^5.0.3", diff --git a/playlet-web/src/App.svelte b/playlet-web/src/App.svelte index 692c5e18..59536b13 100644 --- a/playlet-web/src/App.svelte +++ b/playlet-web/src/App.svelte @@ -11,6 +11,7 @@ playletStateStore, preferencesModelStore, searchHistoryStore, + sponsorBlockConfigStore, userPreferencesStore, } from "lib/Stores"; import BottomNavigation from "lib/BottomNavigation.svelte"; @@ -38,6 +39,10 @@ homeLayoutFileStore.set(value); }); + PlayletApi.getSponsorBlockConfigFile().then((value) => { + sponsorBlockConfigStore.set(value); + }); + PlayletApi.getInvidiousVideoApiFile().then((apiDefinitions) => { invidiousVideoApiStore.set(apiDefinitions); }); diff --git a/playlet-web/src/lib/Api/PlayletApi.ts b/playlet-web/src/lib/Api/PlayletApi.ts index 9d11835c..d74478f1 100644 --- a/playlet-web/src/lib/Api/PlayletApi.ts +++ b/playlet-web/src/lib/Api/PlayletApi.ts @@ -34,6 +34,11 @@ export class PlayletApi { return await response.json(); } + static async getSponsorBlockConfigFile() { + const response = await fetch(`${PlayletApi.host()}/config/sponsorblock_config.json5`); + return await response.json(); + } + static async getInvidiousVideoApiFile() { const response = await fetch(`${PlayletApi.host()}/config/invidious_video_api.yaml`); return await response.json(); diff --git a/playlet-web/src/lib/Screens/Settings/SettingControls/EditHomeScreenControl.svelte b/playlet-web/src/lib/Screens/Settings/SettingControls/EditHomeScreenControl.svelte index ee20aa49..2bc68224 100644 --- a/playlet-web/src/lib/Screens/Settings/SettingControls/EditHomeScreenControl.svelte +++ b/playlet-web/src/lib/Screens/Settings/SettingControls/EditHomeScreenControl.svelte @@ -12,7 +12,6 @@ const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"]; export let displayText: string = ""; - // svelte-ignore unused-export-let export let key: string = ""; export let description: string = ""; export let level: number = 0; @@ -92,7 +91,7 @@ {$translate(displayText)} {@html $translate(description)} {$translate("Edit home screen")}{$translate(displayText)} diff --git a/playlet-web/src/lib/Screens/Settings/SettingControls/SponsorBlockCategoriesControl.svelte b/playlet-web/src/lib/Screens/Settings/SettingControls/SponsorBlockCategoriesControl.svelte new file mode 100644 index 00000000..709665a4 --- /dev/null +++ b/playlet-web/src/lib/Screens/Settings/SettingControls/SponsorBlockCategoriesControl.svelte @@ -0,0 +1,123 @@ + + + + {$translate(displayText)} + {@html $translate(description)} + {$translate(displayText)} + + + + + {#if value && sponsorBlockConfig} + + + {#each sponsorBlockConfig.categoryList as category} + {#if value[category]} + + + + + + + {$translate(sponsorBlockConfig.categories[category].title)} + + + + + + {#each sponsorBlockConfig.categories[category].options as option} + {$translate(optionTitles[option])} + {/each} + + + + + {/if} + {/each} + + + + {$translate("Save")} + {$translate("Close")} + + {/if} + + + {$translate("Close")} + + diff --git a/playlet-web/src/lib/Screens/Settings/SettingsNode.svelte b/playlet-web/src/lib/Screens/Settings/SettingsNode.svelte index 183f4c37..4e00c930 100644 --- a/playlet-web/src/lib/Screens/Settings/SettingsNode.svelte +++ b/playlet-web/src/lib/Screens/Settings/SettingsNode.svelte @@ -8,6 +8,7 @@ import NumberControl from "./SettingControls/NumberControl.svelte"; import ClearCacheControl from "./SettingControls/ClearCacheControl.svelte"; import EditQualityControl from "./SettingControls/EditQualityControl.svelte"; + import SponsorBlockCategoriesControl from "./SettingControls/SponsorBlockCategoriesControl.svelte"; import { translate } from "lib/Stores"; const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"]; @@ -36,6 +37,7 @@ EditHomeScreenControl, PlayletLibVersionControl, EditQualityControl, + SponsorBlockCategoriesControl, }; diff --git a/playlet-web/src/lib/Stores.ts b/playlet-web/src/lib/Stores.ts index 8638051a..d2bc6b78 100644 --- a/playlet-web/src/lib/Stores.ts +++ b/playlet-web/src/lib/Stores.ts @@ -19,6 +19,8 @@ export const homeLayoutStore = writable([] as any); export const homeLayoutFileStore = writable([] as any); +export const sponsorBlockConfigStore = writable({} as any); + export const bookmarksStore = writable([] as any); export const searchHistoryStore = writable([] as any); diff --git a/playlet-web/src/lib/VideoFeed/VideoCell.svelte b/playlet-web/src/lib/VideoFeed/VideoCell.svelte index ad184a51..eddfb6f4 100644 --- a/playlet-web/src/lib/VideoFeed/VideoCell.svelte +++ b/playlet-web/src/lib/VideoFeed/VideoCell.svelte @@ -23,7 +23,6 @@ // svelte-ignore unused-export-let export let type: string = undefined; - // svelte-ignore unused-export-let export let authorId: string = undefined; // svelte-ignore unused-export-let export let authorUrl: string = undefined; diff --git a/tools/generate-sponsorblock-config.js b/tools/generate-sponsorblock-config.js deleted file mode 100644 index 9e2cd278..00000000 --- a/tools/generate-sponsorblock-config.js +++ /dev/null @@ -1,141 +0,0 @@ -// Description: Generates the SponsorBlock config for Playlet - -const fs = require('fs'); -const path = require('path'); -const { ArgumentParser } = require('argparse') -const json5 = require('json5'); - -function getArgumentParser() { - const parser = new ArgumentParser({ - description: 'Generate SponsorBlock config' - }); - - parser.add_argument('--sponsorblock-root', { help: 'Local path to the SponsorBlock repository', required: true }); - - return parser; -} - -const parser = getArgumentParser(); -const args = parser.parse_args() - -const PLAYLEY_CONFIG_PATH = "./playlet-lib/src/config/sponsorblock_config.json5" - -const sponsorblockRoot = args.sponsorblock_root; - -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]).toUpperCase(); - - playletConfig.categories[categoryId] = category; -}); - -fs.writeFileSync(PLAYLEY_CONFIG_PATH, json5.stringify(playletConfig, null, 2));