Fresh start (#110)
* Fresh start * Create an xml include plugin (#111) * Restructure and add testing (#114) * rooibos setup * Restructure and add testing * docs * Restore manifestpipi * Description in tools * A bit of docs * Auto bind feature (#115) * Auto bind feature * Fix children merge * bs plugin fix * Feature/app controller (#120) * Initial layout * Restructuring and plugin work * A couple of tweaks in binding stuff * tweaks * basic stack * Add basic app controller * Support json5/yaml in playlet config files (#123) * Support json5 in playlet config files * Add yaml to the mix * Delete old lib project * plugin fix * plugin tweak * verbose logging * Revert "verbose logging" This reverts commit 25867f4226703d83102519a0d48d1cc46a9876de. * One idea to fix the include plugin * Fix instability in plugins * Feature/navbar (#126) * Navbar * typo * comment * Single content node, and tests * Remove unused field * tweaks * update dependencies command * tweak formatting * Add web app screen * Set id in created screens * Search screen * Tests * Show playlists and channels in search results * Move screen stuff to app controller * Home screen (wip) * Add preferences node * README.md copyedits (#130) * README.md: Fix typos * README.md: Standardize capitalization and punctuation * Update docs/README.md --------- Co-authored-by: Brahim Hadriche <brahim.hadriche@gmail.com> * Web server: round 1 (#131) * web server object * Logging * Web server round 1 * Lint fix * Small tweaks --------- Co-authored-by: github-action linter <githubaction@githubaction.com> * Logging to file * Leftover * Add logs file to web server * Fix for timeout * Disable keepalive connection * add openapi spec file * Lint fix * add prefs version in api * Add ecp api definition * Lint fix * Settings rework (#135) * Settings rework * Standard OnFocusChange event * Video player stuff (#136) * Video player stuff * Restructure things so that focus is better handled * Lint fix --------- Co-authored-by: github-action linter <githubaction@githubaction.com> * Exit dialog * A bunch of changes * New http client * Set TODO priorities * picture in picture * mark video watched * Video player stuff mostly there * update spec file * Sponsorblock * FuncName * SponsorBlock notifications * Lint fix * misc * remove basic auth feature flag (until we start using it) * Play queue part 1 * type fix * handle unicode in request body * SponsorBlock chapter label * modal base * remove a hack * Invidious settings * web server reduce timeout * Test for captions * Lint fix * remove rpc stuff * small change * Solve focus management * a couple of fixes * Remove a bunch of todos * feed error handling wip * Lint fix * navigation in instance settings * home screen pagination support * Refactor feed to support pagination on search page * cell loading animation * Tweak caching * delete test screen * playlist support part 1 * Basic playlist view * Restore playlist/channel handler * Refactor some content node stuff, and add an auth popup dialog * A bad implementation of a playqueue * Lint fix * playlist cast fix * Feature/web app catch up (#139) * playlist cast fix * Move things around * support playlists in web app * update api * Bump deps * Downgrade todo --------- Co-authored-by: Bryce Harrington <bryce@bryceharrington.org> Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
349 files changed
+12784
-7660
No files matched your search
@@ -0,0 +1,103 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
||||
import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.screens = {}
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
m.log = new log.Logger("AppController")
|
||||
|
||||
NodeSetFocus(m.top.root, true)
|
||||
end function
|
||||
|
||||
function PushScreen(node as object)
|
||||
m.stack.appendChild(node)
|
||||
FocusTopScreen(invalid)
|
||||
end function
|
||||
|
||||
function PopScreen(unused as dynamic)
|
||||
childCount = m.stack.getChildCount()
|
||||
if childCount > 1
|
||||
m.stack.removeChildIndex(childCount - 1)
|
||||
FocusTopScreen(invalid)
|
||||
end if
|
||||
end function
|
||||
|
||||
function FocusTopScreen(unused as dynamic)
|
||||
childCount = m.stack.getChildCount()
|
||||
topScreen = m.stack.getChild(childCount - 1)
|
||||
NodeSetFocus(topScreen, true)
|
||||
end function
|
||||
|
||||
function HideRootScreen(screenName as string) as void
|
||||
if StringUtils.IsNullOrEmpty(screenName)
|
||||
return
|
||||
end if
|
||||
if not m.screens.DoesExist(screenName)
|
||||
return
|
||||
end if
|
||||
screen = m.screens[screenName]
|
||||
if screen = invalid
|
||||
return
|
||||
end if
|
||||
screen.visible = false
|
||||
end function
|
||||
|
||||
function ShowRootScreen(screenName as string) as void
|
||||
if StringUtils.IsNullOrEmpty(screenName)
|
||||
return
|
||||
end if
|
||||
if not m.screens.DoesExist(screenName)
|
||||
screen = CreateObject("roSGNode", screenName)
|
||||
screen.id = screenName
|
||||
m.screens[screenName] = screen
|
||||
' insert child at 0 to make sure it is behind the navbar
|
||||
m.root.insertChild(screen, 0)
|
||||
if screen.hasField("binding_done")
|
||||
screen@.BindNode(invalid)
|
||||
end if
|
||||
end if
|
||||
screen = m.screens[screenName]
|
||||
if screen = invalid
|
||||
return
|
||||
end if
|
||||
screen.visible = true
|
||||
end function
|
||||
|
||||
function GetRootScreen(screenName as string) as object
|
||||
if StringUtils.IsNullOrEmpty(screenName)
|
||||
return invalid
|
||||
end if
|
||||
if not m.screens.DoesExist(screenName)
|
||||
return invalid
|
||||
end if
|
||||
return m.screens[screenName]
|
||||
end function
|
||||
|
||||
function onKeyEvent(key as string, press as boolean) as boolean
|
||||
if not press
|
||||
return false
|
||||
end if
|
||||
if key = "options"
|
||||
VideoUtils.ToggleVideoPictureInPicture()
|
||||
else if key = "back"
|
||||
dialog = DialogUtils.ShowDialogButtons("Do you want to exit Playlet?", "Exit", ["Exit", "Cancel"])
|
||||
dialog.observeField("buttonSelected", FuncName(OnExitDialog), ["buttonSelected"])
|
||||
return true
|
||||
end if
|
||||
|
||||
return false
|
||||
end function
|
||||
|
||||
function OnExitDialog(event as object)
|
||||
buttonIndex = event.GetData()
|
||||
if buttonIndex = 0 ' Exit
|
||||
m.log.info("Exiting app")
|
||||
m.top.getScene().exitChannel = true
|
||||
end if
|
||||
end function
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="AppController" extends="Group" includes="AutoBind">
|
||||
<interface>
|
||||
<field id="root" type="node" />
|
||||
<field id="stack" type="node" />
|
||||
<function name="PushScreen" />
|
||||
<function name="PopScreen" />
|
||||
<function name="FocusTopScreen" />
|
||||
<function name="HideRootScreen" />
|
||||
<function name="ShowRootScreen" />
|
||||
<function name="GetRootScreen" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -0,0 +1,30 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.lastFocusedChild = invalid
|
||||
m.top.observeField("focusedChild", FuncName(OnFocusedChildChange))
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
focusNode = invalid
|
||||
if m.lastFocusedChild <> invalid
|
||||
focusNode = m.lastFocusedChild
|
||||
else if m.top.getChildCount() > 0
|
||||
focusNode = m.top.getChild(0)
|
||||
end if
|
||||
|
||||
if focusNode <> invalid
|
||||
NodeSetFocus(focusNode, true)
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnFocusedChildChange() as void
|
||||
if m.top.focusedChild <> invalid
|
||||
m.lastFocusedChild = m.top.focusedChild
|
||||
end if
|
||||
end function
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="AppRoot" extends="Group" includes="Focus">
|
||||
</component>
|
||||
@@ -1,11 +0,0 @@
|
||||
import "pkg:/source/utils/General.bs"
|
||||
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
||||
|
||||
@asynctask
|
||||
function AppVersionTask() as object
|
||||
latest = GetLatestPlayletLibVersion()
|
||||
|
||||
return {
|
||||
latest: latest
|
||||
}
|
||||
end function
|
||||
@@ -0,0 +1,6 @@
|
||||
<component name="ActionContentNode" extends="ContentNode">
|
||||
<interface>
|
||||
<field id="type" type="string" value="action" />
|
||||
<field id="action" type="string" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -0,0 +1,7 @@
|
||||
<component name="ChannelContentNode" extends="ContentNode">
|
||||
<interface>
|
||||
<field id="type" type="string" value="channel" />
|
||||
|
||||
<field id="HDItemWidth" type="float" value="200" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -0,0 +1,8 @@
|
||||
<component name="FeedContentNode" extends="ContentNode">
|
||||
<interface>
|
||||
<field id="feed" type="assocarray" />
|
||||
<field id="loadState" type="string" />
|
||||
<field id="pagination" type="boolean" />
|
||||
<field id="page" type="integer" value="0" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -0,0 +1,5 @@
|
||||
<component name="LoadingContentNode" extends="ContentNode">
|
||||
<interface>
|
||||
<field id="type" type="string" value="loading" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -0,0 +1,33 @@
|
||||
<component name="PlaylistContentNode" extends="ContentNode">
|
||||
<interface>
|
||||
<field id="type" type="string" value="playlist" />
|
||||
<field id="loadState" type="string" />
|
||||
<!--
|
||||
For some strange reason, the "author" field can only be set once.
|
||||
If you try to set it again, it will not be updated, with type mismatch warning:
|
||||
|
||||
=================================================================
|
||||
Warning occurred while setting a field of an RoSGNode
|
||||
- Type mismatch occurred when setting the "author" field of a "PlaylistContentNode" node
|
||||
at line 112 of file InvidiousToContentNode__lib0.brs
|
||||
=================================================================
|
||||
|
||||
This is very strange, because checking the types, everything seems to be correct.
|
||||
The issue does not happen on ANY field, only "author".
|
||||
My wild guess is some hardcoded bs on Roku's side.
|
||||
This is why "_author" is used instead of "author".
|
||||
|
||||
Although we use the field "author" in other components, this is the only place where we modify it after
|
||||
we set it for the first time (because a saved Playlist belongs to the Invidious user at first, but then
|
||||
we can query it's original owner)
|
||||
-->
|
||||
<field id="_author" type="string" />
|
||||
<field id="playlistId" type="string" />
|
||||
<field id="thumbnail" type="uri" />
|
||||
<field id="thumbnailBackground" type="uri" />
|
||||
<field id="videoCount" type="integer" value="-1" />
|
||||
<field id="videoCountText" type="string" />
|
||||
<field id="viewCount" type="integer" />
|
||||
<field id="viewCountText" type="string" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -0,0 +1,21 @@
|
||||
<component name="VideoContentNode" extends="ContentNode">
|
||||
<interface>
|
||||
<field id="type" type="string" value="video" />
|
||||
|
||||
<field id="author" type="string" />
|
||||
<field id="hlsUrl" type="uri" />
|
||||
<!-- index in a playlist -->
|
||||
<field id="index" type="integer" value="-1" />
|
||||
<field id="isUpcoming" type="boolean" />
|
||||
<field id="lengthSeconds" type="integer" />
|
||||
<field id="lengthText" type="string" />
|
||||
<field id="liveNow" type="boolean" />
|
||||
<field id="premiereTimestampText" type="string" />
|
||||
<field id="publishedText" type="string" />
|
||||
<field id="thumbnail" type="uri" />
|
||||
<field id="timestamp" type="integer" />
|
||||
<field id="title" type="string" />
|
||||
<field id="videoId" type="string" />
|
||||
<field id="viewCountText" type="string" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -1,20 +1,22 @@
|
||||
function ShowDialog(message as dynamic, title as string, large = false as boolean) as object
|
||||
return ShowDialogButtons(message, title, ["Ok"], large)
|
||||
end function
|
||||
namespace DialogUtils
|
||||
function ShowDialog(message as dynamic, title as string, large = false as boolean) as object
|
||||
return ShowDialogButtons(message, title, ["Ok"], large)
|
||||
end function
|
||||
|
||||
function ShowDialogButtons(message as dynamic, title as string, buttons as object, large = false as boolean) as object
|
||||
dialog = CreateObject("roSGNode", "SimpleDialog")
|
||||
if GetInterface(message, "ifArray") = invalid
|
||||
message = message.Tokenize(UnixNL()).ToArray()
|
||||
end if
|
||||
dialog.message = message
|
||||
dialog.title = title
|
||||
dialog.buttons = buttons
|
||||
if large
|
||||
deviceInfo = CreateObject("roDeviceInfo")
|
||||
displaySize = deviceInfo.GetDisplaySize()
|
||||
dialog.width = displaySize.w - 100
|
||||
end if
|
||||
m.top.getScene().dialog = dialog
|
||||
return dialog
|
||||
end function
|
||||
function ShowDialogButtons(message as dynamic, title as string, buttons as object, large = false as boolean) as object
|
||||
dialog = CreateObject("roSGNode", "SimpleDialog")
|
||||
if GetInterface(message, "ifArray") = invalid
|
||||
message = message.Tokenize(`\n`).ToArray()
|
||||
end if
|
||||
dialog.message = message
|
||||
dialog.title = title
|
||||
dialog.buttons = buttons
|
||||
if large
|
||||
deviceInfo = CreateObject("roDeviceInfo")
|
||||
displaySize = deviceInfo.GetDisplaySize()
|
||||
dialog.width = displaySize.w - 100
|
||||
end if
|
||||
m.top.getScene().dialog = dialog
|
||||
return dialog
|
||||
end function
|
||||
end namespace
|
||||
@@ -0,0 +1,39 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/Screens/WebAppScreen/GenerateQrCodeTask.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.urlLabel = m.top.findNode("urlLabel")
|
||||
m.qrCode = m.top.findNode("QrCodePoster")
|
||||
|
||||
m.top.width = "920"
|
||||
m.top.observeFieldScoped("buttonSelected", FuncName(Close))
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
address = m.webserver@.GetServerAddress(invalid)
|
||||
isValidIp = not StringUtils.IsNullOrEmpty(address)
|
||||
if isValidIp
|
||||
m.top.url = `${address}/invidious/login`
|
||||
else
|
||||
m.urlLabel.text = "No IP address found"
|
||||
end if
|
||||
|
||||
m.invidious.observeFieldScoped("authToken", FuncName(OnAuthTokenChange))
|
||||
end function
|
||||
|
||||
function Close()
|
||||
m.top.close = true
|
||||
end function
|
||||
|
||||
function OnUrlSet()
|
||||
url = m.top.url
|
||||
|
||||
m.urlLabel.text = url
|
||||
StartAsyncTask(GenerateQrCodeTask, { qrPoster: m.qrCode, text: url })
|
||||
end function
|
||||
|
||||
function OnAuthTokenChange()
|
||||
Close()
|
||||
end function
|
||||
@@ -0,0 +1,43 @@
|
||||
<component name="LoginDialog" extends="StandardDialog" initialFocus="buttonArea" includes="AutoBind">
|
||||
<interface>
|
||||
<field id="webServer" type="node" bind="/WebServer" />
|
||||
<field id="invidious" type="node" bind="/Invidious" />
|
||||
<field id="url" type="string" onChange="OnUrlSet" />
|
||||
</interface>
|
||||
<children>
|
||||
<StdDlgTitleArea primaryTitle="Login to Invidious" />
|
||||
<StdDlgContentArea>
|
||||
<StdDlgTextItem
|
||||
text="Login to Invidious in order to view Subscriptions, Playlists, and use the Watch history." />
|
||||
</StdDlgContentArea>
|
||||
<StdDlgButtonArea id="buttonArea">
|
||||
<StdDlgButton text="OK" />
|
||||
</StdDlgButtonArea>
|
||||
<StdDlgSideCardArea
|
||||
id="sideCarArea"
|
||||
horizAlign="right"
|
||||
width="400"
|
||||
extendToDialogEdge="false"
|
||||
showDivider="true">
|
||||
<Label
|
||||
text="Scan the QR Code"
|
||||
horizAlign="center"
|
||||
wrap="true" width="400">
|
||||
<Font role="font" uri="font:SystemFontFile" size="24" />
|
||||
</Label>
|
||||
<QRPoster
|
||||
id='QrCodePoster'
|
||||
loadWidth='300'
|
||||
loadHeight='300'
|
||||
loadPadding='10'
|
||||
translation="[50, 50]" />
|
||||
<Label
|
||||
id="urlLabel"
|
||||
horizAlign="center"
|
||||
width="400"
|
||||
translation="[0, 380]">
|
||||
<Font role="font" uri="font:BoldSystemFontFile" size="18" />
|
||||
</Label>
|
||||
</StdDlgSideCardArea>
|
||||
</children>
|
||||
</component>
|
||||
@@ -1,5 +1,7 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.top.observeField("buttonSelected", "CloseDialog")
|
||||
m.top.observeField("buttonSelected", FuncName(CloseDialog))
|
||||
end function
|
||||
|
||||
function CloseDialog()
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function InitEcpArgs()
|
||||
m.playQueue = m.top.findNode("PlayQueue")
|
||||
LaunchArgumentsReceived()
|
||||
|
||||
m.scene.ObserveField("inputArgs", FuncName(InputArgumentsReceived))
|
||||
if m.scene.inputArgs <> invalid
|
||||
InputArgumentsReceived()
|
||||
end if
|
||||
end function
|
||||
|
||||
function LaunchArgumentsReceived() as void
|
||||
launchArgs = m.scene.launchArgs
|
||||
m.log.info("LaunchArgumentsReceived", launchArgs)
|
||||
ProcessArguments(launchArgs)
|
||||
end function
|
||||
|
||||
function InputArgumentsReceived() as void
|
||||
inputArgs = m.scene.inputArgs
|
||||
m.log.info("InputArgumentsReceived", inputArgs)
|
||||
ProcessArguments(inputArgs)
|
||||
end function
|
||||
|
||||
function ProcessArguments(args as object) as void
|
||||
if args = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
if not StringUtils.IsNullOrEmpty(args.contentId) and args.mediaType = "video"
|
||||
if StringUtils.IsNullOrEmpty(args.videoId)
|
||||
args.videoId = args.contentId
|
||||
end if
|
||||
end if
|
||||
|
||||
if args.timestamp <> invalid
|
||||
args.timestamp = args.timestamp.ToInt()
|
||||
end if
|
||||
|
||||
if not StringUtils.IsNullOrEmpty(args.videoId)
|
||||
node = CreateObject("roSGNode", "VideoContentNode")
|
||||
node.videoId = args.videoId
|
||||
if args.timestamp <> invalid
|
||||
node.timestamp = args.timestamp
|
||||
end if
|
||||
m.playQueue@.Play(node, -1)
|
||||
end if
|
||||
end function
|
||||
@@ -1,134 +0,0 @@
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/VideoPlayer/Video.bs"
|
||||
import "pkg:/components/HomeGridScreen/HomeGridScreenTask.bs"
|
||||
|
||||
function Init()
|
||||
m.rowList = m.top.FindNode("rowList")
|
||||
m.top.ObserveField("rowItemSelected", "OnHomeGridScreenVideoSelected")
|
||||
m.top.ObserveField("focus", "OnFocusChange")
|
||||
m.top.ObserveField("refresh", "OnRefresh")
|
||||
end function
|
||||
|
||||
function OnFocusChange()
|
||||
if m.top.focus = true
|
||||
m.rowList.SetFocus(true)
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnRefresh()
|
||||
InitContent()
|
||||
end function
|
||||
|
||||
function InitContent()
|
||||
' TODO: stop any currently running tasks before starting a new batch of tasks
|
||||
m.sortedContent = []
|
||||
contentNode = CreateObject("roSGNode", "ContentNode")
|
||||
contentNode.Update({
|
||||
children: []
|
||||
}, true)
|
||||
m.top.content = contentNode
|
||||
|
||||
m.defaultLayout = ParseJson(ReadAsciiFile("libpkg:/config/default_home_layout.json"))
|
||||
|
||||
if m.defaultLayout.Count() > 0
|
||||
m.currentLoadingIndex = 0
|
||||
|
||||
' 3 parallel tasks
|
||||
for x = 1 to 3
|
||||
StartFetchTask()
|
||||
end for
|
||||
end if
|
||||
end function
|
||||
|
||||
function StartFetchTask() as void
|
||||
currentLoadingIndex = m.currentLoadingIndex
|
||||
m.currentLoadingIndex++
|
||||
|
||||
if currentLoadingIndex >= m.defaultLayout.Count()
|
||||
if m.sortedContent.Count() = m.defaultLayout.Count()
|
||||
' All tasks are done
|
||||
m.Delete("sortedContent")
|
||||
end if
|
||||
return
|
||||
end if
|
||||
|
||||
StartAsyncTask(GetHomeScreenContent, {
|
||||
index: currentLoadingIndex,
|
||||
requestData: m.defaultLayout[currentLoadingIndex]
|
||||
}, function(output as object) as void
|
||||
' TODO: this whole logic is not good.
|
||||
' The view should have placeholder, and child nodes get replaced as
|
||||
' They get ready.
|
||||
if output = invalid or not output.success
|
||||
StartFetchTask()
|
||||
return
|
||||
end if
|
||||
|
||||
m.sortedContent.Push(output.result)
|
||||
|
||||
if output.result.rootChildren.Count() > 0
|
||||
m.sortedContent.SortBy("index")
|
||||
|
||||
newChildren = []
|
||||
for each item in m.sortedContent
|
||||
if item.rootChildren.Count() > 0
|
||||
newChildren.append(item.rootChildren)
|
||||
end if
|
||||
end for
|
||||
|
||||
currentChildrenCount = m.top.content.children.Count()
|
||||
|
||||
while m.top.content.getChildCount() > 0
|
||||
m.top.content.removeChildIndex(0)
|
||||
end while
|
||||
|
||||
m.top.content.Update({
|
||||
children: newChildren
|
||||
}, true)
|
||||
|
||||
if currentChildrenCount = 0 and newChildren.Count() > 0
|
||||
OnHomeGridScreenContentLoaded()
|
||||
end if
|
||||
end if
|
||||
|
||||
StartFetchTask()
|
||||
end function)
|
||||
end function
|
||||
|
||||
function OnHomeGridScreenContentLoaded()
|
||||
m.global.loadingIndicator.visible = false
|
||||
end function
|
||||
|
||||
function OnHomeGridScreenVideoSelected(event as object) as void
|
||||
grid = event.GetRoSGNode()
|
||||
|
||||
selectedPair = event.GetData()
|
||||
selectedRow = selectedPair[0]
|
||||
selectedRowItem = selectedPair[1]
|
||||
|
||||
rowContent = grid.content.GetChild(selectedRow)
|
||||
itemContent = rowContent.GetChild(selectedRowItem)
|
||||
|
||||
videoId = itemContent.videoId
|
||||
|
||||
PlayVideo(videoId, {
|
||||
metadata: itemContent,
|
||||
sender: m.top
|
||||
})
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
if press = false
|
||||
return false
|
||||
end if
|
||||
if key = "options"
|
||||
if ToggleVideoPictureInPicture(m.top)
|
||||
return true
|
||||
end if
|
||||
end if
|
||||
if key = "left" or key = "back"
|
||||
m.top.escape = key
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="HomeGridScreen" extends="Group" initialFocus="RowList">
|
||||
<interface>
|
||||
<field id="content" type="node" alias="RowList.content" />
|
||||
<field id="rowItemSelected" type="intarray" alwaysnotify="true" alias="RowList.rowItemSelected" />
|
||||
<field id="rowItemFocused" type="intarray" alwaysnotify="true" alias="RowList.rowItemFocused" />
|
||||
<field id="jumpToRowItem" type="intarray" alias="RowList.jumpToRowItem" />
|
||||
<field id="escape" type="string" alwaysNotify="true" />
|
||||
<field id="focus" type="boolean" alwaysNotify="true" />
|
||||
<field id="refresh" type="boolean" alwaysNotify="true" />
|
||||
</interface>
|
||||
<children>
|
||||
<RowList
|
||||
itemComponentName="VideoRowCell"
|
||||
id="rowList"
|
||||
translation="[0,50]"
|
||||
numRows="2"
|
||||
rowitemSize="[[350,196]]"
|
||||
rowItemSpacing="[[25,0]]"
|
||||
itemSize="[1280,326]"
|
||||
itemSpacing="[0,65]"
|
||||
rowLabelOffset="[[105,20]]"
|
||||
focusXOffset="[105]"
|
||||
showRowLabel="[true]"
|
||||
rowFocusAnimationStyle="floatingfocus"
|
||||
focusBitmapUri="pkg:/images/focus_grid.9.png"
|
||||
/>
|
||||
</children>
|
||||
</component>
|
||||
@@ -1,51 +0,0 @@
|
||||
import "pkg:/source/services/InvidiousService.bs"
|
||||
|
||||
@asynctask
|
||||
function GetHomeScreenContent(input as object) as object
|
||||
rootChildren = []
|
||||
|
||||
service = new InvidiousService()
|
||||
|
||||
requestData = input.requestData
|
||||
|
||||
response = service.MakeRequest(requestData)
|
||||
if response <> invalid
|
||||
for each item in response
|
||||
rowContent = GetCategoryContent(item.title, item.videos)
|
||||
if rowContent <> invalid
|
||||
rootChildren.Push(rowContent)
|
||||
end if
|
||||
end for
|
||||
end if
|
||||
|
||||
return {
|
||||
index: input.index,
|
||||
rootChildren: rootChildren
|
||||
}
|
||||
end function
|
||||
|
||||
function GetCategoryContent(category as string, json as object) as object
|
||||
if json <> invalid and json.Count() > 0
|
||||
row = {}
|
||||
row.title = category
|
||||
row.children = []
|
||||
for each item in json ' parse items and push them to row
|
||||
itemData = GetItemData(item)
|
||||
if itemData <> invalid
|
||||
row.children.Push(itemData)
|
||||
end if
|
||||
end for
|
||||
return row
|
||||
end if
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function GetItemData(video as object) as object
|
||||
' TODO: handle playlists and channels
|
||||
if video.videoId = invalid
|
||||
return invalid
|
||||
end if
|
||||
|
||||
return video
|
||||
end function
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import "pkg:/source/services/InvidiousSettings.bs"
|
||||
|
||||
@asynctask
|
||||
function InvidiousPublicInstancesTask(input as object) as object
|
||||
' TODO: Move this to a better place
|
||||
' Caching backup instances in this task to avoid having to do it in the UI thread
|
||||
' Should be moved to a better place
|
||||
backupInstances = InvidiousSettings.FetchBackupInstances()
|
||||
|
||||
return {
|
||||
backupInstances: backupInstances
|
||||
}
|
||||
end function
|
||||
@@ -0,0 +1,19 @@
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
|
||||
function Init()
|
||||
m.buffer = CreateObject("roByteArray")
|
||||
|
||||
previousLogs = m.top.folder + "/" + m.top.filenamePrevious
|
||||
newLogs = m.top.folder + "/" + m.top.filename
|
||||
|
||||
CreateDirectory(m.top.folder)
|
||||
DeleteFile(previousLogs)
|
||||
MoveFile(newLogs, previousLogs)
|
||||
|
||||
m.logsPath = newLogs
|
||||
end function
|
||||
|
||||
function logItem(name as string, levelNum as integer, text as string) as void
|
||||
m.buffer.FromAsciiString(`[${name}] ${text}\n`)
|
||||
m.buffer.AppendFile(m.logsPath)
|
||||
end function
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<component name='log_FileTransport' extends='Node'>
|
||||
<interface>
|
||||
<field id='folder' type='string' value='cachefs:/logs' />
|
||||
<field id='filename' type='string' value='app_logs.txt' />
|
||||
<field id='filenamePrevious' type='string' value='app_logs_previous.txt' />
|
||||
<function name='logItem' />
|
||||
</interface>
|
||||
<children />
|
||||
</component>
|
||||
@@ -1,153 +1,27 @@
|
||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
||||
import "pkg:/components/VideoPlayer/Video.bs"
|
||||
import "pkg:/components/Invidious/InvidiousPublicInstancesTask.bs"
|
||||
import "pkg:/components/parts/AutoBind/AutoBind.part.bs"
|
||||
import "pkg:/source/utils/LoadingScreen.bs"
|
||||
import "pkg:/source/utils/Logging.bs"
|
||||
import "pkg:/components/EcpArgs.bs"
|
||||
|
||||
function Init()
|
||||
log.initializeLogManager(["log_PrintTransport"], 2)
|
||||
|
||||
m.videoContainer = m.top.findNode("VideoContainer")
|
||||
m.global.addFields({
|
||||
videoContainer: m.videoContainer
|
||||
})
|
||||
|
||||
m.homeGridScreen = m.top.findNode("HomeGridScreen")
|
||||
m.homeGridScreen.ObserveField("escape", "OnHomeGridScreenEscape")
|
||||
m.homeGridScreen.SetFocus(true)
|
||||
m.currentFocued = m.homeGridScreen
|
||||
|
||||
m.settingsScreen = m.top.findNode("SettingsScreen")
|
||||
m.settingsScreen.ObserveField("escape", "OnSettingsScreenEscape")
|
||||
|
||||
m.appInfoScreen = m.top.findNode("AppInfoScreen")
|
||||
|
||||
m.webAppScreen = m.top.findNode("WebAppScreen")
|
||||
|
||||
m.searchScreen = m.top.findNode("SearchScreen")
|
||||
m.searchScreen.ObserveField("escape", "OnSearchScreenEscape")
|
||||
|
||||
m.navBar = m.top.findNode("NavBar")
|
||||
m.navBarScreens = [{
|
||||
node: m.searchScreen,
|
||||
canEscape: true
|
||||
}, {
|
||||
node: m.homeGridScreen,
|
||||
canEscape: true
|
||||
}, {
|
||||
node: m.settingsScreen,
|
||||
canEscape: true
|
||||
}, {
|
||||
node: m.webAppScreen,
|
||||
canEscape: false
|
||||
}, {
|
||||
node: m.appInfoScreen,
|
||||
canEscape: false
|
||||
}]
|
||||
m.navBar.ObserveField("escapeIndex", "OnNavBarEscape")
|
||||
m.navBar.ObserveField("focusIndex", "OnNavIndexChange")
|
||||
|
||||
InitWebServer()
|
||||
|
||||
StartAsyncTask(InvidiousPublicInstancesTask, {}, OnInvidiousPublicInstancesTaskResults)
|
||||
InitializeLogging()
|
||||
m.log = new log.Logger("MainScene")
|
||||
m.scene = m.top.getScene()
|
||||
' At this point, the "MainScene" node is not yet added to the scene, and does not have a parent yet.
|
||||
' Let's wait until it has one.
|
||||
m.MainSceneContainer = m.scene.findNode("MainSceneContainer")
|
||||
m.MainSceneContainer.ObserveField("change", FuncName(MainSceneContainerChanged))
|
||||
end function
|
||||
|
||||
function OnInvidiousPublicInstancesTaskResults(output as object)
|
||||
backupInstances = output.result.backupInstances
|
||||
m.global.addFields({
|
||||
invidiousBackupInstances: backupInstances
|
||||
})
|
||||
|
||||
m.homeGridScreen.refresh = true
|
||||
|
||||
LaunchArgumentsReceived()
|
||||
|
||||
scene = m.top.getScene()
|
||||
scene.ObserveField("inputArgs", "InputArgumentsReceived")
|
||||
scene.signalBeacon("AppLaunchComplete")
|
||||
function MainSceneContainerChanged()
|
||||
AutoBindSceneGraph()
|
||||
StartWebServer()
|
||||
HideLoadingScreen()
|
||||
InitEcpArgs()
|
||||
m.scene.signalBeacon("AppLaunchComplete")
|
||||
end function
|
||||
|
||||
function InitWebServer()
|
||||
m.serverTask = createObject("roSGNode", "WebServerTask")
|
||||
m.serverTask.id = "WebServerTask"
|
||||
m.serverTask.ObserveField("login", "OnWebServerLogin")
|
||||
m.serverTask.ObserveField("command", "OnWebServerCommand")
|
||||
m.serverTask.control = "RUN"
|
||||
end function
|
||||
|
||||
function OnSearchScreenEscape()
|
||||
m.navBar.SetFocus(true)
|
||||
m.navBar.focusIndex = 0
|
||||
m.currentFocued = m.navBar
|
||||
end function
|
||||
|
||||
function OnSettingsScreenEscape()
|
||||
m.navBar.SetFocus(true)
|
||||
m.navBar.focusIndex = 2
|
||||
m.currentFocued = m.navBar
|
||||
end function
|
||||
|
||||
function OnHomeGridScreenEscape()
|
||||
m.navBar.SetFocus(true)
|
||||
m.navBar.focusIndex = 1
|
||||
m.currentFocued = m.navBar
|
||||
end function
|
||||
|
||||
function OnNavBarEscape()
|
||||
index = m.navBar.escapeIndex
|
||||
m.navBarScreens[index].node.focus = true
|
||||
if m.navBarScreens[index].canEscape
|
||||
m.currentFocued = m.navBarScreens[index].node
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnNavIndexChange() as void
|
||||
index = m.navBar.focusIndex
|
||||
if index = -1
|
||||
return
|
||||
end if
|
||||
for i = 0 to m.navBarScreens.count() - 1
|
||||
m.navBarScreens[i].node.visible = i = index
|
||||
end for
|
||||
end function
|
||||
|
||||
function OnWebServerLogin()
|
||||
m.homeGridScreen.refresh = true
|
||||
end function
|
||||
|
||||
function OnWebServerCommand() as void
|
||||
if m.serverTask.command = invalid or m.serverTask.command.command = invalid
|
||||
return
|
||||
end if
|
||||
if m.serverTask.command.command = "play"
|
||||
sender = m.videoContainer.sender ?? m.currentFocued
|
||||
if m.videoContainer.fullscreen
|
||||
dialog = m.top.getScene().dialog
|
||||
if dialog <> invalid
|
||||
dialog.close = true
|
||||
end if
|
||||
end if
|
||||
PlayVideo(m.serverTask.command.videoId, { sender: sender, timestamp: m.serverTask.command.timestamp })
|
||||
end if
|
||||
end function
|
||||
|
||||
function LaunchArgumentsReceived() as void
|
||||
scene = m.top.getScene()
|
||||
launchArgs = scene.launchArgs
|
||||
? "LaunchArgumentsReceived " launchArgs
|
||||
PlayVideoFromArgs(launchArgs)
|
||||
end function
|
||||
|
||||
function InputArgumentsReceived() as void
|
||||
scene = m.top.getScene()
|
||||
inputArgs = scene.inputArgs
|
||||
? "InputArgumentsReceived " inputArgs
|
||||
PlayVideoFromArgs(inputArgs)
|
||||
end function
|
||||
|
||||
function PlayVideoFromArgs(args as object) as void
|
||||
if args = invalid or args.contentId = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
sender = m.videoContainer.sender ?? m.currentFocued
|
||||
PlayVideo(args.contentId, { sender: sender, timestamp: args.timestamp })
|
||||
function StartWebServer()
|
||||
m.webServer = m.top.findNode("WebServer")
|
||||
m.webServer@.StartServer(invalid)
|
||||
end function
|
||||
@@ -0,0 +1,29 @@
|
||||
'import "pkg:/components/parts/AutoBind/AutoBind.part.bs"
|
||||
'import "pkg:/source/utils/LoadingScreen.bs"
|
||||
'import "pkg:/source/utils/Logging.bs"
|
||||
'import "pkg:/components/EcpArgs.bs"
|
||||
|
||||
function Init()
|
||||
InitializeBindings() ' auto-generated!
|
||||
InitializeLogging()
|
||||
m.log = log_Logger("MainScene")
|
||||
m.__le = m.log.enabled
|
||||
m.scene = m.top.getScene()
|
||||
' At this point, the "MainScene" node is not yet added to the scene, and does not have a parent yet.
|
||||
' Let's wait until it has one.
|
||||
m.MainSceneContainer = m.scene.findNode("MainSceneContainer")
|
||||
m.MainSceneContainer.ObserveField("change", FuncName(MainSceneContainerChanged))
|
||||
end function
|
||||
|
||||
function MainSceneContainerChanged()
|
||||
AutoBindSceneGraph()
|
||||
StartWebServer()
|
||||
HideLoadingScreen()
|
||||
InitEcpArgs()
|
||||
m.scene.signalBeacon("AppLaunchComplete")
|
||||
end function
|
||||
|
||||
function StartWebServer()
|
||||
m.webServer = m.top.findNode("WebServer")
|
||||
m.webServer.callfunc("StartServer", invalid)
|
||||
end function'//# sourceMappingURL=./MainScene.bs.map
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<component name="MainScene" extends="Group">
|
||||
<interface>
|
||||
<field id="bindings" type="assocarray" onChange="OnBindingSetRegisterAutoBind" />
|
||||
<field id="binding_done" type="boolean" onChange="OnNodeReady" />
|
||||
<function name="BindNodeFieldsAndProps" />
|
||||
<function name="BindScopeFields" />
|
||||
<function name="BindNode" />
|
||||
</interface>
|
||||
<script type="text/brightscript" uri="pkg:/components/parts/AutoBind/AutoBind.part.brs" />
|
||||
<script type="text/brightscript" uri="pkg:/components/MainScene_bindings.brs" />
|
||||
<script type="text/brightscript" uri="pkg:/components/MainScene.brs" />
|
||||
<script type="text/brightscript" uri="pkg:/source/utils/Logging.brs" />
|
||||
<script type="text/brightscript" uri="pkg:/source/roku_modules/log/LogMixin.brs" />
|
||||
<script type="text/brightscript" uri="pkg:/source/utils/LoadingScreen.brs" />
|
||||
<script type="text/brightscript" uri="pkg:/components/EcpArgs.brs" />
|
||||
<script type="text/brightscript" uri="pkg:/source/utils/Types.brs" />
|
||||
<script type="text/brightscript" uri="pkg:/source/utils/StringUtils.brs" />
|
||||
<script type="text/brightscript" uri="pkg:/components/VideoPlayer/VideoUtils.brs" />
|
||||
<script type="text/brightscript" uri="pkg:/source/utils/FocusManagement.brs" />
|
||||
<script type="text/brightscript" uri="pkg:/source/roku_modules/bslib/bslib.brs" />
|
||||
<children>
|
||||
<AppController id="AppController">
|
||||
<Group id="Stack">
|
||||
<AppRoot id="AppRoot">
|
||||
<NavBar id="NavBar" focusIndex="1">
|
||||
<ContentNode role="items">
|
||||
<NavBarItem screen="SearchScreen" text="Search" icon="pkg:/images/icons/search.png" canFocus="true" />
|
||||
<NavBarItem screen="HomeScreen" text="Home" icon="pkg:/images/icons/home.png" canFocus="true" />
|
||||
<NavBarItem screen="SettingsScreen" text="Settings" icon="pkg:/images/icons/settings.png" canFocus="true" />
|
||||
<NavBarItem screen="WebAppScreen" text="Web App" icon="pkg:/images/icons/phone.png" />
|
||||
<NavBarItem screen="AppInfoScreen" text="Info" icon="pkg:/images/icons/info.png" />
|
||||
</ContentNode>
|
||||
</NavBar>
|
||||
</AppRoot>
|
||||
</Group>
|
||||
<VideoContainer id="VideoContainer" />
|
||||
<Group id="Notifications" />
|
||||
<PlayQueue id="PlayQueue" />
|
||||
<ApplicationInfo id="ApplicationInfo" />
|
||||
<Preferences id="Preferences" />
|
||||
<Invidious id="Invidious" />
|
||||
<PlayletWebServer id="WebServer" port="8888" />
|
||||
</AppController>
|
||||
</children>
|
||||
</component>
|
||||
<!--//# sourceMappingURL=./MainScene.xml.map -->
|
||||
@@ -1,13 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="MainScene" extends="Group">
|
||||
<component name="MainScene" extends="Group" includes="AutoBind">
|
||||
<children>
|
||||
<SearchScreen id="SearchScreen" visible="false" />
|
||||
<HomeGridScreen id="HomeGridScreen" />
|
||||
<SettingsScreen id="SettingsScreen" visible="false" />
|
||||
<WebAppScreen id="WebAppScreen" visible="false" />
|
||||
<AppInfoScreen id="AppInfoScreen" visible="false" />
|
||||
<NavBar id="NavBar" />
|
||||
<VideoContainer id="VideoContainer" />
|
||||
<AppController id="AppController" root="bind:./AppRoot" stack="bind:./Stack">
|
||||
<Group id="Stack">
|
||||
<AppRoot id="AppRoot">
|
||||
<NavBar id="NavBar" focusIndex="1" appController="bind:/AppController">
|
||||
<ContentNode role="items">
|
||||
<NavBarItem
|
||||
screen="SearchScreen"
|
||||
text="Search"
|
||||
icon="pkg:/images/icons/search.png"
|
||||
canFocus="true">
|
||||
</NavBarItem>
|
||||
<NavBarItem
|
||||
screen="HomeScreen"
|
||||
text="Home"
|
||||
icon="pkg:/images/icons/home.png"
|
||||
canFocus="true">
|
||||
</NavBarItem>
|
||||
<NavBarItem
|
||||
screen="SettingsScreen"
|
||||
text="Settings"
|
||||
icon="pkg:/images/icons/settings.png"
|
||||
canFocus="true">
|
||||
</NavBarItem>
|
||||
<NavBarItem
|
||||
screen="WebAppScreen"
|
||||
text="Web App"
|
||||
icon="pkg:/images/icons/phone.png">
|
||||
</NavBarItem>
|
||||
<NavBarItem
|
||||
screen="AppInfoScreen"
|
||||
text="Info"
|
||||
icon="pkg:/images/icons/info.png">
|
||||
</NavBarItem>
|
||||
</ContentNode>
|
||||
</NavBar>
|
||||
</AppRoot>
|
||||
</Group>
|
||||
|
||||
<VideoContainer id="VideoContainer" />
|
||||
<Group id="Notifications" />
|
||||
|
||||
<!-- No render nodes -->
|
||||
<PlayQueue id="PlayQueue"
|
||||
invidious="bind:../Invidious" />
|
||||
<ApplicationInfo id="ApplicationInfo" />
|
||||
<Preferences id="Preferences" />
|
||||
|
||||
<Invidious id="Invidious"
|
||||
webServer="bind:../WebServer"
|
||||
applicationInfo="bind:../ApplicationInfo"
|
||||
preferences="bind:../Preferences" />
|
||||
|
||||
<PlayletWebServer
|
||||
id="WebServer"
|
||||
port="8888"
|
||||
applicationInfo="bind:../ApplicationInfo"
|
||||
invidious="bind:../Invidious"
|
||||
preferences="bind:../Preferences"
|
||||
playQueue="bind:../PlayQueue" />
|
||||
|
||||
<!-- Inherits from WebServer
|
||||
<WebSocketServer id="WebSocketServer" webserver="ref:../WebServer" /> -->
|
||||
</AppController>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,31 @@
|
||||
' This method is auto-generated!
|
||||
function InitializeBindings()
|
||||
m.top.bindings = {
|
||||
fields: {
|
||||
|
||||
},
|
||||
childProps: {
|
||||
"AppController": {
|
||||
"root": "./AppRoot",
|
||||
"stack": "./Stack"
|
||||
},
|
||||
"NavBar": {
|
||||
"appController": "/AppController"
|
||||
},
|
||||
"PlayQueue": {
|
||||
"invidious": "../Invidious"
|
||||
},
|
||||
"Invidious": {
|
||||
"webServer": "../WebServer",
|
||||
"applicationInfo": "../ApplicationInfo",
|
||||
"preferences": "../Preferences"
|
||||
},
|
||||
"WebServer": {
|
||||
"applicationInfo": "../ApplicationInfo",
|
||||
"invidious": "../Invidious",
|
||||
"preferences": "../Preferences",
|
||||
"playQueue": "../PlayQueue"
|
||||
}
|
||||
}
|
||||
}
|
||||
end function'//# sourceMappingURL=./MainScene_bindings.bs.map
|
||||
@@ -10,10 +10,9 @@ function init()
|
||||
m.top.observeField("height", "onHeightChanged")
|
||||
m.top.observeField("width", "onWidthChanged")
|
||||
m.top.observeField("padding", "onPaddingChanged")
|
||||
m.top.observeField("focus", "onFocusChanged")
|
||||
end function
|
||||
|
||||
function onFocusChanged()
|
||||
function OnFocusChange()
|
||||
if m.top.focus
|
||||
m.buttonBackground.blendColor = m.top.focusBackground
|
||||
else
|
||||
@@ -21,12 +20,10 @@ function onFocusChanged()
|
||||
end if
|
||||
m.buttonBackground.visible = m.top.focus
|
||||
m.buttonText.visible = m.top.focus
|
||||
|
||||
end function
|
||||
|
||||
function onBackgroundChanged()
|
||||
m.buttonBackground.blendColor = m.top.background
|
||||
m.top.unobserveField("background")
|
||||
end function
|
||||
|
||||
function onIconChanged()
|
||||
@@ -70,18 +67,3 @@ end function
|
||||
function onPaddingChanged()
|
||||
setIconSize()
|
||||
end function
|
||||
|
||||
function onKeyEvent(key as string, press as boolean) as boolean
|
||||
if not press
|
||||
return false
|
||||
end if
|
||||
if key = "right" and m.top.focus
|
||||
m.top.escape = "right"
|
||||
end if
|
||||
|
||||
if key = "left" and m.top.focus
|
||||
m.top.escape = "left"
|
||||
end if
|
||||
|
||||
return false
|
||||
end function
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<component name="IconButton" extends="Group">
|
||||
<component name="IconButton" extends="Group" includes="Focus">
|
||||
<children>
|
||||
<Poster id="buttonBackground" uri="pkg:/images/white.9.png" visible="false" />
|
||||
<Poster id="buttonIcon" />
|
||||
@@ -13,8 +13,5 @@
|
||||
<field id="height" type="integer" value="" />
|
||||
<field id="width" type="integer" value="" />
|
||||
<field id="icon" type="string" value="" />
|
||||
<field id="selected" type="boolean" value="false" />
|
||||
<field id="focus" type="boolean" />
|
||||
<field id="escape" type="string" value="" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -1,19 +1,58 @@
|
||||
import "pkg:/components/VideoPlayer/Video.bs"
|
||||
import "pkg:/source/utils/ColorUtils.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.buttonGroup = m.top.findNode("NavBarButtonGroup")
|
||||
m.top.observeField("focusIndex", "OnFocusIndexChange")
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
PopulateButtons()
|
||||
m.top.observeField("focusedChild", FuncName(OnFocusedChildChange))
|
||||
m.top.observeField("items", FuncName(PopulateButtons))
|
||||
end function
|
||||
|
||||
function OnFocusedChildChange()
|
||||
m.top.focusIndex = m.top.focusIndex
|
||||
end function
|
||||
|
||||
function PopulateButtons() as void
|
||||
buttonCount = m.buttonGroup.getChildCount()
|
||||
if buttonCount > 0
|
||||
m.buttonGroup.removeChildrenIndex(buttonCount, 0)
|
||||
end if
|
||||
|
||||
if m.top.items = invalid
|
||||
m.top.focusable = false
|
||||
return
|
||||
end if
|
||||
|
||||
navBarItems = m.top.items.getChildren(-1, 0)
|
||||
|
||||
buttons = []
|
||||
for each item in navBarItems
|
||||
button = CreateObject("roSGNode", "IconButton")
|
||||
button.background = ColorUtils.HexToInt("242424")
|
||||
button.focusBackground = ColorUtils.HexToInt("ff1c30")
|
||||
button.padding = 20
|
||||
button.height = 50
|
||||
button.width = 90
|
||||
|
||||
button.icon = item.icon
|
||||
button.text = item.text
|
||||
|
||||
buttons.push(button)
|
||||
end for
|
||||
m.buttonGroup.appendChildren(buttons)
|
||||
|
||||
m.top.focusable = buttons.Count() > 0
|
||||
|
||||
m.top.focusIndex = m.top.focusIndex
|
||||
end function
|
||||
|
||||
function onKeyEvent(key as string, press as boolean) as boolean
|
||||
if not press
|
||||
return false
|
||||
end if
|
||||
if key = "options"
|
||||
if ToggleVideoPictureInPicture(m.top)
|
||||
return true
|
||||
end if
|
||||
end if
|
||||
if key = "down"
|
||||
i = m.top.focusIndex
|
||||
target = i + 1
|
||||
@@ -31,39 +70,54 @@ function onKeyEvent(key as string, press as boolean) as boolean
|
||||
m.top.focusIndex = target
|
||||
return true
|
||||
else if key = "right"
|
||||
' Can only escape to search screen or home screen
|
||||
allowedEscapes = { "0": true, "1": true, "2": true }
|
||||
if allowedEscapes[StrI(m.top.focusIndex).Trim()] = true
|
||||
m.top.escapeIndex = m.top.focusIndex
|
||||
m.top.focusIndex = -1
|
||||
return true
|
||||
if m.top.items = invalid or m.top.focusIndex = -1 or m.top.focusIndex >= m.top.items.getChildCount()
|
||||
return false
|
||||
end if
|
||||
else if key = "back"
|
||||
dialog = ShowDialogButtons("Do you want to exit Playlet?", "Exit", ["Exit", "Cancel"])
|
||||
dialog.observeField("buttonSelected", "OnExitDialog", ["buttonSelected"])
|
||||
navBarItem = m.top.items.getChild(m.top.focusIndex)
|
||||
if navBarItem.canFocus <> true
|
||||
return false
|
||||
end if
|
||||
screen = m.appController@.GetRootScreen(navBarItem.screen)
|
||||
if screen = invalid
|
||||
return false
|
||||
end if
|
||||
NodeSetFocus(screen, true)
|
||||
return true
|
||||
end if
|
||||
|
||||
return false
|
||||
end function
|
||||
|
||||
function OnExitDialog(event as object)
|
||||
buttonIndex = event.GetData()
|
||||
if buttonIndex = 0 ' Exit
|
||||
? "EXITING APP"
|
||||
m.top.getScene().exitChannel = true
|
||||
function OnFocusIndexChange() as void
|
||||
if m.top.items = invalid
|
||||
return
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnFocusIndexChange()
|
||||
buttonCount = m.buttonGroup.getChildCount()
|
||||
if buttonCount = 0
|
||||
return
|
||||
end if
|
||||
focusIndex = m.top.focusIndex
|
||||
childCount = m.buttonGroup.getChildCount()
|
||||
for i = 0 to childCount - 1
|
||||
if focusIndex < 0
|
||||
m.top.focusIndex = 0
|
||||
return
|
||||
end if
|
||||
if focusIndex >= buttonCount
|
||||
m.top.focusIndex = buttonCount - 1
|
||||
return
|
||||
end if
|
||||
|
||||
navBarItems = m.top.items.getChildren(-1, 0)
|
||||
|
||||
buttons = m.buttonGroup.getChildren(-1, 0)
|
||||
for i = 0 to buttonCount - 1
|
||||
if i <> focusIndex
|
||||
m.buttonGroup.getChild(i).focus = false
|
||||
buttons[i].focus = false
|
||||
m.appController@.HideRootScreen(navBarItems[i].screen)
|
||||
end if
|
||||
end for
|
||||
if focusIndex <> -1
|
||||
m.buttonGroup.getChild(focusIndex).focus = true
|
||||
m.buttonGroup.getChild(focusIndex).focus = m.top.hasFocus()
|
||||
m.appController@.ShowRootScreen(navBarItems[focusIndex].screen)
|
||||
end if
|
||||
end function
|
||||
@@ -1,66 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="NavBar" extends="Group">
|
||||
<component name="NavBar" extends="Group" includes="AutoBind">
|
||||
<interface>
|
||||
<field id="focusIndex" type="int" alwaysNotify="true" />
|
||||
<field id="escapeIndex" type="int" alwaysNotify="true" />
|
||||
<field id="appController" type="node" />
|
||||
<field id="buttonGroup" type="node" bind="./NavBarButtonGroup" />
|
||||
<field id="items" type="node" />
|
||||
<field id="focusIndex" type="int" alwaysNotify="true" onChange="OnFocusIndexChange" />
|
||||
</interface>
|
||||
<children>
|
||||
<Rectangle
|
||||
height="720"
|
||||
width="90"
|
||||
width="105"
|
||||
color="#242424"
|
||||
opacity="0.9">
|
||||
<ButtonGroup
|
||||
<LayoutGroup
|
||||
id="NavBarButtonGroup"
|
||||
itemSpacings="[2]"
|
||||
translation="[7, 120]">
|
||||
<IconButton
|
||||
id="searchButton"
|
||||
background="#242424"
|
||||
focusBackground="#ff1c30"
|
||||
padding="20"
|
||||
icon="pkg:/images/icons/search.png"
|
||||
text="Search"
|
||||
height="50"
|
||||
width="90" />
|
||||
<IconButton
|
||||
id="homeButton"
|
||||
background="#242424"
|
||||
focusBackground="#ff1c30"
|
||||
padding="20"
|
||||
icon="pkg:/images/icons/home.png"
|
||||
text="Home"
|
||||
height="50"
|
||||
width="90" />
|
||||
<IconButton
|
||||
id="settingsButton"
|
||||
background="#242424"
|
||||
focusBackground="#ff1c30"
|
||||
padding="20"
|
||||
icon="pkg:/images/icons/settings.png"
|
||||
text="Settings"
|
||||
height="50"
|
||||
width="90" />
|
||||
<IconButton
|
||||
id="webAppButton"
|
||||
background="#242424"
|
||||
focusBackground="#ff1c30"
|
||||
padding="20"
|
||||
icon="pkg:/images/icons/phone.png"
|
||||
text="Web app"
|
||||
height="50"
|
||||
width="90" />
|
||||
<IconButton
|
||||
id="appInfoButton"
|
||||
background="#242424"
|
||||
focusBackground="#ff1c30"
|
||||
padding="20"
|
||||
icon="pkg:/images/icons/info.png"
|
||||
text="Info"
|
||||
height="50"
|
||||
width="90" />
|
||||
</ButtonGroup>
|
||||
</LayoutGroup>
|
||||
</Rectangle>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="NavBarItem" extends="ContentNode">
|
||||
<interface>
|
||||
<field id="screen" type="string" />
|
||||
<field id="icon" type="string" />
|
||||
<field id="text" type="string" />
|
||||
<field id="canFocus" type="boolean" value="false" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -0,0 +1,53 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
|
||||
function SetNavigation(fromNode as object, direction as string, toNode as object, callback = invalid as dynamic)
|
||||
if m._navigation = invalid
|
||||
m._navigation = {}
|
||||
end if
|
||||
|
||||
if not m._navigation.DoesExist(direction)
|
||||
m._navigation[direction] = []
|
||||
end if
|
||||
|
||||
m._navigation[direction].push({
|
||||
fromNode: fromNode,
|
||||
toNode: toNode,
|
||||
callback: callback
|
||||
})
|
||||
end function
|
||||
|
||||
function NavigationKeyHandler(key as string, press as boolean) as object
|
||||
if not press
|
||||
return {
|
||||
handled: false,
|
||||
node: invalid
|
||||
}
|
||||
end if
|
||||
|
||||
navigations = m._navigation[key]
|
||||
if navigations = invalid
|
||||
return {
|
||||
handled: false,
|
||||
node: invalid
|
||||
}
|
||||
end if
|
||||
for each item in navigations
|
||||
if (item.fromNode = invalid or item.fromNode.isInFocusChain()) and item.toNode.focusable
|
||||
if item.fromNode <> invalid
|
||||
NodeSetFocus(item.fromNode, false)
|
||||
end if
|
||||
NodeSetFocus(item.toNode, true)
|
||||
if item.callback <> invalid
|
||||
item.callback()
|
||||
end if
|
||||
return {
|
||||
handled: true,
|
||||
node: item.toNode
|
||||
}
|
||||
end if
|
||||
end for
|
||||
return {
|
||||
handled: false,
|
||||
node: invalid
|
||||
}
|
||||
end function
|
||||
@@ -0,0 +1,42 @@
|
||||
' TODO:P2 refactor this into a ScrollView component
|
||||
' TODO:P2 use this in settings and search screans
|
||||
function ScrollTo(viewPort as object, containerToMove as object, focusNode as object, animation as object, interpolator as object) as void
|
||||
if viewPort = invalid or containerToMove = invalid or focusNode = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
rect = focusNode.boundingRect()
|
||||
translation = containerToMove.translation
|
||||
rect.x = rect.x + translation[0]
|
||||
rect.y = rect.y + translation[1]
|
||||
|
||||
xInBounds = rect.x >= viewPort.x and rect.x + rect.width <= viewPort.x + viewPort.width
|
||||
yInBounds = rect.y >= viewPort.y and rect.y + rect.height <= viewPort.y + viewPort.height
|
||||
|
||||
if xInBounds and yInBounds
|
||||
return
|
||||
end if
|
||||
|
||||
translateX = 0
|
||||
translateY = 0
|
||||
|
||||
if rect.x < viewPort.x
|
||||
translateX = viewPort.x - rect.x
|
||||
else if rect.x + rect.width > viewPort.x + viewPort.width
|
||||
translateX = viewPort.x + viewPort.width - rect.x - rect.width
|
||||
end if
|
||||
|
||||
if rect.y < viewPort.y
|
||||
translateY = viewPort.y - rect.y
|
||||
else if rect.y + rect.height > viewPort.y + viewPort.height
|
||||
translateY = viewPort.y + viewPort.height - rect.y - rect.height
|
||||
end if
|
||||
|
||||
|
||||
animStart = translation
|
||||
animEnd = [translateX + translation[0], translateY + translation[1]]
|
||||
animMid = [(animStart[0] + animEnd[0]) / 2, (animStart[1] + animEnd[1]) / 2]
|
||||
interpolator.keyValue = [animStart, animMid, animEnd]
|
||||
|
||||
animation.control = "start"
|
||||
end function
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="NavigationTestNode" extends="Node">
|
||||
<interface>
|
||||
<function name="SetNavigation" />
|
||||
<function name="NavigationKeyHandler" />
|
||||
</interface>
|
||||
<script type="text/brightscript" uri="pkg:/components/Navigation/Navigation.bs" />
|
||||
</component>
|
||||
@@ -0,0 +1,175 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/VideoFeed/FeedLoadState.bs"
|
||||
import "pkg:/components/PlaylistView/PlaylistContentTask.bs"
|
||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
import "pkg:/source/utils/ArrayUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.log = new log.Logger("PlayQueue")
|
||||
m.pendingLoadTasks = {}
|
||||
' TODO:P1 prevent adding duplicates of the same video/playlist
|
||||
m.queue = CreateObject("roArray", 0, true)
|
||||
end function
|
||||
|
||||
function Play(node as object, playlistIndex as integer)
|
||||
m.top.index += 1
|
||||
m.top.playlistIndex = playlistIndex
|
||||
|
||||
if m.top.index >= m.queue.Count()
|
||||
m.queue.push(node)
|
||||
m.top.index = m.queue.Count() - 1
|
||||
else
|
||||
ArrayUtils.Insert(m.queue, m.top.index, node)
|
||||
end if
|
||||
|
||||
PlayItemAtCurrentIndex()
|
||||
end function
|
||||
|
||||
function AddToQueue(node as object)
|
||||
m.queue.push(node)
|
||||
end function
|
||||
|
||||
' TODO:P1 better model of the queue (Now playing, etc)
|
||||
function GetQueue(unused as dynamic) as object
|
||||
items = []
|
||||
for each item in m.queue
|
||||
if item.type = "video"
|
||||
items.push({
|
||||
type: item.type,
|
||||
videoId: item.videoId,
|
||||
title: item.title,
|
||||
author: item.author,
|
||||
thumbnail: item.thumbnail
|
||||
})
|
||||
else if item.type = "playlist"
|
||||
items.push({
|
||||
type: item.type,
|
||||
playlistId: item.playlistId,
|
||||
title: item.title,
|
||||
thumbnail: item.thumbnail,
|
||||
videoCountText: item.videoCountText
|
||||
})
|
||||
end if
|
||||
end for
|
||||
|
||||
return {
|
||||
index: m.top.index,
|
||||
playlistIndex: m.top.playlistIndex,
|
||||
items: items
|
||||
}
|
||||
end function
|
||||
|
||||
function Clear(unused as dynamic)
|
||||
m.queue.Clear()
|
||||
m.top.index = -1
|
||||
m.top.playlistIndex = -1
|
||||
end function
|
||||
|
||||
function PlayNextItem(unused as dynamic) as boolean
|
||||
if m.queue.Count() = 0
|
||||
return false
|
||||
end if
|
||||
|
||||
if m.top.index <> -1
|
||||
if m.top.index >= m.queue.Count()
|
||||
return false
|
||||
end if
|
||||
node = m.queue[m.top.index]
|
||||
if node.type = "playlist"
|
||||
m.top.playlistIndex += 1
|
||||
if PlayPlaylistAtCurrentIndex(node)
|
||||
return true
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
|
||||
m.top.index += 1
|
||||
m.top.playlistIndex = -1
|
||||
if m.top.index >= m.queue.Count()
|
||||
return false
|
||||
end if
|
||||
|
||||
return PlayItemAtCurrentIndex()
|
||||
end function
|
||||
|
||||
function PlayItemAtCurrentIndex() as boolean
|
||||
node = m.queue[m.top.index]
|
||||
if node = invalid
|
||||
return false
|
||||
end if
|
||||
if node.type = "video"
|
||||
VideoUtils.PlayVideo(node)
|
||||
return true
|
||||
else if node.type = "playlist"
|
||||
if m.top.playlistIndex = -1
|
||||
m.top.playlistIndex = 0
|
||||
end if
|
||||
return PlayPlaylistAtCurrentIndex(node)
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
|
||||
function PlayPlaylistAtCurrentIndex(playlist as object) as boolean
|
||||
if playlist.videoCount < 0
|
||||
LoadPlaylist(playlist)
|
||||
return true
|
||||
end if
|
||||
index = m.top.playlistIndex
|
||||
if index < 0 or index >= playlist.videoCount
|
||||
return false
|
||||
end if
|
||||
|
||||
if index < playlist.getChildCount()
|
||||
child = playlist.getChild(index)
|
||||
VideoUtils.PlayVideo(child)
|
||||
return true
|
||||
end if
|
||||
|
||||
LoadPlaylist(playlist)
|
||||
return true
|
||||
end function
|
||||
|
||||
function LoadPlaylist(playlist as object) as void
|
||||
if playlist.loadState = FeedLoadState.Loading
|
||||
return
|
||||
end if
|
||||
|
||||
playlist.loadState = FeedLoadState.Loading
|
||||
|
||||
task = StartAsyncTask(PlaylistContentTask, {
|
||||
content: playlist,
|
||||
invidious: m.top.invidious
|
||||
}, OnPlaylistContentTaskResult)
|
||||
m.pendingLoadTasks[task.id] = task
|
||||
end function
|
||||
|
||||
function OnPlaylistContentTaskResult(output as object) as void
|
||||
m.pendingLoadTasks.Delete(output.task.id)
|
||||
|
||||
if output.cancelled
|
||||
return
|
||||
end if
|
||||
|
||||
playlist = output.task.input.content
|
||||
if not output.success or not output.result.success
|
||||
' output.error for unhandled exception
|
||||
error = output.error
|
||||
if error = invalid
|
||||
' output.result.error for network errors
|
||||
error = output.result.error
|
||||
end if
|
||||
error = ErrorUtils.Format(error)
|
||||
m.log.error(error)
|
||||
playlistId = playlist.playlistId
|
||||
message = `Failed to load playlist ${playlistId}\n${error}`
|
||||
' TODO:P1 play next upon closing the dialog
|
||||
DialogUtils.ShowDialog(message, "Playlist load fail", true)
|
||||
return
|
||||
end if
|
||||
|
||||
PlayPlaylistAtCurrentIndex(playlist)
|
||||
end function
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="PlayQueue" extends="Node">
|
||||
<interface>
|
||||
<field id="queue" type="array" />
|
||||
<field id="index" type="integer" value="-1" />
|
||||
<field id="playlistIndex" type="integer" value="-1" />
|
||||
<field id="invidious" type="node" />
|
||||
<function name="Play" />
|
||||
<function name="AddToQueue" />
|
||||
<function name="GetQueue" />
|
||||
<function name="Clear" />
|
||||
<function name="PlayNextItem" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -0,0 +1,48 @@
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
||||
|
||||
' TODO:P1 this should only be called from PlaylistContentNode.bs
|
||||
@asynctask
|
||||
function PlaylistContentTask(input as object) as object
|
||||
contentNode = input.content
|
||||
invidiousNode = input.invidious
|
||||
|
||||
if m.top.cancel
|
||||
contentNode.loadState = FeedLoadState.None
|
||||
return invalid
|
||||
end if
|
||||
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
|
||||
index = contentNode.getChildCount()
|
||||
response = service.GetPlaylist(contentNode.playlistId, index, m.top.cancellation)
|
||||
|
||||
if m.top.cancel
|
||||
contentNode.loadState = FeedLoadState.None
|
||||
return invalid
|
||||
end if
|
||||
|
||||
metadata = response.Json()
|
||||
|
||||
if not response.IsSuccess() or metadata = invalid
|
||||
contentNode.loadState = FeedLoadState.Error
|
||||
return {
|
||||
success: false,
|
||||
error: response.ErrorMessage()
|
||||
}
|
||||
end if
|
||||
|
||||
instance = service.GetInstance()
|
||||
InvidiousContent.ToPlaylistContentNode(contentNode, metadata, instance)
|
||||
|
||||
childCount = contentNode.getChildCount()
|
||||
if metadata.videos.Count() > 0 or childCount < metadata.videoCount
|
||||
contentNode.loadState = FeedLoadState.LoadedPage
|
||||
else
|
||||
contentNode.loadState = FeedLoadState.Loaded
|
||||
end if
|
||||
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
end function
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace PlaylistUtils
|
||||
function Open(contentNode as object)
|
||||
playlistView = CreateObject("roSGNode", "PlaylistView")
|
||||
m.appController@.PushScreen(playlistView)
|
||||
playlistView@.BindNode(invalid)
|
||||
playlistView.content = contentNode
|
||||
end function
|
||||
end namespace
|
||||
@@ -0,0 +1,155 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/PlaylistView/PlaylistContentTask.bs"
|
||||
import "pkg:/components/VideoFeed/FeedLoadState.bs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
|
||||
' TODO:P2 use already loaded thumbnail, and crossfade to highres version (using same Poster)
|
||||
function Init()
|
||||
m.log = new log.Logger("PlaylistView")
|
||||
|
||||
m.background = m.top.findNode("background")
|
||||
m.backgroundSmall = m.top.findNode("backgroundSmall")
|
||||
m.titleLabel = m.top.findNode("titleLabel")
|
||||
m.subtitleLabel = m.top.findNode("subtitleLabel")
|
||||
m.descriptionLabel = m.top.findNode("descriptionLabel")
|
||||
m.list = m.top.findNode("list")
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
m.list.ObserveField("itemFocused", FuncName(OnItemFocused))
|
||||
m.list.observeField("itemSelected", FuncName(OnItemSelected))
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.list, true)
|
||||
end function
|
||||
|
||||
function OnContentSet() as void
|
||||
content = m.top.content
|
||||
if content = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.titleLabel.text = content.title
|
||||
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
|
||||
m.subtitleLabel.text = `${content._author} • ${content.videoCountText} • ${content.viewCountText}`
|
||||
m.descriptionLabel.text = content.description
|
||||
|
||||
' TODO:P2 cross fade
|
||||
m.backgroundSmall.uri = content.thumbnail
|
||||
m.background.uri = content.thumbnailBackground
|
||||
|
||||
itemFocused = m.list.itemFocused
|
||||
m.list.content = content
|
||||
if itemFocused > -1 and content.getChildCount() > itemFocused
|
||||
m.list.jumpToItem = itemFocused
|
||||
end if
|
||||
LoadPlaylistIfNeeded()
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
if press = false
|
||||
return false
|
||||
end if
|
||||
|
||||
if key = "back"
|
||||
Close()
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
|
||||
function Close()
|
||||
if m.playlistLoadTask <> invalid
|
||||
m.playlistLoadTask.cancel = true
|
||||
end if
|
||||
|
||||
m.appController@.PopScreen(invalid)
|
||||
end function
|
||||
|
||||
function OnItemFocused()
|
||||
LoadPlaylistIfNeeded()
|
||||
end function
|
||||
|
||||
function OnItemSelected(event as object)
|
||||
index = event.getData()
|
||||
playlist = m.list.content
|
||||
playlistId = playlist.playlistId
|
||||
video = playlist.getChild(index)
|
||||
videoId = video.videoId
|
||||
if not StringUtils.IsNullOrEmpty(videoId)
|
||||
m.log.info("Play playlist: " + playlistId + " video: " + videoId)
|
||||
m.playQueue@.Play(playlist, index)
|
||||
end if
|
||||
end function
|
||||
|
||||
function LoadPlaylistIfNeeded() as void
|
||||
content = m.top.content
|
||||
if content = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
if not content.loadState = FeedLoadState.LoadedPage and not content.loadState = FeedLoadState.None
|
||||
return
|
||||
end if
|
||||
|
||||
videoCount = content.videoCount
|
||||
currentVideosCount = content.getChildCount()
|
||||
if videoCount = currentVideosCount
|
||||
return
|
||||
end if
|
||||
|
||||
itemFocused = m.list.itemFocused
|
||||
if itemFocused < currentVideosCount - 5
|
||||
return
|
||||
end if
|
||||
|
||||
LoadPlaylist()
|
||||
end function
|
||||
|
||||
function LoadPlaylist() as void
|
||||
if m.playlistLoadTask <> invalid
|
||||
m.playlistLoadTask.cancel = true
|
||||
end if
|
||||
|
||||
m.top.content.loadState = FeedLoadState.Loading
|
||||
m.playlistLoadTask = StartAsyncTask(PlaylistContentTask, {
|
||||
content: m.top.content,
|
||||
invidious: m.top.invidious
|
||||
}, OnPlaylistContentTaskResult)
|
||||
end function
|
||||
|
||||
function OnPlaylistContentTaskResult(output as object) as void
|
||||
m.playlistLoadTask = invalid
|
||||
|
||||
if output.cancelled
|
||||
return
|
||||
end if
|
||||
|
||||
if not output.success or not output.result.success
|
||||
' output.error for unhandled exception
|
||||
error = output.error
|
||||
if error = invalid
|
||||
' output.result.error for network errors
|
||||
error = output.result.error
|
||||
end if
|
||||
error = ErrorUtils.Format(error)
|
||||
m.log.error(error)
|
||||
playlistId = output.task.input.content.playlistId
|
||||
message = `Failed to load playlist ${playlistId}\n${error}`
|
||||
DialogUtils.ShowDialog(message, "Playlist load fail", true)
|
||||
return
|
||||
end if
|
||||
|
||||
LoadPlaylistIfNeeded()
|
||||
end function
|
||||
@@ -0,0 +1,58 @@
|
||||
<component name="PlaylistView" extends="Group" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="content" type="node" onChange="OnContentSet" />
|
||||
<field id="appController" type="node" bind="/AppController" />
|
||||
<field id="invidious" type="node" bind="/Invidious" />
|
||||
<field id="playQueue" type="node" bind="/PlayQueue" />
|
||||
</interface>
|
||||
<children>
|
||||
<Rectangle
|
||||
width="1280"
|
||||
height="720"
|
||||
color="0x242424">
|
||||
</Rectangle>
|
||||
<Poster
|
||||
id="backgroundSmall"
|
||||
width="1280"
|
||||
height="720"
|
||||
blendColor="0x323232" />
|
||||
<Poster
|
||||
id="background"
|
||||
width="1280"
|
||||
height="720"
|
||||
blendColor="0x323232">
|
||||
<LayoutGroup
|
||||
itemSpacings="[5,20]"
|
||||
translation="[65,90]">
|
||||
<Label
|
||||
id="titleLabel"
|
||||
width="500"
|
||||
maxLines="2"
|
||||
wrap="true">
|
||||
<Font role="font" uri="font:BoldSystemFontFile" size="36" />
|
||||
</Label>
|
||||
<Label
|
||||
id="subtitleLabel"
|
||||
width="500"
|
||||
font="font:SmallestBoldSystemFont" />
|
||||
<Label
|
||||
id="descriptionLabel"
|
||||
width="500"
|
||||
maxLines="10"
|
||||
wrap="true"
|
||||
font="font:SmallestSystemFont" />
|
||||
</LayoutGroup>
|
||||
|
||||
<MarkupGrid
|
||||
id="list"
|
||||
itemComponentName="PlaylistViewCell"
|
||||
itemSize="[550,106]"
|
||||
itemSpacing="[0,20]"
|
||||
numColumns="1"
|
||||
numRows="5"
|
||||
vertFocusAnimationStyle="floatingFocus"
|
||||
translation="[620,90]" />
|
||||
|
||||
</Poster>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,44 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
import "pkg:/source/utils/TimeUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.titleLabel = m.top.findNode("titleLabel")
|
||||
m.authorLabel = m.top.findNode("authorLabel")
|
||||
m.thumbnail = m.top.findNode("thumbnail")
|
||||
m.durationRect = m.top.FindNode("durationRect")
|
||||
m.durationLabel = m.top.FindNode("durationLabel")
|
||||
|
||||
m.thumbnail.failedBitmapUri = "pkg:/images/thumbnail-missing.jpg"
|
||||
end function
|
||||
|
||||
function OnContentSet() as void
|
||||
content = m.top.itemContent
|
||||
|
||||
if content = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.titleLabel.text = content.title
|
||||
m.authorLabel.text = content.author
|
||||
|
||||
m.thumbnail.uri = content.thumbnail
|
||||
if ValidInt(content.lengthSeconds) <> 0
|
||||
SetDurationText(content.lengthText)
|
||||
m.durationRect.visible = true
|
||||
else
|
||||
m.durationRect.visible = false
|
||||
end if
|
||||
end function
|
||||
|
||||
function SetDurationText(text as string)
|
||||
label = m.durationLabel
|
||||
rect = m.durationRect
|
||||
|
||||
rectParent = rect.getParent()
|
||||
|
||||
label.text = text
|
||||
size = label.localBoundingRect()
|
||||
|
||||
rect.width = size.width + 16
|
||||
rect.translation = [rectParent.width - rect.width, 72]
|
||||
end function
|
||||
@@ -0,0 +1,46 @@
|
||||
<component name="PlaylistViewCell" extends="Group">
|
||||
<interface>
|
||||
<field id="itemContent" type="node" onChange="OnContentSet" />
|
||||
</interface>
|
||||
<children>
|
||||
<Poster
|
||||
id="thumbnail"
|
||||
loadDisplayMode="scaleToZoom"
|
||||
width="190"
|
||||
height="106">
|
||||
<Rectangle
|
||||
id="durationRect"
|
||||
width="60"
|
||||
height="26"
|
||||
color="0x000000"
|
||||
opacity="0.8"
|
||||
translation="[130, 72]">
|
||||
<Label
|
||||
height="26"
|
||||
id="durationLabel"
|
||||
horizAlign="center"
|
||||
vertAlign="center"
|
||||
font="font:SmallestSystemFont"
|
||||
translation="[8, 0]" />
|
||||
</Rectangle>
|
||||
|
||||
</Poster>
|
||||
|
||||
<LayoutGroup
|
||||
itemSpacings="[5,5]"
|
||||
translation="[200,0]">
|
||||
<Label
|
||||
id="titleLabel"
|
||||
width="350"
|
||||
font="font:SmallestBoldSystemFont"
|
||||
maxLines="2"
|
||||
wrap="true" />
|
||||
<Label
|
||||
id="authorLabel"
|
||||
width="350"
|
||||
height="25"
|
||||
font="font:SmallestSystemFont" />
|
||||
</LayoutGroup>
|
||||
</children>
|
||||
|
||||
</component>
|
||||
+12
-21
@@ -1,5 +1,3 @@
|
||||
import "pkg:/source/utils/General.bs"
|
||||
import "pkg:/components/AppInfoScreen/AppVersionTask.bs"
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
|
||||
function Init()
|
||||
@@ -15,19 +13,21 @@ function Init()
|
||||
}
|
||||
|
||||
m.keyValueList = m.top.findNode("KeyValueListContent")
|
||||
m.appInfo = GetAppInfo()
|
||||
m.appInfo["lib_version_latest"] = "N/A"
|
||||
m.appInfo["lib_url"] = "N/A"
|
||||
m.appInfo["lib_url_type"] = "N/A"
|
||||
end function
|
||||
|
||||
scene = m.top.getScene()
|
||||
if scene.playletLibLoadedUrl <> invalid
|
||||
m.appInfo["lib_url"] = scene.playletLibLoadedUrl.link
|
||||
m.appInfo["lib_url_type"] = scene.playletLibLoadedUrl.type
|
||||
end if
|
||||
function OnNodeReady()
|
||||
m.appInfo = m.applicationInfo@.GetAppInfo(invalid)
|
||||
|
||||
UpdateKeyValueList()
|
||||
GetLatestVersion()
|
||||
|
||||
if m.appInfo.lib_version_latest = "N/A"
|
||||
m.applicationInfo.ObserveFieldScoped("lib_version_latest", FuncName(OnAppInfoChanged))
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnAppInfoChanged()
|
||||
m.appInfo["lib_version_latest"] = m.applicationInfo.lib_version_latest
|
||||
UpdateKeyValueList()
|
||||
end function
|
||||
|
||||
function UpdateKeyValueList()
|
||||
@@ -41,12 +41,3 @@ function UpdateKeyValueList()
|
||||
contentNode.title = value
|
||||
end for
|
||||
end function
|
||||
|
||||
function GetLatestVersion()
|
||||
StartAsyncTask(AppVersionTask, {}, function(output as object) as void
|
||||
if output.result.latest <> invalid
|
||||
m.appInfo["lib_version_latest"] = output.result.latest
|
||||
UpdateKeyValueList()
|
||||
end if
|
||||
end function)
|
||||
end function
|
||||
+4
-2
@@ -1,13 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="AppInfoScreen" extends="Group">
|
||||
<component name="AppInfoScreen" extends="Group" includes="AutoBind">
|
||||
<interface>
|
||||
<field id="applicationInfo" type="node" bind="/ApplicationInfo" />
|
||||
</interface>
|
||||
<children>
|
||||
<LabelList
|
||||
translation="[170,92]"
|
||||
itemSize="[1020,48]"
|
||||
font='font:SmallestBoldSystemFont'>
|
||||
font="font:SmallestBoldSystemFont"
|
||||
drawFocusFeedback="false">
|
||||
<ContentNode id="KeyValueListContent" role="content">
|
||||
</ContentNode>
|
||||
</LabelList>
|
||||
@@ -0,0 +1,29 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
|
||||
function Init()
|
||||
m.rowList = m.top.FindNode("rowList")
|
||||
m.pendingLoadTasks = {}
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
SetNavigation(invalid, "back", m.navBar)
|
||||
SetNavigation(invalid, "left", m.navBar)
|
||||
|
||||
m.rowList@.BindNode(invalid)
|
||||
m.rowList.contentData = ParseJson(ReadAsciiFile(m.top.feedFile))
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
NodeSetFocus(m.rowList, true)
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
if NavigationKeyHandler(key, press).handled
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="HomeScreen" extends="Group" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="navBar" type="node" bind="/NavBar" />
|
||||
<field id="invidious" type="node" bind="/Invidious" />
|
||||
<field id="feedFile" type="string" value="libpkg:/config/default_home_layout.json5" />
|
||||
</interface>
|
||||
<children>
|
||||
<VideoRowList
|
||||
itemComponentName="RowCell"
|
||||
id="rowList"
|
||||
translation="[0,50]"
|
||||
numRows="2"
|
||||
rowitemSize="[[350,196]]"
|
||||
rowItemSpacing="[[25,0]]"
|
||||
itemSize="[1280,326]"
|
||||
itemSpacing="[0,65]"
|
||||
rowLabelOffset="[[115,20]]"
|
||||
focusXOffset="[115]"
|
||||
showRowLabel="[true]"
|
||||
rowFocusAnimationStyle="floatingfocus"
|
||||
focusBitmapUri="pkg:/images/focus_grid.9.png"
|
||||
/>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,232 @@
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/components/Screens/SearchScreen/SearchSuggestionsTask.bs"
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/source/services/SearchHistory.bs"
|
||||
import "pkg:/source/utils/LoadingScreen.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.container = m.top.FindNode("container")
|
||||
m.keyboard = m.top.FindNode("keyboard")
|
||||
m.rowList = m.top.FindNode("rowList")
|
||||
m.scrollAnimation = m.top.FindNode("scrollAnimation")
|
||||
m.scrollAnimationInterpolator = m.top.FindNode("scrollAnimationInterpolator")
|
||||
m.suggestions = m.top.FindNode("suggestions")
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
m.log = new log.Logger("SearchScreen")
|
||||
|
||||
m.rowlist@.BindNode(invalid)
|
||||
m.keyboard.ObserveField("text", FuncName(OnTextChange))
|
||||
m.suggestions.ObserveField("buttonFocused", FuncName(OnSearchButtonFocused))
|
||||
m.suggestions.ObserveField("buttonSelected", FuncName(OnSearchButtonSelected))
|
||||
m.top.ObserveField("visible", FuncName(OnVisibilityChange))
|
||||
m.rowlist.ObserveFieldScoped("onError", FuncName(OnSearchError))
|
||||
|
||||
SetNavigation(invalid, "back", m.navBar, function()
|
||||
ScrollUp()
|
||||
end function)
|
||||
SetNavigation(m.suggestions, "right", m.keyboard)
|
||||
SetNavigation(m.keyboard, "left", m.suggestions)
|
||||
SetNavigation(m.suggestions, "left", m.navBar)
|
||||
SetNavigation(m.keyboard, "left", m.navBar)
|
||||
SetNavigation(m.rowList, "left", m.navBar, function()
|
||||
ScrollUp()
|
||||
end function)
|
||||
SetNavigation(invalid, "down", m.rowList, function()
|
||||
ScrollDown()
|
||||
end function)
|
||||
SetNavigation(m.rowList, "up", m.suggestions, function()
|
||||
ScrollUp()
|
||||
end function)
|
||||
|
||||
m.currentNavigtionNode = m.suggestions
|
||||
' Trigger suggestions
|
||||
OnTextChange()
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
if m.currentNavigtionNode.isSameNode(m.suggestions) and not m.suggestions.focusable
|
||||
m.currentNavigtionNode = m.keyboard
|
||||
end if
|
||||
NodeSetFocus(m.currentNavigtionNode, true)
|
||||
if m.currentNavigtionNode.isSameNode(m.suggestions)
|
||||
OnSearchButtonFocused()
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnTextChange() as void
|
||||
if m.suggestions.isInFocusChain()
|
||||
return
|
||||
end if
|
||||
|
||||
if m.searchSuggestionsTask <> invalid
|
||||
m.searchSuggestionsTask.cancel = true
|
||||
end if
|
||||
|
||||
m.searchSuggestionsTask = StartAsyncTask(SearchSuggestionsTask, {
|
||||
q: m.keyboard.text,
|
||||
invidious: m.invidious
|
||||
}, OnSearchSuggestionsTaskResults)
|
||||
end function
|
||||
|
||||
function OnSearchSuggestionsTaskResults(output as object) as void
|
||||
if m.searchSuggestionsTask <> invalid and m.searchSuggestionsTask.id = output.task.id
|
||||
m.searchSuggestionsTask = invalid
|
||||
end if
|
||||
|
||||
if output.cancelled
|
||||
return
|
||||
end if
|
||||
|
||||
if not output.success
|
||||
m.log.error(ErrorUtils.Format(output.error))
|
||||
return
|
||||
end if
|
||||
' In case this is an old request, discard suggestions
|
||||
q = output.result.q
|
||||
if q <> m.keyboard.text
|
||||
return
|
||||
end if
|
||||
suggestions = output.result.response
|
||||
if suggestions = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
if q.len() > 0 and ArrayUtils.IndexOfString(suggestions, q) = -1
|
||||
suggestions.Unshift(q)
|
||||
end if
|
||||
|
||||
' Capture current focused button and restore it after resetting the buttons
|
||||
buttonFocused = -1
|
||||
if m.suggestions.isInFocusChain()
|
||||
buttonFocused = m.suggestions.buttonFocused
|
||||
end if
|
||||
if buttonFocused >= m.suggestions.buttons.Count()
|
||||
buttonFocused = m.suggestions.buttons.Count() - 1
|
||||
end if
|
||||
m.suggestions.buttons = suggestions
|
||||
if buttonFocused <> -1
|
||||
m.suggestions.focusButton = buttonFocused
|
||||
end if
|
||||
m.suggestions.focusable = m.suggestions.buttons.Count() > 0
|
||||
end function
|
||||
|
||||
function OnSearchButtonSelected()
|
||||
selected = m.suggestions.buttonSelected
|
||||
text = m.suggestions.buttons[selected]
|
||||
SearchHistory.Save(text)
|
||||
Search(text)
|
||||
end function
|
||||
|
||||
function OnSearchButtonFocused() as void
|
||||
if not m.suggestions.isInFocusChain()
|
||||
return
|
||||
end if
|
||||
|
||||
buttonCount = m.suggestions.buttons.Count()
|
||||
selected = m.suggestions.buttonFocused
|
||||
if selected >= buttonCount
|
||||
m.suggestions.focusButton = 0
|
||||
end if
|
||||
|
||||
selected = m.suggestions.buttonFocused
|
||||
if selected >= m.suggestions.buttons.Count() or selected < 0
|
||||
return
|
||||
end if
|
||||
text = m.suggestions.buttons[selected]
|
||||
m.keyboard.text = text
|
||||
end function
|
||||
|
||||
function Search(text as string)
|
||||
m.rowlist.UnobserveFieldScoped("someContentReady")
|
||||
m.rowlist.ObserveFieldScoped("someContentReady", FuncName(OnSearchContentReady))
|
||||
ShowLoadingScreen()
|
||||
|
||||
m.rowList.contentData = [{
|
||||
title: `Search - ${text}`,
|
||||
apiType: "Invidious",
|
||||
endpoint: "search",
|
||||
queryParams: {
|
||||
q: text
|
||||
}
|
||||
}]
|
||||
end function
|
||||
|
||||
function OnSearchContentReady() as void
|
||||
if not m.rowlist.someContentReady
|
||||
return
|
||||
end if
|
||||
m.rowlist.UnobserveFieldScoped("someContentReady")
|
||||
m.rowlist.focusable = true
|
||||
m.currentNavigtionNode = m.rowList
|
||||
NodeSetFocus(m.rowlist, true)
|
||||
' There's a bug with the floating focus indicator. If the rowList receives focus after the
|
||||
' content is set, the focus indicator will be "off". This is why we set the content again.
|
||||
m.rowlist.content = m.rowlist.content
|
||||
ScrollDown()
|
||||
HideLoadingScreen()
|
||||
end function
|
||||
|
||||
function OnSearchError()
|
||||
m.rowlist.contentData = invalid
|
||||
m.rowlist.focusable = false
|
||||
HideLoadingScreen()
|
||||
end function
|
||||
|
||||
function OnVisibilityChange()
|
||||
if m.top.visible = false
|
||||
ClearSearch()
|
||||
else
|
||||
OnTextChange()
|
||||
end if
|
||||
end function
|
||||
|
||||
function ClearSearch()
|
||||
m.keyboard.text = ""
|
||||
m.rowlist.contentData = invalid
|
||||
m.rowlist.focusable = false
|
||||
ScrollUp()
|
||||
end function
|
||||
|
||||
function ScrollUp() as void
|
||||
destination = m.scrollAnimationInterpolator.keyValue[0][1]
|
||||
current = m.container.translation[1]
|
||||
if current = destination
|
||||
return
|
||||
end if
|
||||
m.scrollAnimationInterpolator.reverse = true
|
||||
m.scrollAnimation.control = "start"
|
||||
end function
|
||||
|
||||
function ScrollDown() as void
|
||||
destination = m.scrollAnimationInterpolator.keyValue[2][1]
|
||||
current = m.container.translation[1]
|
||||
if current = destination
|
||||
return
|
||||
end if
|
||||
m.scrollAnimationInterpolator.reverse = false
|
||||
m.scrollAnimation.control = "start"
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
navigation = NavigationKeyHandler(key, press)
|
||||
if navigation.handled
|
||||
m.currentNavigtionNode = navigation.node
|
||||
if m.currentNavigtionNode.isSameNode(m.navBar)
|
||||
m.currentNavigtionNode = m.suggestions
|
||||
end if
|
||||
if m.currentNavigtionNode.isSameNode(m.suggestions)
|
||||
OnSearchButtonFocused()
|
||||
end if
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
+13
-10
@@ -1,36 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="SearchScreen" extends="Group">
|
||||
<component name="SearchScreen" extends="Group" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="escape" type="string" alwaysNotify="true" />
|
||||
<field id="focus" type="boolean" alwaysNotify="true" />
|
||||
<field id="navBar" type="node" bind="/NavBar" />
|
||||
<field id="invidious" type="node" bind="/Invidious" />
|
||||
</interface>
|
||||
|
||||
<children>
|
||||
<Group id="container">
|
||||
<MiniKeyboard
|
||||
id="keyboard"
|
||||
translation="[670,110]"
|
||||
translation="[730,110]"
|
||||
/>
|
||||
<ButtonGroup
|
||||
id="suggestions"
|
||||
maxWidth="450"
|
||||
focusable="false"
|
||||
minWidth="400"
|
||||
maxWidth="480"
|
||||
buttonHeight="50"
|
||||
translation="[160,100]"
|
||||
/>
|
||||
<RowList
|
||||
itemComponentName="VideoRowCell"
|
||||
<VideoRowList
|
||||
itemComponentName="RowCell"
|
||||
id="rowList"
|
||||
focusable="false"
|
||||
translation="[0,620]"
|
||||
numRows="1"
|
||||
rowitemSize="[[350,196]]"
|
||||
rowItemSpacing="[[25,0]]"
|
||||
itemSize="[1280,326]"
|
||||
itemSpacing="[0,65]"
|
||||
rowLabelOffset="[[95,20]]"
|
||||
focusXOffset="[95]"
|
||||
rowLabelOffset="[[115,20]]"
|
||||
focusXOffset="[115]"
|
||||
showRowLabel="[true]"
|
||||
rowFocusAnimationStyle="floatingfocus"
|
||||
variableWidthItems="true"
|
||||
focusBitmapUri="pkg:/images/focus_grid.9.png"
|
||||
/>
|
||||
<Animation
|
||||
+13
-2
@@ -1,11 +1,22 @@
|
||||
import "pkg:/source/services/Invidious.bs"
|
||||
import "pkg:/source/services/SearchHistory.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
|
||||
@asynctask
|
||||
function SearchSuggestionsTask(input as object) as object
|
||||
q = input.q
|
||||
invidiousNode = input.invidious
|
||||
|
||||
searchSuggestsions = q <> "" ? Invidious.SearchSuggestions(q) : invalid
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
searchSuggestsions = StringUtils.IsNullOrEmpty(q) ? invalid : service.SearchSuggestions(q, m.top.cancellation)
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
history = SearchHistory.GetSaved(q)
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.top.focusable = true
|
||||
m.checkbox = m.top.findNode("Checkbox")
|
||||
m.top.itemSpacings = [10]
|
||||
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 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
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.checkbox, true)
|
||||
end function
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="BooleanControl" extends="LayoutGroup" includes="Focus">
|
||||
<interface>
|
||||
<field id="displayText" type="string" alias="Checkbox.title" />
|
||||
<field id="description" type="string" alias="Description.text" />
|
||||
<field id="value" type="boolean" alias="Checkbox.value" onChange="OnValueChange" />
|
||||
<function name="BindPreference" />
|
||||
</interface>
|
||||
<children>
|
||||
<Checkbox id="Checkbox" wrapDividerHeight="0" wrapDividerBitmapUri="" />
|
||||
<Label id="Description"
|
||||
width="450"
|
||||
color="0xb4b4b4ff"
|
||||
wrap="true">
|
||||
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||
</Label>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,17 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.top.observeField("checkedState", FuncName(OnCheckedStateChange))
|
||||
end function
|
||||
|
||||
function OnValueChange()
|
||||
m.top.checkedState = [m.top.value]
|
||||
end function
|
||||
|
||||
function OnCheckedStateChange() as void
|
||||
checkedState = m.top.checkedState
|
||||
if checkedState = invalid or checkedState.Count() = 0
|
||||
return
|
||||
end if
|
||||
m.top.value = checkedState[0]
|
||||
end function
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="Checkbox" extends="CheckList">
|
||||
<interface>
|
||||
<field id="title" type="string" alias="checkboxNode.title" />
|
||||
<field id="value" type="boolean" onChange="OnValueChange" />
|
||||
</interface>
|
||||
<children>
|
||||
<ContentNode role="content">
|
||||
<ContentNode id="checkboxNode" title="" />
|
||||
</ContentNode>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,26 @@
|
||||
import "pkg:/source/services/SearchHistory.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.top.focusable = true
|
||||
m.top.itemSpacings = [8]
|
||||
m.button = m.top.findNode("Button")
|
||||
m.button.observeField("buttonSelected", FuncName(OnButtonSelected))
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
NodeSetFocus(m.button, true)
|
||||
end function
|
||||
|
||||
function BindPreference(preferences as object, key as string)
|
||||
' Do nothing
|
||||
end function
|
||||
|
||||
function OnButtonSelected()
|
||||
SearchHistory.Clear()
|
||||
DialogUtils.ShowDialog("Search history cleared.", "Success")
|
||||
end function
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="ClearSearchHistoryControl" extends="LayoutGroup" includes="Focus">
|
||||
<interface>
|
||||
<field id="displayText" type="string" alias="Button.text" />
|
||||
<field id="description" type="string" alias="DescriptionLabel.text" />
|
||||
<function name="BindPreference" />
|
||||
</interface>
|
||||
<children>
|
||||
<Button
|
||||
id="Button"
|
||||
showFocusFootprint="true" />
|
||||
<Label id="DescriptionLabel"
|
||||
width="450"
|
||||
color="0xb4b4b4ff"
|
||||
wrap="true">
|
||||
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||
</Label>
|
||||
</children>
|
||||
</component>
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
|
||||
function Init()
|
||||
m.top.focusable = true
|
||||
m.top.itemSpacings = [8]
|
||||
|
||||
m.button = m.top.findNode("button")
|
||||
AdjustButtonLabel(m.button)
|
||||
|
||||
m.button.observeField("buttonSelected", FuncName(OpenInvidiousInstanceSettings))
|
||||
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 OpenInvidiousInstanceSettings()
|
||||
settings = CreateObject("roSGNode", "InvidiousInstanceSettings")
|
||||
m.appController@.PushScreen(settings)
|
||||
settings@.BindNode(invalid)
|
||||
settings.text = m.top.value
|
||||
settings.observeField("save", FuncName(OnSaveInvidiousInstance))
|
||||
end function
|
||||
|
||||
function OnSaveInvidiousInstance(event as object)
|
||||
settings = event.GetRoSGNode()
|
||||
m.top.value = settings.text
|
||||
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
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousInstanceControl" extends="LayoutGroup" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="displayText" type="string" alias="DisplayTextLabel.text" />
|
||||
<field id="description" type="string" alias="DescriptionLabel.text" />
|
||||
<field id="value" type="string" alias="Button.text" onChange="OnValueChange" />
|
||||
<field id="appController" type="node" bind="/AppController" />
|
||||
<function name="BindPreference" />
|
||||
</interface>
|
||||
<children>
|
||||
<Label id="DisplayTextLabel" width="450" />
|
||||
<Label id="DescriptionLabel"
|
||||
width="450"
|
||||
color="0xb4b4b4ff"
|
||||
wrap="true">
|
||||
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||
</Label>
|
||||
<Button id="Button"
|
||||
iconUri=""
|
||||
focusedIconUri=""
|
||||
showFocusFootprint="true"
|
||||
minWidth="420" />
|
||||
</children>
|
||||
</component>
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.textEditBox = m.top.findNode("textEditBox")
|
||||
m.editButton = m.top.findNode("editButton")
|
||||
m.testButton = m.top.findNode("testButton")
|
||||
m.saveButton = m.top.findNode("saveButton")
|
||||
|
||||
m.publicInstances = m.top.findNode("instances")
|
||||
|
||||
m.editButton.observeField("buttonSelected", FuncName(OnEditButtonSelected))
|
||||
m.saveButton.observeField("buttonSelected", FuncName(OnSaveButtonSelected))
|
||||
m.testButton.observeField("buttonSelected", FuncName(OnTestButtonSelected))
|
||||
m.publicInstances.observeField("instance", FuncName(OnPublicInstanceSelected))
|
||||
|
||||
SetNavigation(m.editButton, "down", m.publicInstances)
|
||||
SetNavigation(m.editButton, "down", m.testButton)
|
||||
SetNavigation(m.publicInstances, "up", m.editButton)
|
||||
|
||||
SetNavigation(m.publicInstances, "down", m.testButton)
|
||||
|
||||
SetNavigation(m.testButton, "up", m.publicInstances)
|
||||
SetNavigation(m.testButton, "up", m.editButton)
|
||||
SetNavigation(m.saveButton, "up", m.publicInstances)
|
||||
SetNavigation(m.saveButton, "up", m.editButton)
|
||||
|
||||
SetNavigation(m.saveButton, "left", m.testButton)
|
||||
SetNavigation(m.testButton, "right", m.saveButton)
|
||||
|
||||
m.currentNavigtionNode = m.editButton
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.currentNavigtionNode, true)
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
navigation = NavigationKeyHandler(key, press)
|
||||
if navigation.handled
|
||||
m.currentNavigtionNode = navigation.node
|
||||
return true
|
||||
end if
|
||||
|
||||
if key = "options" and press
|
||||
' A pass-through to the app controller, so it can toggle picture-in-picture
|
||||
return false
|
||||
end if
|
||||
|
||||
if key = "back" and press
|
||||
Close()
|
||||
return true
|
||||
end if
|
||||
|
||||
return true
|
||||
end function
|
||||
|
||||
function OnPublicInstanceSelected()
|
||||
m.top.text = m.publicInstances.instance
|
||||
m.currentNavigtionNode = m.testButton
|
||||
NodeSetFocus(m.testButton, true)
|
||||
end function
|
||||
|
||||
function OnTestButtonSelected()
|
||||
testing = CreateObject("roSGNode", "InvidiousInstanceTesting")
|
||||
m.appController@.PushScreen(testing)
|
||||
testing@.BindNode(invalid)
|
||||
testing.instance = m.top.text
|
||||
testing.run = true
|
||||
end function
|
||||
|
||||
function OnEditButtonSelected()
|
||||
keyboardDialog = createObject("roSGNode", "StandardKeyboardDialog")
|
||||
keyboardDialog.title = "Edit Instance"
|
||||
keyboardDialog.message = ["Enter the instance url (e.g. https://vid.puffyan.us)"]
|
||||
keyboardDialog.text = m.top.text
|
||||
keyboardDialog.buttons = ["OK", "Cancel"]
|
||||
keyboardDialog.observeField("buttonSelected", FuncName(OnKeyboardButton))
|
||||
|
||||
m.top.getScene().dialog = keyboardDialog
|
||||
end function
|
||||
|
||||
function OnKeyboardButton(event as object)
|
||||
keyboard = event.getRoSGNode()
|
||||
buttonSelected = keyboard.buttonSelected
|
||||
if buttonSelected = 0
|
||||
m.top.text = keyboard.text
|
||||
m.currentNavigtionNode = m.testButton
|
||||
NodeSetFocus(m.testButton, true)
|
||||
end if
|
||||
keyboard.close = true
|
||||
end function
|
||||
|
||||
function OnSaveButtonSelected()
|
||||
m.top.save = true
|
||||
Close()
|
||||
end function
|
||||
|
||||
function Close()
|
||||
m.appController@.PopScreen(invalid)
|
||||
end function
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousInstanceSettings" extends="Group" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="text" type="string" alias="textEditBox.text" />
|
||||
<field id="save" type="boolean" alwaysNotify="true" />
|
||||
<field id="appController" type="node" bind="/AppController" />
|
||||
</interface>
|
||||
<children>
|
||||
<Rectangle
|
||||
width="1280"
|
||||
height="720"
|
||||
color="#000000"
|
||||
opacity="0.5">
|
||||
</Rectangle>
|
||||
<Rectangle
|
||||
width="960"
|
||||
height="600"
|
||||
translation="[160,60]"
|
||||
color="#242424">
|
||||
<Label
|
||||
text="Invidious custom instance"
|
||||
translation="[326,13]" />
|
||||
<TextEditBox
|
||||
id="textEditBox"
|
||||
hintText="e.g. https://https://vid.puffyan.us"
|
||||
width="480"
|
||||
height="50"
|
||||
translation="[200,50]" />
|
||||
<Button
|
||||
id="editButton"
|
||||
text=""
|
||||
minWidth="64"
|
||||
maxWidth="80"
|
||||
height="48"
|
||||
iconUri="pkg:/images/icons/edit-48-white.png"
|
||||
focusedIconUri="pkg:/images/icons/edit-48-black.png"
|
||||
showFocusFootprint="true"
|
||||
translation="[692,50]" />
|
||||
<Label
|
||||
text="OR"
|
||||
translation="[460,110]">
|
||||
<Rectangle
|
||||
width="250"
|
||||
height="1"
|
||||
translation="[-282,10]" />
|
||||
|
||||
<Rectangle
|
||||
width="250"
|
||||
height="1"
|
||||
translation="[71,10]" />
|
||||
|
||||
</Label>
|
||||
|
||||
<Label
|
||||
text="Invidious public instances"
|
||||
translation="[328,145]" />
|
||||
|
||||
<InvidiousPublicInstances
|
||||
id="instances"
|
||||
translation="[50,190]">
|
||||
|
||||
</InvidiousPublicInstances>
|
||||
|
||||
<Button
|
||||
id="testButton"
|
||||
text="Test instance"
|
||||
showFocusFootprint="true"
|
||||
translation="[495,507]" />
|
||||
<Button
|
||||
id="saveButton"
|
||||
text="Save"
|
||||
showFocusFootprint="true"
|
||||
minWidth="150"
|
||||
translation="[768,507]" />
|
||||
</Rectangle>
|
||||
</children>
|
||||
</component>
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/Screens/SettingsScreen/InvidiousInstance/InvidiousInstanceTesting/InvidiousInstanceTestingTask.bs"
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.titleLabel = m.top.findNode("titleLabel")
|
||||
m.closeButton = m.top.findNode("closeButton")
|
||||
m.testList = m.top.findNode("testList")
|
||||
m.closeButton.observeField("buttonSelected", FuncName(Close))
|
||||
m.testList.observeField("itemSelected", FuncName(ShowTestDetails))
|
||||
|
||||
SetNavigation(m.closeButton, "up", m.testList)
|
||||
SetNavigation(m.testList, "down", m.closeButton)
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.closeButton, true)
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
if NavigationKeyHandler(key, press).handled
|
||||
return true
|
||||
end if
|
||||
|
||||
if key = "options" and press
|
||||
' A pass-through to the app controller, so it can toggle picture-in-picture
|
||||
return false
|
||||
end if
|
||||
|
||||
if key = "back" and press
|
||||
Close()
|
||||
return true
|
||||
end if
|
||||
|
||||
return true
|
||||
end function
|
||||
|
||||
function Close()
|
||||
if m.testingTask <> invalid
|
||||
m.testingTask.cancel = true
|
||||
end if
|
||||
|
||||
m.appController@.PopScreen(invalid)
|
||||
end function
|
||||
|
||||
function RunTestsTask()
|
||||
m.titleLabel.text = `Testing ${m.top.instance}`
|
||||
|
||||
if m.testingTask <> invalid
|
||||
m.testingTask.cancel = true
|
||||
end if
|
||||
|
||||
m.testingTask = StartAsyncTask(InvidiousInstanceTestingTask, {
|
||||
instance: m.top.instance,
|
||||
listNode: m.testList
|
||||
})
|
||||
end function
|
||||
|
||||
function ShowTestDetails(event as object) as void
|
||||
selected = m.testList.itemSelected
|
||||
itemContent = m.testList.content.GetChild(selected)
|
||||
if StringUtils.IsNullOrEmpty(itemContent.details)
|
||||
return
|
||||
end if
|
||||
|
||||
message = `Status: ${itemContent.state}\nTest duration: ${itemContent.duration}ms\nDetails: ${itemContent.details}`
|
||||
DialogUtils.ShowDialog(message, `Test: ${itemContent.title}`)
|
||||
end function
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousInstanceTesting" extends="Group" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="instance" type="string" />
|
||||
<field id="run" type="boolean" alwaysNotify="true" onChange="RunTestsTask" />
|
||||
<field id="appController" type="node" bind="/AppController" />
|
||||
</interface>
|
||||
<children>
|
||||
<Rectangle
|
||||
width="1280"
|
||||
height="720"
|
||||
color="#000000"
|
||||
opacity="0.5">
|
||||
</Rectangle>
|
||||
<Rectangle
|
||||
width="960"
|
||||
height="600"
|
||||
translation="[160,60]"
|
||||
color="#242424">
|
||||
<Label
|
||||
id="titleLabel"
|
||||
width="960"
|
||||
horizAlign="center"
|
||||
text=""
|
||||
translation="[0,20]" />
|
||||
|
||||
<MarkupGrid
|
||||
id="testList"
|
||||
itemSize="[860,40]"
|
||||
itemSpacing="[0,20]"
|
||||
numColumns="1"
|
||||
numRows="7"
|
||||
vertFocusAnimationStyle="floatingFocus"
|
||||
translation="[50,80]"
|
||||
itemComponentName="InvidiousInstanceTestingItem" />
|
||||
<Button
|
||||
id="closeButton"
|
||||
text="Close"
|
||||
minWidth="0"
|
||||
showFocusFootprint="true"
|
||||
translation="[404,506]" />
|
||||
</Rectangle>
|
||||
</children>
|
||||
</component>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.busySpinner = m.top.findNode("busySpinner")
|
||||
m.busyspinner.poster.width = 40
|
||||
m.busyspinner.poster.height = 40
|
||||
|
||||
m.nameLabel = m.top.findNode("nameLabel")
|
||||
m.detailsLabel = m.top.findNode("detailsLabel")
|
||||
end function
|
||||
|
||||
function OnContentSet() as void
|
||||
content = m.top.itemContent
|
||||
|
||||
m.nameLabel.text = content.title
|
||||
m.top.state = content.state
|
||||
end function
|
||||
|
||||
function OnStateChange()
|
||||
if m.top.state = "loading"
|
||||
m.busySpinner.poster.uri = "pkg:/images/spinner.png"
|
||||
m.busySpinner.control = "start"
|
||||
else if m.top.state = "failed"
|
||||
m.busySpinner.poster.uri = "pkg:/images/icons/test-failed.png"
|
||||
m.busySpinner.control = "stop"
|
||||
m.busySpinner.poster.rotation = 0
|
||||
else if m.top.state = "passed"
|
||||
m.busySpinner.poster.uri = "pkg:/images/icons/test-passed.png"
|
||||
m.busySpinner.control = "stop"
|
||||
m.busySpinner.poster.rotation = 0
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnItemHasFocusChange() as void
|
||||
if m.top.itemContent = invalid
|
||||
m.detailsLabel.visible = false
|
||||
return
|
||||
end if
|
||||
m.detailsLabel.visible = m.top.itemHasFocus and not StringUtils.IsNullOrEmpty(m.top.itemContent.details)
|
||||
end function
|
||||
|
||||
function OnFocusPercentChange() as void
|
||||
if m.top.itemContent = invalid or not m.top.gridHasFocus
|
||||
m.detailsLabel.visible = false
|
||||
return
|
||||
end if
|
||||
m.detailsLabel.visible = m.top.focusPercent > 0.5 and not StringUtils.IsNullOrEmpty(m.top.itemContent.details)
|
||||
end function
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousInstanceTestingItem" extends="Group">
|
||||
<interface>
|
||||
<field id="itemContent" type="node" onChange="OnContentSet" />
|
||||
<field id="state" type="string" onChange="OnStateChange" />
|
||||
<field id="gridHasFocus" type="boolean" />
|
||||
<field id="itemHasFocus" type="boolean" onChange="OnItemHasFocusChange" />
|
||||
<field id="focusPercent" type="float" onChange="OnFocusPercentChange" />
|
||||
</interface>
|
||||
<children>
|
||||
<BusySpinner
|
||||
id="busySpinner"
|
||||
translation="[5,0]" />
|
||||
<Label
|
||||
id="nameLabel"
|
||||
width="450"
|
||||
translation="[60,10]" />
|
||||
<Label
|
||||
id="detailsLabel"
|
||||
visible="false"
|
||||
horizAlign="right"
|
||||
width="300"
|
||||
text="Press 'OK' for details"
|
||||
translation="[560,10]" />
|
||||
</children>
|
||||
</component>
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
@asynctask
|
||||
function InvidiousInstanceTestingTask(input as object) as object
|
||||
instance = input.instance
|
||||
listNode = input.listNode
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
content = PrepareTests()
|
||||
listNode.content = content
|
||||
|
||||
RunTests(instance, content)
|
||||
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function PrepareTests() as object
|
||||
content = CreateObject("roSGNode", "ContentNode")
|
||||
content.AppendChild(CreateTestNode("Valid url", IsValidUrl))
|
||||
content.AppendChild(CreateTestNode("Instance reachable", IsReachable))
|
||||
content.AppendChild(CreateTestNode("Fetch video details", CanFetchVideoDetails))
|
||||
content.AppendChild(CreateTestNode("Fetch video comments", CanFetchVideoComments))
|
||||
content.AppendChild(CreateTestNode("Fetch video captions", CanFetchVideoCaptions))
|
||||
return content
|
||||
end function
|
||||
|
||||
function CreateTestNode(title as string, func as function) as object
|
||||
testNode = CreateObject("roSGNode", "ContentNode")
|
||||
testNode.title = title
|
||||
testNode.AddFields({
|
||||
func: FuncName(func),
|
||||
state: "loading",
|
||||
details: "",
|
||||
duration: 0
|
||||
})
|
||||
m[testNode.func] = func
|
||||
return testNode
|
||||
end function
|
||||
|
||||
function RunTests(instance as string, content as object) as void
|
||||
testNodes = content.getChildren(-1, 0)
|
||||
|
||||
timer = CreateObject("roTimespan")
|
||||
|
||||
for each testNode in testNodes
|
||||
timer.Mark()
|
||||
m[testNode.func](instance, testNode)
|
||||
testNode.duration = timer.TotalMilliseconds()
|
||||
|
||||
if m.top.cancel
|
||||
return
|
||||
end if
|
||||
end for
|
||||
end function
|
||||
|
||||
function IsValidUrl(instance as string, testNode as object) as void
|
||||
try
|
||||
if not instance.StartsWith("http://") and not instance.StartsWith("https://")
|
||||
testNode.state = "failed"
|
||||
testNode.details = "Url must start with http:// or https://"
|
||||
return
|
||||
end if
|
||||
if instance.EndsWith("/")
|
||||
testNode.state = "failed"
|
||||
testNode.details = "Url must not end with /"
|
||||
return
|
||||
end if
|
||||
|
||||
testNode.state = "passed"
|
||||
testNode.details = "The url seems to be of a valid format"
|
||||
catch e
|
||||
testNode.state = "failed"
|
||||
testNode.details = ErrorUtils.Format(e)
|
||||
end try
|
||||
end function
|
||||
|
||||
function IsReachable(instance as string, testNode as object) as void
|
||||
try
|
||||
url = `${instance}${Invidious.STATS_ENDPOINT}`
|
||||
response = HttpClient.Get(url).NoCache().Await()
|
||||
if not response.IsSuccess()
|
||||
testNode.state = "failed"
|
||||
testNode.details = response.ErrorMessage()
|
||||
return
|
||||
end if
|
||||
|
||||
json = response.Json()
|
||||
if json = invalid
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url}`
|
||||
return
|
||||
end if
|
||||
|
||||
name = json.software?.name
|
||||
if not IsString(name)
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url} (couldn't read software.name)`
|
||||
return
|
||||
end if
|
||||
|
||||
version = json.software?.version
|
||||
if not IsString(version)
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url} (couldn't read software.version)`
|
||||
return
|
||||
end if
|
||||
|
||||
testNode.state = "passed"
|
||||
testNode.details = `The instance is reachable and running ${name} version ${version}`
|
||||
catch e
|
||||
testNode.state = "failed"
|
||||
testNode.details = ErrorUtils.Format(e)
|
||||
end try
|
||||
|
||||
end function
|
||||
|
||||
function CanFetchVideoDetails(instance as string, testNode as object) as void
|
||||
try
|
||||
videoId = "jNQXAC9IVRw"
|
||||
url = `${instance}${Invidious.VIDEOS_ENDPOINT}/${videoId}`
|
||||
response = HttpClient.Get(url).NoCache().Await()
|
||||
|
||||
if not response.IsSuccess()
|
||||
testNode.state = "failed"
|
||||
testNode.details = response.ErrorMessage()
|
||||
return
|
||||
end if
|
||||
|
||||
json = response.Json()
|
||||
if json = invalid
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url}`
|
||||
return
|
||||
end if
|
||||
|
||||
title = json.title
|
||||
if not IsString(title)
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url} (couldn't read title)`
|
||||
return
|
||||
end if
|
||||
|
||||
testNode.state = "passed"
|
||||
testNode.details = `The instance can fetch video details for id "${videoId}" (${title})`
|
||||
catch e
|
||||
testNode.state = "failed"
|
||||
testNode.details = ErrorUtils.Format(e)
|
||||
end try
|
||||
end function
|
||||
|
||||
function CanFetchVideoComments(instance as string, testNode as object) as void
|
||||
try
|
||||
videoId = "jNQXAC9IVRw"
|
||||
url = `${instance}/api/v1/comments/${videoId}`
|
||||
response = HttpClient.Get(url).NoCache().Await()
|
||||
|
||||
if not response.IsSuccess()
|
||||
testNode.state = "failed"
|
||||
testNode.details = response.ErrorMessage()
|
||||
return
|
||||
end if
|
||||
|
||||
json = response.Json()
|
||||
if json = invalid
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url}`
|
||||
return
|
||||
end if
|
||||
|
||||
commentCount = json.commentCount
|
||||
if not IsInt(commentCount)
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url} (couldn't read commentCount)`
|
||||
return
|
||||
end if
|
||||
|
||||
comments = json.comments
|
||||
if not IsArray(comments)
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid json from ${url} (couldn't read comments)`
|
||||
return
|
||||
end if
|
||||
|
||||
testNode.state = "passed"
|
||||
testNode.details = `The instance can fetch video comments for id "${videoId}" (${commentCount} comments)`
|
||||
catch e
|
||||
testNode.state = "failed"
|
||||
testNode.details = ErrorUtils.Format(e)
|
||||
end try
|
||||
end function
|
||||
|
||||
function CanFetchVideoCaptions(instance as string, testNode as object) as void
|
||||
try
|
||||
videoId = "jNQXAC9IVRw"
|
||||
label = "English"
|
||||
url = `${instance}/api/v1/captions/${videoId}?label=${label}`
|
||||
response = HttpClient.Get(url).NoCache().Await()
|
||||
|
||||
if not response.IsSuccess()
|
||||
testNode.state = "failed"
|
||||
testNode.details = response.ErrorMessage()
|
||||
return
|
||||
end if
|
||||
|
||||
headers = response.Headers()
|
||||
contentType = headers["Content-Type"]
|
||||
if StringUtils.IsNullOrEmpty(contentType) or not contentType.StartsWith("text/vtt")
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid caption data ${url} (Content-Type is not text/vtt)`
|
||||
return
|
||||
end if
|
||||
|
||||
text = response.Text()
|
||||
if StringUtils.IsNullOrEmpty(text) or not text.StartsWith("WEBVTT")
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Invalid caption data from ${url} (response is not a valid vtt file)`
|
||||
return
|
||||
end if
|
||||
|
||||
if text.InStr(`All right, so here we are, in front of the\nelephants`) = -1
|
||||
testNode.state = "failed"
|
||||
testNode.details = `Did not find expected text in caption data from ${url}`
|
||||
return
|
||||
end if
|
||||
|
||||
testNode.state = "passed"
|
||||
testNode.details = `The instance can fetch video ${label} captions for id "${videoId}"`
|
||||
catch e
|
||||
testNode.state = "failed"
|
||||
testNode.details = ErrorUtils.Format(e)
|
||||
end try
|
||||
end function
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/Screens/SettingsScreen/InvidiousInstance/InvidiousPublicInstances/InvidiousPublicInstancesTask.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
|
||||
function Init()
|
||||
m.log = new log.Logger("InvidiousPublicInstances")
|
||||
|
||||
m.failedLabel = m.top.findNode("failedLabel")
|
||||
m.refreshButton = m.top.findNode("refreshButton")
|
||||
m.instances = m.top.findNode("instances")
|
||||
m.instancesHeader = m.top.findNode("instancesHeader")
|
||||
|
||||
m.busySpinner = m.top.findNode("busySpinner")
|
||||
m.busyspinner.poster.width = 100
|
||||
m.busyspinner.poster.height = 100
|
||||
m.busySpinner.poster.uri = "pkg:/images/spinner.png"
|
||||
|
||||
m.instances.ObserveField("itemSelected", FuncName(OnInstanceSelected))
|
||||
m.refreshButton.ObserveField("buttonSelected", FuncName(Refresh))
|
||||
Refresh()
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
if m.refreshButton.visible
|
||||
NodeSetFocus(m.refreshButton, true)
|
||||
else
|
||||
NodeSetFocus(m.instances, true)
|
||||
end if
|
||||
end function
|
||||
|
||||
function Refresh()
|
||||
m.top.focusable = false
|
||||
m.instances.visible = false
|
||||
m.instancesHeader.visible = false
|
||||
m.failedLabel.visible = false
|
||||
m.refreshButton.visible = false
|
||||
if m.invidiousPublicInstancesTask <> invalid
|
||||
m.invidiousPublicInstancesTask.cancel = true
|
||||
end if
|
||||
|
||||
m.invidiousPublicInstancesTask = StartAsyncTask(InvidiousPublicInstancesTask, {
|
||||
listNode: m.instances
|
||||
}, OnInvidiousPublicInstancesTaskResults)
|
||||
|
||||
m.busySpinner.visible = true
|
||||
m.busySpinner.control = "start"
|
||||
end function
|
||||
|
||||
function OnInvidiousPublicInstancesTaskResults(output as object) as void
|
||||
m.top.focusable = true
|
||||
m.busySpinner.visible = false
|
||||
m.busySpinner.control = "stop"
|
||||
|
||||
m.invidiousPublicInstancesTask = invalid
|
||||
if output.cancelled
|
||||
return
|
||||
end if
|
||||
|
||||
if not output.success or not output.result.success
|
||||
' output.error for unhandled exception
|
||||
error = output.error
|
||||
if error = invalid
|
||||
' output.result.error for network errors
|
||||
error = output.result.error
|
||||
end if
|
||||
error = ErrorUtils.Format(error)
|
||||
m.log.error(output.error)
|
||||
|
||||
message = `Failed to load Invidious public instances\n${error}`
|
||||
DialogUtils.ShowDialog(message, "Invidious public instances load error", true)
|
||||
|
||||
m.failedLabel.visible = true
|
||||
m.refreshButton.visible = true
|
||||
if m.top.IsInFocusChain()
|
||||
NodeSetFocus(m.top, true)
|
||||
end if
|
||||
return
|
||||
end if
|
||||
|
||||
m.instances.visible = true
|
||||
m.instancesHeader.visible = true
|
||||
|
||||
if m.top.IsInFocusChain()
|
||||
NodeSetFocus(m.top, true)
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnInstanceSelected(event as object) as void
|
||||
selected = m.instances.itemSelected
|
||||
itemContent = m.instances.content.GetChild(selected)
|
||||
m.top.instance = itemContent.uri
|
||||
end function
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousPublicInstances" extends="Group" includes="Focus">
|
||||
<interface>
|
||||
<field id="instance" type="string" />
|
||||
</interface>
|
||||
<children>
|
||||
<BusySpinner
|
||||
id="busySpinner"
|
||||
translation="[380,96]" />
|
||||
<Label
|
||||
id="failedLabel"
|
||||
text="Failed to load Invidious public instances."
|
||||
translation="[190,60]" />
|
||||
<Button
|
||||
id="refreshButton"
|
||||
minWidth="0"
|
||||
text="Refresh"
|
||||
translation="[340,130]" />
|
||||
|
||||
<InvidiousPublicInstancesListItem id="instancesHeader">
|
||||
<InvidiousPublicInstancesListItemContent
|
||||
role="itemContent"
|
||||
name="name"
|
||||
version="version"
|
||||
users="users"
|
||||
signup="signup"
|
||||
location="location"
|
||||
health="health" />
|
||||
</InvidiousPublicInstancesListItem>
|
||||
|
||||
<MarkupGrid
|
||||
id="instances"
|
||||
itemComponentName="InvidiousPublicInstancesListItem"
|
||||
itemSize="[860,16]"
|
||||
itemSpacing="[0,20]"
|
||||
numColumns="1"
|
||||
numRows="7"
|
||||
vertFocusAnimationStyle="floatingFocus"
|
||||
translation="[0,46]" />
|
||||
|
||||
</children>
|
||||
</component>
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
function Init()
|
||||
m.nameLabel = m.top.findNode("nameLabel")
|
||||
m.versionLabel = m.top.findNode("versionLabel")
|
||||
m.usersLabel = m.top.findNode("usersLabel")
|
||||
m.signupLabel = m.top.findNode("signupLabel")
|
||||
m.locationLabel = m.top.findNode("locationLabel")
|
||||
m.flagEmoji = m.top.findNode("flagEmoji")
|
||||
m.healthLabel = m.top.findNode("healthLabel")
|
||||
|
||||
end function
|
||||
|
||||
function OnContentSet() as void
|
||||
content = m.top.itemContent
|
||||
|
||||
m.nameLabel.text = content.name
|
||||
m.versionLabel.text = content.version
|
||||
m.usersLabel.text = content.users
|
||||
m.signupLabel.text = content.signup
|
||||
m.locationLabel.text = content.location
|
||||
m.flagEmoji.uri = content.flag
|
||||
m.healthLabel.text = content.health
|
||||
end function
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousPublicInstancesListItem" extends="Group">
|
||||
<interface>
|
||||
<field id="itemContent" type="node" onChange="OnContentSet" />
|
||||
</interface>
|
||||
<children>
|
||||
<Label
|
||||
id="nameLabel"
|
||||
font="font:SmallestSystemFont"
|
||||
width="240" />
|
||||
<Label
|
||||
id="versionLabel"
|
||||
font="font:SmallestSystemFont"
|
||||
width="220"
|
||||
translation="[240,0]" />
|
||||
<Label
|
||||
id="usersLabel"
|
||||
font="font:SmallestSystemFont"
|
||||
width="100"
|
||||
translation="[460,0]" />
|
||||
<Label
|
||||
id="signupLabel"
|
||||
font="font:SmallestSystemFont"
|
||||
width="90"
|
||||
translation="[550,0]" />
|
||||
<Label
|
||||
id="locationLabel"
|
||||
font="font:SmallestSystemFont"
|
||||
width="100"
|
||||
translation="[650,0]" />
|
||||
<Poster
|
||||
id="flagEmoji"
|
||||
width="16"
|
||||
height="16"
|
||||
translation="[650,0]" />
|
||||
<Label
|
||||
id="healthLabel"
|
||||
font="font:SmallestSystemFont"
|
||||
width="100"
|
||||
translation="[750,0]" />
|
||||
</children>
|
||||
</component>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component name="InvidiousPublicInstancesListItemContent" extends="ContentNode">
|
||||
<interface>
|
||||
<field id="name" type="string" />
|
||||
<field id="version" type="string" />
|
||||
<field id="users" type="string" />
|
||||
<field id="signup" type="string" />
|
||||
<field id="location" type="string" />
|
||||
<field id="flag" type="string" />
|
||||
<field id="health" type="string" />
|
||||
<field id="uri" type="string" />
|
||||
</interface>
|
||||
</component>
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
|
||||
@asynctask
|
||||
function InvidiousPublicInstancesTask(input as object) as object
|
||||
listNode = input.listNode
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
response = HttpClient.Get(Invidious.INSTANCES_API).Await()
|
||||
instances = response.Json()
|
||||
|
||||
if not response.IsSuccess() or instances = invalid
|
||||
return {
|
||||
success: false,
|
||||
error: response.ErrorMessage()
|
||||
}
|
||||
end if
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
instances = FilterInstances(instances)
|
||||
|
||||
content = CreateObject("roSGNode", "ContentNode")
|
||||
|
||||
for each instance in instances
|
||||
item = CreateObject("roSGNode", "InvidiousPublicInstancesListItemContent")
|
||||
item.setFields({
|
||||
name: instance[0],
|
||||
version: instance[1].stats.software.version,
|
||||
users: instance[1].stats.usage.users.total,
|
||||
signup: instance[1].stats.openRegistrations ? "Yes" : "No",
|
||||
' Leave 5 spaces for the flag, just to simplify the layout
|
||||
location: ` ${instance[1].region}`,
|
||||
flag: GetFlagUrl(instance[1].flag),
|
||||
health: instance[1].monitor["30dRatio"].ratio,
|
||||
uri: instance[1].uri
|
||||
})
|
||||
content.AppendChild(item)
|
||||
end for
|
||||
|
||||
listNode.content = content
|
||||
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
end function
|
||||
|
||||
function FilterInstances(instances as object) as object
|
||||
filtered = []
|
||||
|
||||
for each instance in instances
|
||||
flags = instance[1]
|
||||
if flags.type = "https" and flags.api = true and flags.cors = true
|
||||
filtered.Push(instance)
|
||||
end if
|
||||
end for
|
||||
|
||||
return filtered
|
||||
end function
|
||||
|
||||
function GetFlagUrl(flag as string) as string
|
||||
codePoint = emojiToCodePoint(flag)
|
||||
return `https://github.githubassets.com/images/icons/emoji/unicode/${codePoint}.png?v8`
|
||||
end function
|
||||
|
||||
function emojiToCodePoint(emoji as string) as string
|
||||
codes = []
|
||||
chars = emoji.Split("")
|
||||
for i = 0 to chars.count() - 1
|
||||
c = Asc(chars[i])
|
||||
codes.push(StrI(c, 16))
|
||||
end for
|
||||
return codes.join("-")
|
||||
end function
|
||||
+47
-28
@@ -1,19 +1,34 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.top.focusable = true
|
||||
m.radioButtonList = m.top.findNode("RadioButtonList")
|
||||
m.radioButtonListContent = m.top.findNode("RadioButtonListContent")
|
||||
|
||||
m.top.observeField("value", "OnValueChanged")
|
||||
m.top.observeField("options", "OnOptionsChanged")
|
||||
m.radioButtonList.observeField("checkedItem", "OnCheckedItemChanged")
|
||||
m.top.observeField("focusedChild", "OnFocusChanged")
|
||||
m.top.observeField("settings", "OnSettingsScreen")
|
||||
m.top.itemSpacings = [8]
|
||||
m.radioButtonList.observeField("checkedItem", FuncName(OnCheckedItemChange))
|
||||
end function
|
||||
|
||||
function OnSettingsScreen()
|
||||
m.top.value = m.top.settings@.GetPreferenceValue(m.top.key)
|
||||
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 OnValueChanged()
|
||||
function OnPreferenceChange()
|
||||
m.top.value = m.preferences[m.key]
|
||||
end function
|
||||
|
||||
function OnValueChange() as void
|
||||
value = m.top.value
|
||||
options = m.top.options
|
||||
|
||||
@@ -28,29 +43,14 @@ function OnValueChanged()
|
||||
|
||||
m.radioButtonList.checkedItem = checkedItem
|
||||
|
||||
m.top.settings@.SetPreferenceValue(m.top.key, value)
|
||||
end function
|
||||
|
||||
function OnCheckedItemChanged()
|
||||
checkedItem = m.radioButtonList.checkedItem
|
||||
options = m.top.options
|
||||
|
||||
if checkedItem >= 0 and checkedItem < options.Count()
|
||||
m.top.value = options[checkedItem].value
|
||||
if m.preferences = invalid or m.key = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
m.preferences[m.key] = m.top.value
|
||||
end function
|
||||
|
||||
function OnFocusChanged()
|
||||
if m.top.hasFocus()
|
||||
m.radioButtonList.setFocus(true)
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
return m.top.settings@.OnkeyEvent(key, press)
|
||||
end function
|
||||
|
||||
function OnOptionsChanged()
|
||||
function OnOptionsChange()
|
||||
options = m.top.options
|
||||
|
||||
m.radioButtonListContent.removeChildrenIndex(m.radioButtonListContent.getChildCount(), 0)
|
||||
@@ -60,4 +60,23 @@ function OnOptionsChanged()
|
||||
node.title = option
|
||||
m.radioButtonListContent.appendChild(node)
|
||||
end for
|
||||
|
||||
OnValueChange()
|
||||
end function
|
||||
|
||||
function OnCheckedItemChange()
|
||||
checkedItem = m.radioButtonList.checkedItem
|
||||
options = m.top.options
|
||||
|
||||
if checkedItem >= 0 and checkedItem < options.Count()
|
||||
m.top.value = options[checkedItem].value
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.radioButtonList, true)
|
||||
end function
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="RadioControl" extends="LayoutGroup" includes="Focus">
|
||||
<interface>
|
||||
<field id="displayText" type="string" alias="DisplayTextLabel.text" />
|
||||
<field id="description" type="string" alias="DescriptionLabel.text" />
|
||||
<field id="value" type="string" onChange="OnValueChange" />
|
||||
<field id="options" type="array" onChange="OnOptionsChange" />
|
||||
<function name="BindPreference" />
|
||||
</interface>
|
||||
<children>
|
||||
<Label id="DisplayTextLabel" width="450" />
|
||||
<Label id="DescriptionLabel"
|
||||
width="450"
|
||||
color="0xb4b4b4ff"
|
||||
wrap="true">
|
||||
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||
</Label>
|
||||
<RadioButtonList id="RadioButtonList" vertFocusAnimationStyle="floatingFocus">
|
||||
<ContentNode id="RadioButtonListContent" role="content" />
|
||||
</RadioButtonList>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,36 @@
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.container = m.top.findNode("Container")
|
||||
m.displayTextLabel = m.top.findNode("DisplayTextLabel")
|
||||
m.descriptionLabel = m.top.findNode("DescriptionLabel")
|
||||
|
||||
m.displayTextLabel.color = m.top.textColor
|
||||
m.descriptionLabel.color = m.top.textColor2
|
||||
|
||||
m.top.iconUri = ""
|
||||
m.top.focusedIconUri = ""
|
||||
m.top.focusFootprintBitmapUri = "pkg:/images/white.9.png"
|
||||
m.top.observeField("focusedChild", FuncName(OnFocusedChildChange))
|
||||
end function
|
||||
|
||||
function Resize()
|
||||
rect = m.container.boundingRect()
|
||||
width = rect.width + m.top.padding * 2
|
||||
height = rect.height + m.top.padding * 2
|
||||
|
||||
m.top.minWidth = width < m.top.minimumWidth ? m.top.minimumWidth : width
|
||||
m.top.height = height
|
||||
|
||||
m.container.translation = [m.top.padding, m.top.padding]
|
||||
end function
|
||||
|
||||
function OnFocusedChildChange()
|
||||
if m.top.hasFocus()
|
||||
m.displayTextLabel.color = m.top.focusedTextColor
|
||||
m.descriptionLabel.color = m.top.focusedTextColor2
|
||||
else
|
||||
m.displayTextLabel.color = m.top.textColor
|
||||
m.descriptionLabel.color = m.top.textColor2
|
||||
end if
|
||||
end function
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="SettingCategory" extends="Button">
|
||||
<interface>
|
||||
<field id="padding" type="integer" value="10" onChange="Resize" />
|
||||
<field id="minimumWidth" type="integer" value="280" onChange="Resize" />
|
||||
<field id="displayText" type="string" alias="DisplayTextLabel.text" onChange="Resize" />
|
||||
<field id="description" type="string" alias="DescriptionLabel.text" onChange="Resize" />
|
||||
<field id="textColor2" type="Color" value="0xb4b4b4ff" />
|
||||
<field id="focusedTextColor2" type="Color" value="0x262626ff" />
|
||||
</interface>
|
||||
<children>
|
||||
<LayoutGroup id="Container" itemSpacings="[5]">
|
||||
<SimpleLabel
|
||||
id="DisplayTextLabel"
|
||||
fontUri="font:SystemFontFile"
|
||||
fontSize="34" />
|
||||
<SimpleLabel id="DescriptionLabel"
|
||||
fontUri="font:SystemFontFile"
|
||||
fontSize="18"
|
||||
translation="[0,42]" />
|
||||
</LayoutGroup>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,202 @@
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/components/Navigation/ScrollTo.bs"
|
||||
|
||||
function Init()
|
||||
m.container = m.top.findNode("Container")
|
||||
m.scrollAnimation = m.top.findNode("scrollAnimation")
|
||||
m.scrollAnimationInterpolator = m.scrollAnimation.findNode("scrollAnimationInterpolator")
|
||||
m.viewport = {
|
||||
x: 150,
|
||||
y: 96,
|
||||
width: 1920,
|
||||
height: 550
|
||||
}
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
startX = 150
|
||||
startY = 100
|
||||
|
||||
controlsX = 400
|
||||
|
||||
categorySpacing = 80
|
||||
controlSpacing = 30
|
||||
|
||||
model = m.preferences.prefsModel
|
||||
previousCategory = invalid
|
||||
previousControl = invalid
|
||||
for each item in model
|
||||
container = m.container.createChild("Group")
|
||||
category = CreateCategoryNode(item, container, startX, startY)
|
||||
if m.firstCategory = invalid
|
||||
m.firstCategory = category.node
|
||||
m.currentNavigtionNode = m.firstCategory
|
||||
end if
|
||||
if previousCategory <> invalid
|
||||
SetNavigation(previousCategory.node, "down", category.node)
|
||||
SetNavigation(category.node, "up", previousCategory.node)
|
||||
end if
|
||||
controls = CreateControls(item, container, startX + controlsX, startY, controlSpacing)
|
||||
|
||||
if controls <> invalid
|
||||
if controls.nodes.Count() > 0
|
||||
SetNavigation(category.node, "right", controls.nodes[0])
|
||||
end if
|
||||
|
||||
for each control in controls.nodes
|
||||
SetNavigation(control, "left", category.node)
|
||||
|
||||
if previousControl <> invalid
|
||||
SetNavigation(previousControl, "down", control)
|
||||
SetNavigation(control, "up", previousControl)
|
||||
end if
|
||||
|
||||
previousControl = control
|
||||
end for
|
||||
end if
|
||||
|
||||
categoryRect = category.rect
|
||||
controlsRect = controls.rect
|
||||
|
||||
maxHeight = categoryRect.height > controlsRect.height ? categoryRect.height : controlsRect.height
|
||||
startY += maxHeight + categorySpacing
|
||||
previousCategory = category
|
||||
end for
|
||||
|
||||
SetNavigation(invalid, "back", m.navBar)
|
||||
SetNavigation(invalid, "left", m.navBar)
|
||||
end function
|
||||
|
||||
function CreateCategoryNode(item as object, container as object, startX as integer, startY as integer) as object
|
||||
node = container.createChild("SettingCategory")
|
||||
node.translation = [startX, startY]
|
||||
node.displayText = item.displayText
|
||||
node.description = item.description
|
||||
return {
|
||||
node: node,
|
||||
rect: node.boundingRect()
|
||||
}
|
||||
end function
|
||||
|
||||
function CreateControls(item as object, container as object, startX as integer, startY as integer, controlSpacing as integer) as object
|
||||
if item.children = invalid
|
||||
return invalid
|
||||
end if
|
||||
x = startX
|
||||
y = startY
|
||||
width = 0
|
||||
height = 0
|
||||
|
||||
nodes = []
|
||||
for each child in item.children
|
||||
if child.visibility = "web"
|
||||
continue for
|
||||
end if
|
||||
control = CreateControl(child, container, startX, startY)
|
||||
if control <> invalid
|
||||
nodes.push(control.node)
|
||||
controlRect = control.rect
|
||||
startY += controlRect.height + controlSpacing
|
||||
if controlRect.width > width
|
||||
width = controlRect.width
|
||||
end if
|
||||
height += controlRect.height + controlSpacing
|
||||
end if
|
||||
end for
|
||||
|
||||
return {
|
||||
nodes: nodes,
|
||||
rect: {
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height
|
||||
}
|
||||
}
|
||||
end function
|
||||
|
||||
function CreateControl(item as object, container as object, startX as integer, startY as integer) as object
|
||||
control = invalid
|
||||
|
||||
if item.type = "boolean"
|
||||
control = CreateBooleanControl(item, container)
|
||||
else if item.type = "radio"
|
||||
control = CreateRadioControl(item, container)
|
||||
else if item.type = "string"
|
||||
control = CreateStringControl(item, container)
|
||||
else if item.rokuComponent <> invalid
|
||||
control = CreateRokuComponent(item, container)
|
||||
end if
|
||||
|
||||
if control = invalid
|
||||
return invalid
|
||||
end if
|
||||
|
||||
control.id = `preference.${item.key}`
|
||||
control.translation = [startX, startY]
|
||||
if control.hasField("binding_done")
|
||||
control@.BindNode(invalid)
|
||||
end if
|
||||
control@.BindPreference(m.preferences, item.key)
|
||||
|
||||
return {
|
||||
node: control,
|
||||
rect: control.boundingRect()
|
||||
}
|
||||
end function
|
||||
|
||||
function CreateBooleanControl(item as object, container as object) as object
|
||||
node = container.createChild("BooleanControl")
|
||||
node.displayText = item.displayText
|
||||
node.description = item.description
|
||||
return node
|
||||
end function
|
||||
|
||||
function CreateRadioControl(item as object, container as object) as object
|
||||
node = container.createChild("RadioControl")
|
||||
node.displayText = item.displayText
|
||||
node.description = item.description
|
||||
node.options = item.options
|
||||
return node
|
||||
end function
|
||||
|
||||
function CreateStringControl(item as object, container as object) as object
|
||||
node = container.createChild("StringControl")
|
||||
node.displayText = item.displayText
|
||||
node.description = item.description
|
||||
return node
|
||||
end function
|
||||
|
||||
function CreateRokuComponent(item as object, container as object) as object
|
||||
node = container.createChild(item.rokuComponent)
|
||||
if node.hasField("displayText")
|
||||
node.displayText = item.displayText
|
||||
end if
|
||||
if node.hasField("description")
|
||||
node.description = item.description
|
||||
end if
|
||||
return node
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
navigation = NavigationKeyHandler(key, press)
|
||||
if navigation.handled
|
||||
m.currentNavigtionNode = navigation.node
|
||||
if m.currentNavigtionNode.isSameNode(m.navBar)
|
||||
m.currentNavigtionNode = m.firstCategory
|
||||
end if
|
||||
ScrollTo(m.viewport, m.container, m.currentNavigtionNode.getParent(), m.scrollAnimation, m.scrollAnimationInterpolator)
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.currentNavigtionNode, true)
|
||||
ScrollTo(m.viewport, m.container, m.currentNavigtionNode.getParent(), m.scrollAnimation, m.scrollAnimationInterpolator)
|
||||
end function
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="SettingsScreen" extends="Group" includes="AutoBind,Focus">
|
||||
<interface>
|
||||
<field id="navBar" type="node" bind="/NavBar" />
|
||||
<field id="preferences" type="node" bind="/Preferences" />
|
||||
</interface>
|
||||
<children>
|
||||
<Group id="container">
|
||||
<Animation
|
||||
id="scrollAnimation"
|
||||
duration="0.3">
|
||||
<Vector2DFieldInterpolator
|
||||
id="scrollAnimationInterpolator"
|
||||
key="[ 0.0, 0.5, 1.0 ]"
|
||||
keyValue="[ [0.0,0.0], [0.0,-160.0], [0.0,-320.0]]"
|
||||
fieldToInterp="container.translation" />
|
||||
</Animation>
|
||||
|
||||
</Group>
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,84 @@
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.top.focusable = true
|
||||
m.top.itemSpacings = [8]
|
||||
|
||||
m.button = m.top.findNode("button")
|
||||
AdjustButtonLabel(m.button)
|
||||
|
||||
m.button.observeField("buttonSelected", FuncName(ShowEditKeyboard))
|
||||
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 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
|
||||
|
||||
function OnFocusChange() as void
|
||||
if not m.top.focus
|
||||
return
|
||||
end if
|
||||
|
||||
NodeSetFocus(m.button, true)
|
||||
end function
|
||||
|
||||
function ShowEditKeyboard()
|
||||
keyboardDialog = createObject("roSGNode", "StandardKeyboardDialog")
|
||||
keyboardDialog.title = m.top.displayText
|
||||
keyboardDialog.message = [m.top.description]
|
||||
keyboardDialog.text = m.top.value
|
||||
keyboardDialog.buttons = ["OK", "Cancel"]
|
||||
keyboardDialog.observeField("buttonSelected", FuncName(OnKeyboardButton))
|
||||
|
||||
m.top.getScene().dialog = keyboardDialog
|
||||
end function
|
||||
|
||||
function OnKeyboardButton(event as object)
|
||||
keyboard = event.getRoSGNode()
|
||||
buttonSelected = keyboard.buttonSelected
|
||||
if buttonSelected = 0
|
||||
m.top.value = keyboard.text
|
||||
end if
|
||||
keyboard.close = true
|
||||
end function
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="StringControl" extends="LayoutGroup" includes="Focus">
|
||||
<interface>
|
||||
<field id="displayText" type="string" alias="DisplayTextLabel.text" />
|
||||
<field id="description" type="string" alias="DescriptionLabel.text" />
|
||||
<field id="value" type="string" alias="Button.text" onChange="OnValueChange" />
|
||||
<function name="BindPreference" />
|
||||
</interface>
|
||||
<children>
|
||||
<Label id="DisplayTextLabel" width="450" />
|
||||
<Label id="DescriptionLabel"
|
||||
width="450"
|
||||
color="0xb4b4b4ff"
|
||||
wrap="true">
|
||||
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||
</Label>
|
||||
<Button id="Button"
|
||||
iconUri=""
|
||||
focusedIconUri=""
|
||||
showFocusFootprint="true"
|
||||
minWidth="420" />
|
||||
</children>
|
||||
</component>
|
||||
@@ -0,0 +1,8 @@
|
||||
@asynctask
|
||||
function GenerateQrCodeTask(input as object)
|
||||
' TODO:P1 QR Code generation is happening on UI thread and is hanging for a second
|
||||
' Needs to be properly decoupled from Node logic
|
||||
qrPoster = input.qrPoster
|
||||
text = input.text
|
||||
qrPoster.text = text
|
||||
end function
|
||||
@@ -0,0 +1,26 @@
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/Screens/WebAppScreen/GenerateQrCodeTask.bs"
|
||||
|
||||
function Init()
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
address = m.webserver@.GetServerAddress(invalid)
|
||||
isValidIp = not StringUtils.IsNullOrEmpty(address)
|
||||
if isValidIp
|
||||
m.top.url = address
|
||||
end if
|
||||
m.top.findNode("noInternet").visible = not isValidIp
|
||||
m.top.findNode("yesInternet").visible = isValidIp
|
||||
end function
|
||||
|
||||
function OnUrlSet()
|
||||
url = m.top.url
|
||||
|
||||
urlLabel = m.top.findNode("urlLabel")
|
||||
urlLabel.text = url
|
||||
|
||||
qrCode = m.top.findNode("QrCodePoster")
|
||||
StartAsyncTask(GenerateQrCodeTask, { qrPoster: qrCode, text: url })
|
||||
end function
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="WebAppScreen" extends="Group" includes="AutoBind">
|
||||
<interface>
|
||||
<field id="webServer" type="node" bind="/WebServer" />
|
||||
<field id="url" type="string" onChange="OnUrlSet" />
|
||||
<field id="qrCodeUrl" type="string" onChange="OnUrlSet" />
|
||||
</interface>
|
||||
<children>
|
||||
<Group id="noInternet" visible="false">
|
||||
<Label
|
||||
height='720'
|
||||
width='1280'
|
||||
font='font:MediumBoldSystemFont'
|
||||
horizAlign="center"
|
||||
vertAlign="center"
|
||||
text="Could not get IP address: are we connected to the internet?"
|
||||
/>
|
||||
</Group>
|
||||
<Group id="yesInternet" visible="false">
|
||||
<Label
|
||||
height='60'
|
||||
width='1280'
|
||||
font='font:MediumBoldSystemFont'
|
||||
horizAlign="center"
|
||||
translation="[0,92]"
|
||||
text="Scan the QR code with your phone camera, or open the URL in a web browser:"
|
||||
/>
|
||||
<QRPoster
|
||||
id='QrCodePoster'
|
||||
loadWidth='400'
|
||||
loadHeight='400'
|
||||
loadPadding='20'
|
||||
translation='[440, 160]' />
|
||||
|
||||
<Label
|
||||
id='UrlLabel'
|
||||
height='50'
|
||||
width='1280'
|
||||
font='font:MediumBoldSystemFont'
|
||||
horizAlign="center"
|
||||
translation="[0,600]"
|
||||
/>
|
||||
</Group>
|
||||
</children>
|
||||
</component>
|
||||
@@ -1,233 +0,0 @@
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/components/VideoPlayer/Video.bs"
|
||||
import "pkg:/source/services/SearchHistory.bs"
|
||||
import "pkg:/components/SearchScreen/SearchSuggestionsTask.bs"
|
||||
import "pkg:/components/SearchScreen/SearchTask.bs"
|
||||
|
||||
function Init()
|
||||
m.container = m.top.FindNode("container")
|
||||
m.scrollAnimation = m.top.FindNode("scrollAnimation")
|
||||
m.scrollAnimationInterpolator = m.top.FindNode("scrollAnimationInterpolator")
|
||||
m.keyboard = m.top.FindNode("keyboard")
|
||||
m.suggestions = m.top.FindNode("suggestions")
|
||||
m.rowList = m.top.FindNode("rowList")
|
||||
|
||||
m.keyboard.ObserveField("text", "OnTextChange")
|
||||
m.suggestions.ObserveField("buttonSelected", "OnSearchButtonSelected")
|
||||
m.suggestions.ObserveField("buttonFocused", "OnSearchButtonFocused")
|
||||
m.rowList.ObserveField("rowItemSelected", "OnSearchVideoSelected")
|
||||
m.top.ObserveField("focus", "OnFocusChange")
|
||||
m.top.ObserveField("visible", "OnVisibilityChange")
|
||||
|
||||
' Trigger suggestions
|
||||
OnTextChange()
|
||||
end function
|
||||
|
||||
function OnFocusChange() as void
|
||||
if m.top.focus <> true
|
||||
return
|
||||
end if
|
||||
|
||||
if m.rowlist.content <> invalid
|
||||
m.rowlist.SetFocus(true)
|
||||
ScrollDown()
|
||||
return
|
||||
end if
|
||||
if m.suggestions.buttons.Count() > 0
|
||||
if m.suggestions.buttonFocused >= m.suggestions.buttons.Count()
|
||||
m.suggestions.focusButton = 0
|
||||
end if
|
||||
m.suggestions.SetFocus(true)
|
||||
return
|
||||
end if
|
||||
m.keyboard.SetFocus(true)
|
||||
end function
|
||||
|
||||
function OnTextChange() as void
|
||||
if IsNodeFocused("suggestions")
|
||||
return
|
||||
end if
|
||||
|
||||
if m.searchSuggestionsTask <> invalid
|
||||
m.searchSuggestionsTask.control = "stop"
|
||||
end if
|
||||
|
||||
m.searchSuggestionsTask = StartAsyncTask(SearchSuggestionsTask, {
|
||||
q: m.keyboard.text
|
||||
}, OnSearchSuggestionsTaskResults)
|
||||
end function
|
||||
|
||||
function OnSearchSuggestionsTaskResults(output as object) as void
|
||||
' In case this is an old request, discard suggestions
|
||||
q = output.result.q
|
||||
if q <> m.keyboard.text
|
||||
return
|
||||
end if
|
||||
suggestions = output.result.response
|
||||
if suggestions = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
if q.len() > 0 and ArrayIndexOf(suggestions, q) = -1
|
||||
suggestions.Unshift(q)
|
||||
end if
|
||||
|
||||
' Capture current focused button and restore it after resetting the buttons
|
||||
buttonFocused = -1
|
||||
if IsNodeFocused("suggestions")
|
||||
buttonFocused = m.suggestions.buttonFocused
|
||||
end if
|
||||
if buttonFocused >= m.suggestions.buttons.Count()
|
||||
buttonFocused = m.suggestions.buttons.Count() - 1
|
||||
end if
|
||||
m.suggestions.buttons = suggestions
|
||||
if buttonFocused <> -1
|
||||
m.suggestions.focusButton = buttonFocused
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnSearchButtonSelected()
|
||||
selected = m.suggestions.buttonSelected
|
||||
text = m.suggestions.buttons[selected]
|
||||
SearchHistory.Save(text)
|
||||
Search(text)
|
||||
end function
|
||||
|
||||
function OnSearchButtonFocused() as void
|
||||
if not IsNodeFocused("suggestions")
|
||||
return
|
||||
end if
|
||||
|
||||
selected = m.suggestions.buttonFocused
|
||||
text = m.suggestions.buttons[selected]
|
||||
m.keyboard.text = text
|
||||
end function
|
||||
|
||||
function Search(text as string)
|
||||
if m.searchTask <> invalid
|
||||
m.searchTask.control = "stop"
|
||||
end if
|
||||
|
||||
m.global.loadingIndicator.visible = true
|
||||
m.searchTask = StartAsyncTask(SearchTask, {
|
||||
q: text
|
||||
}, OnSearchTaskResults)
|
||||
end function
|
||||
|
||||
function OnSearchTaskResults(output as object)
|
||||
rootChildren = output.result.rootChildren
|
||||
contentNode = CreateObject("roSGNode", "ContentNode")
|
||||
contentNode.Update({
|
||||
children: rootChildren
|
||||
}, true)
|
||||
m.rowList.content = contentNode
|
||||
m.rowList.SetFocus(true)
|
||||
m.rowList.jumpToRowItem = [0, 0]
|
||||
ScrollDown()
|
||||
m.global.loadingIndicator.visible = false
|
||||
end function
|
||||
|
||||
function OnVisibilityChange()
|
||||
if m.top.visible = false
|
||||
ClearSearch()
|
||||
else
|
||||
OnTextChange()
|
||||
end if
|
||||
end function
|
||||
|
||||
function ClearSearch()
|
||||
m.keyboard.text = ""
|
||||
m.rowlist.content = invalid
|
||||
ScrollUp()
|
||||
end function
|
||||
|
||||
function IsNodeFocused(id as string) as boolean
|
||||
return m.top.focusedChild?.id = id or m.container.focusedChild?.id = id
|
||||
end function
|
||||
|
||||
function ScrollUp() as void
|
||||
destination = m.scrollAnimationInterpolator.keyValue[0][1]
|
||||
current = m.container.translation[1]
|
||||
if current = destination
|
||||
return
|
||||
end if
|
||||
m.scrollAnimationInterpolator.reverse = true
|
||||
m.scrollAnimation.control = "start"
|
||||
end function
|
||||
|
||||
function ScrollDown() as void
|
||||
destination = m.scrollAnimationInterpolator.keyValue[2][1]
|
||||
current = m.container.translation[1]
|
||||
if current = destination
|
||||
return
|
||||
end if
|
||||
m.scrollAnimationInterpolator.reverse = false
|
||||
m.scrollAnimation.control = "start"
|
||||
end function
|
||||
|
||||
function OnSearchVideoSelected(event as object)
|
||||
grid = event.GetRoSGNode()
|
||||
|
||||
selectedPair = event.GetData()
|
||||
selectedRow = selectedPair[0]
|
||||
selectedRowItem = selectedPair[1]
|
||||
|
||||
rowContent = grid.content.GetChild(selectedRow)
|
||||
itemContent = rowContent.GetChild(selectedRowItem)
|
||||
|
||||
videoId = itemContent.videoId
|
||||
PlayVideo(videoId, {
|
||||
metadata: itemContent,
|
||||
sender: m.top
|
||||
})
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
if press = false
|
||||
return false
|
||||
end if
|
||||
if key = "options"
|
||||
if ToggleVideoPictureInPicture(m.top)
|
||||
return true
|
||||
end if
|
||||
end if
|
||||
if key = "back"
|
||||
ScrollUp()
|
||||
m.top.escape = key
|
||||
return true
|
||||
end if
|
||||
if key = "left"
|
||||
if IsNodeFocused("keyboard") and m.suggestions.buttons.Count() > 0
|
||||
m.suggestions.SetFocus(true)
|
||||
return true
|
||||
end if
|
||||
ScrollUp()
|
||||
m.top.escape = key
|
||||
return true
|
||||
end if
|
||||
if key = "right"
|
||||
if IsNodeFocused("suggestions")
|
||||
m.keyboard.SetFocus(true)
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end if
|
||||
if key = "down"
|
||||
if m.rowlist.content <> invalid
|
||||
ScrollDown()
|
||||
m.rowlist.SetFocus(true)
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end if
|
||||
if key = "up"
|
||||
if IsNodeFocused("rowList")
|
||||
ScrollUp()
|
||||
m.suggestions.SetFocus(true)
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end if
|
||||
|
||||
return false
|
||||
end function
|
||||
@@ -1,45 +0,0 @@
|
||||
import "pkg:/source/services/Invidious.bs"
|
||||
|
||||
@asynctask
|
||||
function SearchTask(input as object) as object
|
||||
q = input.q
|
||||
|
||||
rootChildren = []
|
||||
|
||||
response = Invidious.Search(q, { type: "video" })
|
||||
|
||||
rowContent = GetCategoryContent(`Search - ${q}`, response)
|
||||
if rowContent <> invalid
|
||||
rootChildren.Push(rowContent)
|
||||
end if
|
||||
|
||||
return {
|
||||
q: q,
|
||||
rootChildren: rootChildren
|
||||
}
|
||||
end function
|
||||
|
||||
function GetCategoryContent(category as string, json as object) as object
|
||||
if json <> invalid and json.Count() > 0
|
||||
row = {}
|
||||
row.title = category
|
||||
row.children = []
|
||||
for each item in json ' parse items and push them to row
|
||||
itemData = GetItemData(item)
|
||||
if itemData <> invalid
|
||||
row.children.Push(itemData)
|
||||
end if
|
||||
end for
|
||||
return row
|
||||
end if
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function GetItemData(video as object) as object
|
||||
' TODO: handle playlists and channels
|
||||
if video.videoId = invalid
|
||||
return invalid
|
||||
end if
|
||||
|
||||
return video
|
||||
end function
|
||||
@@ -0,0 +1,43 @@
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "LatestLibVersionTask.bs"
|
||||
|
||||
import "pkg:/source/services/ApplicationInfo.bs"
|
||||
|
||||
function Init()
|
||||
m.service = new ApplicationInfo(m.top)
|
||||
end function
|
||||
|
||||
function GetAppInfo(unused as dynamic) as object
|
||||
return m.service.GetAppInfo()
|
||||
end function
|
||||
|
||||
function GetDeviceInfo(unused as dynamic) as object
|
||||
return m.service.GetDeviceInfo()
|
||||
end function
|
||||
|
||||
function GetUserCountryCode(unused as dynamic) as string
|
||||
return m.service.GetUserCountryCode()
|
||||
end function
|
||||
|
||||
function GetLocalIpAddress(unused as dynamic) as dynamic
|
||||
return m.service.GetLocalIpAddress()
|
||||
end function
|
||||
|
||||
function GetLatestPlayletLibVersion(unused as dynamic) as dynamic
|
||||
if not StringUtils.IsNullOrEmpty(m.top.lib_version_latest)
|
||||
return m.top.lib_version_latest
|
||||
end if
|
||||
|
||||
if m.latestLibVersionTask <> invalid and m.latestLibVersionTask.state = "run"
|
||||
return invalid
|
||||
end if
|
||||
|
||||
m.latestLibVersionTask = StartAsyncTask(LatestLibVersionTask, {}, function(output as object) as void
|
||||
m.latestLibVersionTask = invalid
|
||||
if output.success and output.result.latest <> invalid
|
||||
m.top.lib_version_latest = output.result.latest
|
||||
end if
|
||||
end function)
|
||||
|
||||
return invalid
|
||||
end function
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="ApplicationInfo" extends="Node">
|
||||
<interface>
|
||||
<field id="lib_version_latest" type="string" />
|
||||
<function name="GetUserCountryCode" />
|
||||
<function name="GetLocalIpAddress" />
|
||||
<function name="GetAppInfo" />
|
||||
<function name="GetLatestPlayletLibVersion" />
|
||||
<function name="GetDeviceInfo" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -0,0 +1,25 @@
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
|
||||
@asynctask
|
||||
function LatestLibVersionTask() as object
|
||||
latest = GetLatestPlayletLibVersionFromGithubReleases()
|
||||
return {
|
||||
latest: latest
|
||||
}
|
||||
end function
|
||||
|
||||
function GetLatestPlayletLibVersionFromGithubReleases() as string
|
||||
response = HttpClient.Head("https://github.com/iBicha/playlet/releases/latest").Await()
|
||||
|
||||
if response.StatusCode() = 200
|
||||
headers = response.Headers()
|
||||
if headers.location <> invalid
|
||||
regex = CreateObject("roRegex", "/v?(\d+\.\d+\.\d+)", "")
|
||||
match = regex.match(headers.location)
|
||||
if match.Count() = 2
|
||||
return match[1]
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
return "N/A"
|
||||
end function
|
||||
@@ -0,0 +1,23 @@
|
||||
import "InvidiousService.bs"
|
||||
|
||||
function Init()
|
||||
m.top.apiDefinitions = ParseJson(ReadAsciiFile("libpkg:/config/invidious_video_api.json5"))
|
||||
m.service = new Invidious.InvidiousService(m.top)
|
||||
m.top.authToken = m.service.GetAuthToken()
|
||||
end function
|
||||
|
||||
function GetCurrentInstance(unused as dynamic) as string
|
||||
return m.service.GetInstance()
|
||||
end function
|
||||
|
||||
function GetAuthorizeTokenLink(unused as dynamic) as dynamic
|
||||
return m.service.GetAuthorizeTokenLink()
|
||||
end function
|
||||
|
||||
function Logout(unused as dynamic)
|
||||
m.service.Logout()
|
||||
end function
|
||||
|
||||
function SetAuthToken(token as string, instance as string, username as dynamic)
|
||||
m.service.SetAuthToken(token, instance, username)
|
||||
end function
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="Invidious" extends="Node">
|
||||
<interface>
|
||||
<field id="applicationInfo" type="node" />
|
||||
<field id="preferences" type="node" />
|
||||
<field id="webServer" type="node" />
|
||||
|
||||
<field id="authToken" type="assocarray" />
|
||||
<field id="apiDefinitions" type="assocarray" />
|
||||
|
||||
<function name="Logout" />
|
||||
<function name="GetCurrentInstance" />
|
||||
<function name="GetAuthorizeTokenLink" />
|
||||
<function name="SetAuthToken" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -0,0 +1,358 @@
|
||||
import "pkg:/source/utils/RegistryUtils.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/source/utils/TimeUtils.bs"
|
||||
import "pkg:/source/utils/CryptoUtils.bs"
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
||||
|
||||
namespace Invidious
|
||||
const INSTANCES_API = "https://api.invidious.io/instances.json?sort_by=type,users"
|
||||
|
||||
const DEFAULT_INSTANCE = "https://vid.puffyan.us"
|
||||
|
||||
const TOKEN_CALLBACK = "/invidious/token_callback"
|
||||
|
||||
const STATS_ENDPOINT = "/api/v1/stats"
|
||||
|
||||
const VIDEOS_ENDPOINT = "/api/v1/videos"
|
||||
const PLAYLISTS_ENDPOINT = "/api/v1/playlists"
|
||||
const HISTORY_ENDPOINT = "/api/v1/auth/history"
|
||||
|
||||
const SEARCH_SUGGEST_ENDPOINT = "/api/v1/search/suggestions"
|
||||
|
||||
const AUTH_SCOPES = "GET:feed,GET:playlists*,POST:tokens/register,POST:tokens/unregister,POST:history*"
|
||||
const AUTH_PLAYLISTS = "/api/v1/auth/playlists"
|
||||
const AUTH_TOKENS_UNREGISTER = "/api/v1/auth/tokens/unregister"
|
||||
const AUTH_TOKENS_REGISTER = "/api/v1/auth/tokens/register"
|
||||
|
||||
const TOKEN_TIMESPAN = 60 * 60 * 24 * 365 * 2 '2 years
|
||||
|
||||
const ERROR_NOT_AUTHENTICATED = "Not authenticated"
|
||||
|
||||
class InvidiousService
|
||||
public node as object
|
||||
|
||||
function new(node as object)
|
||||
m.log = new log.Logger("InvidiousService")
|
||||
|
||||
m.node = node
|
||||
' TODO:P2 api definitions are not needed everytime, move them to a separate function and lazy load
|
||||
apiDefinitions = node.apiDefinitions
|
||||
|
||||
m.endpoints = {}
|
||||
|
||||
for each apiDefinition in apiDefinitions.endpoints
|
||||
m.endpoints[apiDefinition.name] = apiDefinition
|
||||
end for
|
||||
|
||||
m.responseHanlders = {
|
||||
DefaultHandler: m.DefaultHandler,
|
||||
AuthFeedHandler: m.AuthFeedHandler,
|
||||
PlaylistHandler: m.PlaylistHandler,
|
||||
ChannelHandler: m.ChannelHandler
|
||||
}
|
||||
end function
|
||||
|
||||
function DefaultQueryParams() as object
|
||||
return {
|
||||
region: m.node.applicationInfo@.GetUserCountryCode(invalid)
|
||||
}
|
||||
end function
|
||||
|
||||
function GetAuthenticationHeaders(token as string) as object
|
||||
return {
|
||||
"Authorization": `Bearer ${token}`
|
||||
}
|
||||
end function
|
||||
|
||||
function GetInstance() as string
|
||||
instance = m.node.preferences["invidious.instance"]
|
||||
if not StringUtils.IsNullOrEmpty(instance)
|
||||
return instance
|
||||
end if
|
||||
|
||||
return DEFAULT_INSTANCE
|
||||
end function
|
||||
|
||||
function MarkVideoWatched(videoId as dynamic) as void
|
||||
if StringUtils.IsNullOrEmpty(videoId)
|
||||
return
|
||||
end if
|
||||
|
||||
authToken = m.node.authToken
|
||||
if authToken = invalid
|
||||
return
|
||||
end if
|
||||
|
||||
url = `${authToken.instance}${Invidious.HISTORY_ENDPOINT}/${videoId}`
|
||||
request = HttpClient.Post(url, "")
|
||||
request.Headers(m.GetAuthenticationHeaders(authToken.token))
|
||||
request.SendAndForget()
|
||||
end function
|
||||
|
||||
function SearchSuggestions(q as string, cancellation = invalid as object) as object
|
||||
instance = m.GetInstance()
|
||||
url = `${instance}${Invidious.SEARCH_SUGGEST_ENDPOINT}`
|
||||
|
||||
request = HttpClient.Get(url)
|
||||
request.QueryParams(m.DefaultQueryParams())
|
||||
request.QueryParam("q", q)
|
||||
request.CacheSeconds(60 * 60 * 6)' 6 hours
|
||||
|
||||
request.Cancellation(cancellation)
|
||||
|
||||
response = request.Await()
|
||||
return response.Json()
|
||||
end function
|
||||
|
||||
function GetVideoMetadata(videoId as string, cancellation = invalid as object) as object
|
||||
instance = m.GetInstance()
|
||||
url = `${instance}${Invidious.VIDEOS_ENDPOINT}/${videoId}`
|
||||
|
||||
request = HttpClient.Get(url)
|
||||
request.QueryParams(m.DefaultQueryParams())
|
||||
request.CacheSeconds(60 * 60 * 6)' 6 hours
|
||||
request.Cancellation(cancellation)
|
||||
|
||||
return request.Await()
|
||||
end function
|
||||
|
||||
function GetPlaylist(playlistId as string, index = 0 as integer, cancellation = invalid as object) as object
|
||||
authToken = m.node.authToken
|
||||
if authToken = invalid
|
||||
instance = m.GetInstance()
|
||||
url = `${instance}${Invidious.PLAYLISTS_ENDPOINT}/${playlistId}`
|
||||
request = HttpClient.Get(url)
|
||||
else
|
||||
url = `${authToken.instance}${Invidious.AUTH_PLAYLISTS}/${playlistId}`
|
||||
request = HttpClient.Get(url)
|
||||
request.Headers(m.GetAuthenticationHeaders(authToken.token))
|
||||
end if
|
||||
|
||||
request.QueryParams(m.DefaultQueryParams())
|
||||
request.QueryParam("index", index)
|
||||
request.Cancellation(cancellation)
|
||||
|
||||
return request.Await()
|
||||
end function
|
||||
|
||||
function GetVideoStreamUrl(videoId as string) as string
|
||||
instance = m.GetInstance()
|
||||
return `${instance}/latest_version?id=${videoId}`
|
||||
end function
|
||||
|
||||
function MarkFeedPagination(contentNode as object) as void
|
||||
requestData = contentNode.feed
|
||||
|
||||
endpoint = m.endpoints[requestData.endpoint]
|
||||
if endpoint = invalid or endpoint.pagination <> true
|
||||
return
|
||||
end if
|
||||
|
||||
contentNode.pagination = true
|
||||
contentNode.page += 1
|
||||
|
||||
if not requestData.DoesExist("queryParams")
|
||||
requestData.queryParams = {}
|
||||
end if
|
||||
|
||||
requestData.queryParams.page = contentNode.page
|
||||
contentNode.feed = requestData
|
||||
end function
|
||||
|
||||
function MakeRequest(requestData as object, cancellation = invalid as object) as object
|
||||
endpoint = m.endpoints[requestData.endpoint]
|
||||
if endpoint = invalid
|
||||
return {
|
||||
success: false,
|
||||
error: `Endpoint ${requestData.endpoint} not found`
|
||||
}
|
||||
end if
|
||||
|
||||
instance = m.GetInstance()
|
||||
|
||||
request = HttpClient.Get(instance + endpoint.url)
|
||||
|
||||
if endpoint.authenticated = true
|
||||
authToken = m.node.authToken
|
||||
if authToken = invalid
|
||||
return {
|
||||
success: false,
|
||||
error: ERROR_NOT_AUTHENTICATED
|
||||
}
|
||||
end if
|
||||
request.Url(authToken.instance + endpoint.url)
|
||||
request.Headers(m.GetAuthenticationHeaders(authToken.token))
|
||||
end if
|
||||
|
||||
if endpoint.queryParams <> invalid
|
||||
for each queryParamKey in endpoint.queryParams
|
||||
queryParam = endpoint.queryParams[queryParamKey]
|
||||
if queryParam.default <> invalid
|
||||
if IsString(queryParam.type) and queryParam.type = "#ISO3166"
|
||||
if queryParam.default = "GetUserCountryCode"
|
||||
request.QueryParam(queryParamKey, m.node.applicationInfo@.GetUserCountryCode(invalid))
|
||||
else
|
||||
request.QueryParam(queryParamKey, queryParam.default)
|
||||
end if
|
||||
else if IsArray(queryParam.default)
|
||||
if queryParam.arrayType = "repeat"
|
||||
request.QueryParamArray(queryParamKey, queryParam.default, HttpClient.QueryParamArrayType.Repeated)
|
||||
else if queryParam.arrayType = "comma-separated"
|
||||
request.QueryParamArray(queryParamKey, queryParam.default, HttpClient.QueryParamArrayType.CommaSeparated)
|
||||
end if
|
||||
else
|
||||
request.QueryParam(queryParamKey, queryParam.default)
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
end if
|
||||
|
||||
if requestData.cacheSeconds <> invalid
|
||||
request.CacheSeconds(requestData.cacheSeconds)
|
||||
else if endpoint.cacheSeconds <> invalid
|
||||
request.CacheSeconds(endpoint.cacheSeconds)
|
||||
end if
|
||||
|
||||
if requestData.queryParams <> invalid
|
||||
request.QueryParams(requestData.queryParams)
|
||||
end if
|
||||
|
||||
if requestData.pathParams <> invalid
|
||||
request.PathParams(requestData.pathParams)
|
||||
end if
|
||||
|
||||
request.Cancellation(cancellation)
|
||||
|
||||
response = request.Await()
|
||||
|
||||
responseHandler = endpoint.responseHandler <> invalid ? m.responseHanlders[endpoint.responseHandler] : m.responseHanlders["DefaultHandler"]
|
||||
|
||||
result = responseHandler(m, requestData, response)
|
||||
|
||||
if response.IsSuccess() and result <> invalid
|
||||
return {
|
||||
success: true,
|
||||
result: result
|
||||
}
|
||||
else
|
||||
return {
|
||||
success: false,
|
||||
error: response.ErrorMessage()
|
||||
}
|
||||
end if
|
||||
end function
|
||||
|
||||
function DefaultHandler(m as object, requestData as object, response as object) as object
|
||||
return response.Json()
|
||||
end function
|
||||
|
||||
function PlaylistHandler(m as object, requestData as object, response as object) as object
|
||||
if response.StatusCode() = 200
|
||||
json = response.Json()
|
||||
return json.videos
|
||||
end if
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function ChannelHandler(m as object, requestData as object, response as object) as object
|
||||
if response.StatusCode() = 200
|
||||
json = response.Json()
|
||||
return json.videos
|
||||
end if
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function AuthFeedHandler(m as object, requestData as object, response as object) as object
|
||||
m.DeleteExpiredToken(response)
|
||||
|
||||
if response.StatusCode() = 200
|
||||
json = response.Json()
|
||||
videos = []
|
||||
videos.Append(json.notifications)
|
||||
videos.Append(json.videos)
|
||||
return videos
|
||||
end if
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function DeleteExpiredToken(response as object)
|
||||
if response.StatusCode() = 403
|
||||
m.log.warn(`Invidious instance responded with 403: ${response.Text()}`)
|
||||
m.log.warn("Deleting Invidious token...")
|
||||
m.DeleteAuthToken()
|
||||
end if
|
||||
end function
|
||||
|
||||
function GetAuthToken() as object
|
||||
tokenPayload = RegistryUtils.Read(RegistryUtils.INVIDIOUS_TOKEN)
|
||||
if tokenPayload = invalid
|
||||
return invalid
|
||||
end if
|
||||
authData = ParseJson(tokenPayload)
|
||||
if authData = invalid or authData.instance = invalid or authData.token = invalid
|
||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||
return invalid
|
||||
end if
|
||||
return authData
|
||||
end function
|
||||
|
||||
function SetAuthToken(token as string, instance as string, username as dynamic)
|
||||
obj = {
|
||||
token: token,
|
||||
instance: instance,
|
||||
username: username
|
||||
}
|
||||
|
||||
json = FormatJson(obj)
|
||||
RegistryUtils.Write(RegistryUtils.INVIDIOUS_TOKEN, json)
|
||||
|
||||
m.node.authToken = obj
|
||||
end function
|
||||
|
||||
function DeleteAuthToken()
|
||||
m.node.authToken = invalid
|
||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||
end function
|
||||
|
||||
function Logout() as boolean
|
||||
authToken = m.node.authToken
|
||||
if authToken = invalid
|
||||
return false
|
||||
end if
|
||||
|
||||
m.UnregisterToken(authToken)
|
||||
m.DeleteAuthToken()
|
||||
return true
|
||||
end function
|
||||
|
||||
function UnregisterToken(authToken as object) as void
|
||||
url = `${authToken.instance}${Invidious.AUTH_TOKENS_UNREGISTER}`
|
||||
|
||||
request = HttpClient.Post(url, authToken.token)
|
||||
request.Headers(m.GetAuthenticationHeaders(authToken.token))
|
||||
request.Header("Content-Type", "application/json")
|
||||
|
||||
request.SendAndForget()
|
||||
end function
|
||||
|
||||
function GetAuthorizeTokenLink() as dynamic
|
||||
instance = m.GetInstance()
|
||||
' Make sure the host is not on https, because https cannot redirect to http, which is our local server
|
||||
invidiousHost = instance.Replace("https://", "http://")
|
||||
|
||||
address = m.node.webServer@.GetServerAddress()
|
||||
if address = invalid
|
||||
return invalid
|
||||
end if
|
||||
|
||||
expire = TimeUtils.Now().AsSeconds() + Invidious.TOKEN_TIMESPAN
|
||||
|
||||
callbackUrl = `${address}${Invidious.TOKEN_CALLBACK}?ref=${instance}`.EncodeUriComponent()
|
||||
scope = `${Invidious.AUTH_SCOPES}`.EncodeUriComponent()
|
||||
return `${invidiousHost}/authorize_token?scopes=${scope}&callback_url=${callbackUrl}&expire=${expire}`
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,211 @@
|
||||
import "pkg:/source/utils/TimeUtils.bs"
|
||||
import "pkg:/components/VideoFeed/FeedLoadState.bs"
|
||||
|
||||
namespace InvidiousContent
|
||||
|
||||
function ToRowCellContentNode(item as object, instance as dynamic) as object
|
||||
if item.videoId <> invalid and (item.type = invalid or item.type = "shortVideo")
|
||||
item.type = "video"
|
||||
end if
|
||||
|
||||
if item.playlistId <> invalid and (item.type = invalid or item.type = "invidiousPlaylist")
|
||||
item.type = "playlist"
|
||||
end if
|
||||
|
||||
if item.type <> "video" and item.type <> "playlist" and item.type <> "channel"
|
||||
return invalid
|
||||
end if
|
||||
|
||||
if item.type = "video"
|
||||
return ToVideoContentNode(invalid, item, instance)
|
||||
else if item.type = "playlist"
|
||||
return ToPlaylistContentNode(invalid, item, instance)
|
||||
else if item.type = "channel"
|
||||
return invalid
|
||||
' return ToChannelContentNode(item, instance)
|
||||
else
|
||||
return invalid
|
||||
end if
|
||||
end function
|
||||
|
||||
function ToVideoContentNode(node as object, item as object, instance as dynamic) as object
|
||||
if node = invalid
|
||||
node = CreateObject("roSGNode", "VideoContentNode")
|
||||
end if
|
||||
node.type = "video"
|
||||
|
||||
SetIfExists(node, "author", item, "author")
|
||||
SetIfExists(node, "hlsUrl", item, "hlsUrl")
|
||||
SetIfExists(node, "isUpcoming", item, "isUpcoming")
|
||||
SetIfExists(node, "lengthSeconds", item, "lengthSeconds")
|
||||
node.lengthText = TimeUtils.GetFormattedTime(item.lengthSeconds)
|
||||
node.liveNow = VideoIsLive(item)
|
||||
VideoSetPremiereTimestampText(node, item)
|
||||
SetIfExists(node, "publishedText", item, "publishedText")
|
||||
if not StringUtils.IsNullOrEmpty(instance)
|
||||
node.thumbnail = VideoGetThumbnail(item, instance) ?? "pkg:/images/thumbnail-missing.jpg"
|
||||
end if
|
||||
SetIfExists(node, "title", item, "title")
|
||||
SetIfExists(node, "timestamp", item, "timestamp")
|
||||
SetIfExists(node, "videoId", item, "videoId")
|
||||
node.viewCountText = VideoGetViewCountText(item)
|
||||
SetIfExists(node, "index", item, "index")
|
||||
|
||||
return node
|
||||
end function
|
||||
|
||||
function ToPlaylistContentNode(node as object, item as object, instance as dynamic) as object
|
||||
if node = invalid
|
||||
node = CreateObject("roSGNode", "PlaylistContentNode")
|
||||
node.loadState = FeedLoadState.None
|
||||
end if
|
||||
node.type = "playlist"
|
||||
|
||||
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
|
||||
SetIfExists(node, "_author", item, "author")
|
||||
SetIfExists(node, "description", item, "description")
|
||||
SetIfExists(node, "playlistId", item, "playlistId")
|
||||
SetIfExists(node, "title", item, "title")
|
||||
SetIfExists(node, "videoCount", item, "videoCount")
|
||||
node.videoCountText = PlaylistGetVideoCountText(item)
|
||||
SetIfExists(node, "viewCount", item, "viewCount")
|
||||
node.viewCountText = PlaylistGetViewCountText(item)
|
||||
|
||||
if item.videos <> invalid
|
||||
childCount = node.getChildCount()
|
||||
newNodes = []
|
||||
for each video in item.videos
|
||||
video.type = "video"
|
||||
videoNode = ToVideoContentNode(invalid, video, instance)
|
||||
if videoNode <> invalid
|
||||
index = video.index
|
||||
if index <> invalid and index > -1 and index < childCount
|
||||
node.replaceChild(videoNode, index)
|
||||
else
|
||||
newNodes.push(videoNode)
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
if newNodes.Count() > 0
|
||||
node.appendChildren(newNodes)
|
||||
end if
|
||||
end if
|
||||
|
||||
PlaylistSetThumbnail(node, "thumbnail", item, instance)
|
||||
PlaylistSetThumbnail(node, "thumbnailBackground", item, instance, "maxres")
|
||||
|
||||
return node
|
||||
end function
|
||||
|
||||
function ToChannelContentNode(item as object, instance as dynamic) as object
|
||||
node = CreateObject("roSGNode", "ChannelContentNode")
|
||||
node.type = "channel"
|
||||
|
||||
return node
|
||||
end function
|
||||
|
||||
function SetIfExists(dst as object, dstField as string, src as object, srcField as string)
|
||||
if src.DoesExist(srcField)
|
||||
dst[dstField] = src[srcField]
|
||||
end if
|
||||
end function
|
||||
|
||||
function VideoGetThumbnail(videoItem as object, instance as dynamic, quality = "medium" as string) as dynamic
|
||||
videoThumbnails = videoItem.videoThumbnails
|
||||
if videoThumbnails = invalid or videoThumbnails.Count() = 0
|
||||
return invalid
|
||||
end if
|
||||
url = invalid
|
||||
for each thumbnail in videoThumbnails
|
||||
if thumbnail.quality = quality
|
||||
url = thumbnail.url
|
||||
exit for
|
||||
end if
|
||||
end for
|
||||
if url = invalid
|
||||
url = videoThumbnails[0].url
|
||||
end if
|
||||
if url.startsWith("/") and not StringUtils.IsNullOrEmpty(instance)
|
||||
url = instance + url
|
||||
end if
|
||||
return url
|
||||
end function
|
||||
|
||||
function VideoIsLive(videoItem as object) as boolean
|
||||
if videoItem.liveNow = true
|
||||
return true
|
||||
end if
|
||||
' TODO:P2 metadata.liveNow is returning false for live videos...
|
||||
return videoItem.lengthSeconds = 0 and videoItem.viewCount = 0
|
||||
end function
|
||||
|
||||
function VideoIsUpcoming(videoItem as object) as boolean
|
||||
return videoItem.isUpcoming = true
|
||||
end function
|
||||
|
||||
function VideoSetPremiereTimestampText(node as object, videoItem as object)
|
||||
if VideoIsUpcoming(videoItem) and videoItem.premiereTimestamp <> invalid
|
||||
node.premiereTimestampText = `Premeres in ${TimeUtils.GetFormattedTimeLeft(videoItem.premiereTimestamp)}`
|
||||
end if
|
||||
end function
|
||||
|
||||
function VideoGetViewCountText(videoItem as object) as string
|
||||
viewCount = videoItem.viewCount
|
||||
if viewCount = invalid
|
||||
return ""
|
||||
end if
|
||||
if viewCount < 1000
|
||||
return `${FormatFloat(viewCount)} views`
|
||||
end if
|
||||
|
||||
viewCount = viewCount / 1000
|
||||
if viewCount < 1000
|
||||
return `${FormatFloat(viewCount)}K views`
|
||||
end if
|
||||
|
||||
viewCount = viewCount / 1000
|
||||
if viewCount < 1000
|
||||
return `${FormatFloat(viewCount)}M views`
|
||||
end if
|
||||
|
||||
viewCount = viewCount / 1000
|
||||
return `${FormatFloat(viewCount)}B views`
|
||||
end function
|
||||
|
||||
function FormatFloat(X as float) as float
|
||||
X = X * 10
|
||||
X = X + 0.5
|
||||
X = Fix(X)
|
||||
X = X / 10
|
||||
return X
|
||||
end function
|
||||
|
||||
function PlaylistSetThumbnail(node as object, nodeField as string, playlistItem as object, instance as dynamic, quality = "medium" as string) as void
|
||||
thumbnail = ""
|
||||
if IsString(playlistItem.playlistThumbnail)
|
||||
thumbnailUrl = playlistItem.playlistThumbnail
|
||||
if thumbnailUrl.startsWith("/") and not StringUtils.IsNullOrEmpty(playlistItem.instance)
|
||||
thumbnailUrl = playlistItem.instance + thumbnailUrl
|
||||
end if
|
||||
thumbnail = thumbnailUrl
|
||||
else if playlistItem.videos <> invalid and playlistItem.videos.Count() > 0 and playlistItem.videos[0].index = 0
|
||||
thumbnail = VideoGetThumbnail(playlistItem.videos[0], instance, quality)
|
||||
else if node.getChildCount() > 0
|
||||
thumbnail = node.getChild(0).thumbnail
|
||||
end if
|
||||
if StringUtils.IsNullOrEmpty(thumbnail)
|
||||
thumbnail = "pkg:/images/thumbnail-missing.jpg"
|
||||
end if
|
||||
node[nodeField] = thumbnail
|
||||
end function
|
||||
|
||||
function PlaylistGetVideoCountText(playlistItem as object) as string
|
||||
videoCount = ValidInt(playlistItem.videoCount)
|
||||
return videoCount = 1 ? "1 video" : `${videoCount} videos`
|
||||
end function
|
||||
|
||||
function PlaylistGetViewCountText(playlistItem as object) as string
|
||||
return VideoGetViewCountText(playlistItem)
|
||||
end function
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,169 @@
|
||||
import "pkg:/source/utils/RegistryUtils.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.disableSavingToRegistry = false
|
||||
LoadPreferencesFile()
|
||||
AddNodeFields()
|
||||
LoadUserPreferencesFromRegistry()
|
||||
AddNodeFieldsObservers()
|
||||
end function
|
||||
|
||||
function LoadPreferencesFile()
|
||||
m.top.prefsModel = ParseJson(ReadAsciiFile("libpkg:/config/preferences.json5"))
|
||||
end function
|
||||
|
||||
function AddNodeFields()
|
||||
fields = {}
|
||||
prefsModel = m.top.prefsModel
|
||||
for each child in prefsModel
|
||||
AddNodeFieldsFromPreference(child, fields)
|
||||
end for
|
||||
' We keep reference to fields specific to preferences, to avoid default fields like focusedChild
|
||||
m.top.preferenceFields = fields
|
||||
end function
|
||||
|
||||
function AddNodeFieldsFromPreference(pref as object, fields as object)
|
||||
if pref.key <> invalid and pref.type <> invalid
|
||||
fieldType = ""
|
||||
if pref.type = "boolean"
|
||||
fieldType = "boolean"
|
||||
else if pref.type = "string"
|
||||
fieldType = "string"
|
||||
else if pref.type = "radio"
|
||||
fieldType = "string"
|
||||
end if
|
||||
m.top.addField(pref.key, fieldType, false)
|
||||
fields[pref.key] = true
|
||||
end if
|
||||
if pref.children <> invalid
|
||||
for each child in pref.children
|
||||
AddNodeFieldsFromPreference(child, fields)
|
||||
end for
|
||||
end if
|
||||
end function
|
||||
|
||||
function AddNodeFieldsObservers()
|
||||
prefsFields = m.top.preferenceFields
|
||||
for each key in prefsFields
|
||||
m.top.observeField(key, FuncName(SaveUserPreferencesToRegistry))
|
||||
end for
|
||||
end function
|
||||
|
||||
function LoadUserPreferencesFromRegistry()
|
||||
' Step 1: Load user preferences from registry
|
||||
userPrefs = RegistryUtils.Read(RegistryUtils.USER_PREFERENCES)
|
||||
if userPrefs = invalid
|
||||
userPrefs = {}
|
||||
else
|
||||
userPrefs = ParseJson(userPrefs)
|
||||
end if
|
||||
|
||||
' Step 2: Migrate existing preferences to new format (if needed)
|
||||
isDirty = MigrateExistingPreferences(userPrefs)
|
||||
' Step 3: Apply defaults to user preferences (if needed)
|
||||
isDirty = ApplyDefaultsToUserPreferences(userPrefs) or isDirty
|
||||
|
||||
' Step 4: set field values in node
|
||||
for each key in userPrefs
|
||||
m.top[key] = userPrefs[key]
|
||||
end for
|
||||
|
||||
' Step 5: Save user preferences (if needed)
|
||||
if isDirty
|
||||
SaveUserPreferencesToRegistry()
|
||||
end if
|
||||
end function
|
||||
|
||||
function SaveUserPreferencesToRegistry() as void
|
||||
if m.disableSavingToRegistry
|
||||
return
|
||||
end if
|
||||
userPrefs = {}
|
||||
prefsFields = m.top.preferenceFields
|
||||
for each key in prefsFields
|
||||
userPrefs[key] = m.top[key]
|
||||
end for
|
||||
userPrefs.__version = m.top.__version
|
||||
RegistryUtils.Write(RegistryUtils.USER_PREFERENCES, FormatJson(userPrefs))
|
||||
end function
|
||||
|
||||
function MigrateExistingPreferences(userPrefs as object) as boolean
|
||||
isDirty = false
|
||||
|
||||
' v0 -> v1
|
||||
instances = RegistryUtils.Read(RegistryUtils.INVIDIOUS_INSTANCES)
|
||||
if instances <> invalid
|
||||
currentInstance = userPrefs["invidious.instance"]
|
||||
if currentInstance = invalid or currentInstance = ""
|
||||
instances = ParseJson(instances)
|
||||
if instances.Count() > 0
|
||||
instance = instances[0]
|
||||
if instance <> invalid and instance <> ""
|
||||
userPrefs["invidious.instance"] = instance
|
||||
isDirty = true
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_INSTANCES)
|
||||
end if
|
||||
|
||||
' v1 -> v2 goes here (if needed)
|
||||
' if userPrefs.__version = 1
|
||||
' 'do stuff
|
||||
' end if
|
||||
|
||||
' TODO:PX handle case where saved preferences version is higher than current version (e.g. user downgraded)
|
||||
return isDirty
|
||||
end function
|
||||
|
||||
function ApplyDefaultsToUserPreferences(userPrefs as object) as boolean
|
||||
isDirty = false
|
||||
prefsModel = m.top.prefsModel
|
||||
for each child in prefsModel
|
||||
isDirty = ApplyToUserPreferences(userPrefs, child) or isDirty
|
||||
end for
|
||||
return isDirty
|
||||
end function
|
||||
|
||||
function ApplyToUserPreferences(userPrefs as object, model as object) as boolean
|
||||
isDirty = false
|
||||
if model.children <> invalid
|
||||
for each child in model.children
|
||||
isDirty = ApplyToUserPreferences(userPrefs, child) or isDirty
|
||||
end for
|
||||
end if
|
||||
|
||||
if model.defaultValue <> invalid and (not userPrefs.DoesExist(model.key) or userPrefs[model.key] = invalid)
|
||||
userPrefs[model.key] = model.defaultValue
|
||||
isDirty = true
|
||||
end if
|
||||
return isDirty
|
||||
end function
|
||||
|
||||
function GetUserPreferences(unused as dynamic) as object
|
||||
userPrefs = {}
|
||||
prefsFields = m.top.preferenceFields
|
||||
for each key in prefsFields
|
||||
userPrefs[key] = m.top[key]
|
||||
end for
|
||||
userPrefs.__version = m.top.__version
|
||||
return userPrefs
|
||||
end function
|
||||
|
||||
function ApplyUserPreferences(preferences as object) as void
|
||||
if preferences = invalid
|
||||
return
|
||||
end if
|
||||
' TODO:P2 user input validation
|
||||
m.disableSavingToRegistry = true
|
||||
m.top.setFields(preferences)
|
||||
m.disableSavingToRegistry = false
|
||||
SaveUserPreferencesToRegistry()
|
||||
end function
|
||||
|
||||
function ClearUserPreferences(unused as dynamic) as void
|
||||
userPrefs = {}
|
||||
ApplyDefaultsToUserPreferences(userPrefs)
|
||||
ApplyUserPreferences(userPrefs)
|
||||
end function
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<component name="Preferences" extends="Node">
|
||||
<interface>
|
||||
<field id="__version" type="integer" value="1" />
|
||||
<field id="prefsModel" type="array" />
|
||||
<field id="preferenceFields" type="assocarray" />
|
||||
<function name="GetUserPreferences" />
|
||||
<function name="ApplyUserPreferences" />
|
||||
<function name="ClearUserPreferences" />
|
||||
</interface>
|
||||
</component>
|
||||
+5
-3
@@ -1,4 +1,4 @@
|
||||
import "pkg:/source/services/SponsorBlock.bs"
|
||||
import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs"
|
||||
|
||||
function Init()
|
||||
m.categoryLabel = m.top.findNode("categoryLabel")
|
||||
@@ -9,14 +9,16 @@ function Init()
|
||||
m.top.translation = [1280, 20]
|
||||
m.translationAnimation.observeField("state", "OnAnimationState")
|
||||
m.animationTimer.observeField("fire", "OnAnimationTimer")
|
||||
|
||||
m.service = SponsorBlock.SponsorBlockService()
|
||||
end function
|
||||
|
||||
function OnActionSet()
|
||||
action = m.top.action
|
||||
category = m.top.segment.category
|
||||
categoryTitle = SponsorBlock.SegmentShortTitle(category)
|
||||
categoryTitle = m.service.SegmentShortTitle(category)
|
||||
if action = "AutoSkip"
|
||||
m.categoryLabel.text = "Skipped" + chr(10) + categoryTitle
|
||||
m.categoryLabel.text = `Skipped\n${categoryTitle}`
|
||||
else
|
||||
m.categoryLabel.text = categoryTitle
|
||||
end if
|
||||
+6
-5
@@ -3,14 +3,15 @@
|
||||
<component name="SponsorBlockNotification" extends="Group">
|
||||
<interface>
|
||||
<field id="segment" type="assocarray" onChange="OnSegmentSet" />
|
||||
<field id="action" type="string" onChange="OnActionSet" alwaysNotify="true"/>
|
||||
<field id="action" type="string" onChange="OnActionSet" alwaysNotify="true" />
|
||||
</interface>
|
||||
<children>
|
||||
<Rectangle
|
||||
<Poster
|
||||
width="250"
|
||||
height="70"
|
||||
color="#414141"
|
||||
opacity="0.8">
|
||||
opacity="0.8"
|
||||
blendColor="#414141"
|
||||
uri="pkg:/images/white.9.png">
|
||||
<Poster
|
||||
uri="libpkg:/images/LogoSponsorBlockSimple256px.png"
|
||||
width="50"
|
||||
@@ -29,7 +30,7 @@
|
||||
height="70"
|
||||
translation="[70,0]">
|
||||
</Label>
|
||||
</Rectangle>
|
||||
</Poster>
|
||||
<Animation
|
||||
id="translationAnimation"
|
||||
duration="0.3"
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
||||
|
||||
namespace SponsorBlock
|
||||
const NOTIFICATION_NODE_ID = "SponsorBlockNotification"
|
||||
|
||||
function ShowNotifcation(notifications as object, segment as object, action as dynamic) as void
|
||||
' TODO:P2 avoid finding the node over and over
|
||||
' The video player can probably own a single notification, and destroy it when the video is closed
|
||||
notification = notifications.findNode(NOTIFICATION_NODE_ID)
|
||||
if notification = invalid
|
||||
notification = notifications.createChild("SponsorBlockNotification")
|
||||
notification.id = NOTIFICATION_NODE_ID
|
||||
end if
|
||||
notification.segment = segment
|
||||
notification.action = action
|
||||
end function
|
||||
|
||||
function RemoveNotifcation(notifications as object) as void
|
||||
notification = notifications.findNode(NOTIFICATION_NODE_ID)
|
||||
if notification <> invalid
|
||||
notifications.RemoveChild(notification)
|
||||
end if
|
||||
end function
|
||||
|
||||
function SetVisible(notifications as object, visible as boolean)
|
||||
notification = notifications.findNode(NOTIFICATION_NODE_ID)
|
||||
if notification <> invalid
|
||||
notification.visible = visible
|
||||
end if
|
||||
end function
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,9 @@
|
||||
import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs"
|
||||
|
||||
@asynctask
|
||||
function SponsorBlockSegmentViewedTask(input as object)
|
||||
segmentId = input.segmentId
|
||||
service = new SponsorBlock.SponsorBlockService()
|
||||
|
||||
service.PostSegmentViewed(segmentId)
|
||||
end function
|
||||
@@ -0,0 +1,122 @@
|
||||
import "pkg:/source/utils/ColorUtils.bs"
|
||||
import "pkg:/source/utils/CryptoUtils.bs"
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
|
||||
namespace SponsorBlock
|
||||
const SKIP_SEGMENT_ENDPOINT = "/api/skipSegments"
|
||||
const VIEWED_SEGMENT_ENDPOINT = "/api/viewedVideoSponsorTime"
|
||||
|
||||
|
||||
class SponsorBlockService
|
||||
function new()
|
||||
m.sponsorBlockConfig = ParseJson(ReadAsciiFile("libpkg:/config/sponsorblock_config.json5"))
|
||||
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
|
||||
end function
|
||||
|
||||
function GetSkipSegmentsForVideo(videoId as string) as object
|
||||
if m.sponsorBlockConfig = invalid or StringUtils.IsNullOrEmpty(m.sponsorBlockConfig.serverAddress)
|
||||
return invalid
|
||||
end if
|
||||
|
||||
categories = ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "poi_highlight", "chapter", "filler", "exclusive_access"]
|
||||
actionTypes = ["skip", "mute", "chapter", "full", "poi"]
|
||||
|
||||
categoriesJson = FormatJson(categories).EncodeUriComponent()
|
||||
actionTypesJson = FormatJson(actionTypes).EncodeUriComponent()
|
||||
|
||||
' 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}`
|
||||
response = HttpClient.Get(url).Await()
|
||||
json = response.Json()
|
||||
if json = invalid
|
||||
return invalid
|
||||
end if
|
||||
|
||||
for each item in json
|
||||
if item.videoId = videoId
|
||||
return item.segments
|
||||
end if
|
||||
end for
|
||||
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function PostSegmentViewed(segmentId as string) 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, "").SendAndForget()
|
||||
end function
|
||||
|
||||
function GenerateProgressBarBackground(segments as object, lengthSeconds as integer, path as string)
|
||||
bar = CreateObject("roBitmap", { width: 1000, height: 20, AlphaEnable: true })
|
||||
bar.Clear(&hFFFFFF80)
|
||||
width = bar.GetWidth()
|
||||
height = bar.GetHeight()
|
||||
for each segment in segments
|
||||
videoDuration = lengthSeconds
|
||||
if videoDuration = 0 or videoDuration = invalid
|
||||
' We should ignore segment.videoDuration https://github.com/iBicha/playlet/pull/23#issuecomment-1431520676
|
||||
' But in case where we don't have lengthSeconds from Invidious, it's better than nothing
|
||||
videoDuration = segment.videoDuration
|
||||
end if
|
||||
if videoDuration = 0 or videoDuration = invalid
|
||||
continue for
|
||||
end if
|
||||
|
||||
pixelStart = (segment.segment[0] / videoDuration) * width
|
||||
pixelEnd = (segment.segment[1] / videoDuration) * width
|
||||
color = m.SegmentColor(segment.category)
|
||||
' highlight's duration is zero, so it is not visble on the bar.
|
||||
' Add a couple of pixels to see it
|
||||
if pixelStart = pixelEnd
|
||||
pixelEnd += 2
|
||||
end if
|
||||
bar.DrawRect(pixelStart, 0, pixelEnd - pixelStart, height, color)
|
||||
end for
|
||||
bar.Finish()
|
||||
buffer = bar.GetPng(0, 0, width, height)
|
||||
buffer.WriteFile(path)
|
||||
end function
|
||||
|
||||
end class
|
||||
end namespace
|
||||
+5
-4
@@ -1,16 +1,17 @@
|
||||
import "pkg:/source/services/SponsorBlock.bs"
|
||||
import "pkg:/components/Services/SponsorBlock/SponsorBlockService.bs"
|
||||
|
||||
@asynctask
|
||||
function SponsorBlockTask(input as object) as object
|
||||
videoId = input.videoId
|
||||
videoId = input.metadata.videoId
|
||||
lengthSeconds = input.metadata.lengthSeconds
|
||||
|
||||
skipSegments = SponsorBlock.GetSkipSegmentsForVideo(videoId)
|
||||
service = new SponsorBlock.SponsorBlockService()
|
||||
skipSegments = service.GetSkipSegmentsForVideo(videoId)
|
||||
barPath = invalid
|
||||
|
||||
if skipSegments <> invalid
|
||||
barPath = `tmp:/sponsorblock_bar_${videoId}.png`
|
||||
SponsorBlock.GenerateProgressBarBackground(skipSegments, lengthSeconds, barPath)
|
||||
service.GenerateProgressBarBackground(skipSegments, lengthSeconds, barPath)
|
||||
end if
|
||||
|
||||
return {
|
||||
@@ -1,42 +0,0 @@
|
||||
function Init()
|
||||
m.radioButtonList = m.top.findNode("RadioButtonList")
|
||||
|
||||
m.top.observeField("value", "OnValueChanged")
|
||||
m.radioButtonList.observeField("checkedItem", "OnCheckedItemChanged")
|
||||
m.top.observeField("focusedChild", "OnFocusChanged")
|
||||
m.top.observeField("settings", "OnSettingsScreen")
|
||||
end function
|
||||
|
||||
function OnSettingsScreen()
|
||||
m.top.value = m.top.settings@.GetPreferenceValue(m.top.key)
|
||||
end function
|
||||
|
||||
function OnValueChanged()
|
||||
value = m.top.value
|
||||
if value = true
|
||||
m.radioButtonList.checkedItem = 0
|
||||
else if value = false
|
||||
m.radioButtonList.checkedItem = 1
|
||||
end if
|
||||
|
||||
m.top.settings@.SetPreferenceValue(m.top.key, value)
|
||||
end function
|
||||
|
||||
function OnCheckedItemChanged()
|
||||
checkedItem = m.radioButtonList.checkedItem
|
||||
if checkedItem = 0
|
||||
m.top.value = true
|
||||
else if checkedItem = 1
|
||||
m.top.value = false
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnFocusChanged()
|
||||
if m.top.hasFocus()
|
||||
m.radioButtonList.setFocus(true)
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
return m.top.settings@.OnkeyEvent(key, press)
|
||||
end function
|
||||
Loaded 100 of 349 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user