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>
|
||||
@@ -4,11 +4,10 @@ import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/source/utils/General.bs"
|
||||
import "pkg:/source/utils/TimeUtils.bs"
|
||||
import "pkg:/source/utils/WebUtils.bs"
|
||||
import "pkg:/source/services/InvidiousSettings.bs"
|
||||
|
||||
namespace Invidious
|
||||
' TODO: query server status, check if it supports APIs and/or signups
|
||||
const API_URL = "https://vid.puffyan.us"
|
||||
|
||||
const TOKEN_CALLBACK = "/invidious/token_callback"
|
||||
|
||||
const POPULAR_ENDPOINT = "/api/v1/popular"
|
||||
@@ -33,7 +32,8 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function GetPopular() as object
|
||||
url = `${Invidious.API_URL}${Invidious.POPULAR_ENDPOINT}`
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
url = `${instance}${Invidious.POPULAR_ENDPOINT}`
|
||||
|
||||
args = Invidious.DefaultArgs()
|
||||
response = Requests().get(url, args)
|
||||
@@ -45,7 +45,8 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function GetTrending(trendingType = "" as string) as object
|
||||
url = `${Invidious.API_URL}${Invidious.TRENDING_ENDPOINT}`
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
url = `${instance}${Invidious.TRENDING_ENDPOINT}`
|
||||
|
||||
args = Invidious.DefaultArgs()
|
||||
if trendingType <> ""
|
||||
@@ -61,7 +62,8 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function GetVideoUrl(videoId as string, itag as string, local as boolean) as string
|
||||
url = `${Invidious.API_URL}/latest_version?id=${videoId}&itag=${itag}`
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
url = `${instance}/latest_version?id=${videoId}&itag=${itag}`
|
||||
if local
|
||||
url = url + "&local=true"
|
||||
end if
|
||||
@@ -69,7 +71,8 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function GetVideoMetadata(videoId as string) as object
|
||||
url = `${Invidious.API_URL}${Invidious.VIDEOS_ENDPOINT}/${videoId}`
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
url = `${instance}${Invidious.VIDEOS_ENDPOINT}/${videoId}`
|
||||
|
||||
args = Invidious.DefaultArgs()
|
||||
response = Requests().get(url, args)
|
||||
@@ -82,7 +85,8 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function SearchSuggestions(q as string) as object 'SearchSuggestionResult
|
||||
url = `${Invidious.API_URL}${Invidious.SEARCH_SUGGEST_ENDPOINT}`
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
url = `${instance}${Invidious.SEARCH_SUGGEST_ENDPOINT}`
|
||||
|
||||
args = Invidious.DefaultArgs()
|
||||
args.params.q = q
|
||||
@@ -95,7 +99,8 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function Search(q as string, args = invalid as dynamic) as object
|
||||
url = `${Invidious.API_URL}${Invidious.SEARCH_ENDPOINT}`
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
url = `${instance}${Invidious.SEARCH_ENDPOINT}`
|
||||
|
||||
_args = Invidious.DefaultArgs()
|
||||
_args.params.q = q
|
||||
@@ -128,39 +133,33 @@ namespace Invidious
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function GetCurrentHost() as string
|
||||
return Invidious.API_URL
|
||||
end function
|
||||
|
||||
function GetAuthorizeTokenLink() as string
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
' Make sure the host is not on https, because https cannot redirect to http, which is our local server
|
||||
invidiousHost = `${Invidious.API_URL}`.Replace("https://", "http://")
|
||||
invidiousHost = instance.Replace("https://", "http://")
|
||||
|
||||
localIp = GetLocalIpAddress()
|
||||
webServerPort = 8888
|
||||
expire = TimeUtils.Now().AsSeconds() + 60 * 60 * 24 * 30 'A month from now
|
||||
|
||||
callbackUrl = WebUtils.UrlEncode(`http://${localIp}:${webServerPort}${Invidious.TOKEN_CALLBACK}`)
|
||||
callbackUrl = WebUtils.UrlEncode(`http://${localIp}:${webServerPort}${Invidious.TOKEN_CALLBACK}?referer=${instance}`)
|
||||
return `${invidiousHost}/authorize_token?scopes=${Invidious.AUTH_SCOPE}&callback_url=${callbackUrl}&expire=${expire}`
|
||||
end function
|
||||
|
||||
function GetAuthenticationHeaders() as object
|
||||
token = RegistryUtils.Read("invidious_token")
|
||||
if token = invalid
|
||||
return invalid
|
||||
end if
|
||||
function GetAuthenticationHeaders(token as string) as object
|
||||
return {
|
||||
"Authorization": `Bearer ${token}`
|
||||
}
|
||||
end function
|
||||
|
||||
function GetUserFeed() as object
|
||||
headers = Invidious.GetAuthenticationHeaders()
|
||||
if headers = invalid
|
||||
return invalid
|
||||
authToken = InvidiousSettings.GetAuthToken()
|
||||
if authToken = invalid
|
||||
return false
|
||||
end if
|
||||
headers = Invidious.GetAuthenticationHeaders(authToken.token)
|
||||
|
||||
url = `${Invidious.API_URL}${Invidious.AUTH_FEED}`
|
||||
url = `${authToken.instance}${Invidious.AUTH_FEED}`
|
||||
|
||||
args = {
|
||||
headers: headers,
|
||||
@@ -170,7 +169,7 @@ namespace Invidious
|
||||
response = Requests().get(url, args)
|
||||
|
||||
if response.statuscode = 403
|
||||
RegistryUtils.Delete("invidious_token")
|
||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||
end if
|
||||
if response.statuscode = 200
|
||||
return response.json.videos
|
||||
@@ -179,12 +178,13 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function GetUserPlaylists() as object
|
||||
headers = Invidious.GetAuthenticationHeaders()
|
||||
if headers = invalid
|
||||
return invalid
|
||||
authToken = InvidiousSettings.GetAuthToken()
|
||||
if authToken = invalid
|
||||
return false
|
||||
end if
|
||||
headers = Invidious.GetAuthenticationHeaders(authToken.token)
|
||||
|
||||
url = `${Invidious.API_URL}${Invidious.AUTH_PLAYLISTS}`
|
||||
url = `${authToken.instance}${Invidious.AUTH_PLAYLISTS}`
|
||||
|
||||
args = {
|
||||
headers: headers,
|
||||
@@ -194,7 +194,7 @@ namespace Invidious
|
||||
response = Requests().get(url, args)
|
||||
|
||||
if response.statuscode = 403
|
||||
RegistryUtils.Delete("invidious_token")
|
||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||
end if
|
||||
if response.statuscode = 200
|
||||
return response.json
|
||||
@@ -203,24 +203,24 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function Logout() as boolean
|
||||
headers = Invidious.GetAuthenticationHeaders()
|
||||
if headers = invalid
|
||||
authToken = InvidiousSettings.GetAuthToken()
|
||||
if authToken = invalid
|
||||
return false
|
||||
end if
|
||||
headers = Invidious.GetAuthenticationHeaders(authToken.token)
|
||||
|
||||
url = `${Invidious.API_URL}${Invidious.AUTH_TOKENS_UNREGISTER}`
|
||||
url = `${authToken.instance}${Invidious.AUTH_TOKENS_UNREGISTER}`
|
||||
|
||||
' token is already valid json that contains the "session" key needed by the unregister endpoint
|
||||
token = RegistryUtils.Read("invidious_token")
|
||||
' authToken.token is already valid json that contains the "session" key needed by the unregister endpoint
|
||||
headers["Content-Type"] = "application/json"
|
||||
args = {
|
||||
headers: headers,
|
||||
data: token
|
||||
data: authToken.token
|
||||
}
|
||||
|
||||
Requests().post(url, args)
|
||||
|
||||
RegistryUtils.Delete("invidious_token")
|
||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||
return true
|
||||
end function
|
||||
end namespace
|
||||
@@ -1,10 +1,9 @@
|
||||
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
||||
import "pkg:/source/utils/RegistryUtils.bs"
|
||||
import "pkg:/source/utils/General.bs"
|
||||
import "pkg:/source/services/InvidiousSettings.bs"
|
||||
|
||||
class InvidiousService
|
||||
API_URL = "https://vid.puffyan.us"
|
||||
|
||||
private endpoints
|
||||
private responseHanlders
|
||||
|
||||
@@ -29,16 +28,19 @@ class InvidiousService
|
||||
return invalid
|
||||
end if
|
||||
|
||||
url = m.API_URL + endpoint.url
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
|
||||
url = instance + endpoint.url
|
||||
|
||||
args = { params: {} }
|
||||
|
||||
if endpoint.authenticated = true
|
||||
auth_headers = m.GetAuthenticationHeaders()
|
||||
if auth_headers = invalid
|
||||
authToken = InvidiousSettings.GetAuthToken()
|
||||
if authToken = invalid
|
||||
return invalid
|
||||
end if
|
||||
args.headers = auth_headers
|
||||
url = authToken.instance + endpoint.url
|
||||
args.headers = m.GetAuthenticationHeaders(authToken.token)
|
||||
end if
|
||||
|
||||
if endpoint.queryParams <> invalid
|
||||
@@ -73,11 +75,7 @@ class InvidiousService
|
||||
return responseHandler(m, requestData, response)
|
||||
end function
|
||||
|
||||
function GetAuthenticationHeaders() as object
|
||||
token = RegistryUtils.Read("invidious_token")
|
||||
if token = invalid
|
||||
return invalid
|
||||
end if
|
||||
function GetAuthenticationHeaders(token as string) as object
|
||||
return {
|
||||
"Authorization": `Bearer ${token}`
|
||||
}
|
||||
@@ -118,7 +116,7 @@ class InvidiousService
|
||||
if response.statuscode = 403
|
||||
print(`Server responded with 403: ${response.text}`)
|
||||
print("deleting token...")
|
||||
RegistryUtils.Delete("invidious_token")
|
||||
RegistryUtils.Delete(RegistryUtils.INVIDIOUS_TOKEN)
|
||||
end if
|
||||
end function
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
namespace InvidiousSettings
|
||||
|
||||
const DEFAULT_INSTANCE = "https://vid.puffyan.us"
|
||||
|
||||
const INSTANCES_API = "https://api.invidious.io/instances.json?sort_by=type,health,users,api"
|
||||
|
||||
function GetCurrentInstances() as object
|
||||
' TODO: cache this call to avoid json parsing every time
|
||||
instances = InvidiousSettings.GetRegistryInstances()
|
||||
if instances.Count() > 0
|
||||
return instances
|
||||
end if
|
||||
|
||||
publicInstances = InvidiousSettings.GetPublicInstances()
|
||||
if publicInstances <> invalid
|
||||
for i = 0 to 4
|
||||
if i < publicInstances.Count()
|
||||
instances.push(publicInstances[i].uri)
|
||||
end if
|
||||
end for
|
||||
end if
|
||||
|
||||
if instances.Count() > 0
|
||||
InvidiousSettings.SetRegistryInstances(instances)
|
||||
return instances
|
||||
end if
|
||||
|
||||
return [InvidiousSettings.DEFAULT_INSTANCE]
|
||||
end function
|
||||
|
||||
function GetSelectedInstance() as string
|
||||
instances = InvidiousSettings.GetCurrentInstances()
|
||||
return instances[0]
|
||||
end function
|
||||
|
||||
function SetAuthToken(token as string, instance as string)
|
||||
json = FormatJson({
|
||||
token: token,
|
||||
instance: instance
|
||||
})
|
||||
RegistryUtils.Write(RegistryUtils.INVIDIOUS_TOKEN, json)
|
||||
|
||||
instances = InvidiousSettings.GetCurrentInstances()
|
||||
index = ArrayIndexOf(instances, instance)
|
||||
if index = -1
|
||||
instances.push(instance)
|
||||
InvidiousSettings.SetRegistryInstances(instances)
|
||||
end if
|
||||
end function
|
||||
|
||||
function GetAuthToken() as dynamic
|
||||
tokenPayload = RegistryUtils.Read(RegistryUtils.INVIDIOUS_TOKEN)
|
||||
if tokenPayload = invalid
|
||||
return invalid
|
||||
end if
|
||||
return ParseJson(tokenPayload)
|
||||
end function
|
||||
|
||||
function GetRegistryInstances() as object
|
||||
instances = RegistryUtils.Read(RegistryUtils.INVIDIOUS_INSTANCES)
|
||||
if instances = invalid
|
||||
return []
|
||||
end if
|
||||
return ParseJson(instances)
|
||||
end function
|
||||
|
||||
function SetRegistryInstances(instances as object)
|
||||
RegistryUtils.Write(RegistryUtils.INVIDIOUS_INSTANCES, FormatJson(instances))
|
||||
end function
|
||||
|
||||
function GetPublicInstances() as object
|
||||
if m.invidiousPublicInstances <> invalid
|
||||
return m.invidiousPublicInstances
|
||||
end if
|
||||
response = Requests().get(InvidiousSettings.INSTANCES_API)
|
||||
if response.statuscode = 200
|
||||
json = response.json
|
||||
instances = []
|
||||
|
||||
for each instance in json
|
||||
data = instance[1]
|
||||
if data.monitor <> invalid and data.monitor.dailyRatios <> invalid
|
||||
data.monitor.dailyRatios = invalid
|
||||
end if
|
||||
data["name"] = instance[0]
|
||||
instances.push(data)
|
||||
end for
|
||||
|
||||
m.invidiousPublicInstances = instances
|
||||
end if
|
||||
|
||||
return m.invidiousPublicInstances
|
||||
end function
|
||||
|
||||
end namespace
|
||||
@@ -2,6 +2,9 @@ namespace RegistryUtils
|
||||
|
||||
const DEFAULT_SECTION = "Playlet"
|
||||
|
||||
const INVIDIOUS_INSTANCES = "invidious_instances"
|
||||
const INVIDIOUS_TOKEN = "invidious_token"
|
||||
|
||||
function Read(key as string, section = DEFAULT_SECTION as string) as dynamic
|
||||
sec = CreateObject("roRegistrySection", section)
|
||||
if sec.Exists(key)
|
||||
|
||||
@@ -34,12 +34,26 @@ namespace WebUtils
|
||||
url = Mid(url, index + 1)
|
||||
components = url.split("&")
|
||||
for each component in components
|
||||
key = component
|
||||
value = ""
|
||||
hasValue = false
|
||||
if Instr(0, component, "=")
|
||||
keyValue = component.split("=")
|
||||
query[keyValue[0]] = keyValue[1]
|
||||
else
|
||||
query[component] = ""
|
||||
key = keyValue[0]
|
||||
value = keyValue[1]
|
||||
hasValue = true
|
||||
end if
|
||||
|
||||
if query.DoesExist(key) and hasValue
|
||||
oldValue = query[key]
|
||||
if GetInterface(oldValue, "ifArray") = invalid
|
||||
oldValue = [oldValue]
|
||||
end if
|
||||
oldValue.push(value)
|
||||
value = oldValue
|
||||
end if
|
||||
|
||||
query[key] = value
|
||||
end for
|
||||
return query
|
||||
end function
|
||||
|
||||
+162
-10
@@ -5,13 +5,26 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Playlet</title>
|
||||
<style>
|
||||
table,
|
||||
th,
|
||||
td {
|
||||
border: 1px solid;
|
||||
cursor: all-scroll;
|
||||
}
|
||||
|
||||
table {
|
||||
-webkit-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body ondrop="OnDrop(event);" ondragover="OnDragover(event);">
|
||||
<body ondrop="OnBodyDrop(event);" ondragover="OnBodyDragover(event);">
|
||||
<h2>Playlet - Youtube Player for Roku</h2>
|
||||
<h4 id="app-version">Version: </h4>
|
||||
<h4>Invidious Instance: <a id="host" target="_blank">None</a></h4>
|
||||
|
||||
<h4>Invidious Instance: <a id="instance" target="_blank">None</a></h4>
|
||||
<button onclick="PlayVideo()">Play Video</button>
|
||||
<label for="video-id">Video ID:</label>
|
||||
<input type="text" id="video-id" name="video-id" style="min-width:300px;">
|
||||
@@ -20,6 +33,31 @@
|
||||
<button style="display: none" id="login-button" onclick="Login()">Login</button>
|
||||
<button style="display: none" id="logout-button" onclick="Logout()">Logout</button>
|
||||
|
||||
<br />
|
||||
|
||||
<table id="instances">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Instances - find more at <a href="https://api.invidious.io/" target="_blank">api.invidious.io</a></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
<tbody>
|
||||
<tr id="instance-input-row">
|
||||
<td>
|
||||
<input type="text" id="instance-input" name="new-instance" oninput="OnNewInstanceTextChanged()"
|
||||
style="min-width:300px;">
|
||||
</td>
|
||||
<td>
|
||||
<button id="instance-add" disabled="true" onclick="AddInstance()">Add</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</br>
|
||||
<button style="display: none" id="update-instances" onclick="UpdateInstances()">Update Instances</button>
|
||||
|
||||
<h5>Instructions</h5>
|
||||
<ul>
|
||||
<li>Make sure you are logged in the Invidious instance before logging in on this page</li>
|
||||
@@ -124,6 +162,66 @@ ${JSON.stringify(window.appState.device, null, 2)}
|
||||
return urlSearchParams.get('v')
|
||||
}
|
||||
|
||||
function OnNewInstanceTextChanged() {
|
||||
document.getElementById("instance-add").disabled = !IsValidHttpUrl(document.getElementById("instance-input").value)
|
||||
}
|
||||
|
||||
function AddInstance() {
|
||||
instance = document.getElementById("instance-input").value
|
||||
AddInstanceRow(instance)
|
||||
document.getElementById("instance-input").value = ""
|
||||
document.getElementById("update-instances").style.display = "block";
|
||||
}
|
||||
|
||||
function AddInstanceRow(instance) {
|
||||
instances = document.getElementById("instances").getElementsByTagName('tbody')[0];
|
||||
var row = instances.insertRow();
|
||||
row.draggable = true
|
||||
row.addEventListener('dragstart', OnTableRowDragStart);
|
||||
row.addEventListener('dragover', OnTableRowDragover);
|
||||
row.addEventListener('drop', OnTableRowDrop);
|
||||
var cell = row.insertCell();
|
||||
style = instance === window.appState.invidious.selected_instance ? `style="font-weight:bold"` : ""
|
||||
cell.innerHTML = `<a href="${instance}" ${style} target="_blank">${instance}</a>`
|
||||
cell = row.insertCell();
|
||||
cell.innerHTML = `<button onclick="RemoveInstance('${instance}')">Remove</button>`
|
||||
}
|
||||
|
||||
function RemoveInstance(instance) {
|
||||
instanceRows = Array.from(document.getElementById("instances")
|
||||
.getElementsByTagName('tbody')[0]
|
||||
.getElementsByTagName('tr'));
|
||||
|
||||
for (const i in instanceRows) {
|
||||
currentInstance = instanceRows[i].getElementsByTagName('a')[0].innerText
|
||||
if (currentInstance === instance) {
|
||||
instanceRows[i].remove()
|
||||
document.getElementById("update-instances").style.display = "block";
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function UpdateInstances() {
|
||||
instances = Array.from(document.getElementById("instances")
|
||||
.getElementsByTagName('tbody')[0]
|
||||
.getElementsByTagName('td'))
|
||||
.map(el => el.getElementsByTagName('a')[0])
|
||||
.filter(a => !!a)
|
||||
.map(a => a.innerText);
|
||||
|
||||
args = instances.map(instance => `instances=${instance}`).join("&")
|
||||
|
||||
fetch(`/invidious/set-instances?${args}`)
|
||||
.then(function (response) {
|
||||
alert("Instances updated. Restart Playlet to reflect changes.")
|
||||
window.location.reload();
|
||||
})
|
||||
.catch(function (err) {
|
||||
alert(err)
|
||||
});
|
||||
}
|
||||
|
||||
function Initialize() {
|
||||
fetch("/api/state")
|
||||
.then(function (response) {
|
||||
@@ -134,11 +232,24 @@ ${JSON.stringify(window.appState.device, null, 2)}
|
||||
console.log(appState)
|
||||
|
||||
document.getElementById("app-version").innerText = `Version: ${appState.app.version}`
|
||||
document.getElementById("logged-in").innerText = `Logged In: ${appState.invidious.logged_in}`
|
||||
document.getElementById("host").innerText = appState.invidious.host
|
||||
document.getElementById("host").href = appState.invidious.host
|
||||
|
||||
document.getElementById("login-button").style.display = appState.invidious.logged_in ? "none" : "block";
|
||||
if (appState.invidious.logged_in) {
|
||||
document.getElementById("logged-in").innerHTML = `Logged In: true (<a href="${appState.invidious.logged_in_instance}" target="_blank">${appState.invidious.logged_in_instance}</a>)`
|
||||
} else {
|
||||
document.getElementById("logged-in").innerHTML = "Logged In: false"
|
||||
}
|
||||
|
||||
instanceEl = document.getElementById("instance")
|
||||
instanceEl.innerText = instanceEl.href = appState.invidious.selected_instance
|
||||
|
||||
for (var i in appState.invidious.instances) {
|
||||
AddInstanceRow(appState.invidious.instances[i])
|
||||
}
|
||||
|
||||
loginButton = document.getElementById("login-button")
|
||||
loginButton.innerText = `Login (${appState.invidious.selected_instance})`
|
||||
loginButton.style.display = appState.invidious.logged_in ? "none" : "block";
|
||||
|
||||
document.getElementById("logout-button").style.display = !appState.invidious.logged_in ? "none" : "block";
|
||||
|
||||
document.getElementById("feedback-url").href = CreateGithubIssueUrl()
|
||||
@@ -148,12 +259,53 @@ ${JSON.stringify(window.appState.device, null, 2)}
|
||||
});
|
||||
}
|
||||
|
||||
function OnDrop(event) {
|
||||
var tableRow;
|
||||
function OnTableRowDragStart(event) {
|
||||
target = event.target;
|
||||
while (target && target.tagName !== 'TR') {
|
||||
target = target.parentNode
|
||||
}
|
||||
if (target.id === "instance-input-row") {
|
||||
return
|
||||
}
|
||||
tableRow = target
|
||||
}
|
||||
|
||||
function OnTableRowDragover(event) {
|
||||
event.preventDefault();
|
||||
|
||||
if (!tableRow) {
|
||||
return
|
||||
}
|
||||
|
||||
target = event.target;
|
||||
while (target && target.tagName !== 'TR') {
|
||||
target = target.parentNode
|
||||
}
|
||||
if (!target || target.id === "instance-input-row") {
|
||||
return
|
||||
}
|
||||
|
||||
let children = Array.from(target.parentNode.children);
|
||||
|
||||
if (children.indexOf(target) > children.indexOf(tableRow))
|
||||
target.after(tableRow);
|
||||
else
|
||||
target.before(tableRow);
|
||||
}
|
||||
|
||||
function OnTableRowDrop(event) {
|
||||
event.preventDefault();
|
||||
tableRow = undefined
|
||||
document.getElementById("update-instances").style.display = "block";
|
||||
}
|
||||
|
||||
function OnBodyDrop(event) {
|
||||
for (var i in event.dataTransfer.items) {
|
||||
let item = event.dataTransfer.items[i]
|
||||
if (item.kind = 'string' && item.getAsString) {
|
||||
item.getAsString((dataString) => {
|
||||
if (IsValidHttpUrl(dataString)) {
|
||||
if (IsValidHttpUrl(dataString) && GetVideoId(dataString)) {
|
||||
document.getElementById('video-id').value = dataString
|
||||
}
|
||||
});
|
||||
@@ -162,7 +314,7 @@ ${JSON.stringify(window.appState.device, null, 2)}
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
function OnDragover(event) {
|
||||
function OnBodyDragover(event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user