2019-05-03 12:48:59 +00:00
|
|
|
sub init()
|
2020-03-01 01:41:57 +00:00
|
|
|
m.top.optionsAvailable = false
|
2020-10-24 13:56:33 +00:00
|
|
|
m.options = m.top.findNode("options")
|
2020-03-01 01:41:57 +00:00
|
|
|
|
2019-05-03 12:48:59 +00:00
|
|
|
main = m.top.findNode("main_group")
|
2020-06-25 10:37:18 +00:00
|
|
|
main.translation = [96, 175]
|
2019-05-03 12:48:59 +00:00
|
|
|
|
|
|
|
overview = m.top.findNode("overview")
|
2020-06-25 10:37:18 +00:00
|
|
|
overview.width = 1920 - 96 - 300 - 96 - 30
|
2019-05-03 12:48:59 +00:00
|
|
|
|
|
|
|
m.top.findNode("buttons").setFocus(true)
|
|
|
|
end sub
|
|
|
|
|
2019-03-14 17:11:51 +00:00
|
|
|
sub itemContentChanged()
|
2019-05-03 12:48:59 +00:00
|
|
|
' Updates video metadata
|
2019-04-15 00:16:47 +00:00
|
|
|
item = m.top.itemContent
|
|
|
|
itemData = item.json
|
2019-10-12 21:00:07 +00:00
|
|
|
m.top.id = itemData.id
|
2019-03-14 17:11:51 +00:00
|
|
|
|
|
|
|
m.top.findNode("moviePoster").uri = m.top.itemContent.posterURL
|
|
|
|
|
2020-10-24 13:56:33 +00:00
|
|
|
' Find first Audio Stream and set that as default
|
|
|
|
For i=0 To itemData.mediaStreams.Count() - 1
|
|
|
|
if itemData.mediaStreams[i].Type = "Audio" then
|
2020-10-24 16:23:20 +00:00
|
|
|
m.top.selectedAudioStreamIndex = i
|
2020-10-24 13:56:33 +00:00
|
|
|
exit for
|
|
|
|
end if
|
|
|
|
End For
|
|
|
|
|
2019-03-14 17:11:51 +00:00
|
|
|
' Handle all "As Is" fields
|
2019-10-12 21:00:07 +00:00
|
|
|
m.top.overhangTitle = itemData.name
|
2019-03-14 17:11:51 +00:00
|
|
|
setFieldText("releaseYear", itemData.productionYear)
|
|
|
|
setFieldText("officialRating", itemData.officialRating)
|
|
|
|
setFieldText("overview", itemData.overview)
|
|
|
|
|
2020-11-29 05:02:06 +00:00
|
|
|
if itemData.communityRating <> invalid then
|
|
|
|
setFieldText("communityRating", itemData.communityRating)
|
|
|
|
else
|
|
|
|
' hide the star icon
|
|
|
|
m.top.findNode("communityRatingGroup").visible = false
|
|
|
|
end if
|
|
|
|
|
2020-04-04 18:18:41 +00:00
|
|
|
if itemData.CriticRating <> invalid then
|
|
|
|
setFieldText("criticRatingLabel" , itemData.criticRating)
|
|
|
|
if itemData.CriticRating > 60 then
|
|
|
|
tomato = "pkg:/images/fresh.png"
|
|
|
|
else
|
|
|
|
tomato = "pkg:/images/rotten.png"
|
|
|
|
end if
|
|
|
|
m.top.findNode("criticRatingIcon").uri = tomato
|
|
|
|
else
|
|
|
|
m.top.findNode("infoGroup").removeChild(m.top.findNode("criticRatingGroup"))
|
|
|
|
end if
|
|
|
|
|
2019-10-19 03:35:26 +00:00
|
|
|
if type(itemData.RunTimeTicks) = "LongInteger"
|
|
|
|
setFieldText("runtime", stri(getRuntime()) + " mins")
|
2020-05-06 16:22:39 +00:00
|
|
|
setFieldText("ends-at", tr("Ends at %1").Replace("%1", getEndTime()))
|
2019-10-19 03:35:26 +00:00
|
|
|
end if
|
2019-03-14 17:11:51 +00:00
|
|
|
|
|
|
|
if itemData.genres.count() > 0
|
2020-05-05 21:09:18 +00:00
|
|
|
setFieldText("genres", tr("Genres") + ": " + itemData.genres.join(", "))
|
2019-03-14 17:11:51 +00:00
|
|
|
end if
|
2021-04-10 10:20:02 +00:00
|
|
|
|
|
|
|
' show tags if there are no genres to display
|
|
|
|
if itemData.genres.count() = 0 and itemData.tags.count() > 0
|
|
|
|
setFieldText("genres", tr("Tags") + ": " + itemData.tags.join(", "))
|
|
|
|
end if
|
|
|
|
|
2019-03-14 17:11:51 +00:00
|
|
|
director = invalid
|
|
|
|
for each person in itemData.people
|
|
|
|
if person.type = "Director"
|
|
|
|
director = person.name
|
|
|
|
exit for
|
|
|
|
end if
|
|
|
|
end for
|
|
|
|
if director <> invalid
|
2020-05-05 21:09:18 +00:00
|
|
|
setFieldText("director", tr("Director") + ": " + director)
|
2019-03-14 17:11:51 +00:00
|
|
|
end if
|
2021-04-10 10:20:02 +00:00
|
|
|
|
|
|
|
if itemData.mediaStreams[0] <> invalid
|
|
|
|
setFieldText("video_codec", tr("Video") + ": " + itemData.mediaStreams[0].displayTitle)
|
|
|
|
end if
|
|
|
|
if itemData.mediaStreams[m.top.selectedAudioStreamIndex] <> invalid
|
|
|
|
setFieldText("audio_codec", tr("Audio") + ": " + itemData.mediaStreams[m.top.selectedAudioStreamIndex].displayTitle)
|
|
|
|
end if
|
2019-03-14 17:11:51 +00:00
|
|
|
' TODO - cmon now. these are buttons, not words
|
|
|
|
if itemData.taglines.count() > 0
|
|
|
|
setFieldText("tagline", itemData.taglines[0])
|
|
|
|
end if
|
|
|
|
setFavoriteColor()
|
|
|
|
setWatchedColor()
|
2020-10-24 13:56:33 +00:00
|
|
|
SetUpOptions(itemData.mediaStreams)
|
|
|
|
end sub
|
|
|
|
|
|
|
|
|
|
|
|
sub SetUpOptions(streams)
|
|
|
|
|
|
|
|
tracks = []
|
|
|
|
|
|
|
|
for i=0 To streams.Count() - 1
|
|
|
|
if streams[i].Type = "Audio" then
|
2020-10-24 16:23:20 +00:00
|
|
|
tracks.push({"Title": streams[i].displayTitle, "Description" : streams[i].Title, "Selected" : m.top.selectedAudioStreamIndex = i, "StreamIndex" : i})
|
2020-10-24 13:56:33 +00:00
|
|
|
end if
|
|
|
|
end for
|
|
|
|
|
|
|
|
options = {}
|
|
|
|
options.views = tracks
|
|
|
|
m.options.options = options
|
|
|
|
|
2019-03-14 17:11:51 +00:00
|
|
|
end sub
|
|
|
|
|
2020-10-24 13:56:33 +00:00
|
|
|
|
2019-09-24 04:35:26 +00:00
|
|
|
sub setFieldText(field, value)
|
2019-03-14 17:11:51 +00:00
|
|
|
node = m.top.findNode(field)
|
2019-09-24 04:35:26 +00:00
|
|
|
if node = invalid or value = invalid then return
|
|
|
|
|
|
|
|
' Handle non strings... Which _shouldn't_ happen, but hey
|
2019-09-24 04:49:09 +00:00
|
|
|
if type(value) = "roInt" or type(value) = "Integer" then
|
2019-09-24 04:35:26 +00:00
|
|
|
value = str(value)
|
2019-12-09 01:31:07 +00:00
|
|
|
else if type(value) = "roFloat" or type(value) = "Float" then
|
|
|
|
value = str(value)
|
2019-09-24 04:35:26 +00:00
|
|
|
else if type(value) <> "roString" and type(value) <> "String" then
|
|
|
|
value = ""
|
|
|
|
end if
|
2019-03-14 17:11:51 +00:00
|
|
|
|
|
|
|
node.text = value
|
|
|
|
end sub
|
|
|
|
|
2019-05-03 12:48:59 +00:00
|
|
|
function getRuntime() as integer
|
2019-04-15 00:16:47 +00:00
|
|
|
itemData = m.top.itemContent.json
|
2019-03-14 17:11:51 +00:00
|
|
|
|
|
|
|
' 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
|
2019-04-15 00:16:47 +00:00
|
|
|
itemData = m.top.itemContent.json
|
2019-03-14 17:11:51 +00:00
|
|
|
|
|
|
|
date = CreateObject("roDateTime")
|
|
|
|
duration_s = int(itemData.RunTimeTicks / 10000000.0)
|
|
|
|
date.fromSeconds(date.asSeconds() + duration_s)
|
|
|
|
date.toLocalTime()
|
|
|
|
|
2020-04-10 08:04:48 +00:00
|
|
|
return formatTime(date)
|
2019-03-14 17:11:51 +00:00
|
|
|
end function
|
|
|
|
|
|
|
|
sub setFavoriteColor()
|
|
|
|
fave = m.top.itemContent.favorite
|
|
|
|
fave_button = m.top.findNode("favorite-button")
|
2020-02-29 02:09:56 +00:00
|
|
|
if fave <> invalid and fave
|
2019-03-14 17:11:51 +00:00
|
|
|
fave_button.textColor = "#00ff00ff"
|
|
|
|
fave_button.focusedTextColor = "#269926ff"
|
|
|
|
else
|
|
|
|
fave_button.textColor = "0xddddddff"
|
|
|
|
fave_button.focusedTextColor = "#262626ff"
|
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
|
|
|
sub setWatchedColor()
|
|
|
|
watched = m.top.itemContent.watched
|
|
|
|
watched_button = m.top.findNode("watched-button")
|
|
|
|
if watched
|
|
|
|
watched_button.textColor = "#ff0000ff"
|
|
|
|
watched_button.focusedTextColor = "#992626ff"
|
|
|
|
else
|
|
|
|
watched_button.textColor = "0xddddddff"
|
|
|
|
watched_button.focusedTextColor = "#262626ff"
|
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
2019-05-03 12:48:59 +00:00
|
|
|
function round(f as float) as integer
|
2019-03-14 17:11:51 +00:00
|
|
|
' 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
|
2020-10-24 13:56:33 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
'Check if options updated and any reloading required
|
|
|
|
sub optionsClosed()
|
2020-10-24 16:23:20 +00:00
|
|
|
if m.options.audioSteamIndex <> m.top.selectedAudioStreamIndex then
|
|
|
|
m.top.selectedAudioStreamIndex = m.options.audioSteamIndex
|
|
|
|
setFieldText("audio_codec", tr("Audio") + ": " + m.top.itemContent.json.mediaStreams[m.top.selectedAudioStreamIndex].displayTitle)
|
2020-10-24 13:56:33 +00:00
|
|
|
end if
|
|
|
|
m.top.findNode("buttons").setFocus(true)
|
|
|
|
end sub
|
|
|
|
|
|
|
|
|
|
|
|
function onKeyEvent(key as string, press as boolean) as boolean
|
|
|
|
|
|
|
|
' Due to the way the button pressed event works, need to catch the release for the button as the press is being sent
|
|
|
|
' directly to the main loop. Will get this sorted in the layout update for Movie Details
|
|
|
|
if (key = "OK" and m.top.findNode("audio-button").isInFocusChain())
|
|
|
|
m.options.visible = true
|
|
|
|
m.options.setFocus(true)
|
|
|
|
end if
|
|
|
|
|
|
|
|
if not press then return false
|
|
|
|
|
|
|
|
if key = "options"
|
|
|
|
if m.options.visible = true then
|
|
|
|
m.options.visible = false
|
|
|
|
optionsClosed()
|
|
|
|
else
|
|
|
|
m.options.visible = true
|
|
|
|
m.options.setFocus(true)
|
|
|
|
end if
|
|
|
|
return true
|
|
|
|
else if key = "back" then
|
|
|
|
if m.options.visible = true then
|
|
|
|
m.options.visible = false
|
|
|
|
optionsClosed()
|
|
|
|
return true
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
return false
|
|
|
|
end function
|