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

Parsing metadata XML Part Deux.

I still can't wrap my feeble little mind around this, and can't even get the examples from the SDK to run properly.

So I'm breaking it down step by step here, to try to get a better understanding....

Here's the code I have (adapted from the AudioApp NPR example):
Function CreateLiveSongList() as Object
aa = CreateObject("roAssociativeArray")
aa.posteritems = CreateObject("roArray", 10, true)

xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://aqualine.kjsr.net:8000/statistics")
str = xfer.GetToString()
xml = CreateObject("roXMLElement")
' xml.Parse("http://aqualine.kjsr.net:8000/statistics")
xml.Parse(str)

song = CreateSong("Artist - Title","Current Show","Current DJ", "mp3", "http://aqualine.kjsr.net:8000/","http://kjsr.net/images/djicons/currdj.png")
aa.posteritems.push(song)
return aa
End Function


So far, so good.

BUT, I need to replace the sections currently filled by "Artist - Title", "Current Show", and "Current DJ" with the specific variable contained in <SONGTITLE> from the server's statistics XML which looks like this:

<SONGTITLE>Nothing to Say with DJ Charlie ~ No Doubt - Spiderwebs</SONGTITLE>


That needs to be broken down into:

No Doubt - Spiderwebs
Nothing to Say
DJ Charlie

And then displayed properly on the screen.

So. Can someone please tell me exactly what I'm missing? I've tried going through the examples, no joy. Been back and forth through the SDK documentation, no joy. If I could afford it, I'd hire somebody to do it for me, honestly.

And after this is fixed, I still have to set up another section to handle archived shows (mp3 format) being served by the Station. Or call for the nice young men with the clean white coats to take me away...
0 Kudos
11 REPLIES 11
RokuMarkn
Visitor

Re: Parsing metadata XML Part Deux.

You can use roRegex to do this, if you have a clear description of how to divide up the fields. It's not clear to me how to do this given your example, where it seems the word "with" separates the first two fields, but presumably could also appear in the song title (or even the DJ's name).

--Mark
0 Kudos
CWinthrop
Visitor

Re: Parsing metadata XML Part Deux.

Now we're getting somewhere!

So far, I've got this:


xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://aqualine.kjsr.net:8000/statistics")
str = xfer.GetToString()
xml = CreateObject("roXMLElement")
xml.Parse(str)
r = CreateObject("roRegex", "SONGTITLE", "") ' split on one or more slashes
r.Split(str)


Now doing a print str will show me the entire XML in one line.

While doung a print r gives me:
<Component: roRegex>


So I'm using the roRegex for SONGTITLE to get just that part of it. How can I print just that part?

I know, I'm dense today.
0 Kudos
EnTerr
Roku Guru

Re: Parsing metadata XML Part Deux.

"CWinthrop" wrote:
So I'm using the roRegex for SONGTITLE to get just that part of it. How can I print just that part?

Seeing your confusion, regex-es will likely make it worse. You just need to "work it", like so - assuming you already got in variable "s" the string to split (as answered in viewtopic.php?f=34&t=66885 😞
BrightScript Debugger> s = "Nothing to Say with DJ Charlie ~ No Doubt - Spiderweb"
BrightScript Debugger> i = s.instr(" ~ ")
BrightScript Debugger> track = s.left(i)
BrightScript Debugger> album = s.mid(i+3)
BrightScript Debugger> i = track.instr(" with ")
BrightScript Debugger> title = track.left(i)
BrightScript Debugger> dj = track.mid(i+6)
BrightScript Debugger> ? album
No Doubt - Spiderweb
BrightScript Debugger> ? title
Nothing to Say
BrightScript Debugger> ? dj
DJ Charlie
You will have to check in your code that those searches did not fail, e.g. if _s_ was "KJSR.net - Please Stand By...", then you will be getting -1 from inStr
0 Kudos
CWinthrop
Visitor

Re: Parsing metadata XML Part Deux.

"EnTerr" wrote:


Seeing your confusion, regex-es will likely make it worse. You just need to "work it", like so - assuming you already got in variable "s" the string to split:
BrightScript Debugger> s = "Nothing to Say with DJ Charlie ~ No Doubt - Spiderweb"
BrightScript Debugger> i = s.instr(" ~ ")
BrightScript Debugger> track = s.left(i)
BrightScript Debugger> album = s.mid(i+3)
BrightScript Debugger> i = track.instr(" with ")
BrightScript Debugger> title = track.left(i)
BrightScript Debugger> dj = track.mid(i+6)
BrightScript Debugger> ? album
No Doubt - Spiderweb
BrightScript Debugger> ? title
Nothing to Say
BrightScript Debugger> ? dj
DJ Charlie


Ok, the problem is, how to get that string into "s"?
0 Kudos
EnTerr
Roku Guru

Re: Parsing metadata XML Part Deux.

"CWinthrop" wrote:
Ok, the problem is, how to get that string into "s"?

Elaborating one step further from what RokuChris told you here viewtopic.php?f=34&t=66885#p427969

BrightScript Debugger> xml.parse(str)
BrightScript Debugger> s = xml.streamStats.stream.songTitle.getText()
BrightScript Debugger> ? s
KJSR.net - Please Stand By...
neat, huh! (if roXML parser works, that is)
0 Kudos
CWinthrop
Visitor

Re: Parsing metadata XML Part Deux.

"EnTerr" wrote:
Elaborating one step further from what RokuChris told you here viewtopic.php?f=34&t=66885#p427969

BrightScript Debugger> xml.parse(str)
BrightScript Debugger> s = xml.streamStats.stream.songTitle.getText()
BrightScript Debugger> ? s
KJSR.net - Please Stand By...
neat, huh! (if roXML parser works, that is)



Ok, I'm getting there slowly... Now for a special condition.

All our broadcasts have the same format. Namely:

Show Name with DJ Name ~ Artist - Title


EXCEPT when a live DJ (or Johnny) is on. Then it's just:

Artist - Title


Like right now, it just says "KJSR.net - Please Stand By..."

What's the Brightscript equivalent of

if [ s == "KJSR.net - Please Stand By..."]; then


?
0 Kudos
CWinthrop
Visitor

Re: Parsing metadata XML Part Deux.

Cancel that, found it in the Reference. 🙂

I MIGHT just be getting the hang of this!
0 Kudos
CWinthrop
Visitor

Re: Parsing metadata XML Part Deux.

Next question...

Will that metadata update automatically, or do I need to write in something to refresh it every so often?
0 Kudos
CWinthrop
Visitor

Re: Parsing metadata XML Part Deux.

Apparently it does NOT refresh automatically. And hre I was so proud that it was working. 😕
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.