[mythtv-users] Re: Guide data problems

Tony Lill ajlill at ajlc.waterloo.on.ca
Wed Dec 22 18:51:29 UTC 2004


I posted a patch to the -dev list a while ago for this problem
(included below). THe current 0.16) code finds the channel with the largest
number of programs starting between 6 and midnight, and if the number
of programs is less than 10, it refetches. Not really sure why that
logic was chosen...

So, one channel with a number of half-hour shows is required to satisfy
this condition. The consequence is that as long as there is at least
one such channel, then it won't notice missing data for channels. THis
is the Canadian problem. It will also re-fetch unnecessarily if you
don't have enough short programs. I think that was why it would fetch
Saturday data every time it ran.

This patch will cause a re-fetch if it finds any channel without a
show starting between 8 and midnight (which is what Rogers was giving
me). Don't know if it's a good idea in general, but it seems to work
for us cannucks.

It also adds a -dd-max-days option to limit the number of days to
download. THis was my original workaround, if you fetch one less day
than the max, then you usually aviod the problems with missing data.

The patch is against 0.16

? patch
Index: filldata.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfilldatabase/filldata.cpp,v
retrieving revision 1.131
diff -u -r1.131 filldata.cpp
--- filldata.cpp	19 Aug 2004 02:02:26 -0000	1.131
+++ filldata.cpp	22 Dec 2004 18:27:17 -0000
@@ -54,6 +54,7 @@
 QString lastdduserid;
 DataDirectProcessor ddprocessor;
 QString graboptions = "";
+int arg_max_days = 0;
 
 class ChanInfo
 {
@@ -2443,6 +2444,7 @@
     QString status;
     QSqlQuery query;
     QDateTime GuideDataBefore, GuideDataAfter;
+    QString querystr;
 
     query.exec(QString("SELECT MAX(endtime) FROM program;"));
     if (query.isActive() && query.numRowsAffected())
@@ -2456,6 +2458,26 @@
 
     int failures = 0;
     for (it = sourcelist.begin(); it != sourcelist.end(); ++it) {
+
+      querystr.sprintf("SELECT COUNT(*) "
+		       "FROM channel "
+		       "WHERE sourceid = %d",
+		       (*it).id); 
+      int numchans = 11;
+      query.exec(querystr);
+      
+      if (query.isActive() && query.numRowsAffected() > 0)
+	{
+	  query.next();
+	  numchans = query.value(0).toInt();
+	  if (!quiet)
+	    cout << "Found " << numchans
+		 << " channels for source " << (*it).id << "\n";
+	} 
+      else
+	MythContext::DBError("checking number of channels", 
+			     query);
+
         QString xmltv_grabber = (*it).xmltvgrabber;
         if (xmltv_grabber == "tv_grab_uk" || xmltv_grabber == "tv_grab_de" ||
             xmltv_grabber == "tv_grab_fi" || xmltv_grabber == "tv_grab_es" ||
@@ -2479,7 +2501,6 @@
 
             for (int i = 0; i < 7; i++)
             {
-                QString querystr;
                 querystr.sprintf("SELECT COUNT(*) as 'hits' "
                                  "FROM channel LEFT JOIN program USING (chanid) "
                                  "WHERE sourceid = %d AND starttime >= "
@@ -2553,6 +2574,8 @@
                 maxday = 14;
             if (xmltv_grabber == "datadirect")
                 maxday = 14;
+	    if (arg_max_days)
+	      maxday = arg_max_days;
 
             for (int i = 0; i < maxday; i++)
             {
@@ -2576,29 +2599,32 @@
                 bool download_needed = false;
                 QString date(qCurrentDate.addDays(i).toString());
                 QString querystr;
+                QSqlQuery query;
 
+		// Grab the number of start times for each channel
+		// between 8pm and midnight and sort highest to lowest
                 querystr.sprintf("SELECT COUNT(*) as 'hits' "
                                  "FROM channel LEFT JOIN program USING (chanid) "
                                  "WHERE sourceid = %d AND starttime >= "
-                                 "DATE_ADD(CURRENT_DATE(), INTERVAL '%d 18' "
+                                 "DATE_ADD(CURRENT_DATE(), INTERVAL '%d 20' "
                                  "DAY_HOUR) AND "
                                  "starttime < DATE_ADD(CURRENT_DATE(), "
                                  "INTERVAL 1+%d DAY) "
                                  "GROUP BY channel.chanid "
-                                 "ORDER BY hits DESC LIMIT 1",
+                                 "ORDER BY hits DESC",
                                  (*it).id, i, i); 
-                QSqlQuery query;
                 query.exec(querystr);
                
                 if (query.isActive()) 
                 {
-                    // We also need to get this day's data if there's only a 
-                    // suspiciously small amount in the DB.
-                    if (!query.numRowsAffected() ||
-                        (query.next() && query.value(0).toInt() <= 10))
+		  int hits;
+                    // We also need to get this day's data if there's data missing
+		    // from some of the channels
+		  if ((hits = query.numRowsAffected()) < numchans )
                     {
                         download_needed = true;
                     }
+		    cout << "Got " << hits << " channels with data\n";
                 } 
                 else
                     MythContext::DBError("checking existing program data", 
@@ -2950,7 +2976,6 @@
         {
             refresh_tba = false;
         }
-#if 0
         else if (!strcmp(a.argv()[argpos], "--dd-grab-all"))
         {
             dd_grab_all = true;
@@ -2958,7 +2983,18 @@
             refresh_tomorrow = false;
             refresh_second = false;
         }
-#endif
+        else if (!strcmp(a.argv()[argpos], "--dd-max-days"))
+        {
+            if ((argpos + 1) >= a.argc() ||
+                    !strncmp(a.argv()[argpos + 1], "--", 2))
+            {
+	      // print error message
+            }
+            else
+            {
+                arg_max_days = atoi(a.argv()[++argpos]);
+            }
+        }
         else if (!strcmp(a.argv()[argpos], "--quiet"))
         {
              quiet = true;
@@ -3089,10 +3125,10 @@
             cout << "--mark-repeats\n";
             cout << "   Marks any programs with a OriginalAirDate earlier than their start date as a repeat\n";
             cout << "\n";
-#if 0
             cout << "--dd-grab-all\n";
             cout << "   The DataDirect grabber will grab all available data\n";
-#endif
+            cout << "--dd-max-days <#>\n";
+            cout << "   The DataDirect grabber will grab # days instead of the default\n";
             cout << "--help\n";
             cout << "   This text\n";
             cout << "\n";


More information about the mythtv-users mailing list