Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
ackeba
Visitor

referencing XML for content metadata on a gridscreen

I'm finally beginning to understand this language. It's certainly been tough without knowing almost anything before diving into it. Like many others I would have hired someone else if I had the budget, but I also thought this will be a fantastic skill to learn. Anyway...

I'm working with the simpleGridScreen from SDK.

I think I'm reasonably well on my way, but I've run into a bit of a snag, and seem to have a tough time finding anywhere where someone is talking about this issue:

I have all my content metadata in the script right now, but as I'm building a big channel that I plan to be updating regularly I'll need all this in xml files so that I can manipulate. I'm pretty in the dark when it comes to parsing XML files for movie metadata and posters and the likes, and need some help structuring my code right so I'm parsing correctly and the information is going where it should be in the little pop out window for each title.
Could I get away with plugging in my data into one of the xmls from the videoplayer.brs or would I need to change that?
Here's what it looks like.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<feed>
<!-- resultLength indicates the total number of results for this feed -->
<resultLength>5</resultLength>
<!-- endIndix indicates the number of results for this *paged* section of the feed -->
<endIndex>5</endIndex>
<item sdImg="http://cs2308.mojohost.com/watchindie.info/public_html/movie%20trailers/BadReception.jpg" hdImg="http://cs2308.mojohost.com/watchindie.info/public_html/movie%20trailers/BadReception.jpg">
<title>Bad Reception</title>
<contentId>00001</contentId>
<contentType>Movie</contentType>
<contentQuality>HD</contentQuality>
<streamFormat>mp4</streamFormat>
<media>
<streamQuality>HD</streamQuality>
<streamBitrate>1500</streamBitrate>
<streamUrl>http://cs2308.mojohost.com/watchindie.info/public_html/movie%20trailers/BAD%20RECEPTION%20Trailer%201080.mp4</streamUrl>
</media>
<synopsis>A Television has a terrible reception. How will the owner fix it before the Cowboys play at 4???</synopsis>
<genres>Horror</genres>
<runtime>82</runtime>
</item>


also I want to know exactly what this operation is doing. I'm really trying to learn this so I know the language and can expand on this for channels and projects to come.
    
while true
print "Waiting for message"
msg = wait(0, m.port)
'msg = wait(0, screen.GetMessagePort()) ' getmessageport does not work on gridscreen
print "Got Message:";type(msg)
if type(msg) = "roGridScreenEvent" then
print "msg= "; msg.GetMessage() " , index= "; msg.GetIndex(); " data= "; msg.getData()
if msg.isListItemFocused() then
print"list item focused | current show = "; msg.GetIndex()
else if msg.isListItemSelected() then
row = msg.GetIndex()
selection = msg.getData()
print "list item selected row= "; row; " selection= "; selection

' Did we get a selection from the gridstyle selection row?
if (row = 0)
' yes, return so we can come back with new style
return StyleButtons[selection].Title
endif

'm.curShow = displayShowDetailScreen(showList[msg.GetIndex()])
else if msg.isScreenClosed() then
return ""
end if
end If
end while

if anyone can give me a hand with this that'd be much appreciated. I'll give you proper appreciation somewhere in the channel.
0 Kudos
10 REPLIES 10
ackeba
Visitor

Re: referencing XML for content metadata on a gridscreen

okay. I'm making progress. my XML successfully parses when I run it through the debugger. everything appears to work, however nothing is coming up on my gridscreen even though it doesn't say there's anything wrong. I know I'm missing something simple to plug the the metadata into the actual gridscreen, but I'm just lost as to what it is.

here is my gridscreen layout code where row 2 is calling to Category Horror (my parsed xml metadata)
Function showGridScreen(screen As Object, gridstyle as string) As string

print "enter showGridScreen"

categoryList = getCategoryList()
screen.setupLists(categoryList.count())
screen.SetListNames(categoryList)
StyleButtons = getGridControlButtons()
screen.SetContentList(0, StyleButtons)
CategoryAction = getShowsForCategoryAction()
screen.SetContentList(1, CategoryAction)
CategoryHorror = getShowsForCategoryHorror()
screen.SetContentList(2, CategoryHorror)
screen.Show()


and then here is the code for getShowsForCategoryHorror()
Function getShowsForCategoryHorror() As Object

xfer=CreateObject("roUrlTransfer")
port=CreateObject("roMessagePort")
xfer.SetMessagePort(port)
xfer.SetUrl("http://cs2308.mojohost.com/watchindie.info/public_html/xml/Action.xml")
movie = xfer.GetToString()
xml=CreateObject("roXMLElement")
xml.Parse(movie)
?"XML PARSED. . ."
data = []
showList = []
For i= 0 to xml.item.count()-1
data={
Title: xml.item[i].title.GetText()
ReleaseDate: xml.item[i].contentId.GetText()
Description: xml.item[i].synopsis.GetText()
HDPosterUrl: xml.item[i]@sdimg
SDPosterUrl: xml.item[i]@hdImg
}
?"SHOW TITLE. . ."data.title
?"SHOW DATE. . ."data.ReleaseDate
?"SHOW DESCRIPTION. . ."data.Description
?"SHOW HDPosterUrl. . ."data.HDPosterUrl
?"SHOW SDPosterUrl. . ."data.SDPosterUrl
showList.Push(data)
End For
?"SHOWLIST CREATED. . ."
?"SHOWLIST COUNT. . ."showList.count()

End Function
Function ChannelLoop() as object

index=0
while true
msg = wait(0, m.port)
if msg <> invalid
if (msg.isRemoteKeyPressed())
id = msg.GetIndex()
if id=2
data=HoldIndex(index)
'?"DATA. . ."data.count()
endif
endif
endif
end while
End Function



FUNCTION HoldIndex(index)
?"HOLDINDEX SHOWLIST COUNT. . ." showList.count()
return m.showList
end function


I just need some help implementing that metadata into my actual gridscreen.
0 Kudos
ackeba
Visitor

Re: referencing XML for content metadata on a gridscreen

I partially feel bad for blowing up my own feed here, and talking to myself, but I'm making this channel for work, and don't really have an option to stop or get someone else to help as I work for a small company. When I run my script through the debugger it feeds back all the metadata that I parsed from the mxl and appears as if i am doing everything right (i am a novice, and without it explicitly telling my i messed up I likely won't know) however for the life of my I can not get anything to show up on the actual roku device. The contentlist remains blank and continues to frustrate the hell out of me, but I don't know what's wrong.

can anyone help me with this?

I also thought it might be the structure of my code so I went back to a second simplegrid.brs and implemented this code in the getShowsForCategoryItem function
Function getShowsForCategoryItem(category As Object) As Object

xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://cs2308.mojohost.com/watchindie.info/public_html/xml/Action.xml")
webService = xfer.GetToString()
showList = []
xml = CreateObject("roXMLElement")
if xml.Parse(webService) ' where xmlString is a chunk of valid XML you've fetched from some cloud service
for each item in xml.feed
showList.Push({
Title: xml.item[0].title.GetText()
ReleaseDate: xml.item[0].contentId.GetText()
Description: xml.item[0].synopsis.GetText()
HDPosterUrl: xml.item[0].hdimg.GetText()
SDPosterUrl: xml.item[0].sdimg.GetText()
})
next
end for
End Function

however still no luck, and with the debugger I can't even tell if the xml is parsing. it doesn't give me any error.
0 Kudos
belltown
Roku Guru

Re: referencing XML for content metadata on a gridscreen


Function getShowsForCategoryItem(category As Object) As Object

xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://cs2308.mojohost.com/watchindie.info/public_html/xml/Action.xml")
webService = xfer.GetToString()
showList = []
stop
xml = CreateObject("roXMLElement")
if xml.Parse(webService) ' where xmlString is a chunk of valid XML you've fetched from some cloud service
for each item in xml.item
showList.Push({
Title: item.title.GetText()
ReleaseDate: item.contentId.GetText()
Description: item.synopsis.GetText()
HDPosterUrl: item@hdimg
SDPosterUrl: item@sdimg
})
end for
end if
End Function



Put the 'stop' statement in for debugging purposes. You can then use the debugger 'step' command to see line-by-line which code gets executed. If you get to the 'for' statement after the 'xml.Parse' then the xml parsed successfully. As you step past each line of code, examine the variables that your code is setting to see if the expected value actually gets set, e.g. ?Title

The xml code is rather confusing, but basically 'xml' should contain your parsed xml tree. Your 'for each' statement sets the 'item' variable to each Xml <item> in turn (no need to reference <feed> because that's your root element, which is what 'xml' is referrring to). Once you have the 'item' iterator in your 'for each' loop, select its child elements using the "." operator, and its attributes using the @ operator.

And it looks like you had an 'end for' instead of an 'end if'
0 Kudos
ackeba
Visitor

Re: referencing XML for content metadata on a gridscreen

Thank you so much. I just left the office so I shall try this tomorrow. Should this fix the problem of nothing showing up on my ROKU device in that content list? Everything your saying makes sense.
0 Kudos
belltown
Roku Guru

Re: referencing XML for content metadata on a gridscreen

"ackeba" wrote:
Thank you so much. I just left the office so I shall try this tomorrow. Should this fix the problem of nothing showing up on my ROKU device in that content list? Everything your saying makes sense.

It should fix the problem of your content meta-data not being set up correctly, which is a prerequisite for getting any content to display on your screen.

I'm currently putting together an enhanced version of the Roku SDK videoplayer example, which should allow you to get a working channel using your own feed file. It will have some support for grid screens. I should have it out within the next day or two. It may be worth looking into for your project.
0 Kudos
ackeba
Visitor

Re: referencing XML for content metadata on a gridscreen

It might be a bit forward to say this early on in our relationship, but I think I like you.

That's exciting news about the kit. Please do let me know when that's out. That might be helpful.

In regards to what I posted earlier... The first script I had posted accesses the same xml and with it run through the debugger it fed back all the metadata correctly so hopefully by fixing what you said this will function properly. Thanks
0 Kudos
ackeba
Visitor

Re: referencing XML for content metadata on a gridscreen

Alright so after making the changes you suggested... I'm getting this feedback in the debugger. I don't know what it means honestly.
Current Function:
198: Function getShowsForCategoryItem(category As Object) As Object
199:
200: xfer = CreateObject("roURLTransfer")
201: xfer.SetURL("http://cs2308.mojohost.com/watchindie.info/public_html/xml/Action.xml")
202: webService = xfer.GetToString()
203: showList = []
204:* stop
205: xml = CreateObject("roXMLElement")
206: if xml.Parse(webService) ' where xmlString is a chunk of valid XML you've fetched from some cloud service
207: for each item in xml.item
208: showList.Push({
STOP (runtime error &hf7) in pkg:/source/SimpleGrid.brs(204)
204: stop
Backtrace:
#2 Function getshowsforcategoryitem(category As Object) As Object
file/line: pkg:/source/SimpleGrid.brs(205)
#1 Function showgridscreen(screen As Object, gridstyle As String) As String
file/line: pkg:/source/SimpleGrid.brs(129)
#0 Function main() As Void
file/line: pkg:/source/SimpleGrid.brs(21)
Local Variables:
category roString refcnt=1 val:"Reality"
global rotINTERFACE:ifGlobal
m roAssociativeArray refcnt=4 count:1
xfer bsc:roUrlTransfer refcnt=1
webservice roString (2.1 was String) refcnt=1 val:"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<feed>
<!-- resultLength indicates th"...
showlist roArray refcnt=1 count:0
xml <uninitialized>
item <uninitialized>

0 Kudos
belltown
Roku Guru

Re: referencing XML for content metadata on a gridscreen

"ackeba" wrote:
I don't know what it means honestly.

Start by reading the debugger documentation: http://sdkdocs.roku.com/display/sdkdoc/Debugging+Your+Application (you can also type 'help' at the debugger prompt).

The 'stop' BrightScript statement causes your program to enter the debugger, at which point it displays the function it was executing at the time, information about where you are and how you got there (backtrace), and the contents of your program's variables. From there you can type debugger commands:

The 'next' and 'last' commands show the next and previous statements executed without actually executing anything.
The 'step' or 's' command will step through your code one statement at a time.
The 'cont' or 'c' command will continue executing your program from the current statement.
The 'bt' (backtrace) command prints the list of functions that was called to get to where you are now.
To examine the contents of any variable at this point use the 'print' or '?' statement followed by the variable name.

If your variable is an array, the debugger will show a list of data types for the variables in the array, not the actual values themselves. To show an array value, use print arrayvariable where x is the numerical value of the array index.

You can also interactively type arbitrary BrightScript commands at the debugger prompt to see the effect of a given statement without having to write it in your code.

By stepping through your code one statement at a time you can see if the flow of execution is what you were expecting (e.g. if your xml Parse statement worked). After stepping past a variable assigment, print the contents of the variable using 'print' to see if your variable now contains the value you were expecting.
0 Kudos
coskel
Roku Guru

Re: referencing XML for content metadata on a gridscreen

Well, I'm female, so I will happily say I like belltown for helping this far. I would love to see your example, so I can stop fighting with this gridscreen.
Channels: Go Live Sports Cast/Audion - Audiobooks On Demand
"All I've had today is, like, six gummy bears and some scotch."
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.