jf-roku/source/ShowScenes.brs

397 lines
11 KiB
Plaintext
Raw Normal View History

2019-10-13 19:33:14 +00:00
sub CreateServerGroup()
2019-04-29 16:44:37 +00:00
' Get and Save Jellyfin Server Information
2019-10-13 19:33:14 +00:00
group = CreateObject("roSGNode", "ConfigScene")
m.scene.appendChild(group)
group.findNode("prompt").text = "Connect to Server"
2019-10-13 19:33:14 +00:00
config = group.findNode("configOptions")
2019-03-22 03:27:31 +00:00
server_field = CreateObject("roSGNode", "ConfigData")
server_field.label = "Server"
server_field.field = "server"
server_field.type = "string"
if get_setting("server") <> invalid
server_field.value = get_setting("server")
end if
2020-02-20 06:46:55 +00:00
group.findNode("example").text = "192.168.1.100:8096 or https://example.com/jellyfin"
items = [ server_field ]
2019-03-20 03:23:58 +00:00
config.configItems = items
2019-10-13 19:33:14 +00:00
button = group.findNode("submit")
button.observeField("buttonSelected", m.port)
server_hostname = config.content.getChild(0)
while(true)
2019-10-13 19:33:14 +00:00
msg = wait(0, m.port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed()
return
else if type(msg) = "roSGNodeEvent"
node = msg.getNode()
if node = "submit"
set_setting("server", server_hostname.value)
2020-03-04 03:02:05 +00:00
if ServerInfo() = invalid then
' 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"
2019-10-13 19:33:14 +00:00
group.findNode("alert").text = "Server not found, is it online?"
SignOut()
else
2019-10-13 19:33:14 +00:00
group.visible = false
return
endif
end if
end if
end while
2019-10-13 19:33:14 +00:00
' Just hide it when done, in case we need to come back
group.visible = false
end sub
2019-10-13 19:33:14 +00:00
sub CreateSigninGroup()
2019-04-29 16:44:37 +00:00
' Get and Save Jellyfin user login credentials
2019-10-13 19:33:14 +00:00
group = CreateObject("roSGNode", "ConfigScene")
m.scene.appendChild(group)
2019-10-13 19:33:14 +00:00
group.findNode("prompt").text = "Sign In"
2019-10-13 19:33:14 +00:00
config = group.findNode("configOptions")
2019-03-22 03:27:31 +00:00
username_field = CreateObject("roSGNode", "ConfigData")
username_field.label = "Username"
username_field.field = "username"
username_field.type = "string"
password_field = CreateObject("roSGNode", "ConfigData")
password_field.label = "Password"
password_field.field = "password"
password_field.type = "password"
items = [ username_field, password_field ]
2019-03-20 03:23:58 +00:00
config.configItems = items
2019-10-13 19:33:14 +00:00
button = group.findNode("submit")
button.observeField("buttonSelected", m.port)
2019-10-13 19:33:14 +00:00
config = group.findNode("configOptions")
username = config.content.getChild(0)
password = config.content.getChild(1)
while(true)
2019-10-13 19:33:14 +00:00
msg = wait(0, m.port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed()
2019-10-13 19:33:14 +00:00
group.visible = false
return
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 then return
print "Login attempt failed..."
2019-10-13 19:33:14 +00:00
group.findNode("alert").text = "Login attempt failed."
end if
end if
end while
2019-10-13 19:33:14 +00:00
' Just hide it when done, in case we need to come back
group.visible = false
end sub
function CreateHomeGroup()
2019-04-29 16:44:37 +00:00
' Main screen after logging in. Shows the user's libraries
group = CreateObject("roSGNode", "Home")
2019-03-10 05:28:28 +00:00
libs = LibraryList()
2019-10-12 21:23:44 +00:00
group.libraries = libs
con = HomeItemList("continue")
group.continueWatching = con
group.observeField("homeSelection", m.port)
2019-10-12 21:23:44 +00:00
sidepanel = group.findNode("options")
2019-10-13 19:33:14 +00:00
sidepanel.observeField("closeSidePanel", m.port)
2019-03-19 04:17:50 +00:00
new_options = []
options_buttons = [
2019-10-13 19:33:14 +00:00
{"title": "Search", "id": "goto_search"},
2019-03-19 14:11:46 +00:00
{"title": "Change server", "id": "change_server"},
{"title": "Sign out", "id": "sign_out"},
{"title": "Add User", "id": "add_user"}
2019-03-19 04:17:50 +00:00
]
for each opt in options_buttons
o = CreateObject("roSGNode", "OptionsButton")
o.title = opt.title
o.id = opt.id
2019-10-13 19:33:14 +00:00
o.observeField("optionSelected", m.port)
new_options.push(o)
2019-03-19 04:17:50 +00:00
end for
' And a profile button
user_node = CreateObject("roSGNode", "OptionsData")
user_node.id = "active_user"
user_node.title = "Profile"
user_node.base_title = "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)
2019-03-19 04:17:50 +00:00
sidepanel.options = new_options
2019-10-12 21:23:44 +00:00
return group
end function
2019-10-13 19:33:14 +00:00
function CreateMovieListGroup(library)
group = CreateObject("roSGNode", "Movies")
2019-10-13 22:10:23 +00:00
group.id = library.id
group.library = library
group.observeField("movieSelected", m.port)
2019-10-13 19:33:14 +00:00
sidepanel = group.findNode("options")
movie_options = [
{"title": "Sort Field",
"base_title": "Sort Field",
"key": "movie_sort_field",
"default": "DateCreated",
"values": [
{display: "Date Added", value: "DateCreated"},
{display: "Release Date", value: "PremiereDate"},
{display: "Name", value: "SortName"}
]},
{"title": "Sort Order",
"base_title": "Sort Order",
"key": "movie_sort_order",
"default": "Ascending",
"values": [
{display: "Descending", value: "Descending"},
{display: "Ascending", value: "Ascending"}
]}
]
new_options = []
for each opt in movie_options
o = CreateObject("roSGNode", "OptionsData")
o.title = opt.title
o.choices = opt.values
o.base_title = opt.base_title
o.config_key = opt.key
o.value = get_user_setting(opt.key, opt.default)
new_options.append([o])
end for
sidepanel.options = new_options
sidepanel.observeField("closeSidePanel", m.port)
2019-10-13 22:10:23 +00:00
p = CreatePaginator()
group.appendChild(p)
2019-10-13 22:10:23 +00:00
group.pageNumber = 1
p.currentPage = group.pageNumber
MovieLister(group, m.page_size)
return group
end function
2019-10-13 19:33:14 +00:00
function CreateMovieDetailsGroup(movie)
group = CreateObject("roSGNode", "MovieDetails")
2019-03-12 03:49:17 +00:00
movie = ItemMetaData(movie.id)
group.itemContent = movie
buttons = group.findNode("buttons")
for each b in buttons.getChildren(-1, 0)
b.observeField("buttonSelected", m.port)
2019-03-17 23:07:57 +00:00
end for
return group
end function
2019-03-08 03:47:10 +00:00
function CreateSeriesListGroup(library)
group = CreateObject("roSGNode", "TVShows")
group.id = library.id
group.library = library
group.observeField("seriesSelected", m.port)
2019-03-11 01:03:45 +00:00
sidepanel = group.findNode("options")
p = CreatePaginator()
group.appendChild(p)
group.pageNumber = 1
2020-02-15 17:56:56 +00:00
p.currentPage = group.pageNumber
SeriesLister(group, m.page_size)
2019-03-31 03:15:53 +00:00
return group
end function
function CreateSeriesDetailsGroup(series)
group = CreateObject("roSGNode", "TVShowDetails")
group.itemContent = ItemMetaData(series.id)
group.seasonData = TVSeasons(series.id)
2019-03-31 03:15:53 +00:00
group.observeField("seasonSelected", m.port)
2019-04-14 04:47:27 +00:00
return group
end function
2019-04-14 04:47:27 +00:00
function CreateSeasonDetailsGroup(series, season)
group = CreateObject("roSGNode", "TVEpisodes")
2019-04-14 04:47:27 +00:00
group.seasonData = ItemMetaData(season.id).json
group.objects = TVEpisodes(series.id, season.id)
2019-04-14 04:47:27 +00:00
group.observeField("episodeSelected", m.port)
2019-04-14 04:47:27 +00:00
return group
end function
function CreateCollectionsList(library)
' Load Movie Collection Items
group = CreateObject("roSGNode", "Collections")
group.id = library.id
group.library = library
2019-03-20 02:30:08 +00:00
group.observeField("collectionSelected", m.port)
2019-03-20 02:30:08 +00:00
sidepanel = group.findNode("options")
2019-03-20 02:30:08 +00:00
panel_options = [
{"title": "Sort Field",
"base_title": "Sort Field",
"key": "movie_sort_field",
"default": "SortName",
"values": [
{display: "Date Added", value: "DateCreated"},
{display: "Release Date", value: "PremiereDate"},
{display: "Name", value: "SortName"}
]},
2019-03-20 02:30:08 +00:00
{"title": "Sort Order",
"base_title": "Sort Order",
"key": "movie_sort_order",
"default": "Ascending",
"values": [
{display: "Descending", value: "Descending"},
{display: "Ascending", value: "Ascending"}
]}
2019-03-20 02:30:08 +00:00
]
new_options = []
for each opt in panel_options
o = CreateObject("roSGNode", "OptionsData")
o.title = opt.title
o.choices = opt.values
o.base_title = opt.base_title
o.config_key = opt.key
o.value = get_user_setting(opt.key, opt.default)
new_options.append([o])
end for
sidepanel.options = new_options
sidepanel.observeField("closeSidePanel", m.port)
2019-03-20 02:30:08 +00:00
p = CreatePaginator()
group.appendChild(p)
group.pageNumber = 1
p.currentPage = group.pageNumber
CollectionLister(group, m.page_size)
return group
end function
2019-03-20 02:30:08 +00:00
2019-10-13 20:52:34 +00:00
function CreateSearchPage()
' Search + Results Page
group = CreateObject("roSGNode", "SearchResults")
2019-03-14 22:50:20 +00:00
2019-10-13 20:52:34 +00:00
search = group.findNode("SearchBox")
search.observeField("search_value", m.port)
2019-03-14 22:50:20 +00:00
2019-10-13 20:52:34 +00:00
options = group.findNode("SearchSelect")
options.observeField("itemSelected", m.port)
2019-03-14 22:50:20 +00:00
2019-10-13 20:52:34 +00:00
return group
end function
2019-03-14 22:50:20 +00:00
2019-10-13 19:33:14 +00:00
function CreateSidePanel(buttons, options)
group = CreateObject("roSGNode", "OptionsSlider")
group.buttons = buttons
group.options = options
end function
2019-10-13 22:10:23 +00:00
function CreatePaginator()
group = CreateObject("roSGNode", "Pager")
group.id = "paginator"
group.observeField("pageSelected", m.port)
return group
end function
2019-10-13 19:33:14 +00:00
function CreateVideoPlayerGroup(video_id)
2019-04-29 16:44:37 +00:00
' Video is Playing
video = VideoPlayer(video_id)
2020-03-04 02:46:26 +00:00
if video = invalid return invalid
2020-02-17 19:30:04 +00:00
timer = video.findNode("playbackTimer")
video.observeField("backPressed", m.port)
video.observeField("state", m.port)
video.observeField("position", m.port)
2020-02-17 19:30:04 +00:00
timer.control = "start"
timer.observeField("fire", m.port)
return video
end function
2019-10-13 22:10:23 +00:00
function MovieLister(group, page_size)
sort_order = get_user_setting("movie_sort_order", "Ascending")
sort_field = get_user_setting("movie_sort_field", "SortName")
item_list = ItemList(group.id, {"limit": page_size,
"StartIndex": page_size * (group.pageNumber - 1),
"SortBy": sort_field,
"SortOrder": sort_order,
"IncludeItemTypes": "Movie"
})
group.objects = item_list
p = group.findNode("paginator")
p.maxPages = div_ceiling(group.objects.TotalRecordCount, page_size)
end function
function SeriesLister(group, page_size)
sort_order = get_user_setting("series_sort_order", "Ascending")
sort_field = get_user_setting("series_sort_field", "SortName")
item_list = ItemList(group.id, {"limit": page_size,
"StartIndex": page_size * (group.pageNumber - 1),
"SortBy": sort_field,
"SortOrder": sort_order,
"IncludeItemTypes": "Series"
})
group.objects = item_list
p = group.findNode("paginator")
p.maxPages = div_ceiling(group.objects.TotalRecordCount, page_size)
end function
function CollectionLister(group, page_size)
sort_order = get_user_setting("boxsets_sort_order", "Ascending")
sort_field = get_user_setting("boxsets_sort_field", "SortName")
item_list = ItemList(group.id, {"limit": page_size,
"StartIndex": page_size * (group.pageNumber - 1),
"SortBy": sort_field,
"SortOrder": sort_order,
})
group.objects = item_list
p = group.findNode("paginator")
p.maxPages = div_ceiling(group.objects.TotalRecordCount, page_size)
2019-10-13 22:10:23 +00:00
end function