Preferences / Web App (#79)
* Add basic router * Add a preferences file * small changes * Basic settings navigation menu * Lint fix * Add bunch of controls * Lint fix * StringControl * Lint fix * Add description to keyboard * Settings saving and loading * Lint fix * Settings migration stuff * GET web api * Lint fix * PUT and DELETE (I really fucking hate BrightScript) * plug in sponsorblock settings * autoplay, quality, and video proxying * Remove unused stuff * Lint fix * Invidious instance stuff * cache public instances on start * Start loading home screen after fetching instances * Move web app out of settings to its own screen * picture in picture when in settings * Web app (#80) * Update instance stuff * Update dependencies * Add basic layout * Info and settings page, missing styling * Navbar fixes * Settings page formatting * Theme stuff * Feedback link * Fix username badge * Fix svelte warnings * A wip search page * Add a couple of api functions * Wip home screen * user country code * Expose token and proxy auth calls * Use auth requests server side * Some cleanup * Add svelte vs code extension * remove old web app * More layout stuff * Tweak for string control * Filter out old search suggestions * Search history stuff * img size for lazy loading * Basic modal to play video * Lint fix * Dependencies bump * Add video duration and LIVE indicator to cell * Delete legacy stuff * Add dev menu * Lint fix * Video cell layout * Cell stuff * prefs visibility * Modal layout * Drag and drop functionality * Clear search history * Move web calls to main app * changelog * changelog * Mostly comments * Lint fix --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
9a631aab51
commit
8f8c7d38a8
91 files changed
+3979
-1787
No files matched your search
@@ -32,7 +32,7 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function GetServerStats() as object
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
instance = InvidiousSettings.GetCurrentInstance()
|
||||
url = `${instance}${Invidious.STATS_ENDPOINT}`
|
||||
|
||||
response = Requests().get(url)
|
||||
@@ -43,7 +43,7 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function GetVideoStreamUrl(videoId as string, local as boolean) as string
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
instance = InvidiousSettings.GetCurrentInstance()
|
||||
url = `${instance}/latest_version?id=${videoId}`
|
||||
if local
|
||||
url = url + "&local=true"
|
||||
@@ -52,7 +52,7 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function GetVideoDashUrl(videoId as string, local as boolean) as string
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
instance = InvidiousSettings.GetCurrentInstance()
|
||||
url = `${instance}/api/manifest/dash/id/${videoId}`
|
||||
if local
|
||||
url = url + "?local=true"
|
||||
@@ -61,7 +61,7 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function GetVideoMetadata(videoId as string) as object
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
instance = InvidiousSettings.GetCurrentInstance()
|
||||
url = `${instance}${Invidious.VIDEOS_ENDPOINT}/${videoId}`
|
||||
|
||||
args = Invidious.DefaultArgs()
|
||||
@@ -94,7 +94,7 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function SearchSuggestions(q as string) as object 'SearchSuggestionResult
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
instance = InvidiousSettings.GetCurrentInstance()
|
||||
url = `${instance}${Invidious.SEARCH_SUGGEST_ENDPOINT}`
|
||||
|
||||
args = Invidious.DefaultArgs()
|
||||
@@ -110,7 +110,7 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function Search(q as string, args = invalid as dynamic) as object
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
instance = InvidiousSettings.GetCurrentInstance()
|
||||
url = `${instance}${Invidious.SEARCH_ENDPOINT}`
|
||||
|
||||
_args = Invidious.DefaultArgs()
|
||||
@@ -145,7 +145,7 @@ namespace Invidious
|
||||
end function
|
||||
|
||||
function GetAuthorizeTokenLink() as string
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
instance = InvidiousSettings.GetCurrentInstance()
|
||||
' Make sure the host is not on https, because https cannot redirect to http, which is our local server
|
||||
invidiousHost = instance.Replace("https://", "http://")
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
||||
import "pkg:/source/utils/TimeUtils.bs"
|
||||
import "pkg:/source/utils/RegistryUtils.bs"
|
||||
import "pkg:/source/utils/General.bs"
|
||||
import "pkg:/source/utils/Crypto.bs"
|
||||
import "pkg:/source/services/InvidiousSettings.bs"
|
||||
|
||||
class InvidiousService
|
||||
@@ -30,7 +31,7 @@ class InvidiousService
|
||||
return invalid
|
||||
end if
|
||||
|
||||
instance = InvidiousSettings.GetSelectedInstance()
|
||||
instance = InvidiousSettings.GetCurrentInstance()
|
||||
|
||||
url = instance + endpoint.url
|
||||
|
||||
@@ -72,15 +73,18 @@ class InvidiousService
|
||||
end for
|
||||
end if
|
||||
|
||||
if endpoint.requestArgs <> invalid
|
||||
args.append(endpoint.requestArgs)
|
||||
end if
|
||||
|
||||
response = Requests().get(url, args)
|
||||
|
||||
responseHandler = endpoint.responseHandler <> invalid ? m.responseHanlders[endpoint.responseHandler] : m.responseHanlders["DefaultHandler"]
|
||||
|
||||
return responseHandler(m, requestData, response)
|
||||
result = responseHandler(m, requestData, response)
|
||||
|
||||
if result <> invalid and endpoint.authenticated = true
|
||||
' Cache response for use by web app
|
||||
m.CacheResponse(requestData, result)
|
||||
end if
|
||||
|
||||
return result
|
||||
end function
|
||||
|
||||
function GetAuthenticationHeaders(token as string) as object
|
||||
@@ -91,7 +95,7 @@ class InvidiousService
|
||||
|
||||
function DefaultHandler(m as object, requestData as object, response as object) as object
|
||||
if response.statuscode = 200
|
||||
return response.json
|
||||
return [{ title: requestData.title, videos: response.json }]
|
||||
end if
|
||||
return invalid
|
||||
end function
|
||||
@@ -103,7 +107,7 @@ class InvidiousService
|
||||
videos = []
|
||||
videos.Append(response.json.notifications)
|
||||
videos.Append(response.json.videos)
|
||||
return videos
|
||||
return [{ title: requestData.title, videos: videos }]
|
||||
end if
|
||||
return invalid
|
||||
end function
|
||||
@@ -112,9 +116,9 @@ class InvidiousService
|
||||
m.DeleteExpiredToken(response)
|
||||
if response.statuscode = 200
|
||||
playlists = response.json
|
||||
result = {}
|
||||
result = []
|
||||
for each playlist in playlists
|
||||
result.append(m.ProcessPlaylist(requestData, playlist))
|
||||
result.push(m.ProcessPlaylist(requestData, playlist))
|
||||
end for
|
||||
return result
|
||||
end if
|
||||
@@ -124,17 +128,14 @@ class InvidiousService
|
||||
function PlaylistHandler(m as object, requestData as object, response as object) as object
|
||||
if response.statuscode = 200
|
||||
playlist = response.json
|
||||
return m.ProcessPlaylist(requestData, playlist)
|
||||
return [m.ProcessPlaylist(requestData, playlist)]
|
||||
end if
|
||||
return invalid
|
||||
end function
|
||||
|
||||
function ProcessPlaylist(requestData as object, playlist as object) as object
|
||||
title = requestData.title
|
||||
title = m.ProcessTemplate(title, playlist)
|
||||
result = {}
|
||||
result[title] = playlist.videos
|
||||
return result
|
||||
title = m.ProcessTemplate(requestData.title, playlist)
|
||||
return { title: title, videos: playlist.videos }
|
||||
end function
|
||||
|
||||
function ProcessTemplate(template as string, data as object) as string
|
||||
@@ -172,4 +173,11 @@ class InvidiousService
|
||||
currentTime = TimeUtils.Now().AsSeconds()
|
||||
return expire < currentTime
|
||||
end function
|
||||
|
||||
function CacheResponse(requestData as object, result as object)
|
||||
cacheKey = FormatJson(requestData)
|
||||
cacheKey = GetMd5(cacheKey)
|
||||
value = FormatJson(result)
|
||||
WriteAsciiFile(`tmp:/${cacheKey}.json`, value)
|
||||
end function
|
||||
end class
|
||||
@@ -1,4 +1,6 @@
|
||||
import "pkg:/source/utils/RegistryUtils.bs"
|
||||
import "pkg:/components/SettingsScreen/Settings.bs"
|
||||
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
||||
|
||||
namespace InvidiousSettings
|
||||
|
||||
@@ -6,36 +8,17 @@ namespace InvidiousSettings
|
||||
|
||||
const INSTANCES_API = "https://api.invidious.io/instances.json?sort_by=type,users"
|
||||
|
||||
function GetCurrentInstances() as object
|
||||
' TODO: cache this call to avoid json parsing every time
|
||||
instances = InvidiousSettings.GetRegistryInstances()
|
||||
if instances.Count() > 0
|
||||
return instances
|
||||
function GetCurrentInstance() as object
|
||||
settings = FindAndGetPreferenceValues(["invidious.instance"])
|
||||
if settings <> invalid and settings["invidious.instance"] <> invalid and settings["invidious.instance"] <> ""
|
||||
return settings["invidious.instance"]
|
||||
end if
|
||||
|
||||
publicInstances = InvidiousSettings.GetPublicInstances()
|
||||
if publicInstances <> invalid
|
||||
for i = 0 to publicInstances.Count() - 1
|
||||
if InvidiousSettings.IsValidPublicInstance(publicInstances[i])
|
||||
instances.push(publicInstances[i].uri)
|
||||
end if
|
||||
if instances.Count() >= 5
|
||||
exit for
|
||||
end if
|
||||
end for
|
||||
backupInstances = InvidiousSettings.GetBackupInstances()
|
||||
if backupInstances.Count() > 0
|
||||
return backupInstances[0]
|
||||
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]
|
||||
return InvidiousSettings.DEFAULT_INSTANCE
|
||||
end function
|
||||
|
||||
function SetAuthToken(token as string, instance as string, username as dynamic)
|
||||
@@ -49,13 +32,6 @@ namespace InvidiousSettings
|
||||
|
||||
json = FormatJson(obj)
|
||||
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
|
||||
@@ -66,27 +42,34 @@ namespace InvidiousSettings
|
||||
return ParseJson(tokenPayload)
|
||||
end function
|
||||
|
||||
function GetRegistryInstances() as object
|
||||
instances = RegistryUtils.Read(RegistryUtils.INVIDIOUS_INSTANCES)
|
||||
if instances = invalid
|
||||
return []
|
||||
function GetBackupInstances() as object
|
||||
if m.global.hasField("invidiousBackupInstances")
|
||||
return m.global.invidiousBackupInstances
|
||||
end if
|
||||
return ParseJson(instances)
|
||||
return []
|
||||
end function
|
||||
|
||||
function SetRegistryInstances(instances as object)
|
||||
RegistryUtils.Write(RegistryUtils.INVIDIOUS_INSTANCES, FormatJson(instances))
|
||||
function FetchBackupInstances() as object
|
||||
backupInstances = []
|
||||
publicInstances = InvidiousSettings.GetPublicInstances()
|
||||
for i = 0 to publicInstances.Count() - 1
|
||||
if InvidiousSettings.IsValidPublicInstance(publicInstances[i])
|
||||
backupInstances.push(publicInstances[i].uri)
|
||||
end if
|
||||
if backupInstances.Count() >= 5
|
||||
exit for
|
||||
end if
|
||||
end for
|
||||
|
||||
return backupInstances
|
||||
end function
|
||||
|
||||
function GetPublicInstances() as object
|
||||
if m.invidiousPublicInstances <> invalid
|
||||
return m.invidiousPublicInstances
|
||||
end if
|
||||
instances = []
|
||||
|
||||
response = Requests().get(InvidiousSettings.INSTANCES_API)
|
||||
if response.statuscode = 200
|
||||
json = response.json
|
||||
instances = []
|
||||
|
||||
for each instance in json
|
||||
data = instance[1]
|
||||
@@ -97,10 +80,9 @@ namespace InvidiousSettings
|
||||
instances.push(data)
|
||||
end for
|
||||
|
||||
m.invidiousPublicInstances = instances
|
||||
end if
|
||||
|
||||
return m.invidiousPublicInstances
|
||||
return instances
|
||||
end function
|
||||
|
||||
function IsValidPublicInstance(instance as object) as boolean
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
import "pkg:/source/utils/RegistryUtils.bs"
|
||||
|
||||
class PreferencesService
|
||||
private version = 1
|
||||
private prefs_model
|
||||
private user_prefs
|
||||
|
||||
function new()
|
||||
m.LoadConfigFile()
|
||||
m.LoadUserPreferences()
|
||||
end function
|
||||
|
||||
function LoadConfigFile()
|
||||
m.prefs_model = ParseJson(ReadAsciiFile("libpkg:/config/preferences.json"))
|
||||
end function
|
||||
|
||||
function LoadUserPreferences()
|
||||
' Step 1: Load user preferences from registry
|
||||
m.user_prefs = RegistryUtils.Read(RegistryUtils.USER_PREFERENCES)
|
||||
if m.user_prefs = invalid
|
||||
m.user_prefs = "{}"
|
||||
end if
|
||||
m.user_prefs = ParseJson(m.user_prefs)
|
||||
' Step 2: Migrate existing preferences to new format (if needed)
|
||||
isDirty = m.MigrateExistingPreferences()
|
||||
' Step 3: Apply defaults to user preferences (if needed)
|
||||
isDirty = m.ApplyDefaultsToUserPreferences() or isDirty
|
||||
if isDirty
|
||||
m.SaveUserPreferences()
|
||||
end if
|
||||
end function
|
||||
|
||||
function SaveUserPreferences()
|
||||
m.user_prefs.__version = m.version
|
||||
RegistryUtils.Write(RegistryUtils.USER_PREFERENCES, FormatJson(m.user_prefs))
|
||||
end function
|
||||
|
||||
function MigrateExistingPreferences() as boolean
|
||||
isDirty = false
|
||||
|
||||
' v0 -> v1
|
||||
instances = RegistryUtils.Read(RegistryUtils.INVIDIOUS_INSTANCES)
|
||||
if instances <> invalid
|
||||
currentInstance = m.user_prefs["invidious.instance"]
|
||||
if currentInstance = invalid or currentInstance = ""
|
||||
instances = ParseJson(instances)
|
||||
if instances.Count() > 0
|
||||
instance = instances[0]
|
||||
if instance <> invalid and instance <> ""
|
||||
m.user_prefs["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 m.user_prefs.__version = 1
|
||||
' 'do stuff
|
||||
' end if
|
||||
|
||||
' TODO: handle case where saved preferences version is higher than current version (e.g. user downgraded)
|
||||
return isDirty
|
||||
end function
|
||||
|
||||
function ApplyDefaultsToUserPreferences() as boolean
|
||||
isDirty = false
|
||||
for each child in m.prefs_model
|
||||
isDirty = m.ApplyToUserPreferences(m.user_prefs, 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 = m.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() as object
|
||||
return m.user_prefs
|
||||
end function
|
||||
|
||||
function ApplyUserPreferences(preferences as object) as void
|
||||
if preferences = invalid
|
||||
return
|
||||
end if
|
||||
' TODO: user input validation
|
||||
for each key in preferences
|
||||
m.user_prefs[key] = preferences[key]
|
||||
end for
|
||||
m.SaveUserPreferences()
|
||||
end function
|
||||
|
||||
function ClearUserPreferences() as void
|
||||
m.user_prefs = {}
|
||||
m.ApplyDefaultsToUserPreferences()
|
||||
m.SaveUserPreferences()
|
||||
end function
|
||||
|
||||
function GetValue(key as string) as dynamic
|
||||
return m.user_prefs[key]
|
||||
end function
|
||||
|
||||
function SetValue(key as string, value as dynamic) as void
|
||||
if m.user_prefs[key] = value
|
||||
return
|
||||
end if
|
||||
m.user_prefs[key] = value
|
||||
m.SaveUserPreferences()
|
||||
end function
|
||||
end class
|
||||
@@ -0,0 +1,54 @@
|
||||
import "pkg:/source/utils/General.bs"
|
||||
import "pkg:/source/utils/RegistryUtils.bs"
|
||||
|
||||
namespace SearchHistory
|
||||
function Save(q as string, maxItems = 10 as integer)
|
||||
history = GetAllSaved()
|
||||
index = ArrayIndexOf(history, q)
|
||||
if index <> -1
|
||||
history.Delete(index)
|
||||
end if
|
||||
|
||||
history.Unshift(q)
|
||||
|
||||
if history.Count() > maxItems
|
||||
history.Pop()
|
||||
end if
|
||||
|
||||
history = FormatJson(history)
|
||||
|
||||
RegistryUtils.Write(RegistryUtils.SEARCH_HISTORY, history)
|
||||
end function
|
||||
|
||||
function GetSaved(q as string) as object
|
||||
history = GetAllSaved()
|
||||
if history.count() = 0
|
||||
return []
|
||||
end if
|
||||
|
||||
if q = ""
|
||||
return history
|
||||
end if
|
||||
result = []
|
||||
for each keyword in history
|
||||
if keyword.InStr(q) = 0
|
||||
result.push(keyword)
|
||||
end if
|
||||
end for
|
||||
return result
|
||||
end function
|
||||
|
||||
function GetAllSaved() as object
|
||||
history = RegistryUtils.Read(RegistryUtils.SEARCH_HISTORY)
|
||||
if history = invalid
|
||||
return []
|
||||
end if
|
||||
return ParseJson(history)
|
||||
end function
|
||||
|
||||
|
||||
function Clear()
|
||||
RegistryUtils.Delete(RegistryUtils.SEARCH_HISTORY)
|
||||
end function
|
||||
|
||||
end namespace
|
||||
@@ -1,4 +1,5 @@
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
||||
|
||||
function GetLocalIpAddress() as dynamic
|
||||
if m.ipAddress = invalid or m.ipAddress = ""
|
||||
@@ -33,6 +34,28 @@ function GetAppInfo() as object
|
||||
return m.appInfo
|
||||
end function
|
||||
|
||||
function GetLatestPlayletLibVersion() as dynamic
|
||||
if m.latestPlayletLibVersion = invalid
|
||||
args = {
|
||||
parseJson: false
|
||||
}
|
||||
response = Requests().request("HEAD", "https://github.com/iBicha/playlet/releases/latest", args)
|
||||
|
||||
if response.statusCode = 200
|
||||
if response.headers.location <> invalid
|
||||
regex = CreateObject("roRegex", "/v?(\d+\.\d+\.\d+)", "")
|
||||
match = regex.match(response.headers.location)
|
||||
if match.Count() = 2
|
||||
m.latestPlayletLibVersion = match[1]
|
||||
return m.latestPlayletLibVersion
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
m.latestPlayletLibVersion = "N/A"
|
||||
end if
|
||||
return m.latestPlayletLibVersion
|
||||
end function
|
||||
|
||||
function GetLibVersion() as string
|
||||
values = GetLibManifestValues()
|
||||
|
||||
@@ -89,7 +112,9 @@ function GetDeviceInfo() as object
|
||||
video_mode: devInfo.GetVideoMode(),
|
||||
ui_resolution: devInfo.GetUIResolution(),
|
||||
graphics_platform: devInfo.GetGraphicsPlatform(),
|
||||
internet_status: devInfo.GetInternetStatus()
|
||||
internet_status: devInfo.GetInternetStatus(),
|
||||
user_country_code: devInfo.GetUserCountryCode(),
|
||||
friendly_name: devInfo.GetFriendlyName()
|
||||
}
|
||||
end if
|
||||
return m.deviceInfo
|
||||
|
||||
@@ -2,6 +2,11 @@ namespace RegistryUtils
|
||||
|
||||
const DEFAULT_SECTION = "Playlet"
|
||||
|
||||
const USER_PREFERENCES = "user_prefs"
|
||||
|
||||
const SEARCH_HISTORY = "search_history"
|
||||
const PLAYLET_LIB_URLS = "playlet_lib_urls"
|
||||
|
||||
const INVIDIOUS_INSTANCES = "invidious_instances"
|
||||
const INVIDIOUS_TOKEN = "invidious_token"
|
||||
|
||||
|
||||
Reference in new issue
Block a user