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: 
chrono86
Visitor

I'm really confused, need some guidance

I know bits and pieces of scripting languages like Python, PHP, JS, etc. This is the first time I've played with Brightscript.

Here's what I DO have. I have a website that hosts some videos. It doesn't provide RSS but I can generate an XML file for it. This XML file is on a remote server (not local). I can't even find in the Brightscript documentation how to correctly open a URL for reading.

What would be even better would be to skip the XML altogether and just scrape the information directly from the page itself. Is that even possible?
0 Kudos
8 REPLIES 8
RokuChris
Roku Employee
Roku Employee

Re: I'm really confused, need some guidance

"chrono86" wrote:
I can't even find in the Brightscript documentation how to correctly open a URL for reading.


You'd use roURLTransfer http://sdkdocs.roku.com/display/sdkdoc/roUrlTransfer

There is code for doing URL transfers in several of the SDK example channels. For example, the function called http_get_to_string_with_timeout()

"chrono86" wrote:
What would be even better would be to skip the XML altogether and just scrape the information directly from the page itself. Is that even possible?


Possible, but not recommended. Scraping in general is less reliable than an API. In a situation where you control the server side data and can build something in XML or JSON for the channel to consume, it's definitely worth the extra effort to do so.
0 Kudos
chrono86
Visitor

Re: I'm really confused, need some guidance

The website I'm creating a channel for doesn't use XML really. I can generate an XML document for the main page, but after that I'm going to need to parse HTML documents to get individual video links.

I've gotten to the point where I can pull down HTML/XML and even parse XML. Thanks for your help on that! How would I go about telling Brightscript to look for say, specific classes in an HTML doc?
0 Kudos
RokuJoel
Binge Watcher

Re: I'm really confused, need some guidance

Your best bet would be to do that determination on a web server using php or other libraries that are designed for parsing HTML and generate your XML from that and deliver to the device.

Otherwise, you could use a combination of RegEx and string processing functions like instr() Mid() Left() Right() and Len() to try to do it in BrightScript, but it won't be easy and probably will execute very slowly.

-Joel
0 Kudos
chrono86
Visitor

Re: I'm really confused, need some guidance

Yeah, I ended up writing a Python script to scrape the page periodically and generate some nice XML data for Roku to use (thank you BeautifulSoup)
0 Kudos
chrono86
Visitor

Re: I'm really confused, need some guidance

So things are going pretty smoothly now, but I'm having trouble with one thing.

I can make my screen use the poster layout without a problem, but I'd like to set up a grid instead. Here's my current code for the poster screen:

if xml.parse(xmlxfer) then
posterarray=createobject("roarray",1,true)
for each show in xml.show
poster=createobject("roAssociativeArray")
poster.shortdescriptionline1=show.getnamedElements("title").gettext()
poster.HDposterURL=show.getnamedElements("image").gettext()
poster.SDposterURL=show.getnamedElements("image").gettext()
poster.vidurl=show.getnamedelements("feed").gettext()
posterarray.push(poster)
next
end if

posterscrn=createobject("roposterscreen")
posterscrn.setcontentlist(posterarray)
posterscrn.show()


This works great. If I try to create a "rogridscreen" object instead, and then run posterscrn.setcontentlist(posterarray), it complains about a member function not being found.

So how would I convert my current code to use a grid screen?
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: I'm really confused, need some guidance

roGridScreen's SetContentList() requires 2 parameters http://sdkdocs.roku.com/display/sdkdoc/ ... ontentList

You also need to setup your grid rows before you can set their content. Check out the simplegrid example channel in the SDK

Searching the forum for discussions of the grid screen would probably yield some useful info as well.
0 Kudos
chrono86
Visitor

Re: I'm really confused, need some guidance

I'm trying to implement the grid and the screen gets stuck at "Retrieving..."

The simplegrid.brs didn't make a whole lot of sense to me. I tried following the example at http://sdkdocs.roku.com/display/sdkdoc/roGridScreen to make this:


if xml.parse(xmlxfer) then
port = CreateObject("roMessagePort")
grid = CreateObject("roGridScreen")
grid.SetMessagePort(port)
rowTitles = CreateObject("roArray", 10, true)
for j = 0 to 1
rowTitles.Push("[Row Title " + j.toStr() + " ] ")
end for
grid.SetupLists(rowTitles.Count())
grid.SetListNames(rowTitles)
list=createobject("roarray",1,true)
for each show in xml.show
poster=createobject("RoAssociativeArray")
poster.shortdescriptionline1=show.getnamedElements("title").gettext()
poster.HDposterURL=show.getnamedElements("image").gettext()
poster.SDposterURL=show.getnamedElements("image").gettext()
poster.vidurl=show.getnamedelements("feed").gettext()
list.push(poster)
end for
grid.setcontentlist(j, list)
end if
grid.show()
0 Kudos
chrono86
Visitor

Re: I'm really confused, need some guidance

Nevermind, I figured it out!
0 Kudos