Ground work for invidious instance selection (#11)
* Ground work for invidious instance selection * Display logged in instance * Show instances * Reorder instances * Instance management * Add todos * Changelog * Add instances link, trim trailing slash * Small tweaks
This commit is contained in:
1 parent
1d9dc3ecda
commit
a248318c54
14 files changed
+411
-130
No files matched your search
@@ -105,6 +105,8 @@ function OnWebServerCommand()
|
||||
m.settingsScreen.visible = false
|
||||
' Trigger play video from home
|
||||
' TODO: allow returning to current screen, instead of home
|
||||
' BUG: if current video is playing in search screen, new video does not play
|
||||
' TODO: Owner of video player needs to be independant
|
||||
m.homeGridScreen.playvideo = m.serverTask.command.Mid(5)
|
||||
end if
|
||||
end function
|
||||
|
||||
@@ -191,13 +191,14 @@ function SetCaptions(metadata as object, videoPlayer as object, contentNode as o
|
||||
|
||||
contentNode.SubtitleConfig = {
|
||||
ShowSubtitle: 1,
|
||||
TrackName: Invidious.GetCurrentHost() + selectedCaption.url
|
||||
TrackName: InvidiousSettings.GetSelectedInstance() + selectedCaption.url
|
||||
}
|
||||
end function
|
||||
|
||||
function OnPositionChangeSkipSponsorBlockSections() as void
|
||||
segments = m.videoPlayer.skipSegments
|
||||
for each segment in segments
|
||||
' TODO: handle other action types
|
||||
if segment["actionType"] = "skip"
|
||||
segmentRange = segment["segment"]
|
||||
segmentStart = segmentRange[0]
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Http
|
||||
server.task.top.command = `play:${components["v"]}`
|
||||
if components["redirect"] = "true"
|
||||
' 302 to prevent redirection to current host permanently
|
||||
response.Redirect(`${Invidious.GetCurrentHost()}/watch?v=${components["v"]}`, 302)
|
||||
response.Redirect(`${InvidiousSettings.GetSelectedInstance()}/watch?v=${components["v"]}`, 302)
|
||||
else
|
||||
response.Default(204, "OK")
|
||||
end if
|
||||
|
||||
@@ -5,25 +5,57 @@ namespace Http
|
||||
function new()
|
||||
super()
|
||||
|
||||
' TODO: use POST once supported
|
||||
m.Get("*", function(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
|
||||
route = request.uri
|
||||
if not route.StartsWith("/invidious/set-instances")
|
||||
return false
|
||||
end if
|
||||
|
||||
components = WebUtils.UrlQueryComponents(route)
|
||||
|
||||
instances = []
|
||||
if components.DoesExist("instances")
|
||||
instances = components["instances"]
|
||||
if GetInterface(instances, "ifArray") = invalid
|
||||
instances = [instances]
|
||||
end if
|
||||
end if
|
||||
|
||||
for i = 0 to instances.Count() - 1
|
||||
if instances[i].right(1) = "/"
|
||||
instances[i] = instances[i].left(instances[i].len() - 1)
|
||||
end if
|
||||
end for
|
||||
|
||||
InvidiousSettings.SetRegistryInstances(instances)
|
||||
response.Default(200, "OK")
|
||||
return true
|
||||
end function)
|
||||
|
||||
m.Get("*", function(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
server = context.server
|
||||
|
||||
uri = request.uri
|
||||
if uri.StartsWith(Invidious.TOKEN_CALLBACK)
|
||||
components = WebUtils.UrlQueryComponents(uri)
|
||||
if components["token"] <> invalid
|
||||
' Token is encoded twice for some reason
|
||||
token = WebUtils.UrlUnescape(components["token"]).DecodeUriComponent()
|
||||
print(`Got Token: ${token}`)
|
||||
RegistryUtils.Write("invidious_token", token)
|
||||
server.task.top.login = true
|
||||
end if
|
||||
response.Redirect("/", 302)
|
||||
return true
|
||||
route = request.uri
|
||||
if not route.StartsWith(Invidious.TOKEN_CALLBACK)
|
||||
return false
|
||||
end if
|
||||
return false
|
||||
|
||||
components = WebUtils.UrlQueryComponents(route)
|
||||
if components["token"] <> invalid and components["referer"] <> invalid
|
||||
' Token is encoded twice for some reason
|
||||
token = WebUtils.UrlUnescape(components["token"]).DecodeUriComponent()
|
||||
referer = WebUtils.UrlUnescape(components["referer"])
|
||||
InvidiousSettings.SetAuthToken(token, referer)
|
||||
server.task.top.login = true
|
||||
end if
|
||||
response.Redirect("/", 302)
|
||||
return true
|
||||
end function)
|
||||
end function
|
||||
|
||||
|
||||
@@ -8,18 +8,47 @@ namespace Http
|
||||
function new()
|
||||
super()
|
||||
|
||||
m.Get("/api/state", function(context as object) as boolean
|
||||
m.Get("*", function(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
|
||||
state = {
|
||||
app: GetAppInfo(),
|
||||
device: GetDeviceInfo(),
|
||||
invidious: {
|
||||
host: Invidious.GetCurrentHost(),
|
||||
route = request.uri
|
||||
' TODO: this is not the right filtering. /api/state/something will go through, which is not correct
|
||||
if not route.StartsWith("/api/state")
|
||||
return false
|
||||
end if
|
||||
|
||||
keys = ["app", "device", "invidious"]
|
||||
|
||||
components = WebUtils.UrlQueryComponents(route)
|
||||
if components.DoesExist("key")
|
||||
keys = components["key"]
|
||||
if GetInterface(keys, "ifArray") = invalid
|
||||
keys = [keys]
|
||||
end if
|
||||
end if
|
||||
|
||||
state = {}
|
||||
|
||||
if ArrayIndexOf(keys, "app") <> -1
|
||||
state["app"] = GetAppInfo()
|
||||
end if
|
||||
|
||||
if ArrayIndexOf(keys, "device") <> -1
|
||||
state["device"] = GetDeviceInfo()
|
||||
end if
|
||||
|
||||
if ArrayIndexOf(keys, "invidious") <> -1
|
||||
authToken = InvidiousSettings.GetAuthToken()
|
||||
state["invidious"] = {
|
||||
instances: InvidiousSettings.GetCurrentInstances(),
|
||||
selected_instance: InvidiousSettings.GetSelectedInstance(),
|
||||
auth_url: Invidious.GetAuthorizeTokenLink(),
|
||||
logged_in: Invidious.GetAuthenticationHeaders() <> invalid
|
||||
logged_in: authToken <> invalid,
|
||||
logged_in_instance: authToken <> invalid ? authToken.instance : invalid
|
||||
}
|
||||
}
|
||||
end if
|
||||
|
||||
response.Json(state)
|
||||
return true
|
||||
end function)
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import "pkg:/source/services/Invidious.bs"
|
||||
|
||||
sub init()
|
||||
m.instructions = m.top.findNode("instructions")
|
||||
|
||||
text = "- Scan the QR Code" + chr(10)
|
||||
text += "- Login (Create account if needed)" + chr(10)
|
||||
text += "- Scan the QR Code again" + chr(10)
|
||||
text += "- Click ""Authorize""" + chr(10)
|
||||
text += "- If the error ""Invalid signature"" shows, press back and ""Authorize"" again" + chr(10)
|
||||
text += "- Your TV should go to home screen automatically" + chr(10)
|
||||
text += chr(10) + chr(10) + chr(10)
|
||||
text += "Invidious instance: " + Invidious.GetCurrentHost()
|
||||
|
||||
m.instructions.text = text
|
||||
end sub
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<component
|
||||
name='QRTestScene'
|
||||
extends='Scene'>
|
||||
<children>
|
||||
<!-- This is example use of QRPoster: show QRCode centered on screen -->
|
||||
<QRPoster
|
||||
id='TestQRPoster'
|
||||
loadWidth='500'
|
||||
loadHeight='500'
|
||||
loadPadding='20'
|
||||
translation='[100, 110]' />
|
||||
<Label
|
||||
id='instructionsTitle'
|
||||
height='50'
|
||||
width='500'
|
||||
text='Instructions'
|
||||
font='font:MediumBoldSystemFont'
|
||||
wrap='true'
|
||||
translation='[650,110]' />
|
||||
<Label
|
||||
id='instructions'
|
||||
height='500'
|
||||
width='500'
|
||||
font='font:MediumSystemFont'
|
||||
wrap='true'
|
||||
translation='[650,160]' />
|
||||
</children>
|
||||
|
||||
</component>
|
||||
Reference in new issue
Block a user