From edab57c45b80ac5f0bcbd98609b6b9dc68d7546f Mon Sep 17 00:00:00 2001 From: Nick Bisby Date: Fri, 6 Dec 2019 20:49:37 -0600 Subject: [PATCH] Make TV series work again, or for the first time\? (#94) --- components/data/series.xml | 2 +- components/data/tvepisode.xml | 2 +- components/data/tvseason.xml | 2 +- components/tvshows/details.brs | 159 ++++++++++++++++---- components/tvshows/details.xml | 32 ++-- components/tvshows/episode.brs | 5 + components/tvshows/episodes.xml | 19 +-- components/tvshows/rowlist-season.brs | 24 +-- components/tvshows/rowlist-season.xml | 1 - components/tvshows/scene.brs | 14 +- components/tvshows/scene.xml | 15 +- source/Main.brs | 47 ++++++ source/ShowScenes.brs | 207 ++++++-------------------- source/api/Items.brs | 4 +- 14 files changed, 290 insertions(+), 243 deletions(-) diff --git a/components/data/series.xml b/components/data/series.xml index b16b3529..e09491d4 100644 --- a/components/data/series.xml +++ b/components/data/series.xml @@ -3,7 +3,7 @@ - + diff --git a/components/data/tvepisode.xml b/components/data/tvepisode.xml index e4c548b5..74c72847 100644 --- a/components/data/tvepisode.xml +++ b/components/data/tvepisode.xml @@ -7,7 +7,7 @@ - + diff --git a/components/data/tvseason.xml b/components/data/tvseason.xml index 0bbd45a4..811ddb6b 100644 --- a/components/data/tvseason.xml +++ b/components/data/tvseason.xml @@ -5,7 +5,7 @@ - + diff --git a/components/tvshows/details.brs b/components/tvshows/details.brs index 2df508e7..9a36d213 100644 --- a/components/tvshows/details.brs +++ b/components/tvshows/details.brs @@ -1,32 +1,139 @@ sub init() - set = m.top.findNode("panelset") - set.height = 1080 - - panel = set.findNode("panel-desc") - panel.panelSize = "full" - panel.hasNextPanel = true - panel.isFullScreen = true - panel.leftPosition = 150 - - panel2 = set.findNode("panel-seasons") - panel2.panelSize = "full" - panel2.hasNextPanel = false - panel2.isFullScreen = true - panel2.leftPosition = 150 - ' TODO - set the bounds so seasons dont go off the edge of the screen + m.top.overhangTitle = "TV Show" + main = m.top.findNode("toplevel") + main.translation = [50, 175] end sub -sub panelFocusChanged() - set = m.top.findNode("panelset") - index = m.top.panelFocused +sub itemContentChanged() + ' Updates video metadata + ' TODO - make things use item rather than itemData + item = m.top.itemContent + itemData = item.json - if index = 0 - ' Description page - ' TODO - get the buttons to actually take focus back - set.findNode("description").findNode("buttons").setFocus(true) - else if index = 1 - ' Seasons page - set.findNode("seasons").setFocus(true) + m.top.findNode("tvshowPoster").uri = m.top.itemContent.posterURL + + ' Handle all "As Is" fields + m.top.overhangTitle = itemData.name + setFieldText("releaseYear", itemData.productionYear) + setFieldText("officialRating", itemData.officialRating) + setFieldText("communityRating", str(itemData.communityRating)) + setFieldText("overview", itemData.overview) + + + if type(itemData.RunTimeTicks) = "LongInteger" + setFieldText("runtime", stri(getRuntime()) + " mins") + end if + + setFieldText("history", getHistory()) + + if itemData.genres.count() > 0 + setFieldText("genres", itemData.genres.join(", ")) + end if + director = invalid + for each person in itemData.people + if person.type = "Director" + director = person.name + exit for end if + end for + if itemData.taglines.count() > 0 + setFieldText("tagline", itemData.taglines[0]) + end if + ' m.top.findNode("TVSeasonSelect").TVSeasonData = m.top.itemContent.seasons +end sub -end sub \ No newline at end of file +sub setFieldText(field, value) + node = m.top.findNode(field) + if node = invalid or value = invalid then return + + ' Handle non strings... Which _shouldn't_ happen, but hey + if type(value) = "roInt" or type(value) = "Integer" then + value = str(value) + else if type(value) <> "roString" and type(value) <> "String" then + value = "" + end if + + node.text = value +end sub + +function getRuntime() as integer + 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 + return round(itemData.RunTimeTicks / 600000000.0) +end function + +function getEndTime() as string + itemData = m.top.itemContent.json + + date = CreateObject("roDateTime") + duration_s = int(itemData.RunTimeTicks / 10000000.0) + date.fromSeconds(date.asSeconds() + duration_s) + date.toLocalTime() + hours = date.getHours() + meridian = "AM" + if hours = 0 + hours = 12 + meridian = "AM" + else if hours = 12 + hours = 12 + meridian = "PM" + else if hours > 12 + hours = hours - 12 + meridian = "PM" + end if + + return Substitute("{0}:{1} {2}", stri(hours).trim(), stri(date.getMinutes()).trim(), meridian) +end function + +function getHistory() as string + itemData = m.top.itemContent.json + ' Aired Fridays at 9:30 PM on ABC (US) + + airwords = invalid + studio = invalid + if itemData.status = "Ended" + verb = "Aired" + else + verb = "Airs" + end if + + airdays = itemData.airdays + airtime = itemData.airtime + if airtime <> invalid and airdays.count() = 1 + airwords = airdays[0] + " at " + airtime + end if + + if itemData.studios.count() > 0 + studio = itemData.studios[0].name + end if + + if studio = invalid and airwords = invalid + return "" + end if + + words = verb + if airwords <> invalid + words = words + " " + airwords + end if + if studio <> invalid + words = words + " on " + studio + end if + + return words +end function + +function round(f as float) as integer + ' BrightScript only has a "floor" round + ' This compares floor to floor + 1 to find which is closer + m = int(f) + n = m + 1 + x = abs(f - m) + y = abs(f - n) + if y > x + return m + else + return n + end if +end function diff --git a/components/tvshows/details.xml b/components/tvshows/details.xml index 1b41f4be..3c8033c0 100644 --- a/components/tvshows/details.xml +++ b/components/tvshows/details.xml @@ -1,19 +1,29 @@ - + - - - - - - - - + + + + + + + + + + - + - + +