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:
authored and GitHub committed 2023-09-07 17:18:25 -04:00
1 parent 79f74141c5
commit 43166fb43b
349 files changed
+12784 -7660

No files matched your search

@@ -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
@@ -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>
@@ -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
@@ -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>
@@ -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
@@ -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>
@@ -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
@@ -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>
@@ -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
@@ -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
@@ -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>
@@ -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
@@ -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>
@@ -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>
@@ -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