[mythtv] XMLTV - DataDirect patch

David Shay david at shay.net
Tue Mar 23 23:47:42 EST 2004


Here is a patch that enables usage of the datadirect service (labs.zap2it.com).  I had to make some modifications to the tv_grab_na_dd that is currently in the xmltv package to make this work (to fully enable GUI interaction).  I am going to work with the xmltv maintainer to work this functionality into the final release.  For now, though, just overwrite the version of tv_grab_na_dd that comes in the latest release with the one attached here.

Please let me know if this works for you.

I had initially intended to fully integrate this functionality directly into Myth, but ran across several roadblocks, the first of which was the lack of authentication functionality in the QHttp class. It was much easier to use the perl SOAP module which includes this functionality.

Also, this patch does not enable really all of the new potential of the service.  I would like to do the following eventually:
* Include the program ID and series ID indicator for improved scheduling ease
* Grab all category information and include in new table
* Get the data all in one fell swoop instead of 13 separate iterations.  Also, with the new service, it would be easy/less of a drain to do a complete update of guide data every single day
* Optimize performance -- eliminate the extra XML conversion step, potentially use temporary database tables which would map to the datadirect structures closely

Any other ideas?

Don't be too harsh -- this is my first real efforts in C++ or Qt...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mythtv.org/pipermail/mythtv-dev/attachments/20040324/47805c69/tv_grab_na_dd.htm
-------------- next part --------------
Index: libs/libmythtv/dbcheck.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/dbcheck.cpp,v
retrieving revision 1.37
diff -u -r1.37 dbcheck.cpp
--- libs/libmythtv/dbcheck.cpp	14 Mar 2004 07:35:32 -0000	1.37
+++ libs/libmythtv/dbcheck.cpp	24 Mar 2004 04:28:00 -0000
@@ -8,7 +8,7 @@
 
 #include "mythcontext.h"
 
-const QString currentDatabaseVersion = "1035";
+const QString currentDatabaseVersion = "1036";
 
 void UpdateDBVersionNumber(const QString &newnumber)
 {
@@ -670,6 +670,17 @@
 };
         performActualUpdate(updates, "1035", dbver);
     }
+
+    if (dbver == "1035")
+    {
+        const QString updates[] = {
+"ALTER TABLE videosource ADD datadirectlineupid VARCHAR(255) NULL;",
+"ALTER TABLE videosource ADD datadirectuserid VARCHAR(64) NULL;",
+"ALTER TABLE videosource ADD datadirectpassword VARCHAR(64) NULL;",
+""
+};
+        performActualUpdate(updates, "1036", dbver);
+    }
 }
 
 void InitializeDatabase(void)
Index: libs/libmythtv/videosource.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/videosource.cpp,v
retrieving revision 1.47
diff -u -r1.47 videosource.cpp
--- libs/libmythtv/videosource.cpp	2 Mar 2004 06:31:52 -0000	1.47
+++ libs/libmythtv/videosource.cpp	24 Mar 2004 04:28:01 -0000
@@ -72,6 +72,67 @@
         .arg(getValue());
 }
 
+void DataDirectLineupSelector::fillSelections(const QString& uid, const QString& pwd) {
+
+    QString waitMsg = QString("Fetching lineups from DataDirect service for this account... Please be patient.");
+    VERBOSE(VB_GENERAL, waitMsg);
+    MythProgressDialog pdlg(waitMsg, 2);
+    clearSelections();
+    pdlg.show();
+    QString filename = QString("%1/.mythtv/%2.xmltv")
+        .arg(QDir::homeDirPath()).arg(parent.getSourceName());
+    QString pwdfilename = QString("%1/.mythtv/%2.xmltv.pwd")
+        .arg(QDir::homeDirPath()).arg(parent.getSourceName());    
+    QString command = QString("tv_grab_na_dd --config-file '%1' --password-file '%2' --autoconfigure --dd_user %3 --dd_password %4")
+        .arg(filename)
+        .arg(pwdfilename)
+        .arg(uid)
+        .arg(pwd);
+     int ret=system(command);
+
+   if (ret != 0)
+   {  
+     VERBOSE(VB_GENERAL, command);
+        VERBOSE(VB_GENERAL, QString("exited with status %1").arg(ret));
+        MythPopupBox::showOkPopup(gContext->GetMainWindow(),
+                                  QObject::tr("Failed to retrieve lineup information "),
+                                  QObject::tr("MythTV was unable to retrieve lineup information from "
+                                              "the DataDirect service.\n"
+                                              "Please check the "
+                                              "terminal window for more "
+                                              "information"));
+       return;                                       
+    }
+     
+      QString command2 = QString("tv_grab_na_dd --config-file '%1' --password-file '%2' --lineup list")
+        .arg(filename)
+        .arg(pwdfilename);
+      FILE* fp = popen(command2.ascii(), "r");
+
+      if (fp == NULL) {
+        pdlg.Close();
+        VERBOSE(VB_GENERAL, "Failed to retrieve lineup list");
+        MythPopupBox::showOkPopup(gContext->GetMainWindow(), 
+                            QObject::tr("Failed to retrieve lineup list"), 
+                            QObject::tr("You probably need to update the XMLTV datadirect grabber."));
+        qApp->processEvents();
+        perror(command2.ascii());
+        return;
+      }
+    pdlg.setProgress(1);
+
+    QFile f;
+    f.open(IO_ReadOnly, fp);
+    for(QString line ; f.readLine(line, 1024) > 0 ; ) {
+        addSelection(line.stripWhiteSpace(),line.stripWhiteSpace());
+    }
+    pdlg.setProgress( 2 );
+    pdlg.Close();
+    f.close();
+    fclose(fp);
+    
+}
+
 void RegionSelector::fillSelections() {
     clearSelections();
 
Index: libs/libmythtv/videosource.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/videosource.h,v
retrieving revision 1.62
diff -u -r1.62 videosource.h
--- libs/libmythtv/videosource.h	2 Mar 2004 06:31:52 -0000	1.62
+++ libs/libmythtv/videosource.h	24 Mar 2004 04:28:02 -0000
@@ -28,6 +28,40 @@
     const VideoSource& parent;
 };
 
+class DataDirectUserID: public LineEditSetting, public VSSetting {
+public:
+  DataDirectUserID(const VideoSource& parent): VSSetting(parent, "datadirectuserid") {
+       setLabel(QObject::tr("Data Direct User ID"));
+   };
+};   
+
+class DataDirectPassword: public LineEditSetting, public VSSetting {
+public:
+  DataDirectPassword(const VideoSource& parent): VSSetting(parent, "datadirectpassword") {
+       setLabel(QObject::tr("Data Direct Password"));
+   };
+};   
+
+class DataDirectButton: public ButtonSetting, public TransientStorage {
+   Q_OBJECT
+public:
+  DataDirectButton() {
+    setLabel(QObject::tr("Retrieve Lineups"));
+   };
+// public slots:
+//  void pressed();
+};
+
+class DataDirectLineupSelector: public ComboBoxSetting, public VSSetting {
+   Q_OBJECT
+public:
+  DataDirectLineupSelector(const VideoSource& parent): VSSetting(parent, "datadirectlineupid") {
+       setLabel(QObject::tr("Data Direct Lineup"));
+   };
+   
+ public slots:
+    void fillSelections(const QString& uid, const QString& pwd);
+};   
 
 class XMLTVGrabber: public ComboBoxSetting, public VSSetting {
 public:
@@ -100,6 +134,40 @@
     QString freq;
 };
 
+class DataDirect_config: public VerticalConfigurationGroup {
+   Q_OBJECT
+public:
+    DataDirect_config(const VideoSource& _parent): parent(_parent) {
+        setLabel(QObject::tr("DataDirect configuration"));
+        datadirectuserid = new DataDirectUserID(parent);
+        addChild(datadirectuserid);
+        datadirectpassword = new DataDirectPassword(parent);
+        addChild(datadirectpassword);
+        datadirectbutton = new DataDirectButton();
+        addChild(datadirectbutton);
+        datadirectlineupselector = new DataDirectLineupSelector(parent);
+        addChild(datadirectlineupselector);
+        if (datadirectuserid->getValue()  != "") {
+            fillDataDirectLineupSelector();
+            }
+        connect(datadirectbutton, SIGNAL(pressed()),
+                this, SLOT(fillDataDirectLineupSelector()));
+  }
+          
+   protected slots:
+   
+   void fillDataDirectLineupSelector() {
+         datadirectlineupselector->fillSelections(datadirectuserid->getValue(),datadirectpassword->getValue());
+   }
+    
+  protected:
+    const VideoSource& parent;
+    DataDirectUserID* datadirectuserid;
+    DataDirectPassword* datadirectpassword;
+    DataDirectLineupSelector* datadirectlineupselector;
+    DataDirectButton* datadirectbutton;
+  };
+
 class XMLTV_na_config: public VerticalConfigurationGroup {
     Q_OBJECT
 public:
@@ -183,6 +251,9 @@
         // only save settings for the selected grabber
         setSaveAll(false);
 
+        addTarget("tv_grab_na_dd", new DataDirect_config(parent));
+        grabber->addSelection("North America (datadirect)","tv_grab_na_dd");
+        
         addTarget("tv_grab_na", new XMLTV_na_config(parent));
         grabber->addSelection("North America (xmltv)", "tv_grab_na");
 
Index: programs/mythfilldatabase/filldata.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfilldatabase/filldata.cpp,v
retrieving revision 1.96
diff -u -r1.96 filldata.cpp
--- programs/mythfilldatabase/filldata.cpp	14 Mar 2004 07:35:32 -0000	1.96
+++ programs/mythfilldatabase/filldata.cpp	24 Mar 2004 04:28:04 -0000
@@ -147,6 +147,9 @@
     int id;
     QString name;
     QString xmltvgrabber;
+    QString datadirectuserid;
+    QString datadirectpassword;
+    QString datadirectlineupid;
     QString userid;
 };
 
@@ -1430,6 +1433,8 @@
     QString home = QDir::homeDirPath();
     QString configfile = QString("%1/.mythtv/%2.xmltv").arg(home)
                                                        .arg(source.name);
+    QString pwdfile = QString("%1/.mythtv/%2.xmltv.pwd").arg(home)
+                                                       .arg(source.name);                                                   
     QString command;
     QString xmltv_grabber = source.xmltvgrabber;
 
@@ -1491,13 +1496,20 @@
     else
     {
         isNorthAmerica = true;
-        command.sprintf("nice %s --days 1 --offset %d --config-file '%s' "
+        if (xmltv_grabber == "tv_grab_na")
+           command.sprintf("nice %s --days 1 --offset %d --config-file '%s' "
                         "--output %s", xmltv_grabber.ascii(),
                         offset, configfile.ascii(), filename.ascii());
+        else if (xmltv_grabber == "tv_grab_na_dd")
+           command.sprintf("nice %s --config-file '%s' --password-file '%s' --days 1 --offset %d "
+                           "--old-chan-id --output %s --lineup '%s'",xmltv_grabber.ascii(),
+                           configfile.ascii(), pwdfile.ascii(), offset, filename.ascii(), source.datadirectlineupid.ascii());
+            
     }
 
     if (quiet &&
         (xmltv_grabber == "tv_grab_na" ||
+         xmltv_grabber == "tv_grab_na_dd" ||
          xmltv_grabber == "tv_grab_de" ||
          xmltv_grabber == "tv_grab_fi" ||
          xmltv_grabber == "tv_grab_es" ||
@@ -1673,7 +1685,8 @@
                                          query);
             }
         }
-        else if (xmltv_grabber == "tv_grab_na" || 
+        else if (xmltv_grabber == "tv_grab_na" ||
+                 xmltv_grabber == "tv_grab_na_dd" || 
                  xmltv_grabber == "tv_grab_uk_rt" ||
                  xmltv_grabber == "tv_grab_sn")
         {
@@ -1710,7 +1723,9 @@
             if (xmltv_grabber == "tv_grab_uk_rt" ||
                 xmltv_grabber == "tv_grab_sn")
                 maxday = 14;
-
+            if (xmltv_grabber == "tv_grab_na_dd") maxday=13;
+                
+                
             for (int i = 0; i < maxday; i++)
             {
                 if ((i == 0 && refresh_today) || (i == 1 && refresh_tomorrow) ||
@@ -2173,7 +2188,7 @@
         QValueList<Source> sourcelist;
 
         QSqlQuery sourcequery;
-        QString querystr = QString("SELECT sourceid,name,xmltvgrabber,userid "
+        QString querystr = QString("SELECT sourceid,name,xmltvgrabber,userid,datadirectuserid,datadirectpassword,datadirectlineupid "
                                    "FROM videosource ORDER BY sourceid;");
         sourcequery.exec(querystr);
         
@@ -2189,7 +2204,9 @@
                        newsource.name = sourcequery.value(1).toString();
                        newsource.xmltvgrabber = sourcequery.value(2).toString();
                        newsource.userid = sourcequery.value(3).toString();
-
+                       newsource.datadirectuserid = sourcequery.value(4).toString();
+                       newsource.datadirectpassword = sourcequery.value(5).toString();
+                       newsource.datadirectlineupid = sourcequery.value(6).toString();
                        sourcelist.append(newsource);
                   }
              }


More information about the mythtv-dev mailing list