Ticket #10747: mythtv.airdate.patch

File mythtv.airdate.patch, 8.2 KB (added by Bradley Baetz <bbaetz@…>, 12 years ago)

Patch

  • mythtv/programs/mythbackend/housekeeper.cpp

    diff --git a/mythtv/programs/mythbackend/housekeeper.cpp b/mythtv/programs/mythbackend/housekeeper.cpp
    index 29ab7ea..9cfbcc2 100644
    a b void HouseKeeper::CleanupProgramListings(void) 
    668668    // Keep as many days of listings data as we keep matching, non-recorded
    669669    // oldrecorded entries to allow for easier post-mortem analysis
    670670    int offset = gCoreContext->GetNumSetting( "CleanOldRecorded", 10);
     671    // Also make sure to keep enough data so that we can flag the original
     672    // air date, for when that isn't included in guide data
     673    int newEpiWindow = gCoreContext->GetNumSetting( "NewEpisodeWindow", 14);
     674    if (newEpiWindow > offset)
     675        offset = newEpiWindow;
    671676
    672677    query.prepare("DELETE FROM oldprogram WHERE airdate < "
    673678                  "DATE_SUB(CURRENT_DATE, INTERVAL 320 DAY);");
  • mythtv/programs/mythfilldatabase/main.cpp

    diff --git a/mythtv/programs/mythfilldatabase/main.cpp b/mythtv/programs/mythfilldatabase/main.cpp
    index 57d4709..4c013ee 100644
    a b int main(int argc, char *argv[]) 
    607607        LOG(VB_GENERAL, LOG_INFO, QString("    Found %1").arg(found));
    608608    }
    609609
    610     if (mark_repeats)
    611     {
    612         LOG(VB_GENERAL, LOG_INFO, "Marking repeats.");
    613 
    614         int newEpiWindow = gCoreContext->GetNumSetting( "NewEpisodeWindow", 14);
    615 
    616         MSqlQuery query(MSqlQuery::InitCon());
    617         query.prepare("UPDATE program SET previouslyshown = 1 "
    618                       "WHERE previouslyshown = 0 "
    619                       "AND originalairdate is not null "
    620                       "AND (to_days(starttime) - to_days(originalairdate)) "
    621                       "    > :NEWWINDOW;");
    622         query.bindValue(":NEWWINDOW", newEpiWindow);
    623 
    624         if (query.exec())
    625             LOG(VB_GENERAL, LOG_INFO,
    626                 QString("    Found %1").arg(query.numRowsAffected()));
    627 
    628         LOG(VB_GENERAL, LOG_INFO, "Unmarking new episode rebroadcast repeats.");
    629         query.prepare("UPDATE program SET previouslyshown = 0 "
    630                       "WHERE previouslyshown = 1 "
    631                       "AND originalairdate is not null "
    632                       "AND (to_days(starttime) - to_days(originalairdate)) "
    633                       "    <= :NEWWINDOW;");
    634         query.bindValue(":NEWWINDOW", newEpiWindow);
    635 
    636         if (query.exec())
    637             LOG(VB_GENERAL, LOG_INFO,
    638                 QString("    Found %1").arg(query.numRowsAffected()));
    639     }
    640 
    641610    // Mark first and last showings
    642611
    643612    if (grab_data)
    int main(int argc, char *argv[]) 
    647616        if (!updt.exec())
    648617            MythDB::DBError("Clearing first and last showings", updt);
    649618
     619        MSqlQuery updtAirdate(MSqlQuery::InitCon());
     620
    650621        LOG(VB_GENERAL, LOG_INFO, "Marking episode first showings.");
    651622
    652623        MSqlQuery query(MSqlQuery::InitCon());
    653         query.prepare("SELECT MIN(starttime),programid FROM program "
     624        query.prepare("SELECT MIN(starttime),programid,previouslyshown "
     625                      "FROM program "
    654626                      "WHERE programid > '' GROUP BY programid;");
    655627        if (query.exec())
    656628        {
    657629            updt.prepare("UPDATE program set first = 1 "
    658630                         "WHERE starttime = :STARTTIME "
    659631                         "  AND programid = :PROGRAMID;");
     632            updtAirdate.prepare("UPDATE program "
     633                                "   SET originalairdate = :ORIGINALAIRDATE "
     634                                "WHERE originalairdate IS NULL "
     635                                "  AND first = 0 "
     636                                "  AND previouslyshown = 1 "
     637                                "  AND programid = :PROGRAMID;");
    660638            while(query.next())
    661639            {
    662640                updt.bindValue(":STARTTIME", query.value(0).toDateTime());
    663641                updt.bindValue(":PROGRAMID", query.value(1).toString());
    664642                if (!updt.exec())
    665643                    MythDB::DBError("Marking first showings by id", updt);
     644                // If we have the first showing, then we know the
     645                // originalairdate for any repeats. Make sure to
     646                // not override anything actually given in the source data
     647                if (!query.value(2).toBool()) {
     648                    updtAirdate.bindValue(":ORIGINALAIRDATE", query.value(0).toDate());
     649                    updtAirdate.bindValue(":PROGRAMID", query.value(1).toString());
     650                    if (!updtAirdate.exec())
     651                        MythDB::DBError("Marking originalairdate by id", updtAirdate);
     652                }
    666653            }
    667654        }
    668655        int found = query.size();
    669656        query.prepare("SELECT MIN(starttime),title,subtitle,"
    670                       "       LEFT(description, 1024) AS partdesc "
     657                      "       LEFT(description, 1024) AS partdesc,"
     658                      "       previouslyshown "
    671659                      "FROM program WHERE programid = '' "
    672660                      "GROUP BY title,subtitle,partdesc;");
    673661        if (query.exec())
    int main(int argc, char *argv[]) 
    677665                         "  AND title = :TITLE "
    678666                         "  AND subtitle = :SUBTITLE "
    679667                         "  AND LEFT(description, 1024) = :PARTDESC");
     668            updtAirdate.prepare("UPDATE program "
     669                                "   SET originalairdate = :ORIGINALAIRDATE "
     670                                "WHERE originalairdate IS NULL "
     671                                "  AND first = 0 "
     672                                "  AND previouslyshown = 1 "
     673                                "  AND title = :TITLE "
     674                                "  AND subtitle = :SUBTITLE "
     675                                "  AND LEFT(description, 1024) = :PARTDESC");
    680676            while(query.next())
    681677            {
    682678                updt.bindValue(":STARTTIME", query.value(0).toDateTime());
    int main(int argc, char *argv[]) 
    685681                updt.bindValue(":PARTDESC", query.value(3).toString());
    686682                if (!updt.exec())
    687683                    MythDB::DBError("Marking first showings", updt);
     684                if (!query.value(4).toBool()) {
     685                    updtAirdate.bindValue(":ORIGINALAIRDATE", query.value(0).toDate());
     686                    updtAirdate.bindValue(":TITLE", query.value(1).toString());
     687                    updtAirdate.bindValue(":SUBTITLE", query.value(2).toString());
     688                    updtAirdate.bindValue(":PARTDESC", query.value(3).toString());
     689                    if (!updtAirdate.exec())
     690                        MythDB::DBError("Marking original airdate", updt);
     691                }
    688692            }
    689693        }
    690694        found += query.size();
    int main(int argc, char *argv[]) 
    732736        LOG(VB_GENERAL, LOG_INFO, QString("    Found %1").arg(found));
    733737    }
    734738
     739    if (mark_repeats)
     740    {
     741        LOG(VB_GENERAL, LOG_INFO, "Marking repeats.");
     742
     743        int newEpiWindow = gCoreContext->GetNumSetting( "NewEpisodeWindow", 14);
     744
     745        MSqlQuery query(MSqlQuery::InitCon());
     746        query.prepare("UPDATE program SET previouslyshown = 1 "
     747                      "WHERE previouslyshown = 0 "
     748                      "AND originalairdate is not null "
     749                      "AND (to_days(starttime) - to_days(originalairdate)) "
     750                      "    > :NEWWINDOW;");
     751        query.bindValue(":NEWWINDOW", newEpiWindow);
     752
     753        if (query.exec())
     754            LOG(VB_GENERAL, LOG_INFO,
     755                QString("    Found %1").arg(query.numRowsAffected()));
     756
     757        LOG(VB_GENERAL, LOG_INFO, "Unmarking new episode rebroadcast repeats.");
     758        query.prepare("UPDATE program SET previouslyshown = 0 "
     759                      "WHERE previouslyshown = 1 "
     760                      "AND originalairdate is not null "
     761                      "AND (to_days(starttime) - to_days(originalairdate)) "
     762                      "    <= :NEWWINDOW;");
     763        query.bindValue(":NEWWINDOW", newEpiWindow);
     764
     765        if (query.exec())
     766            LOG(VB_GENERAL, LOG_INFO,
     767                QString("    Found %1").arg(query.numRowsAffected()));
     768    }
     769
    735770    if (1) // limit MSqlQuery's lifetime
    736771    {
    737772        MSqlQuery query(MSqlQuery::InitCon());