[mythtv-users] Per-channel time offset?

Joel Feenstra joelf at altelco.net
Tue Jul 29 22:36:21 EDT 2003


I had written a patch for that, I still have it, but I doubt it will 
apply cleanly to current cvs. I didn't need it anymore, but I will in a 
month (when I head back to school) so I'll probably get that working 
again. I've attached it if you want to mess with it. If you get it to 
work with current cvs please put it on the list.

Joel Feenstra

Will Dormann wrote:
> Running MythTV 0.10
> 
> Is it possible to have a time offset for a particular channel.   One
> particular channel is a couple of minutes behind schedule and I always miss
> the end of the show.
> 
> thanks
> -WD
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> mythtv-users mailing list
> mythtv-users at snowman.net
> http://lists.snowman.net/cgi-bin/mailman/listinfo/mythtv-users
-------------- next part --------------
Index: database/0-8-to-0-9.sql
===================================================================
RCS file: MC/database/0-8-to-0-9.sql,v
retrieving revision 1.2
diff -u -w -r1.2 0-8-to-0-9.sql
--- database/0-8-to-0-9.sql	19 Apr 2003 03:59:50 -0000	1.2
+++ database/0-8-to-0-9.sql	21 Apr 2003 23:24:40 -0000
@@ -22,6 +22,8 @@
 
 ALTER TABLE videosource ADD COLUMN userid VARCHAR(128) NOT NULL default '';
 
+ALTER TABLE channel ADD COLUMN timeoffset VARCHAR(128) NOT NULL default '';
+
 CREATE INDEX progid ON record (chanid, starttime);
 CREATE INDEX title ON record (title(10)); 
 CREATE INDEX title ON program (title(10));   
Index: programs/mythfilldatabase/filldata.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythfilldatabase/filldata.cpp,v
retrieving revision 1.55
diff -u -w -r1.55 filldata.cpp
--- programs/mythfilldatabase/filldata.cpp	20 Apr 2003 01:13:51 -0000	1.55
+++ programs/mythfilldatabase/filldata.cpp	21 Apr 2003 23:24:44 -0000
@@ -43,6 +43,7 @@
                                       xmltvid = other.xmltvid;
                                       name = other.name;
                                       finetune = other.finetune;
+                                      timeoffset = other.timeoffset;
                                     }

     QString callsign;
@@ -51,6 +52,7 @@
     QString xmltvid;
     QString name;
     QString finetune;
+    QString timeoffset;
 };

 struct ProgRating
@@ -169,8 +171,44 @@
     return "";
 }

-ChanInfo *parseChannel(QDomElement &element, QUrl baseUrl)
+int getChannelTimeOffset(QString xmltvid, int sourceid)
 {
+    QString default_offset = gContext->GetSetting("TimeOffset");
+
+    int offset = 0;
+    int offset_sign = 1;
+
+    if (default_offset != "")
+        offset = default_offset.left(1).toInt() *
+                 (default_offset.mid(1,2).toInt() * 60 + default_offset.right(2).toInt());
+
+
+    // Check to see if an offset in the db exists that is different than the given offset
+    QString querystr;
+    querystr.sprintf("SELECT timeoffset FROM channel "
+                     "WHERE xmltvid = \"%s\" AND sourceid = %d"
+                     , xmltvid.ascii(), sourceid);
+
+    QSqlQuery query;
+    query.exec(querystr);
+
+    if (query.isActive() && query.numRowsAffected() > 0)
+    {
+        query.next();
+        if (query.value(0).toString() != "")
+            if (query.value(0).toString().left(1) == "-")
+                offset_sign = -1;
+
+            offset = query.value(0).toString().left(3).toInt() * 60 +
+                      (offset_sign * query.value(0).toString().right(2).toInt());
+    }
+
+    return offset;
+}
+
+ChanInfo *parseChannel(QDomElement &element, QUrl baseUrl, int sourceid)
+{
+
     ChanInfo *chaninfo = new ChanInfo;
 
     QString xmltvid = element.attribute("id", "");
@@ -232,35 +270,35 @@
         }
     }
 
+    chaninfo->timeoffset = getChannelTimeOffset(chaninfo->xmltvid, sourceid);
+
     return chaninfo;
 }
 
-void addTimeOffset(QString &timestr, int config_off, QString offset )
+void addTimeOffset(QString &timestr, int offset)
 {
-    bool ok;
-    int off = offset.stripWhiteSpace().left(3).toInt(&ok, 10);
+    bool ok = true;
             
-    if (ok && (off != config_off))
+    if (ok)
     {
-        int diff = config_off - off;
         int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0;
                 
         if (timestr.length() == 14)
         {
-            year  = timestr.left(4).toInt(&ok, 10);
-            month = timestr.mid(4,2).toInt(&ok, 10);
-            day   = timestr.mid(6,2).toInt(&ok, 10);
-            hour  = timestr.mid(8,2).toInt(&ok, 10);
-            min   = timestr.mid(10,2).toInt(&ok, 10);
-            sec   = timestr.mid(12,2).toInt(&ok, 10);
+            year  = timestr.left(4).toInt();
+            month = timestr.mid(4,2).toInt();
+            day   = timestr.mid(6,2).toInt();
+            hour  = timestr.mid(8,2).toInt();
+            min   = timestr.mid(10,2).toInt();
+            sec   = timestr.mid(12,2).toInt();
         }
         else if (timestr.length() == 12)
         {
-            year  = timestr.left(4).toInt(&ok, 10);
-            month = timestr.mid(4,2).toInt(&ok, 10);
-            day   = timestr.mid(6,2).toInt(&ok, 10);
-            hour  = timestr.mid(8,2).toInt(&ok, 10);
-            min   = timestr.mid(10,2).toInt(&ok, 10);
+            year  = timestr.left(4).toInt();
+            month = timestr.mid(4,2).toInt();
+            day   = timestr.mid(6,2).toInt();
+            hour  = timestr.mid(8,2).toInt();
+            min   = timestr.mid(10,2).toInt();
             sec   = 0;
         }
         else
@@ -269,11 +307,12 @@
         }
                 
         QDateTime dt = QDateTime(QDate(year, month, day),QTime(hour, min, sec));
-        dt = dt.addSecs(diff * 60 * 60);
+        dt = dt.addSecs(offset * 60);
         timestr = dt.toString("yyyyMMddhhmmss");
     }
     else if (isgist)
     {
+    // Note, this doesn't work anymore. Specifically offset is a different offset now
 #if 0
         int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0;
 
@@ -314,61 +353,41 @@
     }
 }
 
-ProgInfo *parseProgram(QDomElement &element)
+ProgInfo *parseProgram(QDomElement &element, int sourceid)
 {
-    QString config_offset = gContext->GetSetting("TimeOffset");
-    
-    bool ok;
-    int config_off = 0;
-
-    if (config_offset != "")
-        config_off = config_offset.left(3).toInt(&ok, 10);
 
     ProgInfo *pginfo = new ProgInfo;
  
     QString text = element.attribute("start", "");
     QStringList split = QStringList::split(" ", text);
 
-    QString st = split[0];
-    QString offset;
-    if (split.size() > 1)
-        offset = split[1];
-    else
-        offset = config_offset;
-
-    if (config_off >= 0 && config_off <= 24 && offset != "")
-        addTimeOffset(st, config_off, offset);
-
-    pginfo->startts = st;
+    pginfo->startts = split[0];
 
     text = element.attribute("stop", "");
     split = QStringList::split(" ", text);
 
-    QString et;
-
     if (split.size() > 0)
     {
-        et = split[0];
-        if (split.size() > 1)
-            offset = split[1];
-        else
-            offset = config_offset;
+        pginfo->endts = split[0];
     }
     else
-        et = "";
-
-    if (config_off >= 0 && config_off <= 24 && offset != "")
-        addTimeOffset(et, config_off, offset);
-
-    pginfo->endts = et;
+        pginfo->endts = "";
 
     text = element.attribute("channel", "");
     split = QStringList::split(" ", text);
     
     pginfo->channel = split[0];
 
-    pginfo->start = fromXMLTVDate(pginfo->startts);
-    pginfo->end = fromXMLTVDate(pginfo->endts);
+    QString st = pginfo->startts;
+    QString et = pginfo->endts;
+
+    addTimeOffset(st, getChannelTimeOffset(pginfo->channel, sourceid));
+    if (et.length() > 0)
+        addTimeOffset(et, getChannelTimeOffset(pginfo->channel, sourceid));
+
+
+    pginfo->start = fromXMLTVDate(st);
+    pginfo->end = fromXMLTVDate(et);
 
     pginfo->subtitle = pginfo->title = pginfo->desc = pginfo->category = "";
     pginfo->repeat = false;   
@@ -454,7 +473,7 @@
 }
                   
 void parseFile(QString filename, QValueList<ChanInfo> *chanlist,
-               QMap<QString, QValueList<ProgInfo> > *proglist)
+               QMap<QString, QValueList<ProgInfo> > *proglist, int sourceid)
 {
     QDomDocument doc;
     QFile f(filename);
@@ -494,13 +513,13 @@
         {
             if (e.tagName() == "channel")
             {
-                ChanInfo *chinfo = parseChannel(e, baseUrl);
+                ChanInfo *chinfo = parseChannel(e, baseUrl, sourceid);
                 chanlist->push_back(*chinfo);
                 delete chinfo;
             }
             else if (e.tagName() == "programme")
             {
-                ProgInfo *pginfo = parseProgram(e);
+                ProgInfo *pginfo = parseProgram(e, sourceid);
                 (*proglist)[pginfo->channel].push_back(*pginfo);
                 delete pginfo;
             }
@@ -629,6 +648,8 @@
 
     (*chaninfo).iconpath = getResponse("Choose a channel icon image (any path "
                                        "name) ",(*chaninfo).iconpath);
+    (*chaninfo).timeoffset = getResponse("Choose a time offset (eg -0100 or "
+                                         " +0200 ect.) ",(*chaninfo).timeoffset);
 
     return(chanid);
 }
@@ -674,7 +695,7 @@
         QSqlQuery query;
 
         QString querystr;
-        querystr.sprintf("SELECT chanid,name,callsign,channum,finetune,icon "
+        querystr.sprintf("SELECT chanid,name,callsign,channum,finetune,icon,timeoffset "
                          "FROM channel WHERE xmltvid = \"%s\" AND "
                          "sourceid = %d;", (*i).xmltvid.ascii(), id); 
 
@@ -691,6 +712,7 @@
                 QString chanstr  = QString::fromUtf8(query.value(3).toString());
                 QString finetune = QString::fromUtf8(query.value(4).toString());
                 QString icon     = QString::fromUtf8(query.value(5).toString());
+                QString timeoffset = QString::fromUtf8(query.value(6).toString());
 
                 cout << "### " << endl;
                 cout << "### Existing channel found" << endl;
@@ -702,12 +724,14 @@
                 cout << "### channum  = " << chanstr.ascii()      << endl;
                 cout << "### finetune = " << finetune.ascii()     << endl;
                 cout << "### icon     = " << icon.ascii()         << endl;
+                cout << "### timeoffset = " << timeoffset.ascii()   << endl;
                 cout << "### " << endl;
 
                 (*i).name = name;
                 (*i).callsign = callsign;
                 (*i).chanstr  = chanstr;
                 (*i).finetune = finetune;
+                (*i).timeoffset = timeoffset;
 
                 promptForChannelUpdates(i, atoi(chanid.ascii()));
 
@@ -715,12 +739,13 @@
                     callsign != (*i).callsign ||
                     chanstr  != (*i).chanstr ||
                     finetune != (*i).finetune ||
+                    timeoffset != (*i).timeoffset ||
                     icon     != localfile)
                 {
                     querystr.sprintf("UPDATE channel SET chanid = %s, "
                                      "name = \"%s\", callsign = \"%s\", "
                                      "channum = \"%s\", finetune = %d, "
-                                     "icon = \"%s\" WHERE xmltvid = \"%s\" "
+                                     "icon = \"%s\", timeoffset = \"%s\" WHERE xmltvid = \"%s\" "
                                      "AND sourceid = %d;",
                                      chanid.ascii(),
                                      (*i).name.ascii(),
@@ -728,6 +753,7 @@
                                      (*i).chanstr.ascii(),
                                      atoi((*i).finetune.ascii()),
                                      localfile.ascii(),
+                                     (*i).timeoffset.ascii(),
                                      (*i).xmltvid.ascii(),
                                      id);
 
@@ -780,6 +806,7 @@
                 cout << "### channum  = " << (*i).chanstr.ascii()      << endl;
                 cout << "### finetune = " << (*i).finetune.ascii()     << endl;
                 cout << "### icon     = " << localfile.ascii()         << endl;
+                cout << "### timeoffset = " << (*i).timeoffset.ascii()   << endl;
                 cout << "### " << endl;
 
                 unsigned int chanid = promptForChannelUpdates(i,0);
@@ -787,15 +814,16 @@
                 if (chanid > 0)
                 {
                     querystr.sprintf("INSERT INTO channel (chanid,name,"
-                                     "callsign,channum,finetune,icon,"
+                                     "callsign,channum,finetune,icon,timeoffset,"
                                      "xmltvid,sourceid) VALUES(%d,\"%s\","
-                                     "\"%s\",\"%s\",%d,\"%s\",\"%s\",%d);", 
+                                     "\"%s\",\"%s\",%d,\"%s\",\"%s\",\"%s\",%d);",
                                      chanid,
                                      (*i).name.ascii(),
                                      (*i).callsign.ascii(),
                                      (*i).chanstr.ascii(),
                                      atoi((*i).finetune.ascii()),
                                      localfile.ascii(),
+                                     (*i).timeoffset.ascii(),
                                      (*i).xmltvid.ascii(),
                                      id);
 
@@ -842,8 +870,8 @@
                 }
 
                 querystr.sprintf("INSERT INTO channel (chanid,name,callsign,"
-                                 "channum,finetune,icon,xmltvid,sourceid) "
-                                 "VALUES(%d,\"%s\",\"%s\",\"%s\",%d,\"%s\","
+                                 "channum,finetune,icon,timeoffset,xmltvid,sourceid) "
+                                 "VALUES(%d,\"%s\",\"%s\",\"%s\",\"%s\",%d,\"%s\","
                                  "\"%s\",%d);", 
                                  chanid,
                                  (*i).name.ascii(),
@@ -851,6 +879,7 @@
                                  (*i).chanstr.ascii(),
                                  atoi((*i).finetune.ascii()),
                                  localfile.ascii(),
+                                 (*i).timeoffset.ascii(),
                                  (*i).xmltvid.ascii(),
                                  id);
 
@@ -1090,7 +1119,7 @@
     QValueList<ChanInfo> chanlist;
     QMap<QString, QValueList<ProgInfo> > proglist;
 
-    parseFile(filename, &chanlist, &proglist);
+    parseFile(filename, &chanlist, &proglist, id);
 
     handleChannels(id, &chanlist);
     handlePrograms(id, offset, &proglist);
@@ -1275,7 +1304,7 @@
                 if (query.isActive() && query.numRowsAffected() > 0) {
 
                     query.next();
-                    if (query.value(0).toInt() < 60)
+                    if (query.value(0).toInt() < 20)
                         grabData(*it, i);
 
                 } else {
@@ -1331,7 +1360,7 @@
     return (failures == 0);
 }
 
-ChanInfo *xawtvChannel(QString &id, QString &channel, QString &fine)
+ChanInfo *xawtvChannel(QString &id, QString &channel, QString &fine, int sourceid)
 {
     ChanInfo *chaninfo = new ChanInfo;
     chaninfo->xmltvid = id;
@@ -1342,6 +1371,9 @@
 
     chaninfo->iconpath = "";
 
+
+    chaninfo->timeoffset = getChannelTimeOffset(chaninfo->xmltvid, sourceid);
+
     return chaninfo;
 }
 
@@ -1371,7 +1403,7 @@
                 {
                     if ((xawid != "") && (channel != ""))
                     {
-                        ChanInfo *chinfo = xawtvChannel(xawid, channel, fine);
+                        ChanInfo *chinfo = xawtvChannel(xawid, channel, fine, id);
                         chanlist.push_back(*chinfo);
                         delete chinfo;
                     }
@@ -1400,7 +1432,7 @@
 
     if ((xawid != "") && (channel != ""))
     {
-        ChanInfo *chinfo = xawtvChannel(xawid, channel, fine);
+        ChanInfo *chinfo = xawtvChannel(xawid, channel, fine, id);
         chanlist.push_back(*chinfo);
         delete chinfo;
     }


More information about the mythtv-users mailing list