[mythtv] [PATCH] Support for Scheduling changes in DVB EPG

Stuart Auchterlonie stuarta at squashedfrog.net
Fri Apr 8 12:31:13 UTC 2005


Hi all,

I've sat down and come up with a proper patch that adds support for
scheduling changes that show up in the EPG.

What happens is when epg records are received the database is checked
for existing records that conflict with the new data being received.
If there is a conflict detected then the old record is removed in
favour of the new record.

What this means is that if the network moves a show back half an
hour and this change is reflect in the trasmitted EPG then we will
use the new (&correct) information....



Stuart Auchterlonie

-------------- next part --------------
Index: libs/libmythtv/siscan.cpp
===================================================================
--- libs/libmythtv/siscan.cpp	(revision 4)
+++ libs/libmythtv/siscan.cpp	(working copy)
@@ -928,6 +928,7 @@
 void SIScan::AddEvents()
 {
     MSqlQuery query(MSqlQuery::InitCon());
+    MSqlQuery query2(MSqlQuery::InitCon());
     QString theQuery;
     int counter = 0;
 
@@ -997,25 +998,66 @@
 #endif
         for (e = events->begin() ; e != events->end() ; ++e)
         {
+            query.prepare("select starttime, endtime, title "
+                        "from program where (chanid=:CHANID and "
+                        "starttime>=:STARTTIME and starttime<:ENDTIME) "
+                        " and not (chanid=:CHANID and starttime=:STARTTIME "
+                        " and endtime=:ENDTIME and title=:TITLE)");
+            query.bindValue(":CHANID",ChanID);
+            query.bindValue(":STARTTIME",(*e).StartTime.toString(QString("yyyy-MM-dd hh:mm:00")));
+            query.bindValue(":ENDTIME",(*e).EndTime.toString(QString("yyyy-MM-dd hh:mm:00")));
+            query.bindValue(":TITLE",(*e).Event_Name.utf8());
 
-            query.prepare("select * from  program where chanid=:CHANID and "
-                      "starttime=:STARTTIME and title=:TITLE;");
+            if(!query.exec())
+                MythContext::DBError("Checking Rescheduled Event", query);
+            if (!query.isActive())
+                MythContext::DBError("Checking Rescheduled Event", query);
+
+            for (int i=query.first(); i<query.size();i++, query.next()) 
+            // New guide data overriding existing
+            // Possibly more than one conflict
+            {
+                VERBOSE(VB_GENERAL, QString("Schedule Change on Channel %1:\n"
+                    "Old Program: S=%2 E=%3 %4\n"
+                    "New Program: S=%5 E=%6 %7") 
+                    .arg(ChanID)
+                    .arg(query.value(0).toString())
+                    .arg(query.value(1).toString())
+                    .arg(query.value(2).toString())
+                    .arg((*e).StartTime.toString(QString("yyyy-MM-dd hh:mm:00")))
+                    .arg((*e).EndTime.toString(QString("yyyy-MM-dd hh:mm:00")))
+                    .arg((*e).Event_Name.utf8()));
+                // Delete old EPG record.
+                query2.prepare("delete from program where chanid=:CHANID and "
+                    "starttime=:STARTTIME and endtime=:ENDTIME and title=:TITLE");
+                query2.bindValue(":CHANID",ChanID);
+                query2.bindValue(":STARTTIME",query.value(0).toString());
+                query2.bindValue(":ENDTIME",query.value(1).toString());
+                query2.bindValue(":TITLE",query.value(2).toString());
+                if(!query2.exec())
+                    MythContext::DBError("Deleting Rescheduled Event", query2);
+                if (!query2.isActive())
+                    MythContext::DBError("Deleting Rescheduled Event", query2);
+            }
+
+            query.prepare("select 1 from program where chanid=:CHANID and "
+                        "starttime=:STARTTIME and endtime=:ENDTIME and "
+                        "title=:TITLE");
             query.bindValue(":CHANID",ChanID);
             query.bindValue(":STARTTIME",(*e).StartTime.toString(QString("yyyy-MM-dd hh:mm:00")));
             query.bindValue(":ENDTIME",(*e).EndTime.toString(QString("yyyy-MM-dd hh:mm:00")));
             query.bindValue(":TITLE",(*e).Event_Name.utf8());
 
             if(!query.exec())
-                MythContext::DBError("Checking Event", query);
-
+                MythContext::DBError("Checking If Event Exists", query);
             if (!query.isActive())
-                MythContext::DBError("Checking Event", query);
+                MythContext::DBError("Checking If Event Exists", query);
 
             if (query.size() <= 0)
             {
-                 counter++;
+                counter++;
 
-                 query.prepare("INSERT INTO program (chanid,starttime,endtime,"
+                query.prepare("REPLACE INTO program (chanid,starttime,endtime,"
                           "title,description,subtitle,category,"
                           "stereo,closecaptioned,hdtv,airdate,originalairdate)"
                           "VALUES (:CHANID,:STARTTIME,:ENDTIME,:TITLE,:DESCRIPTION,:SUBTITLE,:CATEGORY,:STEREO,:CLOSECAPTIONED,:HDTV,:AIRDATE,:ORIGINALAIRDATE);");
@@ -1036,7 +1078,7 @@
                     MythContext::DBError("Adding Event", query);
 
                 if (!query.isActive())
-                   MythContext::DBError("Adding Event", query);
+                    MythContext::DBError("Adding Event", query);
 
                 for(QValueList<Person>::Iterator it=(*e).Credits.begin();it!=(*e).Credits.end();it++)
                 {
@@ -1063,7 +1105,6 @@
                     if (!query.isActive())
                         MythContext::DBError("Adding Event (Credits)", query);
                 }
-
             }
         }
 
@@ -1079,4 +1120,3 @@
     }
     pthread_mutex_unlock(&events_lock);
 }
-


More information about the mythtv-dev mailing list