Ticket #10747: mythtv.airdate.2.patch

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

Updated 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..38b9ce3 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 "
    654                       "WHERE programid > '' GROUP BY programid;");
     624        // Get the data for the first showing
     625        query.prepare("SELECT starttime,programfirst.programid, "
     626                      "  previouslyshown "
     627                      "FROM program, "
     628                      "  (SELECT MIN(starttime) AS minstarttime,programid "
     629                      "     FROM program WHERE programid > '' "
     630                      "     GROUP BY programid) "
     631                      "    AS programfirst "
     632                      "WHERE program.programid > '' "
     633                      "  AND program.starttime=programfirst.minstarttime "
     634                      "  AND program.programid=programfirst.programid;"); 
    655635        if (query.exec())
    656636        {
    657637            updt.prepare("UPDATE program set first = 1 "
    658638                         "WHERE starttime = :STARTTIME "
    659639                         "  AND programid = :PROGRAMID;");
     640            updtAirdate.prepare("UPDATE program "
     641                                "   SET originalairdate = :ORIGINALAIRDATE "
     642                                "WHERE originalairdate IS NULL "
     643                                "  AND first = 0 "
     644                                "  AND previouslyshown = 1 "
     645                                "  AND programid = :PROGRAMID;");
    660646            while(query.next())
    661647            {
    662648                updt.bindValue(":STARTTIME", query.value(0).toDateTime());
    663649                updt.bindValue(":PROGRAMID", query.value(1).toString());
    664650                if (!updt.exec())
    665651                    MythDB::DBError("Marking first showings by id", updt);
     652                // If we have the first showing, then we know the
     653                // originalairdate for any repeats. Make sure to
     654                // not override anything actually given in the source data
     655                if (!query.value(2).toBool()) {
     656                    updtAirdate.bindValue(":ORIGINALAIRDATE", query.value(0).toDate());
     657                    updtAirdate.bindValue(":PROGRAMID", query.value(1).toString());
     658                    if (!updtAirdate.exec())
     659                        MythDB::DBError("Marking originalairdate by id", updtAirdate);
     660                }
    666661            }
    667662        }
    668663        int found = query.size();
    669         query.prepare("SELECT MIN(starttime),title,subtitle,"
    670                       "       LEFT(description, 1024) AS partdesc "
    671                       "FROM program WHERE programid = '' "
    672                       "GROUP BY title,subtitle,partdesc;");
     664        // Get the data for the first showing
     665        query.prepare("SELECT starttime,programfirst.title, "
     666                      "  programfirst.subtitle,programfirst.partdesc, "
     667                      "  previouslyshown "
     668                      "FROM program, "
     669                      "  (SELECT MIN(starttime) AS minstarttime,title, "
     670                      "   subtitle, LEFT(description, 1024) AS partdesc "
     671                      "     FROM program WHERE programid = '' "
     672                      "     GROUP BY title,subtitle,partdesc) "
     673                      "    AS programfirst "
     674                      "WHERE program.programid = '' "
     675                      "  AND program.starttime=programfirst.minstarttime "
     676                      "  AND program.title=programfirst.title "
     677                      "  AND program.subtitle=programfirst.subtitle "
     678                      "  AND LEFT(program.description, 1024) = programfirst.partdesc;");
    673679        if (query.exec())
    674680        {
    675681            updt.prepare("UPDATE program set first = 1 "
    int main(int argc, char *argv[]) 
    677683                         "  AND title = :TITLE "
    678684                         "  AND subtitle = :SUBTITLE "
    679685                         "  AND LEFT(description, 1024) = :PARTDESC");
     686            updtAirdate.prepare("UPDATE program "
     687                                "   SET originalairdate = :ORIGINALAIRDATE "
     688                                "WHERE originalairdate IS NULL "
     689                                "  AND first = 0 "
     690                                "  AND previouslyshown = 1 "
     691                                "  AND title = :TITLE "
     692                                "  AND subtitle = :SUBTITLE "
     693                                "  AND LEFT(description, 1024) = :PARTDESC");
    680694            while(query.next())
    681695            {
    682696                updt.bindValue(":STARTTIME", query.value(0).toDateTime());
    int main(int argc, char *argv[]) 
    685699                updt.bindValue(":PARTDESC", query.value(3).toString());
    686700                if (!updt.exec())
    687701                    MythDB::DBError("Marking first showings", updt);
     702                if (!query.value(4).toBool()) {
     703                    updtAirdate.bindValue(":ORIGINALAIRDATE", query.value(0).toDate());
     704                    updtAirdate.bindValue(":TITLE", query.value(1).toString());
     705                    updtAirdate.bindValue(":SUBTITLE", query.value(2).toString());
     706                    updtAirdate.bindValue(":PARTDESC", query.value(3).toString());
     707                    if (!updtAirdate.exec())
     708                        MythDB::DBError("Marking original airdate", updt);
     709                }
    688710            }
    689711        }
    690712        found += query.size();
    int main(int argc, char *argv[]) 
    732754        LOG(VB_GENERAL, LOG_INFO, QString("    Found %1").arg(found));
    733755    }
    734756
     757    if (mark_repeats)
     758    {
     759        LOG(VB_GENERAL, LOG_INFO, "Marking repeats.");
     760
     761        int newEpiWindow = gCoreContext->GetNumSetting( "NewEpisodeWindow", 14);
     762
     763        MSqlQuery query(MSqlQuery::InitCon());
     764        query.prepare("UPDATE program SET previouslyshown = 1 "
     765                      "WHERE previouslyshown = 0 "
     766                      "AND originalairdate is not null "
     767                      "AND (to_days(starttime) - to_days(originalairdate)) "
     768                      "    > :NEWWINDOW;");
     769        query.bindValue(":NEWWINDOW", newEpiWindow);
     770
     771        if (query.exec())
     772            LOG(VB_GENERAL, LOG_INFO,
     773                QString("    Found %1").arg(query.numRowsAffected()));
     774
     775        LOG(VB_GENERAL, LOG_INFO, "Unmarking new episode rebroadcast repeats.");
     776        query.prepare("UPDATE program SET previouslyshown = 0 "
     777                      "WHERE previouslyshown = 1 "
     778                      "AND originalairdate is not null "
     779                      "AND (to_days(starttime) - to_days(originalairdate)) "
     780                      "    <= :NEWWINDOW;");
     781        query.bindValue(":NEWWINDOW", newEpiWindow);
     782
     783        if (query.exec())
     784            LOG(VB_GENERAL, LOG_INFO,
     785                QString("    Found %1").arg(query.numRowsAffected()));
     786    }
     787
    735788    if (1) // limit MSqlQuery's lifetime
    736789    {
    737790        MSqlQuery query(MSqlQuery::InitCon());