components_data_HomeData.bs
import "pkg:/source/api/baserequest.bs"
import "pkg:/source/api/Image.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/misc.bs"
sub setData()
' We keep json around just as a reference,
' but ideally everything should be going through one of the interfaces
datum = m.top.json
m.top.id = datum.id
m.top.name = datum.name
m.top.type = datum.type
if not isValid(datum.CollectionType)
m.top.CollectionType = datum.type
else
m.top.CollectionType = datum.CollectionType
end if
' Set appropriate Images for Wide and Tall based on type
if LCase(datum.type) = "collectionfolder" or LCase(datum.type) = "userview"
if isValid(datum.ImageTags) and isValidAndNotEmpty(datum.ImageTags.Primary)
params = { "Tag": datum.ImageTags.Primary, "maxHeight": 261, "maxWidth": 464 }
m.top.thumbnailURL = ImageURL(datum.id, "Primary", params)
m.top.widePosterUrl = m.top.thumbnailURL
else
m.top.thumbnailURL = ""
m.top.widePosterUrl = ""
end if
' Add Icon URLs for display if there is no Poster
if LCase(m.top.CollectionType) = "livetv"
m.top.iconUrl = "pkg:/images/media_type_icons/live_tv_white.png"
else if LCase(m.top.CollectionType) = "folders"
m.top.iconUrl = "pkg:/images/media_type_icons/folder_white.png"
end if
else if datum.type = "Episode" or LCase(datum.type) = "recording" or datum.type = "MusicVideo"
m.top.isWatched = datum.UserData.Played
imgParams = {}
imgParams.Append({ "maxHeight": 261 })
imgParams.Append({ "maxWidth": 464 })
if isValid(datum.ImageTags) and isValidAndNotEmpty(datum.ImageTags.Primary)
param = { "Tag": datum.ImageTags.Primary }
imgParams.Append(param)
m.top.thumbnailURL = ImageURL(datum.id, "Primary", imgParams)
else
m.top.thumbnailURL = ""
end if
' Add Wide Poster (Series Backdrop)
if isValidAndNotEmpty(datum.ParentThumbImageTag) and isValid(datum.ParentThumbItemId)
imgParams["Tag"] = datum.ParentThumbImageTag
m.top.widePosterUrl = ImageURL(datum.ParentThumbItemId, "Thumb", imgParams)
else if isValid(datum.ParentBackdropImageTags) and isValidAndNotEmpty(datum.ParentBackdropImageTags[0]) and isValid(datum.ParentBackdropItemId)
imgParams["Tag"] = datum.ParentBackdropImageTags[0]
m.top.widePosterUrl = ImageURL(datum.ParentBackdropItemId, "Backdrop", imgParams)
else if isValid(datum.ImageTags) and isValidAndNotEmpty(datum.ImageTags.Primary) and isValidAndNotEmpty(datum.SeriesPrimaryImageTag)
imgParams["Tag"] = datum.SeriesPrimaryImageTag
m.top.widePosterUrl = ImageURL(datum.id, "Primary", imgParams)
else
m.top.widePosterUrl = ""
end if
else if datum.type = "Series"
m.top.isWatched = datum.UserData.Played
imgParams = { "maxHeight": 261 }
imgParams.Append({ "maxWidth": 464 })
if isValid(datum.ImageTags) and isValidAndNotEmpty(datum.ImageTags.Primary)
imgParams["Tag"] = datum.ImageTags.Primary
m.top.posterURL = ImageURL(datum.id, "Primary", imgParams)
else
m.top.posterURL = ""
end if
' Add Wide Poster (Series Backdrop)
if isValid(datum.ImageTags) and isValidAndNotEmpty(datum.ImageTags.Thumb)
imgParams["Tag"] = datum.ImageTags.Thumb
m.top.widePosterUrl = ImageURL(datum.Id, "Thumb", imgParams)
else if isValid(datum.BackdropImageTags) and isValidAndNotEmpty(datum.BackdropImageTags[0])
imgParams["Tag"] = datum.BackdropImageTags[0]
m.top.widePosterUrl = ImageURL(datum.Id, "Backdrop", imgParams)
else
m.top.widePosterUrl = ""
end if
else if datum.type = "Movie"
m.top.isWatched = datum.UserData.Played
imgParams = {}
imgParams.Append({ "maxHeight": 261 })
imgParams.Append({ "maxWidth": 175 })
if isValid(datum.ImageTags) and isValidAndNotEmpty(datum.ImageTags.Primary)
param = { "Tag": datum.ImageTags.Primary }
imgParams.Append(param)
m.top.posterURL = ImageURL(datum.id, "Primary", imgParams)
else
m.top.posterURL = ""
end if
' For wide image, use backdrop
imgParams["maxWidth"] = 464
if isValid(datum.ImageTags) and isValidAndNotEmpty(datum.ImageTags.Thumb)
imgParams["Tag"] = datum.ImageTags.Thumb
m.top.thumbnailUrl = ImageURL(datum.Id, "Thumb", imgParams)
else if isValid(datum.BackdropImageTags) and isValidAndNotEmpty(datum.BackdropImageTags[0])
imgParams["Tag"] = datum.BackdropImageTags[0]
m.top.thumbnailUrl = ImageURL(datum.id, "Backdrop", imgParams)
else
m.top.thumbnailUrl = ""
end if
else if datum.type = "Video"
m.top.isWatched = datum.UserData.Played
imgParams = {
"maxHeight": 261,
"maxWidth": 464
}
if isValid(datum.ImageTags) and isValidAndNotEmpty(datum.ImageTags.Primary)
imgParams.Append({ "Tag": datum.ImageTags.Primary })
m.top.posterURL = ImageURL(datum.id, "Primary", imgParams)
m.top.thumbnailUrl = m.top.posterURL
else
m.top.posterURL = ""
m.top.thumbnailUrl = ""
end if
else if datum.type = "MusicAlbum"
if isValid(datum.ImageTags) and isValidAndNotEmpty(datum.ImageTags.Primary)
params = { "Tag": datum.ImageTags.Primary, "maxHeight": 261, "maxWidth": 261 }
m.top.thumbnailURL = ImageURL(datum.id, "Primary", params)
m.top.widePosterUrl = m.top.thumbnailURL
m.top.posterUrl = m.top.thumbnailURL
else
m.top.thumbnailURL = ""
m.top.widePosterUrl = ""
m.top.posterUrl = ""
end if
else if datum.type = "TvChannel" or datum.type = "Channel"
if isValid(datum.ImageTags) and isValidAndNotEmpty(datum.ImageTags.Primary)
params = { "Tag": datum.ImageTags.Primary, "maxHeight": 261, "maxWidth": 464 }
m.top.thumbnailURL = ImageURL(datum.id, "Primary", params)
m.top.widePosterUrl = m.top.thumbnailURL
else
m.top.thumbnailURL = ""
m.top.widePosterUrl = ""
end if
m.top.iconUrl = "pkg:/images/media_type_icons/live_tv_white.png"
else if datum.type = "Photo"
if isValid(datum.ImageTags) and isValidAndNotEmpty(datum.ImageTags.Primary)
params = { "Tag": datum.ImageTags.Primary, "maxHeight": 261, "maxWidth": 464 }
m.top.thumbnailURL = ImageURL(datum.id, "Primary", params)
m.top.widePosterUrl = m.top.thumbnailURL
m.top.posterUrl = m.top.thumbnailURL
else
m.top.thumbnailURL = ""
m.top.widePosterUrl = ""
m.top.posterUrl = ""
end if
else if datum.type = "PhotoAlbum"
if isValid(datum.ImageTags) and isValidAndNotEmpty(datum.ImageTags.Primary)
params = { "Tag": datum.ImageTags.Primary, "maxHeight": 261, "maxWidth": 464 }
m.top.thumbnailURL = ImageURL(datum.id, "Primary", params)
m.top.widePosterUrl = m.top.thumbnailURL
m.top.posterUrl = m.top.thumbnailURL
else
m.top.thumbnailURL = ""
m.top.widePosterUrl = ""
m.top.posterUrl = ""
end if
end if
end sub