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

It just stopped working?

The search function on my channel was working but it was having trouble with spaces in the search requests, so when I tried to httpEncode the query everything stopped working...now I don't get any results from the database I'm querying...
I tried calling the php code from a computer with an encoded url and seems to work fine...unless roku encodes urls differently?
I'm using the urlUtils from the roku sdk examples. I don't have access to the debug information because I don't have a roku...so even if someone could tell me what that says would be helpful...it seems to require some sort of secret sauce...or maybe I've just been staring at this too long..
Here's the source code.

Function SearchScreen()
InitTheme()

print "start"
'toggle the search suggestions vs. search history behavior
'this allow you to generate both versions of the example below
displayHistory = false
history = CreateObject("roArray", 1, true)
'prepopulate the search history with sample results
'history.Push("")
'history.Push("")

port = CreateObject("roMessagePort")
screen = CreateObject("roSearchScreen")
'commenting out SetBreadcrumbText() hides breadcrumb on screen
screen.SetBreadcrumbText("", "search")
screen.SetMessagePort(port)

if displayHistory = true
screen.SetSearchTermHeaderText("Recent Searches:")
screen.SetSearchButtonText("search")
screen.SetClearButtonText("clear history")
screen.SetClearButtonEnabled(true) 'defaults to true
screen.SetSearchTermHeaderText("Suggestions:")
else
screen.SetSearchTermHeaderText("Suggestions:")
screen.SetSearchButtonText("search")
screen.SetClearButtonEnabled(false)
endif

print "Doing show screen..."
screen.Show()
print "Waiting for a message from the screen..."

' search screen main event loop
done = false
while done = false
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roSearchScreenEvent"
if msg.isScreenClosed()
print "screen closed"
done = true
screen.close()
else if msg.isCleared()
print "search terms cleared"
history.Clear()
else if msg.isPartialResult()
print "partial search: "; msg.GetMessage()
if not displayHistory
screen.SetSearchTerms(GenerateSearchSuggestions(msg.GetMessage()))
endif
else if msg.isFullResult()
print "full search: "; msg.GetMessage()
history.Push(msg.GetMessage())
if displayHistory
screen.AddSearchTerm(msg.GetMessage())
end if
Print "Delta"
searchResultsScreen(msg.GetMessage())

'uncomment to exit the screen after a full search result:
'done = true
'screen.close()
else
print "Unknown event: "; msg.GetType(); " msg: ";msg.GetMessage()
endif
endif
endwhile
print "Exiting..."
End Function


Function GenerateSearchSuggestions(partSearchText As String) As Object

suggestions = CreateObject("roArray", 1, true)

url = "http://www.map2life.com/roku/php/search.php?"

escsearch = HttpEncode(partSearchText)
partsearch = url + escsearch

result = searchconn(partsearch)



If islist(result) then
Print "Result push"

for each e in result
suggestions.push(e.Title)
end for

Print "Result push completed"
else
Print "Error in search suggestion parse"
'text = "I'm sorry, we Couldn't find any results for your request. Please try again later or try rewording your request."
'title = "Search Error"
'ShowDialog1Button(title, text, "Done")
end if

return suggestions

End Function



Function searchResultsScreen(searchtext As String) As Integer

url = "http://www.map2life.com/roku/php/search.php?"

escsearch = HttpEncode(searchtext)
search = url + escsearch

result = searchconn(search)

If islist(result) then
port = CreateObject("roMessagePort")
poster = CreateObject("roPosterScreen")
poster.SetBreadcrumbText("", "Search Results")
poster.SetMessagePort(port)
poster.SetContentList(result)
poster.show()
While True
msg = wait(0, port)
If msg.isScreenClosed() Then
return -1
ElseIf msg.isListItemSelected()
print "msg: ";msg.GetMessage();"idx: ";msg.GetIndex()
screen = preShowDetailScreen("", "Search Results")
index = msg.GetIndex()
showDetailScreen(screen, result, index)
End If
End While
else
text = "I'm sorry, we Couldn't find any results for your request. Try rewording your request."
title = "Search Error"
ShowDialog1Button(title, text, "Done")
return -1
end if


poster.Show()

While True
msg = wait(0, port)
If msg.isScreenClosed() Then
return -1
ElseIf msg.isListItemSelected()
print "msg: ";msg.GetMessage();"idx: ";msg.GetIndex()
screen = preShowDetailScreen("", "Search Results")
showDetailScreen(screen, shows, showIndex)

End If
End While
End Function





Function searchconn(searchUrl As String) As Dynamic


print searchUrl
http = NewHttp(searchUrl)

'm.Timer.Mark()
rsp = http.GetToStringWithRetry()
'print "Request Time: " + itostr(m.Timer.TotalMilliseconds())

feed = newShowFeed()
xml=CreateObject("roXMLElement")
if not xml.Parse(rsp) then
print "Can't parse feed"
Error = "Can't parse feed"
return Error
endif

if xml.GetName() <> "feed" then
print "no feed tag found"
Error = "Can't parse feed"
return Error
endif

if islist(xml.GetBody()) = false then
print "no feed body found"
Error = "Can't parse feed"
return Error
endif

'm.Timer.Mark()
results = searchfeedparse(xml, feed)
'print "Search Feed Parse Took : " + itostr(m.Timer.TotalMilliseconds())
print "Search feed parse success"

return results

End Function


Function searchfeedparse(xml As Object, feed As Object) As Object

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.ImageCount = strtoi(validstr(curShow.ImageCount.GetText()))
item.Url = validstr(curShow.Url.GetText())
item.HDBifUrl = validstr(curShow.hdBifUrl.GetText())
item.SDBifUrl = validstr(curShow.sdBifUrl.GetText())
item.StreamFormat = validstr(curShow.streamFormat.GetText())
item.StreamBitrates.Push(strtoi(validstr(curShow.streamBitrate.GetText())))
item.StreamQualities.Push(validstr(curShow.streamQuality.GetText()))
item.StreamUrls.Push(validstr(curShow.strealUrl.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 = "0"
item.ContentType = "episode"

showCount = showCount + 1
feed.Push(item)

skipitem:

next

return feed

End Function



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.