[mythtv] [PATCH] category types (movie idenfication)

Ben Bucksch linux.news at bucksch.org
Sun May 25 18:52:33 EDT 2003


My TV listing source and grabber provide explicit information about 
which programmes are movies, series etc.. I wanted to use that 
information to filter out only movies in my EPG app.

MythWeb has a similar feature, but it uses some guessing based on the 
current data in the DB, e.g. MPAA rating, star-rating, airdate, length 
etc.. (In fact, it has the guessing in several places and uses slightly 
different criteria, IIRC.) Given that this guessing doesn't work here, 
but my grabber provides this information unambigously, I thought it 
would make sense to move this out of MythWeb and into the grabber or 
filldatabase.

With my changes, filldatabase reads out the explicit type information 
(if existant) from the XMLTV file. To keep support for the guessing for 
American listings, I added that to filldatabase, similar to what MythWeb 
does right now (but a bit simpler, could easily be improved). I then 
modified MythWeb to use that information instead of doing the guessing.

The new XMLTV dtd will have explicit support for such categorization. 
For now, I hardcode the known values in filldatabase ("movie", "series", 
"tvshow", "sports"). My grabber places those categories as the second 
<category> tag, after the one with human-readable and more informative 
values, and filldatabase uses the first <category> for the displayed 
category, so even if new machine-readable categories are added, it 
should still work as expected, assuming the grabber follows the spec 
(most important info first).

It works just file with my EPG. It's really a help for me, given that I 
could never use the Movies feature of MythWeb. Movies are now also 
marked orange in MythWeb's listing.

However, the Movies page of MythWeb still doesn't work for me, because 
it assumes entries in the programrating table, which I don't have (not 
sure why - my grabber does provide rating, incl. system attribute). So, 
I can't verify, if the page still works. If I introduced a bug there, 
you could still check in the filldatabase patch without the MythWeb 
patch, it then shouldn't regress anything.


-------------- next part --------------
Index: database/cvs.sql
===================================================================
RCS file: /var/lib/mythcvs/mythtv/database/cvs.sql,v
retrieving revision 1.26
diff -u -r1.26 cvs.sql
--- database/cvs.sql	14 May 2003 02:43:28 -0000	1.26
+++ database/cvs.sql	25 May 2003 15:19:09 -0000
@@ -62,3 +62,5 @@
 CREATE INDEX progid ON record (chanid, starttime);
 CREATE INDEX title ON record (title(10)); 
 CREATE INDEX title ON program (title(10));   
+
+ALTER TABLE program ADD COLUMN cat_type VARCHAR(64) NULL;
Index: database/mc.sql
===================================================================
RCS file: /var/lib/mythcvs/mythtv/database/mc.sql,v
retrieving revision 1.34
diff -u -r1.34 mc.sql
--- database/mc.sql	14 May 2003 02:43:28 -0000	1.34
+++ database/mc.sql	25 May 2003 15:19:09 -0000
@@ -61,6 +61,7 @@
     subtitle VARCHAR(128) NULL,
     description TEXT NULL,
     category VARCHAR(64) NULL,
+    cat_type VARCHAR(64) NULL,
     airdate YEAR NOT NULL,
     stars FLOAT UNSIGNED NOT NULL,
     previouslyshown TINYINT NOT NULL default '0',
Index: programs/mythfilldatabase/filldata.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfilldatabase/filldata.cpp,v
retrieving revision 1.45
diff -u -r1.45 filldata.cpp
--- programs/mythfilldatabase/filldata.cpp	3 May 2003 23:13:31 -0000	1.45
+++ programs/mythfilldatabase/filldata.cpp	25 May 2003 15:19:11 -0000
@@ -30,6 +30,7 @@
 bool quiet = false;
 bool no_delete = false;
 bool isgist = false;
+bool isNorthAmerica = false; // XXX global vars are ugly
 
 MythContext *gContext;
 
@@ -76,6 +77,7 @@
                                       subtitle = other.subtitle;
                                       desc = other.desc;
                                       category = other.category;
+                                      catType = other.catType;
                                       start = other.start;
                                       end = other.end;
                                       airdate = other.airdate;
@@ -92,6 +94,7 @@
     QString subtitle;
     QString desc;
     QString category;
+    QString catType;
     QString airdate;
     QString stars;
     QValueList<ProgRating> ratings;
@@ -176,7 +179,7 @@
     QString xmltvid = element.attribute("id", "");
     QStringList split = QStringList::split(" ", xmltvid);
 
-    if (!isgist)
+    if (isNorthAmerica)
     {
         chaninfo->xmltvid = split[0];
         chaninfo->chanstr = split[0];
@@ -362,8 +365,9 @@
 
     pginfo->start = fromXMLTVDate(pginfo->startts);
     pginfo->end = fromXMLTVDate(pginfo->endts);
 
     pginfo->subtitle = pginfo->title = pginfo->desc = pginfo->category = "";
+    pginfo->catType = "";
     pginfo->repeat = false;   
  
     for (QDomNode child = element.firstChild(); !child.isNull();
@@ -391,9 +399,26 @@
             {
                 pginfo->desc = getFirstText(info);
             }
-            else if (info.tagName() == "category" && pginfo->category == "")
+            else if (info.tagName() == "category")
             {
-                pginfo->category = getFirstText(info);
+                QString cat = getFirstText(info);
+                if (cat == "movie" || cat == "series" || cat == "sports" ||
+                    cat == "tvshow")
+                    /* Hack until we have the new XMLTV DTD with category
+                       "system"s.
+                       I can't use a new tag, because I'd then
+                       be incompliant with the (current) XMLTV (I think),
+                       unless I use XML namespaces etc., and it's category
+                       info after all, just formalized and narrow. */
+                {
+                    if (pginfo->catType == "")
+                        pginfo->catType = cat;
+                }
+                else
+                {
+                    if (pginfo->category == "")
+                        pginfo->category = cat;
+                }
             }
             else if (info.tagName() == "date" && pginfo->airdate == "")
             {
@@ -450,6 +475,17 @@
         }
     }
 
+    if (pginfo->category == "" && pginfo->catType != "")
+        pginfo->category == pginfo->catType;
+
+    /* Do what MythWeb does and assume that programmes with
+       star-rating in America are movies. This allows us to
+       unify app code with grabbers which explicitly deliver that
+       info. */
+    if (isNorthAmerica && pginfo->catType == "" &&
+        pginfo->stars != "" && pginfo->airdate != "")
+        pginfo->catType == "movie";
+
     return pginfo;
 }
                   
@@ -1022,10 +1058,10 @@
             }
 
             querystr.sprintf("INSERT INTO program (chanid,starttime,endtime,"
-                             "title,subtitle,description,category,airdate,"
-                             "stars,previouslyshown) "
+                             "title,subtitle,description,category,cat_type,"
+                             "airdate,stars,previouslyshown) "
                              "VALUES(%d,\"%s\",\"%s\",\"%s\",\"%s\","
-                             "\"%s\",\"%s\",\"%s\",\"%s\",\"%d\");", 
+                             "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%d\");", 
                              chanid, 
                              (*i).start.toString("yyyyMMddhhmmss").ascii(), 
                              (*i).end.toString("yyyyMMddhhmmss").ascii(), 
@@ -1033,6 +1069,7 @@
                              (*i).subtitle.utf8().data(), 
                              (*i).desc.utf8().data(), 
                              (*i).category.utf8().data(),
+                             (*i).catType.utf8().data(),
                              (*i).airdate.utf8().data(),
                              (*i).stars.utf8().data(),
                              (*i).repeat);
@@ -1175,6 +1212,8 @@
         command.sprintf("nice -19 %s --days 7 --config-file %s --output %s",
                         xmltv_grabber.ascii(), configfile.ascii(), 
                         filename.ascii());
+    else if (xmltv_grabber == "tv_grab_na")
+        isNorthAmerica = true;
     else if (xmltv_grabber == "tv_grab_nz")
         command.sprintf("nice -19 %s -n 1 -f %d -o %s",
                         xmltv_grabber.ascii(), offset,
-------------- next part --------------
? full
? rsync-streamer.sh
Index: bychannel.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/bychannel.php,v
retrieving revision 1.2
diff -u -r1.2 bychannel.php
--- bychannel.php	4 May 2003 00:51:11 -0000	1.2
+++ bychannel.php	25 May 2003 15:42:17 -0000
@@ -116,7 +116,7 @@
 		{
 			$cellwidth = 1;
 
-			if(smellsLikeMovie($proginfo->duration, $proginfo->progType))
+			if($proginfo->smellsLikeMovie)
 			{
 				$finalColour = $movie_colour;
 			}
Index: classes.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/classes.php,v
retrieving revision 1.9
diff -u -r1.9 classes.php
--- classes.php	4 May 2003 00:51:11 -0000	1.9
+++ classes.php	25 May 2003 15:42:17 -0000
@@ -133,6 +133,7 @@
 	var $startts;
 	var $endts;
 	var $progType;
+	var $catType;
 	var $description;
 	var $duration;
 	var $recordColour;
@@ -242,29 +243,7 @@
 
 	function smellsLikeMovie()
 	{
-		if ($this->rater == "MPAA"
-		|| ($this->airdate && $this->stars > 0))
-			return TRUE;
-
-		if ($this->airdate
-		&& $GLOBALS['includeMoviesMadeForTV']
-		&& $this->duration > 70)
-			switch ($this->progType)
-			{
-				case "Drama":
-				case "Doc":
-				case "Mystery":
-				case "Musical":
-				case "Action":
-				case "Comedy":
-				case "War":
-				case "Romance":
-				case "Crime":
-				case "SciFi":
-				case "Horror":
-					return TRUE;
-			}
-		return FALSE;
+		return ($this->catType == "movie");
 	}
 }
 
Index: functions.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/functions.php,v
retrieving revision 1.13
diff -u -r1.13 functions.php
--- functions.php	9 May 2003 16:19:54 -0000	1.13
+++ functions.php	25 May 2003 15:42:18 -0000
@@ -250,32 +250,6 @@
 	return(FALSE);
 }
 
-//
-//	Make a decent guess about whether this is a movie
-//	or not
-//
-function smellsLikeMovie($length, $type)
-{
-	if($length > 70)
-	{
-		if(	$type == "Drama" ||
-			$type == "Doc" ||
-			$type == "Mystery" ||
-			$type == "Musical" ||
-			$type == "Action" ||
-			$type == "Comedy" ||
-			$type == "War" ||
-			$type == "Romance" ||
-			$type == "Crime" ||
-			$type == "SciFi" ||
-			$type == "Horror")
-		{
-			return(TRUE);
-		}
-	}
-	return(FALSE);
-}
-
 
 //
 //	Build an array of time slots based on the
@@ -401,6 +375,7 @@
 			"program.subtitle, ".
 			"program.description, ".
 			"program.category, ".
+			"program.cat_type, ".
 			"program.airdate, ".
 			"program.stars, ".
 			"concat(repeat('$star', program.stars*$maxStars), if((program.stars*$maxStars*10) % 10, '&frac12;', '')) as starstring, ".
@@ -428,6 +403,7 @@
 			$myprog->startts = $line["starttime"];
 			$myprog->endts = $line["endtime"];
 			$myprog->progType = $line["category"];
+			$myprog->catType = $line["cat_type"];
 			$myprog->duration = $line["duration"];
 			$myprog->description = $line["description"];
 			$myprog->rater = $line["rater"];
@@ -512,6 +488,7 @@
 			"program.subtitle, ".
 			"program.description, ".
 			"program.category, ".
+			"program.cat_type, ".
 			"program.airdate, ".
 			"program.stars, ".
 			"concat(repeat('$star', program.stars*$maxStars), if((program.stars*$maxStars*10) % 10, '&frac12;', '')) as starstring, ".
@@ -522,8 +499,7 @@
 		"WHERE programrating.starttime between if($day, date_add(curdate(), interval $day day), now()) ".
 			                        "and date_add(curdate(), interval $day+1 day) ".
 			"AND program.chanid = channel.chanid ".
-			"AND (UNIX_TIMESTAMP(program.endtime) - UNIX_TIMESTAMP(program.starttime)) / 60 > 70 ".
-			"AND program.stars > 0 AND program.airdate > 0 ".
+			"AND program.cat_type = 'movie' ".
 			$ignore.
 		"GROUP BY programrating.chanid, programrating.starttime ".
 		"ORDER BY programrating.starttime ASC, programrating.system ASC;";
@@ -540,6 +516,7 @@
 		$myprog->startts = $line["starttime"];
 		$myprog->endts = $line["endtime"];
 		$myprog->progType = $line["category"];
+		$myprog->catType = $line["cat_type"];
 		$myprog->duration = $line["duration"];
 		$myprog->description = $line["description"];
 		$myprog->rater = $line["rater"];
@@ -883,7 +860,7 @@
 	$from = date('YmdHis', mktime($theTime['hour'], 00, 00, $theTime['month'], $theTime['day'], $theTime['year']));
 	$to = date('YmdHis', mktime(23, 59, 59, $theTime['month'], $theTime['day'], $theTime['year']));
 
-	$query = "SELECT channel.chanid, channel.channum, icon, name, starttime, endtime, title, subtitle, description, category, ((UNIX_TIMESTAMP(endtime) - UNIX_TIMESTAMP(starttime)) / 60 ) as duration FROM program,channel WHERE program.chanid = channel.chanid AND program.chanid = $chanid AND starttime >= $from  AND starttime <= $to ORDER BY starttime ASC;";
+	$query = "SELECT channel.chanid, channel.channum, icon, name, starttime, endtime, title, subtitle, description, category, cat_type, ((UNIX_TIMESTAMP(endtime) - UNIX_TIMESTAMP(starttime)) / 60 ) as duration FROM program,channel WHERE program.chanid = channel.chanid AND program.chanid = $chanid AND starttime >= $from  AND starttime <= $to ORDER BY starttime ASC;";
 
 	$result = mysql_query($query) or die("Gadzooks! I can't open the program table.");
 
@@ -897,6 +874,7 @@
 		$myprog->startts = $line["starttime"];
 		$myprog->endts = $line["endtime"];
 		$myprog->progType = $line["category"];
+		$myprog->catType = $line["cat_type"];
 		$myprog->duration = $line["duration"];
 		$myprog->description = $line["description"];
 		$myprog->channame = $line["name"];
Index: movies.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/movies.php,v
retrieving revision 1.3
diff -u -r1.3 movies.php
--- movies.php	4 May 2003 00:51:11 -0000	1.3
+++ movies.php	25 May 2003 15:42:18 -0000
@@ -47,8 +47,8 @@
 
 	for ($index = 0; $proginfo = $listingarray[$index]; $index++)
 	{
-		if (!$proginfo->smellsLikeMovie())
-			continue;
+          //		if (!$proginfo->smellsLikeMovie())
+          //			continue;
 
 		if (!$alreadyprinted) {
 			printf("<tr cellpadding=1><td></td><td align=center bgcolor=\"$list_fg_colour\" colspan=%d>", $maxCols-1);
Index: single.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/single.php,v
retrieving revision 1.8
diff -u -r1.8 single.php
--- single.php	4 May 2003 00:51:11 -0000	1.8
+++ single.php	25 May 2003 15:42:18 -0000
@@ -95,10 +95,22 @@
 
 
 
-$thequery = "SELECT channel.chanid, UNIX_TIMESTAMP(starttime), endtime, title, subtitle, description, category,((UNIX_TIMESTAMP(endtime) - UNIX_TIMESTAMP(starttime)) / 60 ) as duration, channel.channum, channel.callsign FROM program,channel WHERE starttime = \"$theStartTime\" and channel.chanid = $theChannel AND program.chanid = channel.chanid";
+$thequery = "SELECT channel.chanid, UNIX_TIMESTAMP(starttime), endtime, title, subtitle, description, category, cat_type, ((UNIX_TIMESTAMP(endtime) - UNIX_TIMESTAMP(starttime)) / 60 ) as duration, channel.channum, channel.callsign, channel.name FROM program,channel WHERE starttime = \"$theStartTime\" and channel.chanid = $theChannel AND program.chanid = channel.chanid";
 $singleQuery = mysql_query($thequery);
 while($aRow = mysql_fetch_row($singleQuery))
 {
+        $chanid = $aRow[0];
+        $start = $aRow[1];
+        $end = $aRow[2];
+        $title = $aRow[3];
+        $subtitle = $aRow[4];
+        $descr = $aRow[5];
+        $category = $aRow[6];
+        $catType= $aRow[7];
+        $duration = $aRow[8];
+        $channum = $aRow[9];
+        $callsign = $aRow[10];
+        $channame = $aRow[11];
 	//
 	//	Print a table with program data and
 	//	some forms
@@ -107,33 +119,33 @@
 	print("<TABLE WIDTH=\"100%\" BGCOLOR=\"$list_bg_colour\" CELLSPACING=\"10\" CELLPADDING=\"7\"><TR><TD>");
 	print("<CENTER>");
 	print("<TABLE BGCOLOR=\"$list_bg_colour\" CELLSPACING=\"5\" CELLPADDING=\"5\">");
-	print("<TR VALIGN=\"TOP\"><TD>Program:</TD><TD BGCOLOR=\"$list_fg_colour\">$aRow[3] ");
+	print("<TR VALIGN=\"TOP\"><TD>Program:</TD><TD BGCOLOR=\"$list_fg_colour\">$title ");
 
 	//
 	//	If it's a movie, add an IMDB link
 	//
-	if(smellsLikeMovie($aRow[7], $aRow[6]))	{
-		print("(<a href=\"http://www.imdb.com/Find?select=Titles&for=" . urlencode($aRow[3]) . "\">IMDB Search</a>)");
+	if($catType == "movie")	{
+		print("(<a href=\"http://www.imdb.com/Find?select=Titles&for=" . urlencode($title) . "\">IMDB Search</a>)");
 	}
-	else print("(<A HREF=\"http://www.google.com/search?q=" . urlencode($aRow[3]) . "\">Google Search</A>)");
+	else print("(<A HREF=\"http://www.google.com/search?q=" . urlencode($title) . "\">Google Search</A>)");
 
 	print("</td>");
-	if(strlen($aRow[6]) > 0) print("</TR><TR VALIGN=\"TOP\"><TD>Category:</TD><TD BGCOLOR=\"$list_fg_colour\">$aRow[6]</TD></TR>");
-	if(strlen($aRow[4]) > 0) print("<TR VALIGN=\"TOP\"><TD>Episode:</TD><TD BGCOLOR=\"$list_fg_colour\">$aRow[4]</TD></TR>");
+	if(strlen($category) > 0) print("</TR><TR VALIGN=\"TOP\"><TD>Category:</TD><TD BGCOLOR=\"$list_fg_colour\">$category</TD></TR>");
+	if(strlen($subtitle) > 0) print("<TR VALIGN=\"TOP\"><TD>Episode:</TD><TD BGCOLOR=\"$list_fg_colour\">$subtitle</TD></TR>");
 	print("<TR VALIGN=\"TOP\"><TD>Channel:</TD><TD BGCOLOR=\"$list_fg_colour\">$aRow[9] $aRow[8]</TD></TR>");
-	if(strlen($aRow[5]) > 0) print("<TR VALIGN=\"TOP\"><TD>Description:</TD><TD WIDTH=\"300\" BGCOLOR=\"$list_fg_colour\">$aRow[5]</TD></TR>");
-	print("<TR VALIGN=\"TOP\"><TD>Airdate:</TD><TD BGCOLOR=\"$list_fg_colour\">".date($date_format." ".$time_format,$aRow[1])."</TD></TR>");
-	print("<TR VALIGN=\"TOP\"><TD>Duration:</TD><TD BGCOLOR=\"$list_fg_colour\">$aRow[7] minutes</TD></TR>");
+	if(strlen($descr) > 0) print("<TR VALIGN=\"TOP\"><TD>Description:</TD><TD WIDTH=\"300\" BGCOLOR=\"$list_fg_colour\">$descr</TD></TR>");
+	print("<TR VALIGN=\"TOP\"><TD>Airdate:</TD><TD BGCOLOR=\"$list_fg_colour\">".date($date_format." ".$time_format,$start)."</TD></TR>");
+	print("<TR VALIGN=\"TOP\"><TD>Duration:</TD><TD BGCOLOR=\"$list_fg_colour\">$duration minutes</TD></TR>");
 
 	//
 	//	Need to check if this is being recorded
 	//	and display a form to toggle it on and
 	//	off 
 	//
-	$isBeingSingleRecorded = isInOnceRecord($aRow[0], date("YmdHis",$aRow[1]));
-	$isBeingTimeslotRecorded = isInTimeslotRecord($aRow[0], date("YmdHis",$aRow[1]), $aRow[2], $aRow[3]);
-	$isBeingChannelAlwaysRecorded = isInChannelAlwaysRecord($aRow[0], $aRow[3]);
-	$isBeingAlwaysRecorded = isInAlwaysRecord($aRow[3]);
+	$isBeingSingleRecorded = isInOnceRecord($chanid, date("YmdHis",$start));
+	$isBeingTimeslotRecorded = isInTimeslotRecord($chanid, date("YmdHis",$start), $end, $title);
+	$isBeingChannelAlwaysRecorded = isInChannelAlwaysRecord($chanid, $title);
+	$isBeingAlwaysRecorded = isInAlwaysRecord($title);
 	$recordArrayIndex = 0;
 	print("<TR><TD></TD><TD BGCOLOR=\"$list_fg_colour\">");
 	
@@ -184,7 +196,7 @@
 	print("<INPUT TYPE=\"HIDDEN\" NAME=\"channel\" VALUE=\"$theChannel\">");
 	print("<INPUT TYPE=\"HIDDEN\" NAME=\"starttime\" VALUE=\"$theStartTime\">");
 	print("<INPUT TYPE=\"HIDDEN\" NAME=\"endtime\" VALUE=\"$theEndTime\">");
-	print("<INPUT TYPE=\"HIDDEN\" NAME=\"program\" VALUE=\"$aRow[3]\">");
+	print("<INPUT TYPE=\"HIDDEN\" NAME=\"program\" VALUE=\"$title\">");
 	print("<INPUT TYPE=\"HIDDEN\" NAME=\"refoffset\" VALUE=\"$theRefOffset\">");
 	print("<CENTER><INPUT TYPE=\"SUBMIT\" NAME=\"submitrecording\" VALUE=\"Update Recording Settings\"></CENTER>");
 	


More information about the mythtv-dev mailing list