Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
matrixebiz
Level 7

code to read XML then add ID number after stream

EDIT: got it sorted out now. need to learn this language
0 Kudos
4 Replies
RokuLeoW
Level 7

Re: code to read XML then add ID number after stream

Hi matrixebiz,

I'm not sure if I understand the question correctly, but it seems like you want to append a ID token key to the end of a url?

If the ID token key is of type string, then you can simply do stream.url = stream.url + ID Key like you stated.

If the ID token key is of type integer, then you can use the .toStr() function to convert the integer into a string like so:

stream.url = stream.url + ID_TOKEN_VARIABLE.toStr()

This is assuming that stream.url is the HLS stream url as a string and the ID_TOKEN_VARIABLE is an integer/float.
https://sdkdocs.roku.com/display/sdkdoc/ifIntOps

If not, the quickest way to go about checking how to append things would be to use the debugger as a REPL to figure out how things work:

You can create a breakpoint in your code by inserting a "stop" in the code where you want to break, telnet to the debugging port 8085/8089 on your Roku device and see what the types of the variable are by running "type(stream.url)" or type(VARIABLE) to check.

Hope that helps! Let me know if that was what you were asking or if you have any additional questions.
0 Kudos
matrixebiz
Level 7

Re: code to read XML then add ID number after stream

Got it working, Thx
0 Kudos
RokuLeoW
Level 7

Re: code to read XML then add ID number after stream

Ohhhh -- what is the _getXmlString method you used in the first post? How does it work and does it return a string or a xml element?

If I understand correctly, streamurl is in XML? In that case you might want to create a roXMLElement so that you can get the HLS stream as a string: https://sdkdocs.roku.com/display/sdkdoc/roXMLElement

So you create a roXMLElement (call it x, for simplicity) and use its parse() method on the XML EG you had: <streamUrl>http://stream/playlist.m3u8?id=</streamUrl> (call it "str")

I.e.
x =createObject("roXMLElement")
x.parse(str)


Then get the text:

somestring = x.getText()


Which will output the HLS Stream as a string (stored in variable somestring above)

Then, if Key is a string, append it by doing something like:

somestring = somestring + "1345n349jc380mcvw87wcd2" 


Not sure if that's the case, let me know if that works Smiley Very Happy

If you're having trouble understanding how to use roXMLElement, take a look at this example below:

  if str = invalid return
xml = CreateObject("roXMLElement")
' Return invalid if string can't be parsed
if not xml.Parse(str) return

if xml <> invalid then
xml = xml.getchildelements()
responsearray = xml.getchildelements()
end if

result = []
'responsearray - <channel>'
for each xmlitem in responsearray
' <title>, <link>, <description>, <pubDate>, <image>, and lots of <item>'s
if xmlitem.getname() = "item"
' All things related to one item (title, link, description, media:content, etc.)
itemaa = xmlitem.getchildelements()
if itemaa <> invalid
item = {}
' Get all <item> attributes
for each xmlitem in itemaa
item[xmlitem.getname()] = xmlitem.gettext()
if xmlitem.getname() = "media:content"
item.stream = {url : xmlitem.url}
item.url = xmlitem.getattributes().url
item.streamformat = "mp4"

mediacontent = xmlitem.getchildelements()
for each mediacontentitem in mediacontent
if mediacontentitem.getname() = "media:thumbnail"
item.hdposterurl = mediacontentitem.getattributes().url
item.hdbackgroundimageurl = mediacontentitem.getattributes().url
item.uri = mediacontentitem.getattributes().url
end if
end for
end if
end for
result.push(item)
end if
end if
end for
0 Kudos
matrixebiz
Level 7

Re: code to read XML then add ID number after stream

Got it working. Thank you.
0 Kudos