Code Cleanup

This commit is contained in:
1hitsong 2022-05-14 17:14:15 -04:00
parent b884cba356
commit 1d608ea840
15 changed files with 143 additions and 192 deletions

View File

@ -1,32 +1,15 @@
sub setFields()
json = m.top.json
m.top.id = json.id
m.top.favorite = json.UserData.isFavorite
m.top.Type = "MusicAlbum"
setPoster()
datum = m.top.json
m.top.id = datum.id
m.top.title = datum.name
m.top.overview = datum.overview
end sub
sub setPoster()
if m.top.image <> invalid
m.top.posterURL = m.top.image.url
else
if m.top.json.ImageTags.Primary <> invalid
imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ImageTags.Primary }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
else if m.top.json.BackdropImageTags[0] <> invalid
imgParams = { "maxHeight": 440, "Tag": m.top.json.BackdropImageTags[0] }
m.top.posterURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
else if m.top.json.ParentThumbImageTag <> invalid and m.top.json.ParentThumbItemId <> invalid
imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ParentThumbImageTag }
m.top.posterURL = ImageURL(m.top.json.ParentThumbItemId, "Thumb", imgParams)
end if
' Add Backdrop Image
if m.top.json.BackdropImageTags[0] <> invalid
imgParams = { "maxHeight": 720, "maxWidth": 1280, "Tag": m.top.json.BackdropImageTags[0] }
m.top.backdropURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
end if
m.top.posterURL = ""
end if
end sub

View File

@ -1,7 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="MusicAlbumData" extends="JFContentItem">
<component name="MusicAlbumData" extends="ContentNode">
<interface>
<field id="id" type="string" />
<field id="title" type="string" />
<field id="image" type="node" onChange="setPoster" />
<field id="posterURL" type="string" />
<field id="overview" type="string" />
<field id="type" type="string" value="Episode" />
<field id="json" type="assocarray" onChange="setFields" />
</interface>
<script type="text/brightscript" uri="MusicAlbumData.brs" />
<script type="text/brightscript" uri="pkg:/source/api/Image.brs" />
<script type="text/brightscript" uri="pkg:/source/api/baserequest.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/config.brs" />
</component>

View File

@ -0,0 +1,32 @@
sub setFields()
json = m.top.json
m.top.id = json.id
m.top.favorite = json.UserData.isFavorite
m.top.Type = "MusicAlbum"
setPoster()
end sub
sub setPoster()
if m.top.image <> invalid
m.top.posterURL = m.top.image.url
else
if m.top.json.ImageTags.Primary <> invalid
imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ImageTags.Primary }
m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
else if m.top.json.BackdropImageTags[0] <> invalid
imgParams = { "maxHeight": 440, "Tag": m.top.json.BackdropImageTags[0] }
m.top.posterURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
else if m.top.json.ParentThumbImageTag <> invalid and m.top.json.ParentThumbItemId <> invalid
imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ParentThumbImageTag }
m.top.posterURL = ImageURL(m.top.json.ParentThumbItemId, "Thumb", imgParams)
end if
' Add Backdrop Image
if m.top.json.BackdropImageTags[0] <> invalid
imgParams = { "maxHeight": 720, "maxWidth": 1280, "Tag": m.top.json.BackdropImageTags[0] }
m.top.backdropURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
end if
end if
end sub

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="MusicAlbumSongListData" extends="JFContentItem">
<script type="text/brightscript" uri="MusicAlbumSongListData.brs" />
<script type="text/brightscript" uri="pkg:/source/api/Image.brs" />
<script type="text/brightscript" uri="pkg:/source/api/baserequest.brs" />
<script type="text/brightscript" uri="pkg:/source/utils/config.brs" />
</component>

View File

@ -4,6 +4,8 @@ sub setFields()
m.top.favorite = json.UserData.isFavorite
m.top.Type = "MusicArtist"
setPoster()
m.top.title = json.name
end sub
sub setPoster()

View File

@ -0,0 +1,15 @@
sub setFields()
datum = m.top.json
m.top.id = datum.id
m.top.title = datum.name
m.top.overview = datum.overview
end sub
sub setPoster()
if m.top.image <> invalid
m.top.posterURL = m.top.image.url
else
m.top.posterURL = ""
end if
end sub

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="MusicSongData" extends="ContentNode">
<interface>
<field id="id" type="string" />
<field id="title" type="string" />
<field id="image" type="node" onChange="setPoster" />
<field id="posterURL" type="string" />
<field id="overview" type="string" />
<field id="type" type="string" value="Song" />
<field id="json" type="assocarray" onChange="setFields" />
</interface>
<script type="text/brightscript" uri="MusicSongData.brs" />
</component>

View File

@ -2,27 +2,30 @@ sub init()
m.top.optionsAvailable = false
main = m.top.findNode("toplevel")
main.translation = [96, 175]
m.extrasSlider = m.top.findNode("tvSeasonExtras")
m.extrasSlider.visible = true
end sub
' Set values for displayed values on screen
sub itemContentChanged()
' Updates video metadata
' TODO - make things use item rather than itemData
item = m.top.itemContent
itemData = item.json
m.top.findNode("musicartistPoster").uri = m.top.itemContent.posterURL
m.top.findNode("musicartistPoster").uri = item.posterURL
' Handle all "As Is" fields
m.top.overhangTitle = itemData.name
m.top.overhangTitle = item.json.name
setFieldText("overview", itemData.overview)
setFieldText("overview", item.json.overview)
setFieldText("numberofsongs", stri(item.json.ChildCount) + " Tracks")
if type(itemData.RunTimeTicks) = "LongInteger"
if type(item.json.ProductionYear) = "roInt"
setFieldText("released", "Released " + stri(item.json.ProductionYear))
end if
if item.json.genres.count() > 0
setFieldText("genres", item.json.genres.join(", "))
end if
if type(item.json.RunTimeTicks) = "LongInteger"
setFieldText("runtime", stri(getRuntime()) + " mins")
end if
end sub
sub setFieldText(field, value)
@ -45,21 +48,10 @@ 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
' then 1/60 for seconds to minutes... 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()
return formatTime(date)
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
@ -77,31 +69,5 @@ end function
function onKeyEvent(key as string, press as boolean) as boolean
if not press then return false
overview = m.top.findNode("overview")
topGrp = m.top.findNode("seasons")
bottomGrp = m.top.findNode("extrasGrid")
if key = "down" and overview.hasFocus()
topGrp.setFocus(true)
return true
else if key = "down" and topGrp.hasFocus()
bottomGrp.setFocus(true)
m.top.findNode("VertSlider").reverse = false
m.top.findNode("extrasFader").reverse = false
m.top.findNode("pplAnime").control = "start"
return true
else if key = "up" and bottomGrp.hasFocus()
if bottomGrp.itemFocused = 0
m.top.findNode("VertSlider").reverse = true
m.top.findNode("extrasFader").reverse = true
m.top.findNode("pplAnime").control = "start"
topGrp.setFocus(true)
return true
end if
else if key = "up" and topGrp.hasFocus()
overview.setFocus(true)
return true
end if
return false
end function

View File

@ -3,15 +3,20 @@
<children>
<LayoutGroup id="toplevel" layoutDirection="vert" itemSpacings="[-10]" >
<LayoutGroup id="main_group" layoutDirection="horiz" itemSpacings="[15]" >
<Poster id="musicartistPoster" width="450" height="450" />
<LayoutGroup layoutDirection="vert" itemSpacings="[15]">
<Poster id="musicartistPoster" width="450" height="450" />
<Label id="numberofsongs" width="450" height="25" />
<Label id="genres" width="450" height="25" />
<Label id="runtime" width="450" height="25" />
<Label id="released" width="450" height="25" />
</LayoutGroup>
<LayoutGroup layoutDirection="vert" itemSpacings="[15]">
<Label id="overview" wrap="true" width="1250" maxLines="5" />
<MusicAlbumSongList id="songList" itemSize="[ 1250, 60 ]" numRows="8" />
</LayoutGroup>
</LayoutGroup>
<MusicArtistAlbumRow id="seasons" />
</LayoutGroup>
<ExtrasSlider id="tvSeasonExtras" />
</children>
<interface>
<field id="itemContent" type="node" onChange="itemContentChanged" />

View File

@ -9,12 +9,12 @@ function getData()
return data
end if
seasonData = m.top.MusicArtistAlbumData
albumData = m.top.MusicArtistAlbumData
data = CreateObject("roSGNode", "ContentNode")
for each item in seasonData.items
itemcontent = data.createChild("ContentNode")
itemcontent.title = item.title
for each song in albumData.items
songcontent = data.createChild("ContentNode")
songcontent.title = song.title
end for
m.top.content = data

View File

@ -1,13 +1,10 @@
sub init()
m.top.itemComponentName = "ListPoster"
m.top.content = getData()
m.top.rowFocusAnimationStyle = "fixedFocusWrap"
m.top.showRowLabel = [false]
m.top.showRowCounter = [true]
m.top.rowLabelOffset = [0, 0]
getData()
updateSize()
m.top.setfocus(true)
@ -20,29 +17,34 @@ sub updateSize()
m.top.visible = true
' size of the whole row
m.top.itemSize = [1800, (itemHeight + 40)]
m.top.itemSize = [1700, (itemHeight + 40)]
' spacing between rows
m.top.itemSpacing = [0, 0]
' size of the item in the row
m.top.rowItemSize = [itemWidth, itemHeight]
' spacing between items in a row
m.top.rowItemSpacing = [0, 0]
m.top.rowItemSpacing = [10, 0]
end sub
function getData()
' If we have no album data, return a blank node
if m.top.MusicArtistAlbumData = invalid
data = CreateObject("roSGNode", "ContentNode")
return data
end if
seasonData = m.top.MusicArtistAlbumData
albumData = m.top.MusicArtistAlbumData
data = CreateObject("roSGNode", "ContentNode")
row = data.CreateChild("ContentNode")
row.title = "Seasons"
for each item in seasonData.items
row.appendChild(item)
for each album in albumData.items
row.appendChild(album)
end for
m.top.content = data
return data
end function

View File

@ -2,27 +2,16 @@ sub init()
m.top.optionsAvailable = false
main = m.top.findNode("toplevel")
main.translation = [96, 175]
m.extrasSlider = m.top.findNode("tvSeasonExtras")
'm.extrasSlider.translation = [30,1014]
m.extrasSlider.visible = true
end sub
sub itemContentChanged()
' Updates video metadata
' TODO - make things use item rather than itemData
item = m.top.itemContent
itemData = item.json
m.top.findNode("musicartistPoster").uri = m.top.itemContent.posterURL
' Handle all "As Is" fields
' Populate scene data
m.top.overhangTitle = itemData.name
m.top.findNode("musicArtistPoster").uri = m.top.itemContent.posterURL
setFieldText("overview", itemData.overview)
if type(itemData.RunTimeTicks) = "LongInteger"
setFieldText("runtime", stri(getRuntime()) + " mins")
end if
end sub
sub setFieldText(field, value)
@ -41,67 +30,8 @@ sub setFieldText(field, value)
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()
return formatTime(date)
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
function onKeyEvent(key as string, press as boolean) as boolean
if not press then return false
overview = m.top.findNode("overview")
topGrp = m.top.findNode("seasons")
bottomGrp = m.top.findNode("extrasGrid")
if key = "down" and overview.hasFocus()
topGrp.setFocus(true)
return true
else if key = "down" and topGrp.hasFocus()
bottomGrp.setFocus(true)
m.top.findNode("VertSlider").reverse = false
m.top.findNode("extrasFader").reverse = false
m.top.findNode("pplAnime").control = "start"
return true
else if key = "up" and bottomGrp.hasFocus()
if bottomGrp.itemFocused = 0
m.top.findNode("VertSlider").reverse = true
m.top.findNode("extrasFader").reverse = true
m.top.findNode("pplAnime").control = "start"
topGrp.setFocus(true)
return true
end if
else if key = "up" and topGrp.hasFocus()
overview.setFocus(true)
return true
end if
return false
end function

View File

@ -3,19 +3,16 @@
<children>
<LayoutGroup id="toplevel" layoutDirection="vert" itemSpacings="[-10]" >
<LayoutGroup id="main_group" layoutDirection="horiz" itemSpacings="[15]" >
<Poster id="musicartistPoster" width="450" height="450" />
<LayoutGroup layoutDirection="vert" itemSpacings="[15]">
<Label id="overview" wrap="true" width="1250" maxLines="8" />
</LayoutGroup>
<Poster id="musicArtistPoster" width="450" height="450" />
<Label id="overview" wrap="true" width="1250" maxLines="8" />
</LayoutGroup>
<MusicArtistAlbumRow id="seasons" />
<MusicArtistAlbumRow id="albums" />
</LayoutGroup>
<ExtrasSlider id="tvSeasonExtras" />
</children>
<interface>
<field id="itemContent" type="node" onChange="itemContentChanged" />
<field id="musicArtistAlbumData" type="assocarray" alias="seasons.MusicArtistAlbumData" />
<field id="musicAlbumSelected" alias="seasons.rowItemSelected" />
<field id="musicArtistAlbumData" type="assocarray" alias="albums.MusicArtistAlbumData" />
<field id="musicAlbumSelected" alias="albums.rowItemSelected" />
</interface>
<script type="text/brightscript" uri="pkg:/source/utils/misc.brs" />
<script type="text/brightscript" uri="MusicArtistDetails.brs" />

View File

@ -326,13 +326,10 @@ function CreateMusicArtistDetailsGroup(musicartist)
m.global.sceneManager.callFunc("pushScene", group)
group.itemContent = ItemMetaData(musicartist.id)
group.musicArtistAlbumData = MusicAlbums(musicartist.id)
group.musicArtistAlbumData = MusicAlbumList(musicartist.id)
group.observeField("musicAlbumSelected", m.port)
extras = group.findNode("extrasGrid")
extras.observeField("selectedItem", m.port)
return group
end function
@ -341,13 +338,10 @@ function CreateMusicAlbumDetailsGroup(album)
m.global.sceneManager.callFunc("pushScene", group)
group.itemContent = ItemMetaData(album.id)
group.musicArtistAlbumData = MusicSongs(album.id)
group.musicArtistAlbumData = MusicSongList(album.id)
group.observeField("musicSongSelected", m.port)
extras = group.findNode("extrasGrid")
extras.observeField("selectedItem", m.port)
return group
end function

View File

@ -119,20 +119,19 @@ function ItemMetaData(id as string)
tmp.json = data
return tmp
else if data.type = "MusicArtist"
' User clicked on an artist and wants to see the list of their albums
tmp = CreateObject("roSGNode", "MusicArtistData")
tmp.image = PosterImage(data.id)
tmp.json = data
return tmp
else if data.type = "MusicAlbum"
tmp = CreateObject("roSGNode", "MusicAlbumData")
' User clicked on an album and wants to see the list of songs
tmp = CreateObject("roSGNode", "MusicAlbumSongListData")
tmp.image = PosterImage(data.id)
tmp.json = data
return tmp
else if data.type = "Audio"
tmp = CreateObject("roSGNode", "MusicAlbumData")
tmp.image = PosterImage(data.id)
tmp.json = data
return tmp
else
print "Items.brs::ItemMetaData processed unhandled type: " data.type
' Return json if we don't know what it is
@ -140,8 +139,8 @@ function ItemMetaData(id as string)
end if
end function
' Music Albums Belonging to an Artist
function MusicAlbums(id as string)
' Get list of albums belonging to an artist
function MusicAlbumList(id as string)
url = Substitute("Users/{0}/Items", get_setting("active_user"), id)
resp = APIRequest(url, {
"UserId": get_setting("active_user"),
@ -153,7 +152,7 @@ function MusicAlbums(id as string)
data = getJson(resp)
results = []
for each item in data.Items
tmp = CreateObject("roSGNode", "TVEpisodeData")
tmp = CreateObject("roSGNode", "MusicAlbumData")
tmp.image = PosterImage(item.id)
tmp.json = item
results.push(tmp)
@ -162,8 +161,8 @@ function MusicAlbums(id as string)
return data
end function
' Music Songs on a Specified Album
function MusicSongs(id as string)
' Get Songs that are on an Album
function MusicSongList(id as string)
url = Substitute("Users/{0}/Items", get_setting("active_user"), id)
resp = APIRequest(url, {
"UserId": get_setting("active_user"),
@ -175,7 +174,7 @@ function MusicSongs(id as string)
data = getJson(resp)
results = []
for each item in data.Items
tmp = CreateObject("roSGNode", "TVEpisodeData")
tmp = CreateObject("roSGNode", "MusicSongData")
tmp.image = PosterImage(item.id)
tmp.json = item
results.push(tmp)