« Home | Exercise » | 500 words a day challenge » | What SciFi / Fantasy character are you? » | Wikileaks » | MythTV » | Redearth - About Last Night - 01/31/2008 » | The De-Evolution of Liberty » | What would I do as president? » | redearth: "How Could THIS Happen?" » | This makes me sick » 


Monday, March 03, 2008 

TV Wish

Awhile back, I wrote about finally switching my DVR software over to MythTV. Since then, I've added a little program called TVWish that allows me to create a wishlist of programs to record should they ever air on TV. One of the features that I like about TVWish is the "suggest" feature, which allows it to record programs based on past and scheduled recordings as well as genre. The problem is, the guide grabber that I am using, zap2xml, does not fill the programgenres table in the database. Unfortunately, this is the table that TVWish uses via its suggest.pl, instead of using the category field of the program table. This left me with two options for implementing genre suggestions.

First, I could patch suggest.pl to use the different field and table. Problem is, I don't know perl. It's close enough to C that I'm sure I could hack around with it and get it going, but it would probably take me awhile.

The second option is to modify zap2xml to fill the table. Again, I don't know perl very well. Zap2xml is a little more complex than the suggest.pl of TVWish, so it would probably take me even longer to get it right.

The third option, the one I went with, was to fill the programgenres table with the required data, taken from the program table. Since I do know PHP, I decided to hack together a very quick script to do this for me. It's certainly not pretty, but here it is anyway (be sure the variables at the top match your system):
$host = 'localhost';
$username = 'user';
$password = 'pass';
$database = 'mythconverg';

$connection = mysql_connect($host, $username, $password) or die ("Unable to connect!");

mysql_select_db($database) or die ("Unable to select database!");

$query = "DELETE FROM programgenres;";

$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());

$query = "SELECT chanid, starttime, category FROM program;";

$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

if (mysql_num_rows($result) > 0)
{
   while($row = mysql_fetch_object($result))
   {
     $query2 = "INSERT INTO programgenres VALUES (" .
         $row->chanid . "," .
         "'" . $row->starttime . "'," .
         "'0' ," .
         "'" . $row->category . "'" .
         ");";
     $result2 = mysql_query($query2) or die ("Error in query: $query2. " .      mysql_error());
   }
}


Please note that this entry is nowhere near 500 words unless I include the code. It does not count for the challenge I mentioned on Saturday ;)

Technorati tags: , ,