From c958894e6a4fffff58b0dc276fc978616560192d Mon Sep 17 00:00:00 2001
From: Rudi Heitbaum <rudi@heitbaum.com>
Date: Fri, 13 Sep 2024 13:22:54 +0000
Subject: [PATCH] fix build with vdr 2.7.1

---
 eepg.c         | 12 ++++++++++++
 eit2.c         |  8 ++++++++
 epghandler.c   | 13 +++++++++++++
 equivhandler.c |  9 +++++++++
 util.c         |  9 +++++++++
 5 files changed, 51 insertions(+)

diff --git a/eepg.c b/eepg.c
index a78819d..d39581d 100644
--- a/eepg.c
+++ b/eepg.c
@@ -1324,12 +1324,20 @@ void cFilterEEPG::WriteToSchedule(tChannelID channelID, cSchedules* pSchedules,
   cEvent *Event = NULL;
   if (ps/*[eq]*/) {
 
+#if APIVERSNUM >= 20502
+      Event = (cEvent *) ps->GetEventById (EventId); //since Nagra uses consistent EventIds, try this first
+#else
       Event = (cEvent *) ps->GetEvent (EventId); //since Nagra uses consistent EventIds, try this first
+#endif
       bool TableIdMatches = false;
       if (Event)
         TableIdMatches = (Event->TableID() == TableId);
       if (!Event || !TableIdMatches || abs(Event->StartTime() - (time_t) StartTime) > Duration * 60) //if EventId does not match, or it matched with wrong TableId, then try with StartTime
+#if APIVERSNUM >= 20502
+        Event = (cEvent *) ps->GetEventByTime (StartTime);
+#else
         Event = (cEvent *) ps->GetEvent (EventId, StartTime);
+#endif
   }
   cEvent *newEvent = NULL;
   if (!Event) {  //event is new
@@ -3477,7 +3485,11 @@ void cFilterEEPG::ProcessPremiere(const u_char *& Data)
               }
 
               bool newEvent = false;
+#if APIVERSNUM >= 20502
+              cEvent *pEvent = (cEvent *) pSchedule->GetEventById (EventId);
+#else
               cEvent *pEvent = (cEvent *) pSchedule->GetEvent (EventId, -1);
+#endif
               if (!pEvent) {
                 LogI(2, "(new)\n");
                 pEvent = new cEvent (EventId);
diff --git a/eit2.c b/eit2.c
index 9ee190d..31aa816 100644
--- a/eit2.c
+++ b/eit2.c
@@ -32,7 +32,11 @@ cEvent* cEIT2::ProcessEitEvent(cSchedule* pSchedule,const SI::EIT::Event* EitEve
   //    int versionNumber = getVersionNumber();
 
   cEvent *newEvent = NULL;
+#if APIVERSNUM >= 20502
+  cEvent *pEvent = (cEvent *) pSchedule->GetEventByTime (EitEvent->getStartTime ());
+#else
   cEvent *pEvent = (cEvent *) pSchedule->GetEvent (EitEvent->getEventId (), EitEvent->getStartTime ());
+#endif
   if (!pEvent) {
     if (OnlyRunningStatus)
       return NULL;
@@ -243,7 +247,11 @@ void cEIT2::ProcessEventDescriptors(bool ExternalData, int Source, u_char Tid,
           tChannelID(Source, channel->Nid(), channel->Tid(), tsed->getReferenceServiceId()));
         if (!rSchedule)
           break;
+#if APIVERSNUM >= 20502
+        rEvent = rSchedule->GetEventById(tsed->getReferenceEventId());
+#else
         rEvent = rSchedule->GetEvent(tsed->getReferenceEventId());
+#endif
         if (!rEvent)
           break;
         pEvent->SetTitle(rEvent->Title());
diff --git a/epghandler.c b/epghandler.c
index 1e2db9f..a81bc86 100644
--- a/epghandler.c
+++ b/epghandler.c
@@ -66,10 +66,23 @@ bool cEEpgHandler::HandleEitEvent(cSchedule* Schedule,
   modified = false;
   //VDR creates new event if the EitEvent StartTime is different than EEPG time so
   //the EPG event has to be deleted but the data should be kept
+#if APIVERSNUM >= 20502
+  const cEvent *ev;
+  if (EitEvent->getStartTime() > 0){
+    ev = schedule->GetEventByTime(EitEvent->getStartTime());
+  } else {
+    ev = schedule->GetEventById(EitEvent->getEventId());
+  }
+#else
   const cEvent* ev = schedule->GetEvent(EitEvent->getEventId(),EitEvent->getStartTime());
+#endif
   searchDuplicates = !ev; //if the event exist with a same start time, it is handled by SetShortText/SetDescription
   if (!ev){
+#if APIVERSNUM >= 20502
+      ev = schedule->GetEventById(EitEvent->getEventId());
+#else
       ev = schedule->GetEvent(EitEvent->getEventId());
+#endif
       // remove shifted duplicates with same ID
       if (ev && ((ev->StartTime()>EitEvent->getStartTime() && ev->StartTime() < EitEvent->getStartTime()+EitEvent->getDuration())
           || (EitEvent->getStartTime() > ev->StartTime() && EitEvent->getStartTime() < ev->EndTime()))) {
diff --git a/equivhandler.c b/equivhandler.c
index 75007ec..cd23d38 100644
--- a/equivhandler.c
+++ b/equivhandler.c
@@ -143,7 +143,16 @@ void cEquivHandler::updateEquivalent(cSchedules * Schedules, tChannelID channelI
     if (equChannel) {
       LogD(2, prep("found Equivalent channel %s"), *equChannelID.ToString());
       cSchedule *pSchedule = (cSchedule *) Schedules->GetSchedule (equChannel, true);
+#if APIVERSNUM >= 20502
+      cEvent *pEqvEvent;
+      if (pEvent->StartTime() > 0){
+        pEqvEvent = (cEvent *) pSchedule->GetEventByTime (pEvent->StartTime());
+      } else {
+        pEqvEvent = (cEvent *) pSchedule->GetEventById (pEvent->EventID());
+      }
+#else
       cEvent *pEqvEvent = (cEvent *) pSchedule->GetEvent (pEvent->EventID(), pEvent->StartTime());
+#endif
       if (pEqvEvent) {
         LogD(3, prep("equivalent event exists"));
         if (pEqvEvent == pEvent) {
diff --git a/util.c b/util.c
index 1109181..029fcc6 100644
--- a/util.c
+++ b/util.c
@@ -214,7 +214,16 @@ void cAddEventThread::Action(void)
       while (((*it).second->First()) != NULL) {
         cEvent* event = (*it).second->First();
 
+#if APIVERSNUM >= 20502
+        cEvent *pEqvEvent;
+        if (event->StartTime() > 0){
+          pEqvEvent = (cEvent *) schedule->GetEventByTime (event->StartTime());
+        } else {
+          pEqvEvent = (cEvent *) schedule->GetEventById (event->EventID());
+        }
+#else
         cEvent *pEqvEvent = (cEvent *) schedule->GetEvent (event->EventID(), event->StartTime());
+#endif
         if (pEqvEvent){
           (*it).second->Del(event);
         } else {
