Ticket #1777: mythfilldatabase_capabilities_backport.diff

File mythfilldatabase_capabilities_backport.diff, 28.5 KB (added by stuartm, 17 years ago)

Backport of the --capabilties changes to -fixes

  • mythtv/programs/mythfilldatabase/filldata.cpp

     
    1212#include <qsqldatabase.h>
    1313#include <qsqlquery.h>
    1414#include <qurl.h>
     15#include <qprocess.h>
    1516
    1617#include <unistd.h>
    1718#include <signal.h>
     
    5455bool isNorthAmerica = false;
    5556bool isJapan = false;
    5657bool interrupted = false;
     58bool endofdata = false;
    5759bool refresh_today = false;
    5860bool refresh_tomorrow = true;
    5961bool refresh_second = false;
     
    212214    QString userid;
    213215    QString password;
    214216    QString lineupid;
     217    bool    xmltvgrabber_baseline;
     218    bool    xmltvgrabber_manualconfig;
     219    bool    xmltvgrabber_cache;
     220    QString xmltvgrabber_prefmethod;
    215221};
    216222
    217223
     
    25052511        return false;
    25062512
    25072513    handleChannels(id, &chanlist);
     2514    if (proglist.count() == 0) {
     2515        VERBOSE(VB_GENERAL,
     2516                QString("No programs found in data."));
     2517        endofdata = true;
     2518    }
     2519    else {
     2520        handlePrograms(id, &proglist);
     2521    }
    25082522    handlePrograms(id, &proglist);
    25092523    return true;
    25102524}
     
    25332547        return grabDDData(source, offset, *qCurrentDate, DD_ZAP2IT);
    25342548    else if (xmltv_grabber == "technovera")
    25352549    {
    2536         VERBOSE(VB_ALL, "This grabber is no longer supported");
     2550        VERBOSE(VB_IMPORTANT, "The technovera grabber is no longer supported");
    25372551        exit(FILLDB_EXIT_INVALID_CMDLINE);
    25382552    }
    2539        
     2553
    25402554    char tempfilename[] = "/tmp/mythXXXXXX";
    25412555    if (mkstemp(tempfilename) == -1)
    25422556    {
     
    25512565    QString home = QDir::homeDirPath();
    25522566    QString configfile = QString("%1/%2.xmltv").arg(MythContext::GetConfDir())
    25532567                                                       .arg(source.name);
    2554     QString command;
    25552568
    2556     if (xmltv_grabber == "tv_grab_uk")
    2557         command.sprintf("nice %s --days 7 --config-file '%s' --output %s",
    2558                         xmltv_grabber.ascii(), configfile.ascii(),
    2559                         filename.ascii());
    2560     else if (xmltv_grabber == "tv_grab_uk_rt")
    2561         command.sprintf("nice %s --days 14 --config-file '%s' --output %s",
    2562                         xmltv_grabber.ascii(),
    2563                         configfile.ascii(), filename.ascii());
    2564     else if (xmltv_grabber == "tv_grab_au")
    2565         command.sprintf("nice %s --days 7 --config-file '%s' --output %s",
    2566                         xmltv_grabber.ascii(), configfile.ascii(),
    2567                         filename.ascii());
    2568     else if (xmltv_grabber == "tv_grab_de_tvtoday")
    2569         command.sprintf("nice %s --slow --days 1 --config-file '%s' --offset %d --output %s",
    2570                         xmltv_grabber.ascii(), configfile.ascii(),
    2571                         offset, filename.ascii());
    2572     else if (xmltv_grabber == "tv_grab_fr")
    2573         command.sprintf("nice %s --days 7 --config-file '%s' --output %s",
    2574                         xmltv_grabber.ascii(), configfile.ascii(),
    2575                         filename.ascii());
    2576     else if (xmltv_grabber == "tv_grab_nl")
    2577         command.sprintf("nice %s --config-file '%s' --output %s",
    2578                         xmltv_grabber.ascii(), configfile.ascii(),
    2579                         filename.ascii());
    2580     else if (xmltv_grabber == "tv_grab_fi")
    2581         // Use the default of 10 days for Finland's grabber
    2582         command.sprintf("nice %s --config-file '%s' --output %s",
    2583                         xmltv_grabber.ascii(), configfile.ascii(),
    2584                         filename.ascii());
    2585     else if (xmltv_grabber == "tv_grab_es" ||
    2586              xmltv_grabber == "tv_grab_es_laguiatv")
    2587         // Use fixed interval of 3 days for Spanish grabber
    2588         command.sprintf("nice %s --days=4  --config-file '%s' --output %s",
    2589                         xmltv_grabber.ascii(),
    2590                         configfile.ascii(), filename.ascii());
    2591     else if (xmltv_grabber == "tv_grab_jp")
     2569    QString command  = QString("nice %1 --config-file '%2' --output %3")
     2570                            .arg(xmltv_grabber.ascii())
     2571                            .arg(configfile.ascii())
     2572                            .arg(filename.ascii());
     2573
     2574    // The one concession to grabber specific behaviour.
     2575    // Will be removed when the grabber allows.
     2576    if (xmltv_grabber == "tv_grab_jp")
    25922577    {
    2593          // Use fixed interval of 7 days for Japanese grabber
    2594          command.sprintf("nice %s --days 7 --enable-readstr --config-file '%s' --output %s",
    2595                          xmltv_grabber.ascii(), configfile.ascii(),
    2596                          filename.ascii());
    2597          isJapan = true;
     2578        command += QString(" --enable-readstr");
     2579        isJapan = true;
    25982580    }
    2599     else if (xmltv_grabber == "tv_grab_no")
    2600         command.sprintf("nice %s --days 1 --offset %d --config-file '%s' --output %s",
    2601                         xmltv_grabber.ascii(), offset, configfile.ascii(),
    2602                         filename.ascii());
    2603     else if (xmltv_grabber == "tv_grab_se_swedb")
    2604          command.sprintf("nice %s --days 1 --offset %d --config-file '%s' --output %s",
    2605                          xmltv_grabber.ascii(), offset, configfile.ascii(),
    2606                          filename.ascii());
    2607     else if (xmltv_grabber == "tv_grab_dk")
    2608         // Use fixed interval of 7 days for Danish grabber
    2609         command.sprintf("nice %s --days 7 --config-file '%s' --output %s",
    2610                         xmltv_grabber.ascii(), configfile.ascii(),
    2611                         filename.ascii());
    2612     else if (xmltv_grabber == "tv_grab_pt")
    2613         // Use fixed interval of 3 days for Portuguese grabber
    2614         command.sprintf("nice %s --days=4  --config-file '%s' --output %s",
    2615                         xmltv_grabber.ascii(),
    2616                         configfile.ascii(), filename.ascii());
    2617     else if (xmltv_grabber == "tv_grab_be_tvb")
    2618         command.sprintf("nice %s --days 1 --offset %d --config-file '%s' --output %s",
    2619                         xmltv_grabber.ascii(), offset, configfile.ascii(),
    2620                         filename.ascii());
    2621     else if (xmltv_grabber == "tv_grab_be_tlm")
    2622         command.sprintf("nice %s --days 1 --offset %d --config-file '%s' --output %s",
    2623                         xmltv_grabber.ascii(), offset, configfile.ascii(),
    2624                         filename.ascii());
    2625     else if (xmltv_grabber == "tv_grab_ee")
    2626         // Estonian grabber returns all known data by default
    2627         command.sprintf("nice %s --output %s",
    2628                         xmltv_grabber.ascii(),
    2629                         filename.ascii());
    2630     else if (xmltv_grabber == "tv_grab_il")
    2631         // Israeli grabber returns all known data by default
    2632         command.sprintf("nice %s --config-file '%s' --output %s",
    2633                         xmltv_grabber.ascii(), configfile.ascii(),
    2634                         filename.ascii());
    2635     else if (xmltv_grabber == "tv_grab_ru")
    2636         // Russian grabber returns all known data by default
    2637         command.sprintf("nice %s --config-file '%s' --output %s",
    2638                         xmltv_grabber.ascii(), configfile.ascii(),
    2639                         filename.ascii());
    2640     else
     2581    else if (source.xmltvgrabber_prefmethod != "allatonce")
    26412582    {
    2642         isNorthAmerica = true;
    2643         command.sprintf("nice %s --days 1 --offset %d --config-file '%s' "
    2644                         "--output %s", xmltv_grabber.ascii(),
    2645                         offset, configfile.ascii(), filename.ascii());
     2583        // XMLTV Docs don't recommend grabbing one day at a
     2584        // time but the current myth code is heavily geared
     2585        // that way so until it is re-written behave as
     2586        // we always have done.
     2587        command += QString(" --days 1 --offset %1").arg(offset);
    26462588    }
    26472589
    2648     if (((print_verbose_messages & VB_GENERAL) == 0) &&
    2649         (xmltv_grabber == "tv_grab_na" ||
    2650          xmltv_grabber == "tv_grab_de_tvtoday" ||
    2651          xmltv_grabber == "tv_grab_fi" ||
    2652          xmltv_grabber == "tv_grab_es" ||
    2653          xmltv_grabber == "tv_grab_es_laguiatv" ||
    2654          xmltv_grabber == "tv_grab_se_swedb" ||
    2655          xmltv_grabber == "tv_grab_no" ||
    2656          xmltv_grabber == "tv_grab_dk" ||
    2657          xmltv_grabber == "tv_grab_uk" ||
    2658          xmltv_grabber == "tv_grab_uk_rt" ||
    2659          xmltv_grabber == "tv_grab_nl" ||
    2660          xmltv_grabber == "tv_grab_fr" ||
    2661          xmltv_grabber == "tv_grab_fi" ||
    2662          xmltv_grabber == "tv_grab_jp" ||
    2663          xmltv_grabber == "tv_grab_pt" ||
    2664          xmltv_grabber == "tv_grab_be_tvb" ||
    2665          xmltv_grabber == "tv_grab_be_tlm" ||
    2666          xmltv_grabber == "tv_grab_ee" ||
    2667          xmltv_grabber == "tv_grab_ru"))
    2668          command += " --quiet";
    2669 
    2670 
    26712590    command += graboptions;
    26722591
    2673     VERBOSE(VB_GENERAL,
    2674             "----------------- Start of XMLTV output -----------------");
     2592    if (! (print_verbose_messages & VB_GENERAL))
     2593        command += " --quiet";
    26752594
    26762595    QDateTime qdtNow = QDateTime::currentDateTime();
    26772596    MSqlQuery query(MSqlQuery::InitCon());
     
    26852604                       "WHERE value='mythfilldatabaseLastRunStatus'")
    26862605                       .arg(status));
    26872606
     2607    VERBOSE(VB_GENERAL, QString("Grabber Command: %1").arg(command));
     2608
     2609    VERBOSE(VB_GENERAL,
     2610            "----------------- Start of XMLTV output -----------------");
     2611
    26882612    int systemcall_status = system(command.ascii());
    26892613    bool succeeded = WIFEXITED(systemcall_status) &&
    26902614         WEXITSTATUS(systemcall_status) == 0;
    26912615
     2616    VERBOSE(VB_GENERAL,
     2617            "------------------ End of XMLTV output ------------------");
     2618
    26922619    qdtNow = QDateTime::currentDateTime();
    26932620    query.exec(QString("UPDATE settings SET data ='%1' "
    26942621                       "WHERE value='mythfilldatabaseLastRunEnd'")
     
    27042631        query.exec(QString("UPDATE settings SET data ='%1' "
    27052632                           "WHERE value='mythfilldatabaseLastRunStatus'")
    27062633                           .arg(status));
     2634
     2635        VERBOSE(VB_GENERAL, status);
     2636
    27072637        if (WIFSIGNALED(systemcall_status) &&
    27082638            (WTERMSIG(systemcall_status) == SIGINT || WTERMSIG(systemcall_status) == SIGQUIT))
    27092639            interrupted = true;
    27102640    }
    2711  
    2712     VERBOSE(VB_GENERAL,
    2713             "------------------ End of XMLTV output ------------------");
    27142641
    27152642    grabDataFromFile(source.id, filename);
    27162643
     
    28342761    int failures = 0;
    28352762    int externally_handled = 0;
    28362763    int total_sources = sourcelist.size();
     2764    int source_channels = 0;
    28372765
    2838     query.exec(QString("SELECT MAX(endtime) FROM program WHERE manualid=0;"));
    2839     if (query.isActive() && query.size() > 0)
    2840     {
    2841         query.next();
    2842 
    2843         if (!query.isNull(0))
    2844             GuideDataBefore = QDateTime::fromString(query.value(0).toString(),
    2845                                                     Qt::ISODate);
    2846     }
    2847 
    28482766    QString sidStr = QString("Updating source #%1 (%2) with grabber %3");
    28492767
    28502768    need_post_grab_proc = false;
     2769    int nonewdata = 0;
    28512770
    28522771    for (it = sourcelist.begin(); it != sourcelist.end(); ++it)
    28532772    {
     2773
     2774        query.prepare("SELECT MAX(endtime) FROM program p LEFT JOIN channel c "
     2775                      "ON p.chanid=c.chanid WHERE c.sourceid= :SRCID "
     2776                      "AND manualid = 0;");
     2777        query.bindValue(":SRCID", (*it).id);
     2778        query.exec();
     2779        if (query.isActive() && query.size() > 0)
     2780        {
     2781            query.next();
     2782
     2783            if (!query.isNull(0))
     2784                GuideDataBefore = QDateTime::fromString(query.value(0).toString(),
     2785                                                        Qt::ISODate);
     2786        }
     2787
    28542788        channel_update_run = false;
     2789        endofdata = false;
     2790
     2791        QString xmltv_grabber = (*it).xmltvgrabber;
     2792
     2793        if (xmltv_grabber == "eitonly")
     2794        {
     2795            VERBOSE(VB_IMPORTANT, "Source configured to use only the "
     2796                    "broadcasted guide data. Skipping.");
     2797            externally_handled++;
     2798            query.exec(QString("UPDATE settings SET data ='%1' "
     2799                               "WHERE value='mythfilldatabaseLastRunStart' OR "
     2800                               "value = 'mythfilldatabaseLastRunEnd'")
     2801                       .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm")));
     2802            continue;
     2803        }
     2804        else if (xmltv_grabber == "/bin/true" ||
     2805                 xmltv_grabber == "none" ||
     2806                 xmltv_grabber == "")
     2807        {
     2808            VERBOSE(VB_IMPORTANT,
     2809                    "Source configured with no grabber. Nothing to do.");
     2810            externally_handled++;
     2811            query.exec(QString("UPDATE settings SET data ='%1' "
     2812                               "WHERE value='mythfilldatabaseLastRunStart' OR "
     2813                               "value = 'mythfilldatabaseLastRunEnd'")
     2814                       .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm")));
     2815            continue;
     2816        }
     2817
    28552818        VERBOSE(VB_GENERAL, sidStr.arg((*it).id)
    28562819                                  .arg((*it).name)
    2857                                   .arg((*it).xmltvgrabber));
     2820                                  .arg(xmltv_grabber));
    28582821
    2859         QString xmltv_grabber = (*it).xmltvgrabber;
    2860         need_post_grab_proc |= (xmltv_grabber != "datadirect");
     2822        query.prepare(
     2823            "SELECT COUNT(chanid) FROM channel WHERE sourceid = "
     2824             ":SRCID AND xmltvid != ''");
     2825        query.bindValue(":SRCID", (*it).id);
     2826        query.exec();
    28612827
    2862         if (xmltv_grabber == "tv_grab_uk" || xmltv_grabber == "tv_grab_uk_rt" ||
    2863             xmltv_grabber == "tv_grab_fi" || xmltv_grabber == "tv_grab_es" ||
    2864             xmltv_grabber == "tv_grab_es_laguiatv" ||
    2865             xmltv_grabber == "tv_grab_nl" || xmltv_grabber == "tv_grab_au" ||
    2866             xmltv_grabber == "tv_grab_fr" || xmltv_grabber == "tv_grab_jp" ||
    2867             xmltv_grabber == "tv_grab_pt" || xmltv_grabber == "tv_grab_ee" ||
    2868             xmltv_grabber == "tv_grab_dk")
     2828        if (query.isActive() && query.size() > 0) {
     2829            query.next();
     2830            source_channels = query.value(0).toInt();
     2831            if (source_channels > 0)
     2832            {
     2833                VERBOSE(VB_GENERAL, QString("Found %1 channels for "
     2834                                "source %2 which use grabber")
     2835                                .arg(source_channels).arg((*it).id));
     2836            }
     2837            else
     2838            {
     2839                VERBOSE(VB_GENERAL, QString("No channels are "
     2840                    "configured to use grabber."));
     2841            }
     2842        }
     2843        else {
     2844            source_channels = 0;
     2845            VERBOSE(VB_GENERAL,
     2846                    QString("Can't get a channel count for source id %1")
     2847                            .arg((*it).id));
     2848        }
     2849
     2850        bool hasprefmethod = false;
     2851
     2852        if (xmltv_grabber != "datadirect") {
     2853
     2854            QProcess grabber_capabilities_proc(xmltv_grabber);
     2855            grabber_capabilities_proc.addArgument(QString("--capabilities"));
     2856            if ( grabber_capabilities_proc.start() )
     2857            {
     2858
     2859                int i=0;
     2860                // Assume it shouldn't take more than 10 seconds
     2861                // Broken versions of QT cause QProcess::start
     2862                // and QProcess::isRunning to return true even
     2863                // when the executable doesn't exist
     2864                while (grabber_capabilities_proc.isRunning() && i < 100)
     2865                {
     2866                    usleep(100000);
     2867                    ++i;
     2868                }
     2869
     2870                if (grabber_capabilities_proc.normalExit())
     2871                {
     2872                    QString capabilites = "";
     2873
     2874                    while (grabber_capabilities_proc.canReadLineStdout())
     2875                    {
     2876                        QString capability
     2877                            = grabber_capabilities_proc.readLineStdout();
     2878                        capabilites += capability + " ";
     2879
     2880                        if (capability == "baseline")
     2881                            (*it).xmltvgrabber_baseline = true;
     2882
     2883                        if (capability == "manualconfig")
     2884                            (*it).xmltvgrabber_manualconfig = true;
     2885
     2886                        if (capability == "cache")
     2887                            (*it).xmltvgrabber_cache = true;
     2888
     2889                        if (capability == "preferredmethod")
     2890                            hasprefmethod = true;
     2891                    }
     2892
     2893                    VERBOSE(VB_GENERAL, QString("Grabber has capabilities: %1")
     2894                        .arg(capabilites));
     2895                }
     2896                else {
     2897                    VERBOSE(VB_IMPORTANT, "%1  --capabilities failed or we "
     2898                        "timed out waiting. You may need to upgrade your "
     2899                        "xmltv grabber");
     2900                }
     2901            }
     2902            else {
     2903                QString error = grabber_capabilities_proc.readLineStdout();
     2904                VERBOSE(VB_IMPORTANT, QString("Failed to run %1 "
     2905                        "--capabilities").arg(xmltv_grabber));
     2906            }
     2907        }
     2908
     2909
     2910        if (hasprefmethod)
    28692911        {
    2870             // These don't support the --offset option, so just grab the max.
    2871             // TODO: tv_grab_fi/dk/is seems to support --offset, maybe more. Needs verification.
    2872             if (!grabData(*it, 0))
    2873                 ++failures;
     2912
     2913            QProcess grabber_method_proc(xmltv_grabber);
     2914            grabber_method_proc.addArgument("--preferredmethod");
     2915            if ( grabber_method_proc.start() )
     2916            {
     2917                int i=0;
     2918                // Assume it shouldn't take more than 10 seconds
     2919                // Broken versions of QT cause QProcess::start
     2920                // and QProcess::isRunning to return true even
     2921                // when the executable doesn't exist
     2922                while (grabber_method_proc.isRunning() && i < 100)
     2923                {
     2924                    usleep(100000);
     2925                    ++i;
     2926                }
     2927
     2928                if (grabber_method_proc.normalExit())
     2929                {
     2930                    (*it).xmltvgrabber_prefmethod =
     2931                        grabber_method_proc.readLineStdout();
     2932                }
     2933                else {
     2934                    VERBOSE(VB_IMPORTANT, "%1  --preferredmethod failed or we "
     2935                    "timed out waiting. You may need to upgrade your "
     2936                    "xmltv grabber");
     2937                }
     2938
     2939                VERBOSE(VB_GENERAL, QString("Grabber prefers method: %1")
     2940                .arg((*it).xmltvgrabber_prefmethod));
     2941            }
     2942            else {
     2943                QString error = grabber_method_proc.readLineStdout();
     2944                VERBOSE(VB_IMPORTANT, QString("Failed to run %1 --preferredmethod")
     2945                        .arg(xmltv_grabber));
     2946            }
    28742947        }
    2875         else if ((xmltv_grabber == "datadirect") && dd_grab_all)
     2948
     2949        need_post_grab_proc |= (xmltv_grabber != "datadirect");
     2950
     2951        if ((xmltv_grabber == "datadirect") && dd_grab_all)
    28762952        {
    28772953            if (only_update_channels)
    28782954                DataDirectUpdateChannels(*it);
     
    28822958                grabData(*it, 0, &qCurrentDate);
    28832959            }
    28842960        }
    2885         else if (xmltv_grabber == "datadirect" ||
    2886                  xmltv_grabber == "tv_grab_se_swedb" ||
    2887                  xmltv_grabber == "tv_grab_no" ||
    2888                  xmltv_grabber == "tv_grab_de_tvtoday" ||
    2889                  xmltv_grabber == "tv_grab_be_tvb" ||
    2890                  xmltv_grabber == "tv_grab_be_tlm" ||
    2891                  xmltv_grabber == "tv_grab_is" ||
    2892                  xmltv_grabber == "tv_grab_br" ||
    2893                  xmltv_grabber == "tv_grab_cz" ||
    2894                  xmltv_grabber == "tv_grab_ru")
     2961        else if ((*it).xmltvgrabber_prefmethod == "allatonce")
    28952962        {
    2896             // Grabbers supporting the --offset option
     2963            if (!grabData(*it, 0))
     2964                ++failures;
     2965        }
     2966        else if ((*it).xmltvgrabber_baseline || xmltv_grabber == "datadirect")
     2967        {
    28972968
    2898             if (xmltv_grabber == "tv_grab_no")
    2899                 listing_wrap_offset = 6 * 3600;
    2900 
    29012969            QDate qCurrentDate = QDate::currentDate();
    29022970
    2903             int grabdays = 9;
     2971            // We'll keep grabbing until it returns nothing
     2972            // Max days currently supported is 21
     2973            int grabdays = 21;
    29042974
    2905             // Grab different amount of days for the different grabbers,
    2906             // often decided by the person maintaining the grabbers.
    29072975            if (maxDays > 0) // passed with --max-days
    29082976                grabdays = maxDays;
    29092977            else if (xmltv_grabber == "datadirect")
    29102978                grabdays = 14;
    2911             else if (xmltv_grabber == "tv_grab_se_swedb")
    2912                 grabdays = 10;
    2913             else if (xmltv_grabber == "tv_grab_no" ||
    2914                      xmltv_grabber == "tv_grab_de_tvtoday")
    2915                 grabdays = 7;
    2916             else if (xmltv_grabber == "tv_grab_be_tvb" ||
    2917                      xmltv_grabber == "tv_grab_be_tlm")
    2918                 grabdays = 5;
    29192979
    29202980            grabdays = (only_update_channels) ? 1 : grabdays;
    29212981
     
    29613021                         (i == 2 && refresh_second))
    29623022                {
    29633023                    // Always refresh if the user specified today/tomorrow/second.
    2964                     download_needed = true;
     3024                    if (refresh_today) {
     3025                        VERBOSE(VB_GENERAL,
     3026                            "Data Refresh needed because user specified --refresh-today");
     3027                    }
     3028                    else if (refresh_second) {
     3029                        VERBOSE(VB_GENERAL,
     3030                            "Data Refresh needed because user specified --refresh-second");
     3031                    }
     3032                    else {
     3033                        VERBOSE(VB_GENERAL,
     3034                            "Data Refresh always needed for tomorrow");
     3035                    }
    29653036                }
    2966                 else if (xmltv_grabber == "tv_grab_se_swedb")
    2967                 {
    2968                     // Since tv_grab_se_swedb handles caching internally,
    2969                     // let it do its job and always grab new data.
    2970                     VERBOSE(VB_GENERAL,
    2971                             "Data Refresh needed because the grabber relies on "
    2972                             "internal caching.");
    2973                     download_needed = true;
    2974                 }
    29753037                else
    29763038                {
    29773039                    // Check to see if we already downloaded data for this date.
     
    29873049                                   "INTERVAL '%1' DAY), INTERVAL '18' HOUR) "
    29883050                               "  AND starttime < DATE_ADD(CURRENT_DATE(), "
    29893051                                   "INTERVAL '%2' DAY) "
    2990                                "WHERE c.sourceid = %3 "
     3052                               "WHERE c.sourceid = %3 AND c.xmltvid != '' "
    29913053                               "GROUP BY c.chanid;";
    2992  
     3054
    29933055                    if (query.exec(querystr.arg(i-1).arg(i).arg((*it).id)) &&
    29943056                        query.isActive())
    29953057                    {
     
    30863148                                "offset day %2.").arg(i-1).arg(i));
    30873149                        download_needed = true;
    30883150                    }
    3089                 } 
     3151                }
    30903152
    30913153                if (download_needed)
    30923154                {
     
    31003162                            break;
    31013163                        }
    31023164                    }
     3165
     3166                    if (endofdata) {
     3167                        VERBOSE(VB_GENERAL,
     3168                            QString("Grabber is no longer returning program data, finishing"));
     3169                        break;
     3170                    }
     3171
    31033172                }
    31043173                else
    31053174                {
     
    31093178                }
    31103179            }
    31113180        }
    3112         else if (xmltv_grabber == "eitonly")
    3113         {
    3114             VERBOSE(VB_IMPORTANT, "Source configured to use only the "
    3115                     "broadcasted guide data. Skipping.");
    3116             externally_handled++;
    3117             query.exec(QString("UPDATE settings SET data ='%1' "
    3118                                "WHERE value='mythfilldatabaseLastRunStart' OR "
    3119                                "value = 'mythfilldatabaseLastRunEnd'")
    3120                        .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm")));
    3121         }
    3122         else if (xmltv_grabber == "/bin/true" ||
    3123                  xmltv_grabber == "none" ||
    3124                  xmltv_grabber == "")
    3125         {
    3126             VERBOSE(VB_IMPORTANT,
    3127                     "Source configured with no grabber. Nothing to do.");
    3128             externally_handled++;
    3129             query.exec(QString("UPDATE settings SET data ='%1' "
    3130                                "WHERE value='mythfilldatabaseLastRunStart' OR "
    3131                                "value = 'mythfilldatabaseLastRunEnd'")
    3132                        .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm")));
    3133         }
    31343181        else
    31353182        {
    31363183            VERBOSE(VB_IMPORTANT,
    31373184                    QString("Grabbing XMLTV data using ") + xmltv_grabber +
    3138                             " is not verified as working.");
     3185                            " is not supported. You may need to upgrade to"
     3186                            " the latest version of XMLTV.");
    31393187        }
    31403188
    31413189        if (interrupted)
    31423190        {
    31433191            break;
    31443192        }
     3193
     3194        query.prepare("SELECT MAX(endtime) FROM program p LEFT JOIN channel c "
     3195                      "ON p.chanid=c.chanid WHERE c.sourceid= :SRCID "
     3196                      "AND manualid = 0;");
     3197        query.bindValue(":SRCID", (*it).id);
     3198        query.exec();
     3199        if (query.isActive() && query.size() > 0)
     3200        {
     3201            query.next();
     3202
     3203            if (!query.isNull(0))
     3204                GuideDataAfter = QDateTime::fromString(query.value(0).toString(),
     3205                                                    Qt::ISODate);
     3206        }
     3207
     3208        if (GuideDataAfter == GuideDataBefore)
     3209        {
     3210            nonewdata++;
     3211        }
    31453212    }
    31463213
    31473214    if (only_update_channels && !need_post_grab_proc)
    31483215        return true;
    31493216
    3150     query.exec(QString("SELECT MAX(endtime) FROM program WHERE manualid=0;"));
    3151     if (query.isActive() && query.size() > 0)
    3152     {
    3153         query.next();
    3154 
    3155         if (!query.isNull(0))
    3156             GuideDataAfter = QDateTime::fromString(query.value(0).toString(),
    3157                                                    Qt::ISODate);
    3158     }
    3159 
    31603217    if (failures == 0)
    31613218    {
    3162         if ((GuideDataAfter == GuideDataBefore) &&
     3219        if (nonewdata > 0 &&
    31633220            (total_sources != externally_handled))
    3164             status = "mythfilldatabase ran, but did not insert "
    3165                      "any new data into the Guide.  This can indicate a "
    3166                      "potential grabber failure.";
     3221            status = QString("mythfilldatabase ran, but did not insert "
     3222                     "any new data into the Guide for %1 of %2 sources. "
     3223                     "This can indicate a potential grabber failure.")
     3224                     .arg(nonewdata)
     3225                     .arg(total_sources);
    31673226        else
    31683227            status = "Successful.";
    31693228
     
    36943753            cout << "--refresh-today\n";
    36953754            cout << "--refresh-second\n";
    36963755            cout << "--refresh-all\n";
    3697             cout << "   (Only valid for grabbers: DataDirect, se_swedb, no, ee, de_tvtoday)\n";
     3756            cout << "   (Only valid for selected grabbers: e.g. DataDirect)\n";
    36983757            cout << "   Force a refresh today or two days (or every day) from now,\n";
    36993758            cout << "   to catch the latest changes\n";
    37003759            cout << "--dont-refresh-tomorrow\n";
     
    38433902                                   "FROM videosource ") + where +
    38443903                                   QString(" ORDER BY sourceid;");
    38453904        sourcequery.exec(querystr);
    3846        
     3905
    38473906        if (sourcequery.isActive())
    38483907        {
    38493908             if (sourcequery.size() > 0)
     
    38513910                  while (sourcequery.next())
    38523911                  {
    38533912                       Source newsource;
    3854            
     3913
    38553914                       newsource.id = sourcequery.value(0).toInt();
    38563915                       newsource.name = sourcequery.value(1).toString();
    38573916                       newsource.xmltvgrabber = sourcequery.value(2).toString();
     
    38593918                       newsource.password = sourcequery.value(4).toString();
    38603919                       newsource.lineupid = sourcequery.value(5).toString();
    38613920
     3921                       newsource.xmltvgrabber_baseline = false;
     3922                       newsource.xmltvgrabber_manualconfig = false;
     3923                       newsource.xmltvgrabber_cache = false;
     3924                       newsource.xmltvgrabber_prefmethod = "";
     3925
    38623926                       sourcelist.append(newsource);
    38633927                       if (newsource.xmltvgrabber == "datadirect")
    38643928                           usingDataDirect = true;