jf-roku/source/ShowScenes.brs

474 lines
17 KiB
Plaintext
Raw Normal View History

function CreateServerGroup()
2021-07-09 20:08:32 +00:00
screen = CreateObject("roSGNode", "SetServerScreen")
2021-12-23 01:00:47 +00:00
screen.optionsAvailable = true
m.global.sceneManager.callFunc("pushScene", screen)
2021-07-09 20:08:32 +00:00
port = CreateObject("roMessagePort")
m.colors = {}
if get_setting("server") <> invalid
screen.serverUrl = get_setting("server")
end if
2021-07-09 20:08:32 +00:00
m.viewModel = {}
button = screen.findNode("submit")
button.observeField("buttonSelected", port)
2021-12-23 01:00:47 +00:00
'create delete saved server option
new_options = []
sidepanel = screen.findNode("options")
opt = CreateObject("roSGNode", "OptionsButton")
opt.title = tr("Delete Saved")
2021-12-24 04:08:43 +00:00
opt.id = "delete_saved"
2021-12-23 01:00:47 +00:00
opt.observeField("optionSelected", port)
new_options.push(opt)
sidepanel.options = new_options
sidepanel.observeField("closeSidePanel", port)
2021-12-24 04:08:43 +00:00
2021-07-09 20:08:32 +00:00
screen.observeField("backPressed", port)
while true
msg = wait(0, port)
print type(msg), msg
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed()
return "false"
else if isNodeEvent(msg, "backPressed")
return "backPressed"
2021-12-23 01:00:47 +00:00
else if isNodeEvent(msg, "closeSidePanel")
screen.setFocus(true)
serverPicker = screen.findNode("serverPicker")
serverPicker.setFocus(true)
2021-07-09 20:08:32 +00:00
else if type(msg) = "roSGNodeEvent"
node = msg.getNode()
if node = "submit"
serverUrl = standardize_jellyfin_url(screen.serverUrl)
'If this is a different server from what we know, reset username/password setting
if get_setting("server") <> serverUrl
set_setting("username", "")
set_setting("password", "")
end if
set_setting("server", serverUrl)
' Show Connecting to Server spinner
dialog = createObject("roSGNode", "ProgressDialog")
dialog.title = tr("Connecting to Server")
m.scene.dialog = dialog
m.serverInfoResult = ServerInfo()
2021-07-09 20:08:32 +00:00
dialog.close = true
if m.serverInfoResult = invalid
2021-07-09 20:08:32 +00:00
' Maybe don't unset setting, but offer as a prompt
' Server not found, is it online? New values / Retry
print "Server not found, is it online? New values / Retry"
screen.errorMessage = tr("Server not found, is it online?")
2021-12-30 01:00:13 +00:00
SignOut(false)
else if m.serverInfoResult.Error <> invalid and m.serverInfoResult.Error
2021-07-09 20:08:32 +00:00
' If server redirected received, update the URL
if m.serverInfoResult.UpdatedUrl <> invalid
serverUrl = m.serverInfoResult.UpdatedUrl
2021-07-09 20:08:32 +00:00
set_setting("server", serverUrl)
end if
' Display Error Message to user
message = tr("Error: ")
if m.serverInfoResult.ErrorCode <> invalid
message = message + "[" + m.serverInfoResult.ErrorCode.toStr() + "] "
2021-07-09 20:08:32 +00:00
end if
screen.errorMessage = message + tr(m.serverInfoResult.ErrorMessage)
2021-12-30 01:00:13 +00:00
SignOut(false)
2021-07-09 20:08:32 +00:00
else
screen.visible = false
if m.serverInfoResult.serverName <> invalid
return m.serverInfoResult.ServerName + " (Saved)"
2021-12-26 18:52:43 +00:00
else
return "Saved"
end if
2021-07-09 20:08:32 +00:00
end if
2021-12-23 01:00:47 +00:00
else if node = "delete_saved"
serverPicker = screen.findNode("serverPicker")
itemToDelete = serverPicker.content.getChild(serverPicker.itemFocused)
urlToDelete = itemToDelete.baseUrl
if urlToDelete <> invalid
DeleteFromServerList(urlToDelete)
serverPicker.content.removeChild(itemToDelete)
sidepanel.visible = false
serverPicker.setFocus(true)
2021-12-24 04:08:43 +00:00
end if
2021-07-09 20:08:32 +00:00
end if
end if
end while
2019-10-13 19:33:14 +00:00
2021-07-09 20:08:32 +00:00
' Just hide it when done, in case we need to come back
screen.visible = false
return ""
end function
function CreateUserSelectGroup(users = [])
2021-07-09 20:08:32 +00:00
if users.count() = 0
return ""
end if
2021-07-09 20:08:32 +00:00
group = CreateObject("roSGNode", "UserSelect")
m.global.sceneManager.callFunc("pushScene", group)
2021-07-09 20:08:32 +00:00
port = CreateObject("roMessagePort")
group.itemContent = users
group.findNode("userRow").observeField("userSelected", port)
group.findNode("alternateOptions").observeField("itemSelected", port)
group.observeField("backPressed", port)
while true
msg = wait(0, port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed()
group.visible = false
return -1
else if isNodeEvent(msg, "backPressed")
return "backPressed"
else if type(msg) = "roSGNodeEvent" and msg.getField() = "userSelected"
return msg.GetData()
else if type(msg) = "roSGNodeEvent" and msg.getField() = "itemSelected"
if msg.getData() = 0
return ""
end if
end if
end while
2021-07-09 20:08:32 +00:00
' Just hide it when done, in case we need to come back
group.visible = false
return ""
end function
function CreateSigninGroup(user = "")
2021-07-09 20:08:32 +00:00
' Get and Save Jellyfin user login credentials
2022-05-29 20:00:38 +00:00
group = CreateObject("roSGNode", "LoginScene")
m.global.sceneManager.callFunc("pushScene", group)
2021-07-09 20:08:32 +00:00
port = CreateObject("roMessagePort")
group.findNode("prompt").text = tr("Sign In")
2021-12-24 04:07:35 +00:00
'Load in any saved server data and see if we can just log them in...
server = get_setting("server")
2021-12-26 21:03:59 +00:00
if server <> invalid
server = LCase(server)'Saved server data is always lowercase
end if
2021-12-24 04:07:35 +00:00
saved = get_setting("saved_servers")
2021-12-24 04:08:43 +00:00
if saved <> invalid
2021-12-24 04:07:35 +00:00
savedServers = ParseJson(saved)
for each item in savedServers.serverList
2021-12-26 21:03:59 +00:00
if item.baseUrl = server and item.username <> invalid and item.password <> invalid
2021-12-24 04:07:35 +00:00
get_token(item.username, item.password)
if get_setting("active_user") <> invalid
return "true"
end if
end if
end for
end if
2021-07-09 20:08:32 +00:00
config = group.findNode("configOptions")
username_field = CreateObject("roSGNode", "ConfigData")
username_field.label = tr("Username")
username_field.field = "username"
username_field.type = "string"
if user = "" and get_setting("username") <> invalid
username_field.value = get_setting("username")
else
username_field.value = user
end if
2021-07-09 20:08:32 +00:00
password_field = CreateObject("roSGNode", "ConfigData")
password_field.label = tr("Password")
password_field.field = "password"
password_field.type = "password"
if get_setting("password") <> invalid
password_field.value = get_setting("password")
end if
2021-12-30 03:51:39 +00:00
' Add checkbox for saving credentials
2021-12-30 03:55:02 +00:00
checkbox = group.findNode("onOff")
2021-12-30 03:51:39 +00:00
items = CreateObject("roSGNode", "ContentNode")
items.role = "content"
saveCheckBox = CreateObject("roSGNode", "ContentNode")
saveCheckBox.title = tr("Save Credentials?")
items.appendChild(saveCheckBox)
checkbox.content = items
checkbox.checkedState = [true]
2022-05-29 20:00:38 +00:00
quickConnect = group.findNode("quickConnect")
if m.serverInfoResult = invalid
m.serverInfoResult = ServerInfo()
end if
' Quick Connect only supported for server version 10.8+ right now...
2022-06-01 05:05:54 +00:00
if versionChecker(m.serverInfoResult.Version, "10.8.0")
' Add option for Quick Connect
quickConnect.text = tr("Quick Connect")
quickConnect.observeField("buttonSelected", port)
else
quickConnect.visible = false
end if
2021-12-30 03:51:39 +00:00
2021-07-09 20:08:32 +00:00
items = [username_field, password_field]
config.configItems = items
button = group.findNode("submit")
button.observeField("buttonSelected", port)
config = group.findNode("configOptions")
username = config.content.getChild(0)
password = config.content.getChild(1)
group.observeField("backPressed", port)
while true
msg = wait(0, port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed()
group.visible = false
return "false"
else if isNodeEvent(msg, "backPressed")
group.unobserveField("backPressed")
group.backPressed = false
return "backPressed"
else if type(msg) = "roSGNodeEvent"
node = msg.getNode()
if node = "submit"
' Validate credentials
get_token(username.value, password.value)
if get_setting("active_user") <> invalid
set_setting("username", username.value)
set_setting("password", password.value)
2021-12-30 03:51:39 +00:00
if checkbox.checkedState[0] = true
'Update our saved server list, so next time the user can just click and go
UpdateSavedServerList()
end if
2021-07-09 20:08:32 +00:00
return "true"
end if
print "Login attempt failed..."
group.findNode("alert").text = tr("Login attempt failed.")
2022-05-29 20:00:38 +00:00
else if node = "quickConnect"
json = initQuickConnect()
if json = invalid
group.findNode("alert").text = tr("Quick Connect not available.")
2022-05-30 05:00:43 +00:00
else
' Server user is talking to is at least 10.8 and has quick connect enabled...
m.quickConnectDialog = createObject("roSGNode", "QuickConnectDialog")
m.quickConnectDialog.quickConnectJson = json
m.quickConnectDialog.title = tr("Quick Connect")
m.quickConnectDialog.message = [tr("Here is your Quick Connect code: ") + json.Code, tr("(Dialog will close automatically)")]
m.quickConnectDialog.buttons = [tr("Cancel")]
m.quickConnectDialog.observeField("authenticated", port)
m.scene.dialog = m.quickConnectDialog
2022-05-29 20:00:38 +00:00
end if
else if msg.getField() = "authenticated"
2022-05-30 12:12:43 +00:00
authenticated = msg.getData()
if authenticated = true
' Quick connect authentication was successful...
return "true"
else
dialog = createObject("roSGNode", "Dialog")
dialog.id = "QuickConnectError"
dialog.title = tr("Quick Connect")
dialog.buttons = [tr("OK")]
dialog.message = tr("There was an error authenticating via Quick Connect.")
m.scene.dialog = dialog
m.scene.dialog.observeField("buttonSelected", port)
end if
else
' If there are no other button matches, check if this is a simple "OK" Dialog & Close if so
dialog = msg.getRoSGNode()
if dialog.id = "QuickConnectError"
dialog.unobserveField("buttonSelected")
dialog.close = true
2022-05-30 12:13:53 +00:00
end if
2021-07-09 20:08:32 +00:00
end if
end if
end while
2019-10-13 19:33:14 +00:00
2021-07-09 20:08:32 +00:00
' Just hide it when done, in case we need to come back
group.visible = false
return ""
end function
function CreateHomeGroup()
2021-07-09 20:08:32 +00:00
' Main screen after logging in. Shows the user's libraries
group = CreateObject("roSGNode", "Home")
group.overhangTitle = tr("Home")
group.optionsAvailable = true
2021-07-09 20:08:32 +00:00
group.observeField("selectedItem", m.port)
group.observeField("quickPlayNode", m.port)
sidepanel = group.findNode("options")
sidepanel.observeField("closeSidePanel", m.port)
new_options = []
options_buttons = [
{ "title": "Search", "id": "goto_search" },
{ "title": "Change server", "id": "change_server" },
{ "title": "Sign out", "id": "sign_out" }
]
for each opt in options_buttons
o = CreateObject("roSGNode", "OptionsButton")
o.title = tr(opt.title)
o.id = opt.id
o.observeField("optionSelected", m.port)
new_options.push(o)
end for
' Add settings option to menu
2022-05-01 10:51:28 +00:00
o = CreateObject("roSGNode", "OptionsButton")
o.title = "Settings"
o.id = "settings"
o.observeField("optionSelected", m.port)
new_options.push(o)
2021-07-09 20:08:32 +00:00
' And a profile button
user_node = CreateObject("roSGNode", "OptionsData")
user_node.id = "active_user"
user_node.title = tr("Profile")
user_node.base_title = tr("Profile")
user_options = []
for each user in AvailableUsers()
user_options.push({ display: user.username + "@" + user.server, value: user.id })
end for
user_node.choices = user_options
user_node.value = get_setting("active_user")
new_options.push(user_node)
sidepanel.options = new_options
return group
end function
2019-10-13 19:33:14 +00:00
function CreateMovieDetailsGroup(movie)
2021-07-09 20:08:32 +00:00
group = CreateObject("roSGNode", "MovieDetails")
group.overhangTitle = movie.title
group.optionsAvailable = false
m.global.sceneManager.callFunc("pushScene", group)
2019-03-12 03:49:17 +00:00
2021-07-09 20:08:32 +00:00
movie = ItemMetaData(movie.id)
group.itemContent = movie
2021-07-09 20:08:32 +00:00
buttons = group.findNode("buttons")
for each b in buttons.getChildren(-1, 0)
b.observeField("buttonSelected", m.port)
end for
2019-03-17 23:07:57 +00:00
2022-03-13 08:46:03 +00:00
extras = group.findNode("extrasGrid")
extras.observeField("selectedItem", m.port)
extras.callFunc("loadPeople", movie.json)
2021-07-09 20:08:32 +00:00
return group
end function
2019-03-08 03:47:10 +00:00
function CreateSeriesDetailsGroup(series)
2021-07-09 20:08:32 +00:00
group = CreateObject("roSGNode", "TVShowDetails")
group.optionsAvailable = false
m.global.sceneManager.callFunc("pushScene", group)
2021-07-09 20:08:32 +00:00
group.itemContent = ItemMetaData(series.id)
group.seasonData = TVSeasons(series.id)
2019-03-31 03:15:53 +00:00
2021-07-09 20:08:32 +00:00
group.observeField("seasonSelected", m.port)
2019-04-14 04:47:27 +00:00
2022-03-13 08:46:03 +00:00
extras = group.findNode("extrasGrid")
extras.observeField("selectedItem", m.port)
extras.callFunc("loadPeople", group.itemcontent.json)
2021-07-09 20:08:32 +00:00
return group
end function
2019-04-14 04:47:27 +00:00
function CreateSeasonDetailsGroup(series, season)
2021-07-09 20:08:32 +00:00
group = CreateObject("roSGNode", "TVEpisodes")
group.optionsAvailable = false
m.global.sceneManager.callFunc("pushScene", group)
2019-04-14 04:47:27 +00:00
2021-07-09 20:08:32 +00:00
group.seasonData = ItemMetaData(season.id).json
group.objects = TVEpisodes(series.id, season.id)
2019-04-14 04:47:27 +00:00
2021-07-09 20:08:32 +00:00
group.observeField("episodeSelected", m.port)
group.observeField("quickPlayNode", m.port)
2019-04-14 04:47:27 +00:00
2021-07-09 20:08:32 +00:00
return group
end function
function CreateItemGrid(libraryItem)
2021-07-09 20:08:32 +00:00
group = CreateObject("roSGNode", "ItemGrid")
group.parentItem = libraryItem
group.optionsAvailable = true
2021-07-09 20:08:32 +00:00
group.observeField("selectedItem", m.port)
return group
end function
2019-10-13 20:52:34 +00:00
function CreateSearchPage()
2021-07-09 20:08:32 +00:00
' Search + Results Page
group = CreateObject("roSGNode", "SearchResults")
2019-03-14 22:50:20 +00:00
2021-07-09 20:08:32 +00:00
search = group.findNode("SearchBox")
search.observeField("search_value", m.port)
2019-03-14 22:50:20 +00:00
2021-07-09 20:08:32 +00:00
options = group.findNode("SearchSelect")
options.observeField("itemSelected", m.port)
2019-03-14 22:50:20 +00:00
2021-07-09 20:08:32 +00:00
return group
2019-10-13 20:52:34 +00:00
end function
2019-03-14 22:50:20 +00:00
sub CreateSidePanel(buttons, options)
2021-07-09 20:08:32 +00:00
group = CreateObject("roSGNode", "OptionsSlider")
group.buttons = buttons
group.options = options
end sub
2019-10-13 22:10:23 +00:00
2022-03-13 14:22:55 +00:00
function CreateVideoPlayerGroup(video_id, mediaSourceId = invalid, audio_stream_idx = 1)
2021-07-09 20:08:32 +00:00
' Video is Playing
video = VideoPlayer(video_id, mediaSourceId, audio_stream_idx, defaultSubtitleTrackFromVid(video_id))
2021-07-09 20:08:32 +00:00
if video = invalid then return invalid
video.observeField("selectSubtitlePressed", m.port)
video.observeField("state", m.port)
return video
end function
2021-12-24 04:07:35 +00:00
2022-03-13 08:46:03 +00:00
function CreatePersonView(personData as object) as object
person = CreateObject("roSGNode", "PersonDetails")
m.global.SceneManager.callFunc("pushScene", person)
info = ItemMetaData(personData.id)
person.itemContent = info
person.setFocus(true)
person.observeField("selectedItem", m.port)
person.findNode("favorite-button").observeField("buttonSelected", m.port)
return person
end function
function CreatePhotoPage(photo)
group = CreateObject("roSGNode", "PhotoDetails")
group.optionsAvailable = true
m.global.sceneManager.callFunc("pushScene", group)
group.itemContent = photo
return group
end function
2021-12-24 04:07:35 +00:00
sub UpdateSavedServerList()
server = get_setting("server")
username = get_setting("username")
password = get_setting("password")
2021-12-24 04:08:43 +00:00
if server = invalid or username = invalid or password = invalid
2021-12-24 04:07:35 +00:00
return
end if
2021-12-26 21:03:59 +00:00
server = LCase(server)'Saved server data is always lowercase
2021-12-24 04:07:35 +00:00
saved = get_setting("saved_servers")
2021-12-26 20:41:32 +00:00
if saved <> invalid
2021-12-24 04:07:35 +00:00
savedServers = ParseJson(saved)
2021-12-26 20:25:58 +00:00
if savedServers.serverList <> invalid and savedServers.serverList.Count() > 0
newServers = { serverList: [] }
for each item in savedServers.serverList
2021-12-26 21:03:59 +00:00
if item.baseUrl = server
2021-12-26 20:25:58 +00:00
item.username = username
item.password = password
end if
newServers.serverList.Push(item)
end for
set_setting("saved_servers", FormatJson(newServers))
end if
2021-12-24 04:07:35 +00:00
end if
end sub