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

Can't Parse Feed - ShowFeed.brs

I would really like to use the "videoplayer" template to build my channel, but i am running into problems trying to get my feed to parse. My xml document that contains my content feed is written a specific way and it is hard to change that, so I believe I need to change the ShowFeed.brs file in order to parse my feed correctly. Is that correct?
Here is an excerpt of my xml file:

<media><id>02e5a810c21a46b8a0b7b77d9aeec53f</id><title>Loving Well - Guest: Dr. William P. Smith</title><description>Guest: Dr. William P. Smith. Trade in your bad relationship habits for something better. 
Distance, avoidance, and resentment are hallmarks of a relationship in trouble. We sometimes
find ourselves tearing down the very relationships we were trying to build. Are we doomed to
repeat this cycle forever? In his book, Loving Well, Dr. William P. Smith lets readers know
that they can exchange empty ways for new ones. A rich, practical relationship with Jesus
enables you to develop rich, practical relationships with others in spite of your brokenness
and theirs. Through Christ, you no longer have to do what you have always done. In short, you
can learn to love well.</description><media_type>Video</media_type><duration_in_milliseconds>1709975</duration_in_milliseconds><tags><tag>bst</tag></tags><thumbnails><thumbnail width="120" height="66"><url>http://images.lvp.llnw.net/6b96c3aac33d4e09af62de4415635f01/media/02e5a810c21a46b8a0b7b77d9aeec53f/cSr.120x66.jpeg</url></thumbnail><thumbnail width="540" height="304"><url>http://images.lvp.llnw.net/6b96c3aac33d4e09af62de4415635f01/media/02e5a810c21a46b8a0b7b77d9aeec53f/cSr.540x304.jpeg</url></thumbnail></thumbnails><encodings><encoding><height>720</height><width>1280</width><video_codec>H264</video_codec><audio_codec>Aac</audio_codec><container_type>Mpegts</container_type><video_bitrate>2000</video_bitrate><audio_bitrate>128</audio_bitrate><size_in_bytes>366555226</size_in_bytes><master_playlist_url>http://s2.cpl.delvenetworks.com/media/6b96c3aac33d4e09af62de4415635f01/02e5a810c21a46b8a0b7b77d9aeec53f/loving-well--w-dr-william-p-smith-be0db17048d21a8ba4fc6e120d5b19f70d4ef521.m3u8</master_playlist_url><primary_use>HttpLiveStreaming</primary_use></encoding><encoding><height>480</height><width>852</width><video_codec>H264</video_codec><audio_codec>Aac</audio_codec><container_type>Mpegts</container_type><video_bitrate>800</video_bitrate><audio_bitrate>128</audio_bitrate><size_in_bytes>173789990</size_in_bytes><master_playlist_url>http://s2.cpl.delvenetworks.com/media/6b96c3aac33d4e09af62de4415635f01/02e5a810c21a46b8a0b7b77d9aeec53f/loving-well--w-dr-william-p-smith-be0db17048d21a8ba4fc6e120d5b19f70d4ef521.m3u8</master_playlist_url><primary_use>HttpLiveStreaming</primary_use></encoding><encoding><height>240</height><width>426</width><video_codec>H264</video_codec><audio_codec>Aac</audio_codec><container_type>Mpegts</container_type><video_bitrate>250</video_bitrate><audio_bitrate>64</audio_bitrate><size_in_bytes>70385529</size_in_bytes><master_playlist_url>http://s2.cpl.delvenetworks.com/media/6b96c3aac33d4e09af62de4415635f01/02e5a810c21a46b8a0b7b77d9aeec53f/loving-well--w-dr-william-p-smith-be0db17048d21a8ba4fc6e120d5b19f70d4ef521.m3u8</master_playlist_url><primary_use>HttpLiveStreaming</primary_use></encoding><encoding><height>1080</height><width>1920</width><video_codec>H264</video_codec><audio_codec>Aac</audio_codec><container_type>Mpegts</container_type><video_bitrate>3000</video_bitrate><audio_bitrate>128</audio_bitrate><size_in_bytes>528881194</size_in_bytes><master_playlist_url>http://s2.cpl.delvenetworks.com/media/6b96c3aac33d4e09af62de4415635f01/02e5a810c21a46b8a0b7b77d9aeec53f/loving-well--w-dr-william-p-smith-be0db17048d21a8ba4fc6e120d5b19f70d4ef521.m3u8</master_playlist_url><primary_use>HttpLiveStreaming</primary_use></encoding></encodings><publish_date>1389887773</publish_date></media>


Would I need to change the ShowFeed.brs file to match every tag in my xml file, i.e. all of these?
Function init_show_feed_item() As Object
o = CreateObject("roAssociativeArray")

o.ContentId = ""
o.Title = ""
o.ContentType = ""
o.ContentQuality = ""
o.Synopsis = ""
o.Genre = ""
o.Runtime = ""
o.StreamQualities = CreateObject("roArray", 5, true)
o.StreamBitrates = CreateObject("roArray", 5, true)
o.StreamUrls = CreateObject("roArray", 5, true)

return o
End Function


and these too?
Function parse_show_feed(xml As Object, feed As Object) As Void

showCount = 0
showList = xml.GetChildElements()

for each curShow in showList

'for now, don't process meta info about the feed size
if curShow.GetName() = "resultLength" or curShow.GetName() = "endIndex" then
goto skipitem
endif

item = init_show_feed_item()

'fetch all values from the xml for the current show
item.hdImg = validstr(curShow@hdImg)
item.sdImg = validstr(curShow@sdImg)
item.ContentId = validstr(curShow.contentId.GetText())
item.Title = validstr(curShow.title.GetText())
item.Description = validstr(curShow.description.GetText())
item.ContentType = validstr(curShow.contentType.GetText())
item.ContentQuality = validstr(curShow.contentQuality.GetText())
item.Synopsis = validstr(curShow.synopsis.GetText())
item.Genre = validstr(curShow.genres.GetText())
item.Runtime = validstr(curShow.runtime.GetText())
item.HDBifUrl = validstr(curShow.hdBifUrl.GetText())
item.SDBifUrl = validstr(curShow.sdBifUrl.GetText())
item.StreamFormat = validstr(curShow.streamFormat.GetText())
if item.StreamFormat = "" then 'set default streamFormat to mp4 if doesn't exist in xml
item.StreamFormat = "mp4"
endif

'map xml attributes into screen specific variables
item.ShortDescriptionLine1 = item.Title
item.ShortDescriptionLine2 = item.Description
item.HDPosterUrl = item.hdImg
item.SDPosterUrl = item.sdImg

item.Length = strtoi(item.Runtime)
item.Categories = CreateObject("roArray", 5, true)
item.Categories.Push(item.Genre)
item.Actors = CreateObject("roArray", 5, true)
item.Actors.Push(item.Genre)
item.Description = item.Synopsis

'Set Default screen values for items not in feed
item.HDBranded = false
item.IsHD = false
item.StarRating = "90"
item.ContentType = "episode"

'media may be at multiple bitrates, so parse an build arrays
for idx = 0 to 4
e = curShow.media[idx]
if e <> invalid then
item.StreamBitrates.Push(strtoi(validstr(e.streamBitrate.GetText())))
item.StreamQualities.Push(validstr(e.streamQuality.GetText()))
item.StreamUrls.Push(validstr(e.streamUrl.GetText()))
endif
next idx

showCount = showCount + 1
feed.Push(item)

skipitem:

next

End Function


I tried doing this to some degree but still received the telnet error "can't parse feed."
Here is what I changed on the ShowFeed.brs file:
Function init_show_feed_item() As Object
o = CreateObject("roAssociativeArray")

o.id = ""
o.title = ""
o.description = ""
o.Media_Type = ""
o.ContentQuality = ""
o.duration_in_milliseconds = ""
o.video_bitrate = CreateObject("roArray", 5, true)
o.master_playlist_url = CreateObject("roArray", 5, true)

return o
End Function

I am really sorry for the extremely long post. Can anyone help me do this successfully? I would really appreciate any tips.
Dean
0 Kudos
3 REPLIES 3
joetesta
Roku Guru

Re: Can't Parse Feed - ShowFeed.brs

I think that special characters can sometimes cause problems with the feed parsing; I'd try with a super-simple stripped down version of your XML and see if you get the same error. If so then there's probably an issue with the parsing code you're using; I'd post that updated "parse_show_feed" function here in that event.
aspiring
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Can't Parse Feed - ShowFeed.brs

Short answer, yes. If you're using a different schema than the parsing logic is expecting, you need to write new parsing logic. That's a normal part of channel development. You may want to look at some of the other samples as well to get a feel for how they go about parsing various XML schemas. The MRSS, deviantart, and twitter examples come to mind.

But if you're getting "Can't parse feed", there may be a different problem. If you look at where that error is generated, you see this:

    if not xml.Parse(rsp) then
print "Can't parse feed"
return feed
endif


It's telling you that the call to Parse() faIled. That usually indicates that your XML isn't valid or that for some reason it isn't getting stored to the rsp variable. You might try printing the contents of rsp to the console just to make sure it has the value you expect it to.

"srbsdean" wrote:
Would I need to change the ShowFeed.brs file to match every tag in my xml file, i.e. all of these?
Function init_show_feed_item() As Object
o = CreateObject("roAssociativeArray")

o.ContentId = ""
o.Title = ""
o.ContentType = ""
o.ContentQuality = ""
o.Synopsis = ""
o.Genre = ""
o.Runtime = ""
o.StreamQualities = CreateObject("roArray", 5, true)
o.StreamBitrates = CreateObject("roArray", 5, true)
o.StreamUrls = CreateObject("roArray", 5, true)

return o
End Function


init_show_feed_item() just sets up the structure that will be the result of the parsing routine. There is no actual parsing of XML happening here, so you may not need to change this. In fact, if you change the names of the attributes here, your channel will not behave as expected. The returned structure needs to be a standard content-meta-data. http://sdkdocs.roku.com/display/sdkdoc/ ... +Meta-Data

"srbsdean" wrote:
and these too?
Function parse_show_feed(xml As Object, feed As Object) As Void

showCount = 0
showList = xml.GetChildElements()

for each curShow in showList

'for now, don't process meta info about the feed size
if curShow.GetName() = "resultLength" or curShow.GetName() = "endIndex" then
goto skipitem
endif

item = init_show_feed_item()

'fetch all values from the xml for the current show
item.hdImg = validstr(curShow@hdImg)
item.sdImg = validstr(curShow@sdImg)
item.ContentId = validstr(curShow.contentId.GetText())
item.Title = validstr(curShow.title.GetText())
item.Description = validstr(curShow.description.GetText())
item.ContentType = validstr(curShow.contentType.GetText())
item.ContentQuality = validstr(curShow.contentQuality.GetText())
item.Synopsis = validstr(curShow.synopsis.GetText())
item.Genre = validstr(curShow.genres.GetText())
item.Runtime = validstr(curShow.runtime.GetText())
item.HDBifUrl = validstr(curShow.hdBifUrl.GetText())
item.SDBifUrl = validstr(curShow.sdBifUrl.GetText())
item.StreamFormat = validstr(curShow.streamFormat.GetText())
if item.StreamFormat = "" then 'set default streamFormat to mp4 if doesn't exist in xml
item.StreamFormat = "mp4"
endif

'map xml attributes into screen specific variables
item.ShortDescriptionLine1 = item.Title
item.ShortDescriptionLine2 = item.Description
item.HDPosterUrl = item.hdImg
item.SDPosterUrl = item.sdImg

item.Length = strtoi(item.Runtime)
item.Categories = CreateObject("roArray", 5, true)
item.Categories.Push(item.Genre)
item.Actors = CreateObject("roArray", 5, true)
item.Actors.Push(item.Genre)
item.Description = item.Synopsis

'Set Default screen values for items not in feed
item.HDBranded = false
item.IsHD = false
item.StarRating = "90"
item.ContentType = "episode"

'media may be at multiple bitrates, so parse an build arrays
for idx = 0 to 4
e = curShow.media[idx]
if e <> invalid then
item.StreamBitrates.Push(strtoi(validstr(e.streamBitrate.GetText())))
item.StreamQualities.Push(validstr(e.streamQuality.GetText()))
item.StreamUrls.Push(validstr(e.streamUrl.GetText()))
endif
next idx

showCount = showCount + 1
feed.Push(item)

skipitem:

next

End Function


Yes, this is where the parsing happens.
0 Kudos
srbsdean
Visitor

Re: Can't Parse Feed - ShowFeed.brs

Thanks very much. I did a stripped down version of my XML document and it is working the way it should.
0 Kudos