From 5fd5c9eec24b70251a4bf7b820085d2cdc0ece27 Mon Sep 17 00:00:00 2001 From: Nick Bisby Date: Sun, 14 Apr 2019 19:16:47 -0500 Subject: [PATCH] Make things use Content rather than json --- components/collections/details.brs | 7 ++-- components/collections/rowlist.xml | 5 +-- components/data/collection.xml | 15 ++++--- components/data/movie.xml | 14 ++++--- components/data/search-result.xml | 14 ++++--- components/data/series.xml | 14 ++++--- components/data/tvepisode.xml | 14 +++++-- components/data/tvseason.xml | 12 +++--- components/movies/details.brs | 7 ++-- components/search/rowlist.xml | 7 ++-- components/tvshows/group-description.brs | 10 +++-- components/tvshows/rowlist-episode.xml | 5 +-- components/tvshows/rowlist-season.xml | 5 +-- source/ShowScenes.brs | 51 +++++++++++++----------- source/api/itemdata.brs | 32 +++++++++++++-- source/utils/misc.brs | 7 ++-- 16 files changed, 132 insertions(+), 87 deletions(-) diff --git a/components/collections/details.brs b/components/collections/details.brs index 00c8ce95..2849b0d1 100644 --- a/components/collections/details.brs +++ b/components/collections/details.brs @@ -1,5 +1,6 @@ sub itemContentChanged() - itemData = m.top.itemContent.full_data + item = m.top.itemContent + itemData = item.json m.top.findNode("poster").uri = m.top.itemContent.posterURL @@ -44,7 +45,7 @@ sub setFieldText(field as string, value) end sub function getRuntime() as Integer - itemData = m.top.itemContent.full_data + itemData = m.top.itemContent.json ' A tick is .1ms, so 1/10,000,000 for ticks to seconds, ' then 1/60 for seconds to minutess... 1/600,000,000 @@ -52,7 +53,7 @@ function getRuntime() as Integer end function function getEndTime() as string - itemData = m.top.itemContent.full_data + itemData = m.top.itemContent.json date = CreateObject("roDateTime") duration_s = int(itemData.RunTimeTicks / 10000000.0) diff --git a/components/collections/rowlist.xml b/components/collections/rowlist.xml index a429f653..8acca289 100644 --- a/components/collections/rowlist.xml +++ b/components/collections/rowlist.xml @@ -80,9 +80,8 @@ if index > itemData.items.count() then exit for end if - datum = itemData.Items[index-1] - item = row.CreateChild("CollectionData") - item.full_data = datum + item = itemData.Items[index-1] + row.appendChild(item) end for end for return data diff --git a/components/data/collection.xml b/components/data/collection.xml index 8301c125..4bd110c9 100644 --- a/components/data/collection.xml +++ b/components/data/collection.xml @@ -1,29 +1,32 @@ + - + diff --git a/components/data/movie.xml b/components/data/movie.xml index 1d5605f8..67145e43 100644 --- a/components/data/movie.xml +++ b/components/data/movie.xml @@ -8,22 +8,24 @@ - + diff --git a/components/data/search-result.xml b/components/data/search-result.xml index de0ea612..97e8260c 100644 --- a/components/data/search-result.xml +++ b/components/data/search-result.xml @@ -1,19 +1,21 @@ + + - - - + diff --git a/components/data/tvseason.xml b/components/data/tvseason.xml index 8a05df1d..07263942 100644 --- a/components/data/tvseason.xml +++ b/components/data/tvseason.xml @@ -1,25 +1,27 @@ + - - + diff --git a/components/movies/details.brs b/components/movies/details.brs index 284e0204..145913b3 100644 --- a/components/movies/details.brs +++ b/components/movies/details.brs @@ -1,5 +1,6 @@ sub itemContentChanged() - itemData = m.top.itemContent.full_data + item = m.top.itemContent + itemData = item.json m.top.findNode("moviePoster").uri = m.top.itemContent.posterURL @@ -44,7 +45,7 @@ sub setFieldText(field as string, value) end sub function getRuntime() as Integer - itemData = m.top.itemContent.full_data + itemData = m.top.itemContent.json ' A tick is .1ms, so 1/10,000,000 for ticks to seconds, ' then 1/60 for seconds to minutess... 1/600,000,000 @@ -52,7 +53,7 @@ function getRuntime() as Integer end function function getEndTime() as string - itemData = m.top.itemContent.full_data + itemData = m.top.itemContent.json date = CreateObject("roDateTime") duration_s = int(itemData.RunTimeTicks / 10000000.0) diff --git a/components/search/rowlist.xml b/components/search/rowlist.xml index e9a88c97..ae2e145e 100644 --- a/components/search/rowlist.xml +++ b/components/search/rowlist.xml @@ -67,8 +67,8 @@ } for each item in itemData.searchHints - if content_types[item.Type] <> invalid - content_types[item.Type].count += 1 + if content_types[item.type] <> invalid + content_types[item.type].count += 1 end if end for @@ -89,8 +89,7 @@ row.title = title for each item in itemData.SearchHints if item.type = type_filter - child = row.createChild("SearchData") - child.full_data = item + row.appendChild(item) end if end for end function diff --git a/components/tvshows/group-description.brs b/components/tvshows/group-description.brs index 88785b51..ce12aa30 100644 --- a/components/tvshows/group-description.brs +++ b/components/tvshows/group-description.brs @@ -1,5 +1,7 @@ sub itemContentChanged() - itemData = m.top.itemContent.full_data + ' TODO - make things use item rather than itemData + item = m.top.itemContent + itemData = item.json m.top.findNode("tvshowPoster").uri = m.top.itemContent.posterURL @@ -38,7 +40,7 @@ sub setFieldText(field as string, value) end sub function getRuntime() as Integer - itemData = m.top.itemContent.full_data + itemData = m.top.itemContent.json ' A tick is .1ms, so 1/10,000,000 for ticks to seconds, ' then 1/60 for seconds to minutess... 1/600,000,000 @@ -46,7 +48,7 @@ function getRuntime() as Integer end function function getEndTime() as string - itemData = m.top.itemContent.full_data + itemData = m.top.itemContent.json date = CreateObject("roDateTime") duration_s = int(itemData.RunTimeTicks / 10000000.0) @@ -69,7 +71,7 @@ function getEndTime() as string end function function getHistory() as string - itemData = m.top.itemContent.full_data + itemData = m.top.itemContent.json ' Aired Fridays at 9:30 PM on ABC (US) airwords = invalid diff --git a/components/tvshows/rowlist-episode.xml b/components/tvshows/rowlist-episode.xml index 1935ee02..90e44e43 100644 --- a/components/tvshows/rowlist-episode.xml +++ b/components/tvshows/rowlist-episode.xml @@ -66,9 +66,8 @@ rowsize = m.top.rowSize data = CreateObject("roSGNode", "ContentNode") row = data.CreateChild("ContentNode") - for each datum in episodeData.items - item = row.CreateChild("TVEpisodeData") - item.full_data = datum + for each item in episodeData.items + row.appendChild(item) end for m.top.content = data return data diff --git a/components/tvshows/rowlist-season.xml b/components/tvshows/rowlist-season.xml index 577973bc..2a89654c 100644 --- a/components/tvshows/rowlist-season.xml +++ b/components/tvshows/rowlist-season.xml @@ -60,9 +60,8 @@ data = CreateObject("roSGNode", "ContentNode") row = data.CreateChild("ContentNode") row.title = "Seasons" - for each datum in seasonData.items - item = row.CreateChild("TVSeasonData") - item.full_data = datum + for each item in seasonData.items + row.appendChild(item) end for m.top.content = data return data diff --git a/source/ShowScenes.brs b/source/ShowScenes.brs index 9a619cc0..92c206ae 100644 --- a/source/ShowScenes.brs +++ b/source/ShowScenes.brs @@ -102,6 +102,8 @@ sub ShowLibrarySelect() scene.libraries = libs scene.observeField("librarySelected", port) + library = scene.findNode("LibrarySelect") + search = scene.findNode("search") search.observeField("escape", port) search.observeField("search_value", port) @@ -252,7 +254,7 @@ sub ShowMovieOptions(library) options.setFocus(true) else if nodeEventQ(msg, "itemSelected") target = getMsgRowTarget(msg) - ShowMovieDetails(target.movieID) + ShowMovieDetails(target) else print msg print msg.getField() @@ -261,7 +263,7 @@ sub ShowMovieOptions(library) end while end sub -sub ShowMovieDetails(movie_id) +sub ShowMovieDetails(movie) port = CreateObject("roMessagePort") screen = CreateObject("roSGScreen") screen.setMessagePort(port) @@ -271,7 +273,8 @@ sub ShowMovieDetails(movie_id) themeScene(scene) - scene.itemContent = ItemMetaData(movie_id) + movie = ItemMetaData(movie.id) + scene.itemContent = movie buttons = scene.findNode("buttons") for each b in buttons.getChildren(-1, 0) @@ -284,21 +287,21 @@ sub ShowMovieDetails(movie_id) return else if nodeEventQ(msg, "buttonSelected") if msg.getNode() = "play-button" - showVideoPlayer(movie_id) + showVideoPlayer(movie.id) else if msg.getNode() = "watched-button" - if content.watched - UnmarkItemWatched(movie_id) + if movie.watched + UnmarkItemWatched(movie.id) else - MarkItemWatched(movie_id) + MarkItemWatched(movie.id) end if - content.watched = not content.watched + movie.watched = not movie.watched else if msg.getNode() = "favorite-button" - if content.favorite - UnmarkItemFavorite(movie_id) + if movie.favorite + UnmarkItemFavorite(movie.id) else - MarkItemFavorite(movie_id) + MarkItemFavorite(movie.id) end if - content.favorite = not content.favorite + movie.favorite = not movie.favorite end if else print msg @@ -363,12 +366,12 @@ sub ShowTVShowOptions(library) return else if nodeEventQ(msg, "itemSelected") target = getMsgRowTarget(msg) - ShowTVShowDetails(target.showID) + ShowTVShowDetails(target) end if end while end sub -sub ShowTVShowDetails(show_id) +sub ShowTVShowDetails(series) port = CreateObject("roMessagePort") screen = CreateObject("roSGScreen") screen.setMessagePort(port) @@ -378,9 +381,10 @@ sub ShowTVShowDetails(show_id) themeScene(scene) - scene.itemData = ItemMetaData(show_id) + series = ItemMetaData(series.id) + scene.itemData = series scene.findNode("description").findNode("buttons").setFocus(true) - scene.seasonData = TVSeasons(show_id) + scene.seasonData = TVSeasons(series.id) scene.findNode("description").findNode("buttons").setFocus(true) @@ -395,14 +399,13 @@ sub ShowTVShowDetails(show_id) return else if nodeEventQ(msg, "buttonSelected") ' What button could we even be watching yet - print "HELLO" else if nodeEventQ(msg, "rowItemSelected") ' Assume for now it's a season being selected season_list = msg.getRoSGNode() item = msg.getData() season = season_list.content.getChild(item[0]).getChild(item[1]) - ShowTVSeasonEpisodes(show_id, season.full_data.id) + ShowTVSeasonEpisodes(series, season) else print msg print type(msg) @@ -410,7 +413,7 @@ sub ShowTVShowDetails(show_id) end while end sub -sub ShowTVSeasonEpisodes(show_id, season_id) +sub ShowTVSeasonEpisodes(series, season) port = CreateObject("roMessagePort") screen = CreateObject("roSGScreen") screen.setMessagePort(port) @@ -420,9 +423,9 @@ sub ShowTVSeasonEpisodes(show_id, season_id) themeScene(scene) - scene.showData = ItemMetaData(show_id) - scene.seasonData = TVSeasons(show_id) - scene.episodeData = TVEpisodes(show_id, season_id) + scene.showData = ItemMetaData(series.id) + scene.seasonData = TVSeasons(series.id) + scene.episodeData = TVEpisodes(series.id, season.id) scene.findNode("TVEpisodeSelect").observeField("rowItemSelected", port) @@ -435,7 +438,7 @@ sub ShowTVSeasonEpisodes(show_id, season_id) item = msg.getData() episode = episode_list.content.getChild(item[0]).getChild(item[1]) - ShowVideoPlayer(episode.full_data.id) + ShowVideoPlayer(episode.id) else print msg print type(msg) @@ -566,7 +569,7 @@ sub ShowSearchOptions(query) target = getMsgRowTarget(msg) ' TODO - swap this based on target.mediatype ' types: [ Episode, Movie, Audio, Person, Studio, MusicArtist ] - ShowMovieDetails(target.mediaID) + ShowMovieDetails(target) else print msg print msg.getField() diff --git a/source/api/itemdata.brs b/source/api/itemdata.brs index 666c1485..226ddd10 100644 --- a/source/api/itemdata.brs +++ b/source/api/itemdata.brs @@ -17,6 +17,7 @@ end function function SearchMedia(query as String) resp = APIRequest("Search/Hints", {"searchTerm": query}) data = getJson(resp) + results = [] for each item in data.SearchHints if item.type = "Movie" item.posterURL = ImageURL(item.id) @@ -25,7 +26,12 @@ function SearchMedia(query as String) else if item.type = "Episode" item.posterURL = ImageURL(item.id) end if + + tmp = CreateObject("roSGNode", "SearchData") + tmp.json = item + results.push(tmp) end for + data.SearchHints = results return data end function @@ -48,11 +54,15 @@ function ItemList(library_id=invalid as String, params={}) if item.type = "Movie" tmp = CreateObject("roSGNode", "MovieData") - tmp.full_data = item + tmp.json = item results.push(tmp) else if item.type = "Series" tmp = CreateObject("roSGNode", "SeriesData") - tmp.full_data = item + tmp.json = item + results.push(tmp) + else if item.type = "Cllection" + tmp = CreateObject("roSGNode", "CollectionData") + tmp.json = item results.push(tmp) else print item.type @@ -72,12 +82,16 @@ function ItemMetaData(id as String) data.posterURL = ImageURL(data.id) if data.type = "Movie" tmp = CreateObject("roSGNode", "MovieData") - tmp.full_data = data + tmp.json = data return tmp else if data.type = "Series" tmp = CreateObject("roSGNode", "SeriesData") - tmp.full_data = data + tmp.json = data return tmp + else if item.type = "Cllection" + tmp = CreateObject("roSGNode", "CollectionData") + tmp.json = item + results.push(tmp) else print data.type ' Return json if we don't know what it is @@ -92,9 +106,14 @@ function TVSeasons(id as String) resp = APIRequest(url, {"UserId": get_setting("active_user")}) data = getJson(resp) + results = [] for each item in data.Items item.posterURL = ImageURL(item.id) + tmp = CreateObject("roSGNode", "TVEpisodeData") + tmp.json = item + results.push(tmp) end for + data.Items = results return data end function @@ -103,9 +122,14 @@ function TVEpisodes(show_id as String, season_id as String) resp = APIRequest(url, {"seasonId": season_id, "UserId": get_setting("active_user")}) data = getJson(resp) + results = [] for each item in data.Items item.posterURL = ImageURL(item.id) + tmp = CreateObject("roSGNode", "TVEpisodeData") + tmp.json = item + results.push(tmp) end for + data.Items = results return data end function diff --git a/source/utils/misc.brs b/source/utils/misc.brs index 1f49cfb2..54282eb0 100644 --- a/source/utils/misc.brs +++ b/source/utils/misc.brs @@ -1,12 +1,13 @@ ' "Q" stands for "Question mark" since nodeEvent? wasn't acceptable ' Probably needs a better name, but unique for now -function nodeEventQ(msg, field) as boolean +function nodeEventQ(msg, field as string) as boolean return type(msg) = "roSGNodeEvent" and msg.getField() = field end function -function getMsgRowTarget(msg, subnode=invalid) as object +function getMsgRowTarget(msg, subnode="" as string) as object node = msg.getRoSGNode() - if subnode <> invalid + ' Subnode allows for handling alias messages + if subnode <> "" node = node.findNode(subnode) end if coords = node.rowItemSelected