All pastes #190157 Raw Edit

Something

public text v1 · immutable
·published 2006-10-03 19:38 UTC
rendered paste body
Index: programs/mythfilldatabase/filldata.cpp
===================================================================
--- programs/mythfilldatabase/filldata.cpp      (revision 11412)
+++ programs/mythfilldatabase/filldata.cpp      (working copy)
@@ -12,6 +12,7 @@
 #include <qsqldatabase.h>
 #include <qsqlquery.h>
 #include <qurl.h>
+#include <qprocess.h>

 #include <unistd.h>
 #include <signal.h>
@@ -212,6 +213,9 @@
     QString userid;
     QString password;
     QString lineupid;
+    bool xmltvgrabber_baseline;
+    bool xmltvgrabber_manualconfig;
+    bool xmltvgrabber_cache;
 };


@@ -2536,7 +2540,7 @@
         VERBOSE(VB_ALL, "This grabber is no longer supported");
         exit(FILLDB_EXIT_INVALID_CMDLINE);
     }
-
+
     char tempfilename[] = "/tmp/mythXXXXXX";
     if (mkstemp(tempfilename) == -1)
     {
@@ -2551,123 +2555,41 @@
     QString home = QDir::homeDirPath();
     QString configfile = QString("%1/%2.xmltv").arg(MythContext::GetConfDir())
                                                        .arg(source.name);
+    QString cachefile = QString("%1/%2.cache").arg(MythContext::GetConfDir())
+                                                       .arg(source.name);
     QString command;

-    if (xmltv_grabber == "tv_grab_uk")
-        command.sprintf("nice %s --days 7 --config-file '%s' --output %s",
-                        xmltv_grabber.ascii(), configfile.ascii(),
-                        filename.ascii());
-    else if (xmltv_grabber == "tv_grab_uk_rt")
-        command.sprintf("nice %s --days 14 --config-file '%s' --output %s",
-                        xmltv_grabber.ascii(),
-                        configfile.ascii(), filename.ascii());
-    else if (xmltv_grabber == "tv_grab_au")
-        command.sprintf("nice %s --days 7 --config-file '%s' --output %s",
-                        xmltv_grabber.ascii(), configfile.ascii(),
-                        filename.ascii());
-    else if (xmltv_grabber == "tv_grab_de_tvtoday")
-        command.sprintf("nice %s --slow --days 1 --config-file '%s' --offset %d --output %s",
-                        xmltv_grabber.ascii(), configfile.ascii(),
-                        offset, filename.ascii());
-    else if (xmltv_grabber == "tv_grab_fr")
-        command.sprintf("nice %s --days 7 --config-file '%s' --output %s",
-                        xmltv_grabber.ascii(), configfile.ascii(),
-                        filename.ascii());
-    else if (xmltv_grabber == "tv_grab_nl")
-        command.sprintf("nice %s --output %s",
-                        xmltv_grabber.ascii(),
-                        filename.ascii());
-    else if (xmltv_grabber == "tv_grab_fi")
-        // Use the default of 10 days for Finland's grabber
-        command.sprintf("nice %s --config-file '%s' --output %s",
-                        xmltv_grabber.ascii(), configfile.ascii(),
-                        filename.ascii());
-    else if (xmltv_grabber == "tv_grab_es" ||
-             xmltv_grabber == "tv_grab_es_laguiatv")
-        // Use fixed interval of 3 days for Spanish grabber
-        command.sprintf("nice %s --days=4  --config-file '%s' --output %s",
-                        xmltv_grabber.ascii(),
-                        configfile.ascii(), filename.ascii());
-    else if (xmltv_grabber == "tv_grab_jp")
+    if (xmltv_grabber == "tv_grab_jp")
     {
-         // Use fixed interval of 7 days for Japanese grabber
-         command.sprintf("nice %s --days 7 --enable-readstr --config-file '%s' --output %s",
+         command.sprintf("nice %s --enable-readstr --config-file '%s' --output %s",
                          xmltv_grabber.ascii(), configfile.ascii(),
                          filename.ascii());
          isJapan = true;
     }
-    else if (xmltv_grabber == "tv_grab_no")
-        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_se_swedb")
-         command.sprintf("nice %s --days 1 --offset %d --config-file '%s' --output %s",
+    else if (source.xmltvgrabber_cache)
+         command.sprintf("nice %s --offset %d --config-file '%s' --cache '%s' --output %s",
                          xmltv_grabber.ascii(), offset, configfile.ascii(),
-                         filename.ascii());
-    else if (xmltv_grabber == "tv_grab_dk")
-        // Use fixed interval of 7 days for Danish grabber
-        command.sprintf("nice %s --days 7 --config-file '%s' --output %s",
-                        xmltv_grabber.ascii(), configfile.ascii(),
-                        filename.ascii());
-    else if (xmltv_grabber == "tv_grab_pt")
-        // Use fixed interval of 3 days for Portuguese grabber
-        command.sprintf("nice %s --days=4  --config-file '%s' --output %s",
-                        xmltv_grabber.ascii(),
-                        configfile.ascii(), filename.ascii());
-    else if (xmltv_grabber == "tv_grab_be_tvb")
+                         cachefile.ascii(), filename.ascii());
+    else if (source.xmltvgrabber_baseline)
         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_be_tlm")
-        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_ee")
-        // Estonian grabber returns all known data by default
-        command.sprintf("nice %s --output %s",
-                        xmltv_grabber.ascii(),
-                        filename.ascii());
-    else if (xmltv_grabber == "tv_grab_il")
-        // Israeli grabber returns all known data by default
-        command.sprintf("nice %s --config-file '%s' --output %s",
-                        xmltv_grabber.ascii(), configfile.ascii(),
-                        filename.ascii());
-    else if (xmltv_grabber == "tv_grab_ru")
-        // Russian grabber returns all known data by default
-        command.sprintf("nice %s --config-file '%s' --output %s",
-                        xmltv_grabber.ascii(), configfile.ascii(),
-                        filename.ascii());
-    else
+    else if (xmltv_grabber == "datadirect")
     {
         isNorthAmerica = true;
         command.sprintf("nice %s --days 1 --offset %d --config-file '%s' "
                         "--output %s", xmltv_grabber.ascii(),
                         offset, configfile.ascii(), filename.ascii());
     }
+    else
+    {
+        command.sprintf("nice %s --config-file '%s' --output %s --quiet",
+                        xmltv_grabber.ascii(), configfile.ascii(),
+                        filename.ascii());
+    }

-    if (((print_verbose_messages & VB_GENERAL) == 0) &&
-        (xmltv_grabber == "tv_grab_na" ||
-         xmltv_grabber == "tv_grab_de_tvtoday" ||
-         xmltv_grabber == "tv_grab_fi" ||
-         xmltv_grabber == "tv_grab_es" ||
-         xmltv_grabber == "tv_grab_es_laguiatv" ||
-         xmltv_grabber == "tv_grab_se_swedb" ||
-         xmltv_grabber == "tv_grab_no" ||
-         xmltv_grabber == "tv_grab_dk" ||
-         xmltv_grabber == "tv_grab_uk" ||
-         xmltv_grabber == "tv_grab_uk_rt" ||
-         xmltv_grabber == "tv_grab_nl" ||
-         xmltv_grabber == "tv_grab_fr" ||
-         xmltv_grabber == "tv_grab_fi" ||
-         xmltv_grabber == "tv_grab_jp" ||
-         xmltv_grabber == "tv_grab_pt" ||
-         xmltv_grabber == "tv_grab_be_tvb" ||
-         xmltv_grabber == "tv_grab_be_tlm" ||
-         xmltv_grabber == "tv_grab_ee" ||
-         xmltv_grabber == "tv_grab_ru"))
-         command += " --quiet";
+//    if ((print_verbose_messages & VB_GENERAL) == 0) command += " --quiet";

-
     command += graboptions;

     VERBOSE(VB_GENERAL,
@@ -2895,16 +2817,81 @@
         QString xmltv_grabber = (*it).xmltvgrabber;
         need_post_grab_proc |= (xmltv_grabber != "datadirect");

-        if (xmltv_grabber == "tv_grab_uk" || xmltv_grabber == "tv_grab_uk_rt" ||
-            xmltv_grabber == "tv_grab_fi" || xmltv_grabber == "tv_grab_es" ||
-            xmltv_grabber == "tv_grab_es_laguiatv" ||
-            xmltv_grabber == "tv_grab_nl" || xmltv_grabber == "tv_grab_au" ||
-            xmltv_grabber == "tv_grab_fr" || xmltv_grabber == "tv_grab_jp" ||
-            xmltv_grabber == "tv_grab_pt" || xmltv_grabber == "tv_grab_ee" ||
-            xmltv_grabber == "tv_grab_dk")
+// Start
+        QString arg = xmltv_grabber;
+
+        QProcess grabber_capabilities_proc(xmltv_grabber);
+        grabber_capabilities_proc.addArgument("--capabilities");
+        if ( !grabber_capabilities_proc.start() )
         {
+            QString error = grabber_capabilities_proc.readLineStdout();
+            VERBOSE(VB_IMPORTANT, QString("Failed to run %1")
+                .arg(arg));
+        }
+
+        while (grabber_capabilities_proc.isRunning())
+        {
+            usleep(100000);
+        }
+
+        QString capabilites = "";
+
+        if (grabber_capabilities_proc.normalExit())
+        {
+            while (grabber_capabilities_proc.canReadLineStdout())
+            {
+                QString capability = grabber_capabilities_proc.readLineStdout();
+                capabilites += capability + " ";
+
+                if (capability == "baseline")
+                    (*it).xmltvgrabber_baseline = true;
+
+                if (capability == "manualconfig")
+                    (*it).xmltvgrabber_manualconfig = true;
+
+                if (capability == "cache")
+                    (*it).xmltvgrabber_cache = true;
+            }
+        }
+
+        VERBOSE(VB_GENERAL, QString("Grabber has capabilities: %1")
+                .arg(capabilites));
+
+//         if ((*it).xmltvgrabber_cache)
+//         {
+//             QString cachefile = QString("%1/%2_cache.conf").arg(MythContext::GetConfDir())
+//                                                        .arg((*it).name);
+//
+//             QFile file(cachefile);
+//             if (!file.exists())
+//             {
+//                 QString cachedir = QString("%1/%2_cache").arg(MythContext::GetConfDir())
+//                                                         .arg((*it).name);
+//
+//                 if (file.open( IO_WriteOnly )) {
+//                     QTextStream stream( &file );
+//                     stream << "BasePath " << cachedir << "\n";
+//                     stream << "Verbose 1" << "\n";
+//                     file.close();
+//                 }
+//                 else {
+//                     VERBOSE(VB_IMPORTANT, QString("Creating cache config, %1, failed.").arg(cachedir));
+//                     (*it).xmltvgrabber_cache = false;
+//                 }
+//
+//                 QDir dir(cachedir);
+//                 if (!dir.exists() && !dir.mkdir(dir.path()))
+//                 {
+//                     VERBOSE(VB_IMPORTANT, QString("Creating cache directory, %1, failed.").arg(cachedir));
+//                     (*it).xmltvgrabber_cache = false;
+//                 }
+//             }
+//         }
+// End
+
+        if (!(*it).xmltvgrabber_baseline)
+        {
             // These don't support the --offset option, so just grab the max.
-            // TODO: tv_grab_fi/dk/is seems to support --offset, maybe more. Needs verification.
             if (!grabData(*it, 0))
                 ++failures;
         }
@@ -2918,16 +2905,7 @@
                 grabData(*it, 0, &qCurrentDate);
             }
         }
-        else if (xmltv_grabber == "datadirect" ||
-                 xmltv_grabber == "tv_grab_se_swedb" ||
-                 xmltv_grabber == "tv_grab_no" ||
-                 xmltv_grabber == "tv_grab_de_tvtoday" ||
-                 xmltv_grabber == "tv_grab_be_tvb" ||
-                 xmltv_grabber == "tv_grab_be_tlm" ||
-                 xmltv_grabber == "tv_grab_is" ||
-                 xmltv_grabber == "tv_grab_br" ||
-                 xmltv_grabber == "tv_grab_cz" ||
-                 xmltv_grabber == "tv_grab_ru")
+        else if ((*it).xmltvgrabber_baseline)
         {
             // Grabbers supporting the --offset option

@@ -2999,9 +2977,9 @@
                     // Always refresh if the user specified today/tomorrow/second.
                     download_needed = true;
                 }
-                else if (xmltv_grabber == "tv_grab_se_swedb")
+                else if ((*it).xmltvgrabber_cache)
                 {
-                    // Since tv_grab_se_swedb handles caching internally,
+                    // Since the grabber handles caching internally,
                     // let it do its job and always grab new data.
                     VERBOSE(VB_GENERAL,
                             "Data Refresh needed because the grabber relies on "
@@ -3908,6 +3886,9 @@
                        newsource.userid = sourcequery.value(3).toString();
                        newsource.password = sourcequery.value(4).toString();
                        newsource.lineupid = sourcequery.value(5).toString();
+                       newsource.xmltvgrabber_baseline = false;
+                       newsource.xmltvgrabber_manualconfig = false;
+                       newsource.xmltvgrabber_cache = false;

                        sourcelist.append(newsource);
                        if (newsource.xmltvgrabber == "datadirect")