components_data_MovieData.bs
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/api/Image.bs"
import "pkg:/source/roku_modules/log/LogMixin.brs"
import "pkg:/source/utils/backdropUtils.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/misc.bs"
sub init()
m.log = log.Logger("MovieData")
end sub
sub setFields()
if not isValid(m.top.json) then return
json = m.top.json
m.top.id = json.id
m.top.Title = json.name
m.top.Description = json.overview
if isValid(json.UserData)
if isValid(json.UserData.isFavorite)
m.top.favorite = json.UserData.isFavorite
end if
if isValid(json.UserData.played)
m.top.watched = json.UserData.played
end if
end if
m.top.Type = "Movie"
if isValid(json.MediaSourceCount) and json.MediaSourceCount > 1
if isValid(json.MediaSources)
m.top.mediaSources = []
for each source in json.MediaSources
m.top.mediaSources.push(source)
end for
end if
end if
if isValid(json.ProductionYear)
m.top.SubTitle = json.ProductionYear
end if
if isValid(json.OfficialRating) and json.OfficialRating <> ""
m.top.Rating = json.OfficialRating
if m.top.SubTitle <> ""
m.top.SubTitle = m.top.SubTitle + " - " + m.top.Rating
else
m.top.SubTitle = m.top.Rating
end if
end if
setPoster()
setContainer()
end sub
sub setPoster()
if isValid(m.top.image)
m.top.posterURL = m.top.image.url
else
if isValid(m.top.json)
if isValid(m.top.json.ImageTags) and isValidAndNotEmpty(m.top.json.ImageTags.Primary)
imgParams = { "maxHeight": 440, "maxWidth": 295, "tag": m.top.json.ImageTags.Primary }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
else if isValid(m.top.json.BackdropImageTags) and isValidAndNotEmpty(m.top.json.BackdropImageTags[0])
imgParams = { "maxHeight": 440, "tag": m.top.json.BackdropImageTags[0] }
m.top.posterURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
else if isValidAndNotEmpty(m.top.json.ParentThumbImageTag) and isValid(m.top.json.ParentThumbItemId)
imgParams = { "maxHeight": 440, "maxWidth": 295, "tag": m.top.json.ParentThumbImageTag }
m.top.posterURL = ImageURL(m.top.json.ParentThumbItemId, "Thumb", imgParams)
else
' Set posterURL to empty string when no valid tags exist to prevent 404 requests
m.top.posterURL = ""
end if
else
' Set posterURL to empty string when json is invalid
m.top.posterURL = ""
end if
end if
' Always set backdrop URL using centralized utility (outside of poster logic)
if isValid(m.top.json)
localDevice = m.global.device
deviceResolution = [localDevice.uiResolution[0], localDevice.uiResolution[1]]
m.top.backdropUrl = getBackdropUrl(m.top.json, deviceResolution)
m.log.info("backdropUrl set to", m.top.backdropUrl)
else
m.log.info("cannot set backdropUrl, json is invalid")
end if
end sub
sub setContainer()
json = m.top.json
if not isValid(json.mediaSources) then return
if json.mediaSources.count() = 0 then return
m.top.container = json.mediaSources[0].container
if not isValid(m.top.container) then m.top.container = ""
if m.top.container = "m4v" or m.top.container = "mov"
m.top.container = "mp4"
end if
end sub