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

Category & Leafs | XML Help

Hi all,
I've asked a a question on the forums earlier this week about dynamic XML.
Well I'm back with a question about the categories in my channel.

Right now I'm using this code to call my categories:

Function InitCategoryFeedConnection() As Object

conn = CreateObject("roAssociativeArray")

conn.UrlPrefix = "http://mysite.com"
conn.UrlCategoryFeed = conn.UrlPrefix + "/categories.xml"

conn.Timer = CreateObject("roTimespan")

conn.LoadCategoryFeed = load_category_feed
conn.GetCategoryNames = get_category_names

print "created feed connection for " + conn.UrlCategoryFeed
return conn

End Function


Then this is my category XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<categories>

<category title="Radio" description="Lets Talk!" sd_img="http://mysite.com/pic1.png" hd_img="http://mysite.com/pic1.png">
<categoryLeaf title="Show 1" description="" feed="http://mysite.com/show1.xml"/>
<categoryLeaf title="Show 2" description="" feed="http://mysite.com/show2.xml" />
</category>
</categories>


Basically what I would like to do is categorize my radio shows like this:

Show 1 > Years Recorded > Months > Shows For That Month
Show 2 > Years Recorded > Months > Shows For That Month

The problem is that I don't know if I have to do it that way via XML or in my actual channel code.
Any help would be appreciated and if you would like further explanation of what I want please say so.

Cheers,
Kapture
Darkness cannot drive out darkness; only light can do that. Hate cannot drive out hate; only love can do that. Hate multiplies
hate, violence multiplies violence, and toughness multiplies toughness in a descending spiral of destruction. - MLK Jr.
0 Kudos
4 REPLIES 4
destruk
Streaming Star

Re: Category & Leafs | XML Help

If you're generating your xml on demand from a database with php, you can use code to sort the database by year, then month, then day. Generally you'd be feeding that xml during each new screen creation. Or you could download the entire database xml contents to tmp, parse it from there, and have the roku do the sorting and display work. (IMO the second option is a lot more complex, so I chose not to do it that way.)

It is easier to create the source xml by hand, but then you'll have to edit it by hand whenever it changes, and searching becomes difficult.

This would generate your top level categories (Year and Month) and then the feeds for the leaf/month categories send the year and month value to a second index page to have the database return a second xml file to roku with the specific episode data requested.


$sql="SELECT * FROM showdatabase WHERE showname='".$value2."' ORDER BY showdate DESC"; //Do search query based on show name in descending order so the date is always newest first
$res=mysqli_query($con, $sql);
if (mysqli_num_rows($res)==0) //no shows were found in the search
{
$_xml="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
$_xml.="<feed>";
$_xml.="<item hdImg=\"http://www.yourserver.com/thumbs/empty.png\">";
$_xml.="<title>Placeholder</title>";
$_xml.="</item>";
$_xml.="</feed>";
echo $_xml;
}
else
{
$mx=0;
$yearcount=0;
$monthcount=0;
while ($info=mysqli_fetch_array($res,MYSQLI_NUM))
{
$ShowName[$mx]=$info[0]; //Show Name
$ShowDate[$mx]=$info[1]; //Date - listed as YYYYMMDD or 20110807 for today
$EpisodeTitle[$mx]=$info[2]; //Title
$EpisodeThumbnail[$mx]=$info[3]; //Thumbnail
$VideoLink[$mx]=$info[4]; //Video Filename

$tempYear=substr($ShowDate[$mx],0,4);
$tempMonth=substr($ShowDate[$mx],0,6);

$found=0;
for($i=0;$i<$yearcount;$i++)
{
if($yearscollect[$i]==$tempYear){$found=1;}
}
if($found==0)
{
$yearscollect[$yearcount]=$tempYear;
$yearcount++;
}
$found=0;
for($i=0;$i<$monthcount;$i++)
{
if($monthscollect[$i]==$tempMonth){$found=1;}
}
if($found==0)
{
$monthscollect[$monthcount]=$tempMonth;
$monthcount++;
}
$mx++;
}
header("Content-Type: application/force-download");
header("Content-Type: text/plain");
header("Content-Transfer-Encoding: binary ");
$_xml='<?xml version="1.0" encoding="UTF-8" ?>'.chr(13);
$_xml.='<categories>'.chr(13);
For ($i=0;$i<$yearcount;$i++)
{
$_xml.="<category title=\"".$yearscollect[$i]."\" hdImg=\"http://www.yourserver.com/thumbs/".$yearscollect[$i]."_HD.png\" sdImg=\"http://www.yourserver.com/thumbs/".$yearscollect[$i]."_SD.png\">".chr(13);
for ($j=0;$j<$monthcount;$j++)
{
$tempoutput=substr($monthscollect[$j],-2);
if($tempoutput=="01"){$tempoutput="January ";}
if($tempoutput=="02"){$tempoutput="February ";}
if($tempoutput=="03"){$tempoutput="March ";}
if($tempoutput=="04"){$tempoutput="April ";}
if($tempoutput=="05"){$tempoutput="May ";}
if($tempoutput=="06"){$tempoutput="June ";}
if($tempoutput=="07"){$tempoutput="July ";}
if($tempoutput=="08"){$tempoutput="August ";}
if($tempoutput=="09"){$tempoutput="September ";}
if($tempoutput=="10"){$tempoutput="October ";}
if($tempoutput=="11"){$tempoutput="November ";}
if($tempoutput=="12"){$tempoutput="December ";}

if(substr($monthscollect[$j],0,4)==$yearscollect[$i]){$_xml.="<categoryLeaf title=\"".$tempoutput.substr($monthscollect[$j],0,4)."\" feed=\"http://www.yourserver.com/index2.html?ind=".$monthscollect[$j]."&amp;show=".$value2."\" />".chr(13);}
}
$_xml.='</category>'.chr(13);
}
$_xml.='</categories>'.chr(13);
echo $_xml;
}


ie, for the second index page the url request would be http://www.yourserver.com/index2.html?ind=201108&show=MyCarsCollection
The index2 page would grab the value of show, and insert it into the sql request like
SELECT * FROM showdatabase WHERE showname="MyCarsCollection" AND ShowDate LIKE "201108%" ORDER BY ShowDate DESC


$sql="SELECT * FROM showdatabase WHERE showname='".$value2."' AND ShowDate LIKE '".$value1."%' ORDER BY ShowDate DESC"; //Do search query

$res=mysqli_query($con, $sql);
if (mysqli_num_rows($res)==0) //no shows
{
$_xml="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
$_xml.="<feed>";
$_xml.="<item hdImg=\"http://www.yourserver.com/thumbs/Empty.png\">";
$_xml.="<title>Placeholder</title>";
$_xml.="</item>";
$_xml.="</feed>";
echo $_xml;
}
else
{
$mx=0;
while ($info=mysqli_fetch_array($res,MYSQLI_NUM))
{
$ShowName[$mx]=$info[0]; //Show Name
$ShowDate[$mx]=$info[1]; //Date - listed as YYYYMMDD or 20110807 for today
$EpisodeTitle[$mx]=$info[2]; //Title
$EpisodeThumbnail[$mx]=$info[3]; //Thumbnail
$VideoLink[$mx]=$info[4]; //Video Filename
$mx++;
}

header("Content-Type: application/force-download");
header("Content-Type: text/plain");
header("Content-Transfer-Encoding: binary ");

$_xml="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>".chr(13);
$_xml.="<feed>".chr(13);
For ($i=0;$i<$mx;$i++)
{
$_xml.="<item hdImg=\"http://www.yourserver.com/thumbs/".$EpisodeThumbnail[$i]."\">".chr(13);
$_xml.="<title>".substr($ShowDate[$i],4,2)."/".substr($ShowDate[$i],6,2)."/".substr($ShowDate[$i],0,4)." - ".$EpisodeTitle[$i]."</title>".chr(13);
$_xml.="<media><streamUrl>http://www.yourserver.com/".$VideoLink[$i]."</streamUrl></media>".chr(13);
$_xml.="</item>".chr(13);
}
$_xml.="</feed>".chr(13);
echo $_xml;
}


Naturally, any code can be improved, like having it create multiple streams on the fly, adding other meta data for the episode, adding extra features customized within the database schema, etc etc, but this gives you a good starting point to dynamically interface and generate XML. Any xml you are generating, the channel should be scripted to deal with the format it's being given.
0 Kudos
Kapture
Visitor

Re: Category & Leafs | XML Help

Sorry for the late reply, but to be honest I really don't understand what you just gave me.. :?
I'm not much of a web person and I don't have my server with PHP. Is there a way to categorize it
like that in my current XML? I would really like a beginner friendly answer as I'm just starting out
with BrightScript and XML. 🙂
Darkness cannot drive out darkness; only light can do that. Hate cannot drive out hate; only love can do that. Hate multiplies
hate, violence multiplies violence, and toughness multiplies toughness in a descending spiral of destruction. - MLK Jr.
0 Kudos
destruk
Streaming Star

Re: Category & Leafs | XML Help

"Kapture" wrote:
Basically what I would like to do is categorize my radio shows like this:
Show 1 > Years Recorded > Months > Shows For That Month
Show 2 > Years Recorded > Months > Shows For That Month

The problem is that I don't know if I have to do it that way via XML or in my actual channel code.
Any help would be appreciated and if you would like further explanation of what I want please say so.


Any XML you give your channel must be acceptable to the channel code. So you'd be working on both the XML, and the actual channel code to make anything work using external XML files. This way you don't need to repackage and reupload your channel when you want to make a change to the video/audio it plays. Your initial category XML, the top level you are posting is fine for the top level menu of your channel. What the top level menu should be doing is set up the parent level of your categories for the "Show" and it should point to the feeds to get the second menu data for "Year Recorded". You need a separate XML file for each year that your top level XML points to in order to be in line with what you want done here.
Following with what you want to do, the Year Recorded XML should look pretty much identical for code as what you use now - and it will pull another XML file for each "Month" which points to the actual show information and streams that are available for that month. An important note with XML is that some characters will cause it to break - & should be &amp;
To test your XML before running the channel, open it in a browser and if there's an error it will tell you where it is.

You could have the channel parse all four tiers of xml using a single XML file, but that would require a lot of changes to your current category feed/parsing routine, so keep it simple at first. Each little routine does it's little piece, load what you need for the screen you are displaying, and link them together with correct feed urls, thumbnails, etc etc. It also helps to troubleshoot if your functions are shorter.
0 Kudos
Kapture
Visitor

Re: Category & Leafs | XML Help

Ah, now I see.
Well I'll have a go at what you just explained as it seems
more clear to me now. If I need any more help then I guess I'll
post back with what I can't get working. Thanks for the help! 😄
Darkness cannot drive out darkness; only light can do that. Hate cannot drive out hate; only love can do that. Hate multiplies
hate, violence multiplies violence, and toughness multiplies toughness in a descending spiral of destruction. - MLK Jr.
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.