<?xml version="1.0" encoding="UTF-8"?>
<component name="SearchTask" extends="Task" >

	<script type="text/brightscript" uri="pkg:/components/generalUtils.brs"/>
	<script type="text/brightscript" >
		 <![CDATA[
		
			sub init()
				'print "In SearchTask"
			  	m.top.functionName = "go"
			end sub
			
			sub go()
				content = createObject("roSGNode", "ContentNode")
				'parent = content.createChild("ContentNode")
				contentxml = createObject("roXMLElement")
			    request = CreateObject("roUrlTransfer")
			    url = m.global.serverURL+"/RokuDevSG/buscar.php?p=" + m.top.searchTerm.Escape()
			    'print "Search Url = "; url
			    usuario = getStrValFromReg("user_tv", "datos_tv")
			    pass = getStrValFromReg("pass_tv", "datos_tv")
			    ba = CreateObject("roByteArray") 
			    ba.FromAsciiString(usuario+":"+pass) 
			    request.AddHeader("X-Roku-Reserved-Dev-Id", "132fdf0cb94f9eb9a3a0132af460b8cd")
			    request.AddHeader("X-Content", ba.ToBase64String())   
			    request.SetUrl(url)
			    html = request.GetToString()
			    data = html.Trim() 
			    contentxml.parse(data)
				
				if contentxml.getName()="Content"
			        for each item in contentxml.GetNamedElements("item")
			          itemcontent = content.createChild("ContentNode")
			          itemcontent.setFields(item.getAttributes())
			          if itemcontent.StreamFormat = "hls" then
			            itemcontent.live = true
			          end if
			        end for
			    end if
				
				m.top.content = content
			end sub
		]]>

  	</script>
	<interface>
	    <field id="content" type="node"/>
	    <field id="searchTerm" type="string" />  	
  	</interface>

</component>
