2021-07-09 20:08:32 +00:00
sub Main (args as dynamic) as void
' The main function that runs when the application is launched.
m.screen = CreateObject("roSGScreen")
' Set global constants
setConstants()
2022-06-03 01:29:07 +00:00
' Write screen tracker for screensaver
WriteAsciiFile("tmp:/scene.temp", "")
MoveFile("tmp:/scene.temp", "tmp:/scene")
2021-07-09 20:08:32 +00:00
m.port = CreateObject("roMessagePort")
m.screen.setMessagePort(m.port)
' Set any initial Global Variables
m.global = m.screen.getGlobalNode()
2023-04-22 19:36:52 +00:00
SaveAppToGlobal()
SaveDeviceToGlobal()
2023-06-01 12:43:27 +00:00
session.Init()
2023-04-22 19:36:52 +00:00
m.scene = m.screen.CreateScene("JFScene")
m.screen.show() ' vscode_rale_tracker_entry
2021-09-01 00:39:35 +00:00
playstateTask = CreateObject("roSGNode", "PlaystateTask")
playstateTask.id = "playstateTask"
2021-10-10 01:51:33 +00:00
sceneManager = CreateObject("roSGNode", "SceneManager")
2023-05-07 01:26:02 +00:00
sceneManager.observeField("dataReturned", m.port)
2021-07-09 20:08:32 +00:00
2021-10-10 01:51:33 +00:00
m.global.addFields({ app_loaded: false, playstateTask: playstateTask, sceneManager: sceneManager })
2022-11-29 22:05:46 +00:00
m.global.addFields({ queueManager: CreateObject("roSGNode", "QueueManager") })
2023-02-27 23:51:27 +00:00
m.global.addFields({ audioPlayer: CreateObject("roSGNode", "AudioPlayer") })
2021-07-09 20:08:32 +00:00
app_start:
' First thing to do is validate the ability to use the API
if not LoginFlow() then return
2023-05-27 20:43:05 +00:00
' tell jellyfin server about device capabilities
PostDeviceProfile()
2023-03-22 18:10:07 +00:00
' remove previous scenes from the stack
2021-10-10 02:04:37 +00:00
sceneManager.callFunc("clearScenes")
2023-06-01 12:43:27 +00:00
2023-11-05 01:48:39 +00:00
stopLoadingSpinner()
2021-07-09 20:08:32 +00:00
' load home page
2023-06-01 12:43:27 +00:00
sceneManager.currentUser = m.global.session.user.name
2021-07-09 20:08:32 +00:00
group = CreateHomeGroup()
group.callFunc("loadLibraries")
2021-10-10 01:51:33 +00:00
sceneManager.callFunc("pushScene", group)
2021-07-09 20:08:32 +00:00
2021-09-14 02:03:32 +00:00
m.scene.observeField("exit", m.port)
2021-07-09 20:08:32 +00:00
2023-02-04 16:41:00 +00:00
' Downloads and stores a fallback font to tmp:/
2023-05-05 17:45:53 +00:00
configEncoding = api.system.GetConfigurationByName("encoding")
2023-04-11 00:38:02 +00:00
if isValid(configEncoding) and isValid(configEncoding.EnableFallbackFont)
if configEncoding.EnableFallbackFont
re = CreateObject("roRegex", "Name.:.(.*?).,.Size", "s")
filename = APIRequest("FallbackFont/Fonts").GetToString()
if isValid(filename)
filename = re.match(filename)
2023-04-11 01:38:11 +00:00
if isValid(filename) and filename.count() > 0
2023-04-11 00:38:02 +00:00
filename = filename[1]
APIRequest("FallbackFont/Fonts/" + filename).gettofile("tmp:/font")
end if
end if
2023-02-19 18:30:48 +00:00
end if
2023-02-04 16:41:00 +00:00
end if
2023-09-21 18:12:15 +00:00
' Save the global last run version of the app
if m.global.app.version <> m.global.app.lastRunVersion
' update global LastRunVersion
set_setting("LastRunVersion", m.global.app.version)
' Show the Whats New popup
if m.global.session.user.settings["load.allowwhatsnew"] = true
dialog = createObject("roSGNode", "WhatsNewDialog")
m.scene.dialog = dialog
m.scene.dialog.observeField("buttonSelected", m.port)
end if
end if
' Save the user last run version of the app
if m.global.session.user.lastRunVersion <> m.global.app.lastRunVersion
' update user LastRunVersion
set_user_setting("LastRunVersion", m.global.app.version)
session.user.Update("lastRunVersion", m.global.app.version)
2023-09-17 00:10:42 +00:00
end if
2021-07-09 20:08:32 +00:00
' Handle input messages
input = CreateObject("roInput")
input.SetMessagePort(m.port)
2023-03-27 16:50:44 +00:00
device = CreateObject("roDeviceInfo")
device.setMessagePort(m.port)
device.EnableScreensaverExitedEvent(true)
2023-05-27 20:43:05 +00:00
device.EnableAppFocusEvent(true)
device.EnableLowGeneralMemoryEvent(true)
device.EnableLinkStatusEvent(true)
device.EnableCodecCapChangedEvent(true)
2023-04-21 23:02:28 +00:00
device.EnableAudioGuideChangedEvent(true)
2021-07-09 20:08:32 +00:00
' Check if we were sent content to play with the startup command (Deep Link)
2022-12-29 00:51:31 +00:00
if isValidAndNotEmpty(args.mediaType) and isValidAndNotEmpty(args.contentId)
2023-05-18 10:59:34 +00:00
deepLinkVideo = {
id: args.contentId,
type: "video"
}
m.global.queueManager.callFunc("push", deepLinkVideo)
m.global.queueManager.callFunc("playQueue")
2021-07-09 20:08:32 +00:00
end if
' This is the core logic loop. Mostly for transitioning between scenes
' This now only references m. fields so could be placed anywhere, in theory
' "group" is always "whats on the screen"
' m.scene's children is the "previous view" stack
while true
msg = wait(0, m.port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed()
print "CLOSING SCREEN"
return
2021-09-14 02:03:32 +00:00
else if isNodeEvent(msg, "exit")
return
2021-07-09 20:08:32 +00:00
else if isNodeEvent(msg, "closeSidePanel")
2021-10-10 01:51:33 +00:00
group = sceneManager.callFunc("getActiveScene")
2021-07-09 20:08:32 +00:00
if group.lastFocus <> invalid
group.lastFocus.setFocus(true)
else
group.setFocus(true)
end if
else if isNodeEvent(msg, "quickPlayNode")
2023-09-19 02:39:44 +00:00
' measure processing time
timeSpan = CreateObject("roTimespan")
2023-09-17 01:18:12 +00:00
startMediaLoadingSpinner()
2023-09-19 02:39:44 +00:00
2022-12-10 19:27:49 +00:00
group = sceneManager.callFunc("getActiveScene")
2021-07-09 20:08:32 +00:00
reportingNode = msg.getRoSGNode()
2023-09-16 21:18:03 +00:00
itemNode = invalid
if isValid(reportingNode)
itemNode = reportingNode.quickPlayNode
reportingNodeType = reportingNode.subtype()
2023-09-23 21:48:46 +00:00
print "Quick Play reporting node type=", reportingNodeType
' prevent double fire bug
if isValid(reportingNodeType) and (reportingNodeType = "Home" or reportingNodeType = "TVEpisodes")
2023-09-16 21:18:03 +00:00
reportingNode.quickPlayNode = invalid
end if
end if
2023-09-19 02:39:44 +00:00
print "Quick Play started. itemNode=", itemNode
2023-09-24 01:31:01 +00:00
' if itemNode.json <> invalid
' print "itemNode.json=", itemNode.json
' end if
2023-05-07 01:26:02 +00:00
if isValid(itemNode) and isValid(itemNode.id) and itemNode.id <> ""
2023-09-19 02:39:44 +00:00
' make sure there is a type and convert type to lowercase
2023-09-16 21:18:03 +00:00
itemType = invalid
2023-09-19 02:39:44 +00:00
if isValid(itemNode.type) and itemNode.type <> ""
2023-09-16 21:18:03 +00:00
itemType = Lcase(itemNode.type)
2023-09-19 02:39:44 +00:00
else
' grab type from json and convert to lowercase
2023-09-16 21:18:03 +00:00
if isValid(itemNode.json) and isValid(itemNode.json.type)
itemType = Lcase(itemNode.json.type)
2023-05-07 01:26:02 +00:00
end if
2023-09-16 21:18:03 +00:00
end if
2023-09-19 02:39:44 +00:00
print "Quick Play itemNode type=", itemType
' can't play the item without knowing what type it is
if isValid(itemType)
m.global.queueManager.callFunc("clear") ' empty queue/playlist
m.global.queueManager.callFunc("resetShuffle") ' turn shuffle off
if itemType = "episode" or itemType = "movie" or itemType = "video"
quickplay.video(itemNode)
' restore focus
if LCase(group.subtype()) = "tvepisodes"
if isValid(group.lastFocus)
group.lastFocus.setFocus(true)
2023-09-16 21:18:03 +00:00
end if
2023-05-07 01:26:02 +00:00
end if
2023-09-19 02:39:44 +00:00
else if itemType = "audio"
quickplay.audio(itemNode)
else if itemType = "musicalbum"
quickplay.album(itemNode)
else if itemType = "musicartist"
quickplay.artist(itemNode)
else if itemType = "series"
quickplay.series(itemNode)
else if itemType = "season"
quickplay.season(itemNode)
else if itemType = "boxset"
quickplay.boxset(itemNode)
else if itemType = "collectionfolder"
quickplay.collectionFolder(itemNode)
else if itemType = "playlist"
quickplay.playlist(itemNode)
else if itemType = "userview"
quickplay.userView(itemNode)
2023-09-23 13:47:21 +00:00
else if itemType = "folder"
quickplay.folder(itemNode)
2023-09-23 14:52:29 +00:00
else if itemType = "musicvideo"
quickplay.musicVideo(itemNode)
2023-09-23 22:33:00 +00:00
else if itemType = "person"
quickplay.person(itemNode)
2023-09-24 01:31:01 +00:00
else if itemType = "tvchannel"
quickplay.tvChannel(itemNode)
2023-10-27 20:39:35 +00:00
else if itemType = "program"
quickplay.program(itemNode)
2022-12-10 01:26:32 +00:00
end if
2023-09-17 21:50:24 +00:00
2023-09-19 02:39:44 +00:00
m.global.queueManager.callFunc("playQueue")
2022-12-10 01:26:32 +00:00
end if
2021-07-09 20:08:32 +00:00
end if
2023-09-17 01:18:12 +00:00
stopLoadingSpinner()
2023-09-19 02:39:44 +00:00
elapsed = timeSpan.TotalMilliseconds() / 1000
2023-09-19 02:44:00 +00:00
print "Quick Play finished loading in " + elapsed.toStr() + " seconds."
2021-07-09 20:08:32 +00:00
else if isNodeEvent(msg, "selectedItem")
' If you select a library from ANYWHERE, follow this flow
selectedItem = msg.getData()
2023-05-07 01:26:02 +00:00
if isValid(selectedItem)
selectedItemType = selectedItem.type
2022-09-24 00:16:52 +00:00
2022-12-30 16:11:19 +00:00
2023-05-07 01:26:02 +00:00
if selectedItemType = "CollectionFolder"
if selectedItem.collectionType = "movies"
group = CreateMovieLibraryView(selectedItem)
else if selectedItem.collectionType = "music"
group = CreateMusicLibraryView(selectedItem)
else
group = CreateItemGrid(selectedItem)
end if
sceneManager.callFunc("pushScene", group)
else if selectedItemType = "Folder" and selectedItem.json.type = "Genre"
' User clicked on a genre folder
if selectedItem.json.MovieCount > 0
group = CreateMovieLibraryView(selectedItem)
else
group = CreateItemGrid(selectedItem)
end if
sceneManager.callFunc("pushScene", group)
else if selectedItemType = "Folder" and selectedItem.json.type = "MusicGenre"
2022-12-10 05:06:56 +00:00
group = CreateMusicLibraryView(selectedItem)
2023-05-07 01:26:02 +00:00
sceneManager.callFunc("pushScene", group)
else if selectedItemType = "UserView" or selectedItemType = "Folder" or selectedItemType = "Channel" or selectedItemType = "Boxset"
2022-09-24 00:16:52 +00:00
group = CreateItemGrid(selectedItem)
2023-05-07 01:26:02 +00:00
sceneManager.callFunc("pushScene", group)
else if selectedItemType = "Episode"
' User has selected a TV episode they want us to play
2023-05-12 03:57:15 +00:00
audio_stream_idx = 0
2023-05-11 22:29:05 +00:00
if isValid(selectedItem.selectedAudioStreamIndex) and selectedItem.selectedAudioStreamIndex > 0
2023-05-07 01:26:02 +00:00
audio_stream_idx = selectedItem.selectedAudioStreamIndex
end if
2021-07-09 20:08:32 +00:00
2023-05-07 01:26:02 +00:00
selectedItem.selectedAudioStreamIndex = audio_stream_idx
2023-09-14 02:02:50 +00:00
' Display playback options dialog
if selectedItem.json.userdata.PlaybackPositionTicks > 0
m.global.queueManager.callFunc("hold", selectedItem)
playbackOptionDialog(selectedItem.json.userdata.PlaybackPositionTicks, selectedItem.json)
else
2023-05-07 01:26:02 +00:00
m.global.queueManager.callFunc("clear")
m.global.queueManager.callFunc("push", selectedItem)
m.global.queueManager.callFunc("playQueue")
end if
2022-12-08 18:33:08 +00:00
2023-05-07 01:26:02 +00:00
else if selectedItemType = "Series"
group = CreateSeriesDetailsGroup(selectedItem.json.id)
else if selectedItemType = "Season"
group = CreateSeasonDetailsGroupByID(selectedItem.json.SeriesId, selectedItem.id)
else if selectedItemType = "Movie"
' open movie detail page
group = CreateMovieDetailsGroup(selectedItem)
else if selectedItemType = "Person"
CreatePersonView(selectedItem)
else if selectedItemType = "TvChannel" or selectedItemType = "Video" or selectedItemType = "Program"
' User selected a Live TV channel / program
' Show Channel Loading spinner
dialog = createObject("roSGNode", "ProgressDialog")
dialog.title = tr("Loading Channel Data")
2021-07-09 20:08:32 +00:00
m.scene.dialog = dialog
2023-05-07 01:26:02 +00:00
' User selected a program. Play the channel the program is on
if LCase(selectedItemType) = "program"
selectedItem.id = selectedItem.json.ChannelId
end if
' Display playback options dialog
if selectedItem.json.userdata.PlaybackPositionTicks > 0
dialog.close = true
m.global.queueManager.callFunc("hold", selectedItem)
playbackOptionDialog(selectedItem.json.userdata.PlaybackPositionTicks, selectedItem.json)
else
m.global.queueManager.callFunc("clear")
m.global.queueManager.callFunc("push", selectedItem)
m.global.queueManager.callFunc("playQueue")
dialog.close = true
end if
else if selectedItemType = "Photo"
' Nothing to do here, handled in ItemGrid
else if selectedItemType = "MusicArtist"
group = CreateArtistView(selectedItem.json)
if not isValid(group)
message_dialog(tr("Unable to find any albums or songs belonging to this artist"))
end if
else if selectedItemType = "MusicAlbum"
group = CreateAlbumView(selectedItem.json)
2023-09-23 15:16:15 +00:00
else if selectedItemType = "MusicVideo"
group = CreateMovieDetailsGroup(selectedItem)
2023-05-07 01:26:02 +00:00
else if selectedItemType = "Playlist"
group = CreatePlaylistView(selectedItem.json)
else if selectedItemType = "Audio"
m.global.queueManager.callFunc("clear")
m.global.queueManager.callFunc("resetShuffle")
m.global.queueManager.callFunc("push", selectedItem.json)
m.global.queueManager.callFunc("playQueue")
else
' TODO - switch on more node types
message_dialog("This type is not yet supported: " + selectedItemType + ".")
2022-10-02 18:23:42 +00:00
end if
2021-07-09 20:08:32 +00:00
end if
else if isNodeEvent(msg, "movieSelected")
' If you select a movie from ANYWHERE, follow this flow
node = getMsgPicker(msg, "picker")
group = CreateMovieDetailsGroup(node)
else if isNodeEvent(msg, "seriesSelected")
' If you select a TV Series from ANYWHERE, follow this flow
node = getMsgPicker(msg, "picker")
2023-05-07 01:26:02 +00:00
group = CreateSeriesDetailsGroup(node.id)
2021-07-09 20:08:32 +00:00
else if isNodeEvent(msg, "seasonSelected")
' If you select a TV Season from ANYWHERE, follow this flow
ptr = msg.getData()
' ptr is for [row, col] of selected item... but we only have 1 row
series = msg.getRoSGNode()
2023-03-05 13:28:30 +00:00
if isValid(ptr) and ptr.count() >= 2 and isValid(ptr[1]) and isValid(series) and isValid(series.seasonData) and isValid(series.seasonData.items)
2023-03-02 17:05:36 +00:00
node = series.seasonData.items[ptr[1]]
group = CreateSeasonDetailsGroup(series.itemContent, node)
end if
2022-05-14 03:46:05 +00:00
else if isNodeEvent(msg, "musicAlbumSelected")
' If you select a Music Album from ANYWHERE, follow this flow
ptr = msg.getData()
albums = msg.getRoSGNode()
2022-07-19 02:28:06 +00:00
node = albums.musicArtistAlbumData.items[ptr]
2022-07-19 00:42:22 +00:00
group = CreateAlbumView(node)
2022-09-27 01:26:17 +00:00
else if isNodeEvent(msg, "appearsOnSelected")
' If you select a Music Album from ANYWHERE, follow this flow
ptr = msg.getData()
albums = msg.getRoSGNode()
node = albums.musicArtistAppearsOnData.items[ptr]
group = CreateAlbumView(node)
2022-05-21 20:45:01 +00:00
else if isNodeEvent(msg, "playSong")
' User has selected audio they want us to play
2022-05-15 02:30:29 +00:00
selectedIndex = msg.getData()
2022-05-21 20:45:01 +00:00
screenContent = msg.getRoSGNode()
2022-11-29 22:05:46 +00:00
2023-02-25 16:43:36 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2023-02-25 16:43:36 +00:00
m.global.queueManager.callFunc("push", screenContent.albumData.items[selectedIndex])
m.global.queueManager.callFunc("playQueue")
else if isNodeEvent(msg, "playItem")
' User has selected audio they want us to play
selectedIndex = msg.getData()
screenContent = msg.getRoSGNode()
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("push", screenContent.albumData.items[selectedIndex])
m.global.queueManager.callFunc("playQueue")
2022-05-15 19:10:21 +00:00
else if isNodeEvent(msg, "playAllSelected")
2022-05-21 20:45:01 +00:00
' User has selected playlist of of audio they want us to play
screenContent = msg.getRoSGNode()
2022-05-22 21:32:03 +00:00
m.spinner = screenContent.findNode("spinner")
m.spinner.visible = true
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("set", screenContent.albumData.items)
m.global.queueManager.callFunc("playQueue")
2022-07-19 02:28:06 +00:00
else if isNodeEvent(msg, "playArtistSelected")
' User has selected playlist of of audio they want us to play
screenContent = msg.getRoSGNode()
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("set", CreateArtistMix(screenContent.pageContent.id).Items)
m.global.queueManager.callFunc("playQueue")
2022-06-08 13:08:05 +00:00
else if isNodeEvent(msg, "instantMixSelected")
' User has selected instant mix
' User has selected playlist of of audio they want us to play
screenContent = msg.getRoSGNode()
m.spinner = screenContent.findNode("spinner")
2022-07-19 02:28:06 +00:00
if isValid(m.spinner)
m.spinner.visible = true
end if
2022-10-10 21:12:04 +00:00
2022-11-29 22:05:46 +00:00
viewHandled = false
2022-10-10 21:12:04 +00:00
' Create instant mix based on selected album
2022-07-19 02:28:06 +00:00
if isValid(screenContent.albumData)
2022-10-10 21:12:04 +00:00
if isValid(screenContent.albumData.items)
if screenContent.albumData.items.count() > 0
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("set", CreateInstantMix(screenContent.albumData.items[0].id).Items)
m.global.queueManager.callFunc("playQueue")
viewHandled = true
2022-10-10 21:12:04 +00:00
end if
end if
2022-07-19 02:28:06 +00:00
end if
2022-10-10 21:12:04 +00:00
2022-11-29 22:05:46 +00:00
if not viewHandled
' Create instant mix based on selected artist
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("set", CreateInstantMix(screenContent.pageContent.id).Items)
m.global.queueManager.callFunc("playQueue")
2022-10-10 21:12:04 +00:00
end if
2021-07-09 20:08:32 +00:00
else if isNodeEvent(msg, "search_value")
query = msg.getRoSGNode().search_value
group.findNode("SearchBox").visible = false
options = group.findNode("SearchSelect")
options.visible = true
options.setFocus(true)
dialog = createObject("roSGNode", "ProgressDialog")
dialog.title = tr("Loading Search Data")
m.scene.dialog = dialog
results = SearchMedia(query)
dialog.close = true
options.itemData = results
options.query = query
else if isNodeEvent(msg, "itemSelected")
' Search item selected
node = getMsgPicker(msg)
' TODO - swap this based on target.mediatype
' types: [ Series (Show), Episode, Movie, Audio, Person, Studio, MusicArtist ]
if node.type = "Series"
2023-05-07 01:26:02 +00:00
group = CreateSeriesDetailsGroup(node.id)
2022-09-05 06:50:13 +00:00
else if node.type = "Movie"
2021-07-09 20:08:32 +00:00
group = CreateMovieDetailsGroup(node)
2022-09-05 06:50:13 +00:00
else if node.type = "MusicArtist"
group = CreateArtistView(node.json)
else if node.type = "MusicAlbum"
group = CreateAlbumView(node.json)
2023-09-23 15:16:15 +00:00
else if node.type = "MusicVideo"
group = CreateMovieDetailsGroup(node)
2022-09-05 06:50:13 +00:00
else if node.type = "Audio"
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("push", node.json)
m.global.queueManager.callFunc("playQueue")
2022-09-05 06:50:13 +00:00
else if node.type = "Person"
group = CreatePersonView(node)
else if node.type = "TvChannel"
group = CreateVideoPlayerGroup(node.id)
sceneManager.callFunc("pushScene", group)
else if node.type = "Episode"
group = CreateVideoPlayerGroup(node.id)
sceneManager.callFunc("pushScene", group)
else if node.type = "Audio"
selectedIndex = msg.getData()
screenContent = msg.getRoSGNode()
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("push", screenContent.albumData.items[node.id])
m.global.queueManager.callFunc("playQueue")
2022-09-05 06:50:13 +00:00
else
' TODO - switch on more node types
message_dialog("This type is not yet supported: " + node.type + ".")
2021-04-14 07:03:15 +00:00
end if
2021-07-09 20:08:32 +00:00
else if isNodeEvent(msg, "buttonSelected")
' If a button is selected, we have some determining to do
btn = getButton(msg)
2021-10-10 01:51:33 +00:00
group = sceneManager.callFunc("getActiveScene")
2023-03-02 16:57:31 +00:00
if isValid(btn) and btn.id = "play-button"
2023-05-07 01:26:02 +00:00
' User chose Play button from movie detail view
2022-10-27 04:04:44 +00:00
2022-03-13 00:36:11 +00:00
' Check if a specific Audio Stream was selected
2023-05-07 01:26:02 +00:00
audio_stream_idx = 0
2023-03-05 13:28:30 +00:00
if isValid(group) and isValid(group.selectedAudioStreamIndex)
2021-07-09 20:08:32 +00:00
audio_stream_idx = group.selectedAudioStreamIndex
end if
2023-05-07 01:26:02 +00:00
group.itemContent.selectedAudioStreamIndex = audio_stream_idx
group.itemContent.id = group.selectedVideoStreamId
' Display playback options dialog
if group.itemContent.json.userdata.PlaybackPositionTicks > 0
m.global.queueManager.callFunc("hold", group.itemContent)
playbackOptionDialog(group.itemContent.json.userdata.PlaybackPositionTicks, group.itemContent.json)
else
m.global.queueManager.callFunc("clear")
m.global.queueManager.callFunc("push", group.itemContent)
m.global.queueManager.callFunc("playQueue")
2021-07-09 20:08:32 +00:00
end if
2022-05-10 07:04:23 +00:00
2023-03-05 13:28:30 +00:00
if isValid(group) and isValid(group.lastFocus) and isValid(group.lastFocus.id) and group.lastFocus.id = "main_group"
2022-12-09 23:27:16 +00:00
buttons = group.findNode("buttons")
if isValid(buttons)
2023-03-02 18:12:25 +00:00
group.lastFocus = group.findNode("buttons")
2022-12-09 23:27:16 +00:00
end if
end if
2023-03-05 13:28:30 +00:00
if isValid(group) and isValid(group.lastFocus)
2022-09-03 07:31:15 +00:00
group.lastFocus.setFocus(true)
end if
2022-12-09 23:27:16 +00:00
2022-09-03 07:31:15 +00:00
else if btn <> invalid and btn.id = "trailer-button"
2023-05-07 01:26:02 +00:00
' User chose to play a trailer from the movie detail view
2022-10-27 04:04:44 +00:00
dialog = createObject("roSGNode", "ProgressDialog")
dialog.title = tr("Loading trailer")
m.scene.dialog = dialog
2022-09-03 07:31:15 +00:00
2023-06-01 12:43:27 +00:00
trailerData = api.users.GetLocalTrailers(m.global.session.user.id, group.id)
2022-09-03 07:31:15 +00:00
2023-03-05 13:28:30 +00:00
if isValid(trailerData) and isValid(trailerData[0]) and isValid(trailerData[0].id)
2023-05-07 01:26:02 +00:00
m.global.queueManager.callFunc("clear")
m.global.queueManager.callFunc("set", trailerData)
m.global.queueManager.callFunc("playQueue")
2022-10-27 04:04:44 +00:00
dialog.close = true
2022-09-03 07:31:15 +00:00
end if
2023-03-05 13:28:30 +00:00
if isValid(group) and isValid(group.lastFocus)
2022-05-10 07:04:23 +00:00
group.lastFocus.setFocus(true)
end if
2021-07-09 20:08:32 +00:00
else if btn <> invalid and btn.id = "watched-button"
movie = group.itemContent
2023-03-05 13:28:30 +00:00
if isValid(movie) and isValid(movie.watched) and isValid(movie.id)
2023-03-02 18:04:06 +00:00
if movie.watched
UnmarkItemWatched(movie.id)
else
MarkItemWatched(movie.id)
end if
movie.watched = not movie.watched
2021-07-09 20:08:32 +00:00
end if
else if btn <> invalid and btn.id = "favorite-button"
movie = group.itemContent
if movie.favorite
UnmarkItemFavorite(movie.id)
else
MarkItemFavorite(movie.id)
end if
movie.favorite = not movie.favorite
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 = "OKDialog"
dialog.unobserveField("buttonSelected")
dialog.close = true
end if
end if
else if isNodeEvent(msg, "optionSelected")
button = msg.getRoSGNode()
2021-10-10 01:51:33 +00:00
group = sceneManager.callFunc("getActiveScene")
2023-03-05 13:28:30 +00:00
if button.id = "goto_search" and isValid(group)
2021-07-09 20:08:32 +00:00
' Exit out of the side panel
2021-10-09 19:02:34 +00:00
panel = group.findNode("options")
2021-07-09 20:08:32 +00:00
panel.visible = false
2023-03-05 13:28:30 +00:00
if isValid(group.lastFocus)
2021-07-09 20:08:32 +00:00
group.lastFocus.setFocus(true)
else
group.setFocus(true)
end if
group = CreateSearchPage()
2021-10-10 01:51:33 +00:00
sceneManager.callFunc("pushScene", group)
2022-09-05 06:50:13 +00:00
group.findNode("SearchBox").findNode("search_Key").setFocus(true)
group.findNode("SearchBox").findNode("search_Key").active = true
2021-07-09 20:08:32 +00:00
else if button.id = "change_server"
unset_setting("server")
2023-09-21 13:58:07 +00:00
session.server.Delete()
2021-12-30 01:00:13 +00:00
SignOut(false)
2021-10-10 02:04:37 +00:00
sceneManager.callFunc("clearScenes")
2021-07-09 20:08:32 +00:00
goto app_start
2023-09-14 15:52:32 +00:00
else if button.id = "change_user"
2021-12-30 01:00:13 +00:00
SignOut(false)
2021-10-10 02:04:37 +00:00
sceneManager.callFunc("clearScenes")
2021-07-09 20:08:32 +00:00
goto app_start
else if button.id = "sign_out"
SignOut()
2021-10-10 02:04:37 +00:00
sceneManager.callFunc("clearScenes")
2021-07-09 20:08:32 +00:00
goto app_start
2022-05-01 10:51:28 +00:00
else if button.id = "settings"
' Exit out of the side panel
panel = group.findNode("options")
panel.visible = false
2023-03-05 13:28:30 +00:00
if isValid(group) and isValid(group.lastFocus)
2022-05-01 10:51:28 +00:00
group.lastFocus.setFocus(true)
else
group.setFocus(true)
end if
sceneManager.callFunc("settings")
2021-07-09 20:08:32 +00:00
end if
else if isNodeEvent(msg, "selectSubtitlePressed")
node = m.scene.focusedChild
2021-12-23 07:56:57 +00:00
if node.focusedChild <> invalid and node.focusedChild.isSubType("JFVideo")
2021-07-09 20:08:32 +00:00
trackSelected = selectSubtitleTrack(node.Subtitles, node.SelectedSubtitle)
if trackSelected <> invalid and trackSelected <> -2
changeSubtitleDuringPlayback(trackSelected)
end if
end if
2022-09-06 04:38:37 +00:00
else if isNodeEvent(msg, "selectPlaybackInfoPressed")
node = m.scene.focusedChild
if node.focusedChild <> invalid and node.focusedChild.isSubType("JFVideo")
info = GetPlaybackInfo()
show_dialog(tr("Playback Information"), info)
end if
2021-07-09 20:08:32 +00:00
else if isNodeEvent(msg, "state")
node = msg.getRoSGNode()
2023-03-05 13:28:30 +00:00
if isValid(node) and isValid(node.state)
2023-05-07 01:26:02 +00:00
if node.selectedItemType = "TvChannel" and node.state = "finished"
2023-03-02 18:23:35 +00:00
video = CreateVideoPlayerGroup(node.id)
m.global.sceneManager.callFunc("pushScene", video)
m.global.sceneManager.callFunc("deleteSceneAtIndex", 2)
else if node.state = "finished"
node.control = "stop"
' If node allows retrying using Transcode Url, give that shot
if isValid(node.retryWithTranscoding) and node.retryWithTranscoding
retryVideo = CreateVideoPlayerGroup(node.Id, invalid, node.audioIndex, true, false)
m.global.sceneManager.callFunc("popScene")
2023-03-05 13:28:30 +00:00
if isValid(retryVideo)
2023-03-02 18:23:35 +00:00
m.global.sceneManager.callFunc("pushScene", retryVideo)
end if
2023-03-05 13:28:30 +00:00
else if not isValid(node.showID)
2023-01-31 01:02:00 +00:00
sceneManager.callFunc("popScene")
2023-03-02 18:23:35 +00:00
else
2023-05-19 01:57:04 +00:00
autoPlayNextEpisode(node.id, node.showID)
2023-01-31 01:02:00 +00:00
end if
2021-07-09 20:08:32 +00:00
end if
end if
else if type(msg) = "roDeviceInfoEvent"
event = msg.GetInfo()
2023-03-02 18:33:54 +00:00
2021-07-09 20:08:32 +00:00
if event.exitedScreensaver = true
2021-10-10 01:51:33 +00:00
sceneManager.callFunc("resetTime")
2023-03-02 18:33:54 +00:00
group = sceneManager.callFunc("getActiveScene")
2023-03-05 13:28:30 +00:00
if isValid(group) and isValid(group.subtype())
2023-03-15 02:55:09 +00:00
' refresh the current view
2023-03-02 18:33:54 +00:00
if group.subtype() = "Home"
currentTime = CreateObject("roDateTime").AsSeconds()
group.timeLastRefresh = currentTime
group.callFunc("refresh")
end if
' todo: add other screens to be refreshed - movie detail, tv series, episode list etc.
2021-07-09 20:08:32 +00:00
end if
2023-05-27 20:43:05 +00:00
else if isValid(event.audioGuideEnabled)
2023-04-21 23:02:28 +00:00
tmpGlobalDevice = m.global.device
2023-04-21 23:16:19 +00:00
tmpGlobalDevice.AddReplace("isaudioguideenabled", event.audioGuideEnabled)
2023-04-21 23:02:28 +00:00
' update global device array
m.global.setFields({ device: tmpGlobalDevice })
2023-05-27 20:43:05 +00:00
else if isValid(event.Mode)
' Indicates the current global setting for the Caption Mode property, which may be one of the following values:
' "On"
' "Off"
' "Instant replay"
' "When mute" (Only returned for a TV; this option is not available on STBs).
print "event.Mode = ", event.Mode
if isValid(event.Mute)
print "event.Mute = ", event.Mute
end if
else if isValid(event.linkStatus)
' True if the device currently seems to have an active network connection.
print "event.linkStatus = ", event.linkStatus
else if isValid(event.generalMemoryLevel)
' This event will be sent first when the OS transitions from "normal" to "low" state and will continue to be sent while in "low" or "critical" states.
' - "normal" means that the general memory is within acceptable levels
' - "low" means that the general memory is below acceptable levels but not critical
' - "critical" means that general memory are at dangerously low level and that the OS may force terminate the application
print "event.generalMemoryLevel = ", event.generalMemoryLevel
2023-09-23 12:09:36 +00:00
session.Update("memoreyLevel", event.generalMemoryLevel)
2023-05-27 20:43:05 +00:00
else if isValid(event.audioCodecCapabilityChanged)
' The audio codec capability has changed if true.
print "event.audioCodecCapabilityChanged = ", event.audioCodecCapabilityChanged
PostDeviceProfile()
else if isValid(event.videoCodecCapabilityChanged)
' The video codec capability has changed if true.
print "event.videoCodecCapabilityChanged = ", event.videoCodecCapabilityChanged
PostDeviceProfile()
else if isValid(event.appFocus)
' It is set to False when the System Overlay (such as the confirm partner button HUD or the caption control overlay) takes focus and True when the channel regains focus
print "event.appFocus = ", event.appFocus
2021-07-09 20:08:32 +00:00
else
print "Unhandled roDeviceInfoEvent:"
print msg.GetInfo()
end if
else if type(msg) = "roInputEvent"
if msg.IsInput()
info = msg.GetInfo()
if info.DoesExist("mediatype") and info.DoesExist("contentid")
2023-05-24 01:07:18 +00:00
inputEventVideo = {
id: info.contentId,
type: "video"
}
m.global.queueManager.callFunc("clear")
m.global.queueManager.callFunc("push", inputEventVideo)
m.global.queueManager.callFunc("playQueue")
2021-07-09 20:08:32 +00:00
end if
end if
2023-05-07 01:26:02 +00:00
else if isNodeEvent(msg, "dataReturned")
2023-05-09 12:21:20 +00:00
popupNode = msg.getRoSGNode()
if isValid(popupNode) and isValid(popupNode.returnData)
2023-05-07 01:26:02 +00:00
selectedItem = m.global.queueManager.callFunc("getHold")
m.global.queueManager.callFunc("clearHold")
if isValid(selectedItem) and selectedItem.count() > 0 and isValid(selectedItem[0])
2023-05-09 12:21:20 +00:00
if popupNode.returnData.indexselected = 0
2023-05-07 01:26:02 +00:00
'Resume video from resume point
startingPoint = 0
if isValid(selectedItem[0].json) and isValid(selectedItem[0].json.UserData) and isValid(selectedItem[0].json.UserData.PlaybackPositionTicks)
if selectedItem[0].json.UserData.PlaybackPositionTicks > 0
startingPoint = selectedItem[0].json.UserData.PlaybackPositionTicks
end if
end if
selectedItem[0].startingPoint = startingPoint
m.global.queueManager.callFunc("clear")
m.global.queueManager.callFunc("push", selectedItem[0])
m.global.queueManager.callFunc("playQueue")
2023-05-09 12:21:20 +00:00
else if popupNode.returnData.indexselected = 1
2023-05-07 01:26:02 +00:00
'Start Over from beginning selected, set position to 0
selectedItem[0].startingPoint = 0
m.global.queueManager.callFunc("clear")
m.global.queueManager.callFunc("push", selectedItem[0])
m.global.queueManager.callFunc("playQueue")
2023-05-09 12:21:20 +00:00
else if popupNode.returnData.indexselected = 2
2023-05-07 15:28:11 +00:00
' User chose Go to series
2023-05-07 01:26:02 +00:00
CreateSeriesDetailsGroup(selectedItem[0].json.SeriesId)
2023-05-09 12:21:20 +00:00
else if popupNode.returnData.indexselected = 3
2023-05-07 01:26:02 +00:00
' User chose Go to season
CreateSeasonDetailsGroupByID(selectedItem[0].json.SeriesId, selectedItem[0].json.seasonID)
2023-05-09 12:21:20 +00:00
else if popupNode.returnData.indexselected = 4
2023-05-07 15:28:11 +00:00
' User chose Go to episode
2023-05-07 01:26:02 +00:00
CreateMovieDetailsGroup(selectedItem[0])
end if
end if
end if
2021-07-09 20:08:32 +00:00
else
print "Unhandled " type(msg)
print msg
end if
end while
2019-04-22 19:08:10 +00:00
end sub