premiereepg.c
author nathan
Sat, 29 Dec 2007 11:20:25 +0100
branchtrunk
changeset 14 feccb11658b1
parent 12 5213337a6614
child 18 b55e482869c7
permissions -rw-r--r--
release 0.0.8
     1 /*
     2  * PremiereEpg plugin to VDR (C++)
     3  *
     4  * (C) 2005-2007 Stefan Huelswitt <s.huelswitt@gmx.de>
     5  *
     6  * This code is base on the commandline tool premiereepg2vdr
     7  * (C) 2004-2005 by Axel Katzur software@katzur.de
     8  * but has been rewritten from scratch
     9  *
    10  * This code is free software; you can redistribute it and/or
    11  * modify it under the terms of the GNU General Public License
    12  * as published by the Free Software Foundation; either version 2
    13  * of the License, or (at your option) any later version.
    14  *
    15  * This code is distributed in the hope that it will be useful,
    16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18  * GNU General Public License for more details.
    19  *
    20  * You should have received a copy of the GNU General Public License
    21  * along with this program; if not, write to the Free Software
    22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    23  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
    24  */
    25 
    26 #include <vdr/plugin.h>
    27 #include <vdr/filter.h>
    28 #include <vdr/epg.h>
    29 #include <vdr/channels.h>
    30 #include <vdr/dvbdevice.h>
    31 #include <vdr/i18n.h>
    32 #include <vdr/config.h>
    33 #include <libsi/section.h>
    34 #include <libsi/descriptor.h>
    35 
    36 #if APIVERSNUM < 10401
    37 #error You need at least VDR API version 1.4.1 for this plugin
    38 #endif
    39 #if APIVERSNUM < 10507
    40 #define trNOOP(s) (s)
    41 #endif
    42 
    43 //#define DEBUG
    44 //#define DEBUG2
    45 
    46 #ifdef DEBUG
    47 #define d(x) { (x); }
    48 #else
    49 #define d(x) ; 
    50 #endif
    51 #ifdef DEBUG2
    52 #define d2(x) { (x); }
    53 #else
    54 #define d2(x) ; 
    55 #endif
    56 
    57 #define PMT_SCAN_TIMEOUT  10  // seconds
    58 #define PMT_SCAN_IDLE     300 // seconds
    59 
    60 static const char *VERSION        = "0.0.8";
    61 static const char *DESCRIPTION    = trNOOP("Parses extended Premiere EPG data");
    62 
    63 // --- cSetupPremiereEpg -------------------------------------------------------
    64 
    65 const char *optPats[] = {
    66   "%s",
    67   "%s (Option %d)",
    68   "%s (O%d)",
    69   "#%2$d %1$s",
    70   "[%2$d] %1$s"
    71   };
    72 #define NUM_PATS (sizeof(optPats)/sizeof(char *))
    73 
    74 class cSetupPremiereEpg {
    75 public:
    76   int OptPat;
    77   int OrderInfo;
    78   int RatingInfo;
    79   int FixEpg;
    80 public:
    81   cSetupPremiereEpg(void);
    82   };
    83 
    84 cSetupPremiereEpg SetupPE;
    85 
    86 cSetupPremiereEpg::cSetupPremiereEpg(void)
    87 {
    88   OptPat=1;
    89   OrderInfo=1;
    90   RatingInfo=1;
    91   FixEpg=0;
    92 }
    93 
    94 // --- i18n --------------------------------------------------------------------
    95 
    96 #if APIVERSNUM < 10507
    97 const tI18nPhrase Phrases[] = {
    98   { "PremiereEPG",
    99     "PremiereEPG",
   100     "", // TODO
   101     "", // TODO
   102     "", // TODO
   103     "", // TODO
   104     "", // TODO
   105     "", // TODO
   106     "", // TODO
   107     "", // TODO
   108     "", // TODO
   109     "", // TODO
   110     "", // TODO
   111     "", // TODO
   112     "", // TODO
   113     "", // TODO
   114   },
   115   { "Parses extended Premiere EPG data",
   116     "Liest erweiterte Premiere EPG Daten ein",
   117     "", // TODO
   118     "", // TODO
   119     "", // TODO
   120     "", // TODO
   121     "", // TODO
   122     "", // TODO
   123     "", // TODO
   124     "", // TODO
   125     "", // TODO
   126     "", // TODO
   127     "", // TODO
   128     "", // TODO
   129     "", // TODO
   130     "", // TODO
   131   },
   132   { "off",
   133     "aus",
   134     "", // TODO
   135     "", // TODO
   136     "", // TODO
   137     "", // TODO
   138     "", // TODO
   139     "", // TODO
   140     "", // TODO
   141     "", // TODO
   142     "", // TODO
   143     "", // TODO
   144     "", // TODO
   145     "", // TODO
   146     "", // TODO
   147     "", // TODO
   148   },
   149   { "Tag option events",
   150     "Options Events markieren",
   151     "", // TODO
   152     "", // TODO
   153     "", // TODO
   154     "", // TODO
   155     "", // TODO
   156     "", // TODO
   157     "", // TODO
   158     "", // TODO
   159     "", // TODO
   160     "", // TODO
   161     "", // TODO
   162     "", // TODO
   163     "", // TODO
   164     "", // TODO
   165   },
   166   { "Show order information",
   167     "Bestellhinweise anzeigen",
   168     "", // TODO
   169     "", // TODO
   170     "", // TODO
   171     "", // TODO
   172     "", // TODO
   173     "", // TODO
   174     "", // TODO
   175     "", // TODO
   176     "", // TODO
   177     "", // TODO
   178     "", // TODO
   179     "", // TODO
   180     "", // TODO
   181     "", // TODO
   182   },
   183   { "Show rating information",
   184     "Altersfreigaben anzeigen",
   185     "", // TODO
   186     "", // TODO
   187     "", // TODO
   188     "", // TODO
   189     "", // TODO
   190     "", // TODO
   191     "", // TODO
   192     "", // TODO
   193     "", // TODO
   194     "", // TODO
   195     "", // TODO
   196     "", // TODO
   197     "", // TODO
   198     "", // TODO
   199   },
   200 
   201   { "Ordernumber",
   202     "Bestellnummer",
   203     "", // TODO
   204     "", // TODO
   205     "", // TODO
   206     "", // TODO
   207     "", // TODO
   208     "", // TODO
   209     "", // TODO
   210     "", // TODO
   211     "", // TODO
   212     "", // TODO
   213     "", // TODO
   214     "", // TODO
   215     "", // TODO
   216     "", // TODO
   217   },
   218   { "Price",
   219     "Preis",
   220     "", // TODO
   221     "", // TODO
   222     "", // TODO
   223     "", // TODO
   224     "", // TODO
   225     "", // TODO
   226     "", // TODO
   227     "", // TODO
   228     "", // TODO
   229     "", // TODO
   230     "", // TODO
   231     "", // TODO
   232     "", // TODO
   233     "", // TODO
   234   },
   235   { "Ordering",
   236     "Bestellen",
   237     "", // TODO
   238     "", // TODO
   239     "", // TODO
   240     "", // TODO
   241     "", // TODO
   242     "", // TODO
   243     "", // TODO
   244     "", // TODO
   245     "", // TODO
   246     "", // TODO
   247     "", // TODO
   248     "", // TODO
   249     "", // TODO
   250     "", // TODO
   251   },
   252   { "SMS",
   253     "SMS",
   254     "", // TODO
   255     "", // TODO
   256     "", // TODO
   257     "", // TODO
   258     "", // TODO
   259     "", // TODO
   260     "", // TODO
   261     "", // TODO
   262     "", // TODO
   263     "", // TODO
   264     "", // TODO
   265     "", // TODO
   266     "", // TODO
   267     "", // TODO
   268   },
   269   { "WWW",
   270     "WWW",
   271     "", // TODO
   272     "", // TODO
   273     "", // TODO
   274     "", // TODO
   275     "", // TODO
   276     "", // TODO
   277     "", // TODO
   278     "", // TODO
   279     "", // TODO
   280     "", // TODO
   281     "", // TODO
   282     "", // TODO
   283     "", // TODO
   284     "", // TODO
   285   },
   286   { "Rating",
   287     "Altersfreigabe",
   288     "", // TODO
   289     "", // TODO
   290     "", // TODO
   291     "", // TODO
   292     "", // TODO
   293     "", // TODO
   294     "", // TODO
   295     "", // TODO
   296     "", // TODO
   297     "", // TODO
   298     "", // TODO
   299     "", // TODO
   300     "", // TODO
   301     "", // TODO
   302   },
   303   { "years",
   304     "Jahre",
   305     "", // TODO
   306     "", // TODO
   307     "", // TODO
   308     "", // TODO
   309     "", // TODO
   310     "", // TODO
   311     "", // TODO
   312     "", // TODO
   313     "", // TODO
   314     "", // TODO
   315     "", // TODO
   316     "", // TODO
   317     "", // TODO
   318     "", // TODO
   319   },
   320   { "Fix EPG data",
   321     "EPG Daten korrigieren",
   322     "", // TODO
   323     "", // TODO
   324     "", // TODO
   325     "", // TODO
   326     "", // TODO
   327     "", // TODO
   328     "", // TODO
   329     "", // TODO
   330     "", // TODO
   331     "", // TODO
   332     "", // TODO
   333     "", // TODO
   334     "", // TODO
   335     "", // TODO
   336   },
   337 
   338   { NULL }
   339   };
   340 #endif
   341 
   342 // --- cMenuSetupPremiereEpg ------------------------------------------------------------
   343 
   344 class cMenuSetupPremiereEpg : public cMenuSetupPage {
   345 private:
   346   cSetupPremiereEpg data;
   347   const char *optDisp[NUM_PATS];
   348   char buff[NUM_PATS][32];
   349 protected:
   350   virtual void Store(void);
   351 public:
   352   cMenuSetupPremiereEpg(void);
   353   };
   354 
   355 cMenuSetupPremiereEpg::cMenuSetupPremiereEpg(void)
   356 {
   357   data=SetupPE;
   358   SetSection(tr("PremiereEPG"));
   359   optDisp[0]=tr("off");
   360   for(unsigned int i=1; i<NUM_PATS; i++) {
   361     snprintf(buff[i],sizeof(buff[i]),optPats[i],"Event",1);
   362     optDisp[i]=buff[i];
   363     }
   364   Add(new cMenuEditStraItem(tr("Tag option events"),&data.OptPat,NUM_PATS,optDisp));
   365   Add(new cMenuEditBoolItem(tr("Show order information"),&data.OrderInfo));
   366   Add(new cMenuEditBoolItem(tr("Show rating information"),&data.RatingInfo));
   367   Add(new cMenuEditBoolItem(tr("Fix EPG data"),&data.FixEpg));
   368 }
   369 
   370 void cMenuSetupPremiereEpg::Store(void)
   371 {
   372   SetupPE=data;
   373   SetupStore("OptionPattern",SetupPE.OptPat);
   374   SetupStore("OrderInfo",SetupPE.OrderInfo);
   375   SetupStore("RatingInfo",SetupPE.RatingInfo);
   376   SetupStore("FixEpg",SetupPE.FixEpg);
   377 }
   378 
   379 // --- CRC16 -------------------------------------------------------------------
   380 
   381 #define POLY 0xA001 // CRC16
   382 
   383 unsigned int crc16(unsigned int crc, unsigned char const *p, int len)
   384 {
   385   while(len--) {
   386     crc^=*p++;
   387     for(int i=0; i<8; i++)
   388       crc=(crc&1) ? (crc>>1)^POLY : (crc>>1);
   389     }
   390   return crc&0xFFFF;
   391 }
   392 
   393 // --- cFilterPremiereEpg ------------------------------------------------------
   394 
   395 #define STARTTIME_BIAS (20*60)
   396 
   397 class cFilterPremiereEpg : public cFilter {
   398 private:
   399   int pmtpid, pmtsid, pmtidx, pmtnext;
   400   //
   401   void NextPmt(void);
   402 protected:
   403   virtual void Process(u_short Pid, u_char Tid, const u_char *Data, int Length);
   404 public:
   405   cFilterPremiereEpg(void);
   406   virtual void SetStatus(bool On);
   407   void Trigger(void);
   408   };
   409 
   410 cFilterPremiereEpg::cFilterPremiereEpg(void)
   411 {
   412   Trigger();
   413   Set(0x00,0x00);
   414 }
   415 
   416 void cFilterPremiereEpg::Trigger(void)
   417 {
   418   d(printf("trigger\n"))
   419   pmtpid=0; pmtidx=0; pmtnext=0;
   420 }
   421 
   422 void cFilterPremiereEpg::SetStatus(bool On)
   423 {
   424   d(printf("setstatus %d\n",On))
   425   cFilter::SetStatus(On);
   426   Trigger();
   427 }
   428 
   429 void cFilterPremiereEpg::NextPmt(void)
   430 {
   431   Del(pmtpid,0x02);
   432   pmtpid=0;
   433   pmtidx++;
   434   d(printf("PMT next\n"))
   435 }
   436 
   437 void cFilterPremiereEpg::Process(u_short Pid, u_char Tid, const u_char *Data, int Length)
   438 {
   439   int now=time(0);
   440   if(Pid==0 && Tid==SI::TableIdPAT) {
   441     if(!pmtnext || now>pmtnext) {
   442       if(pmtpid) NextPmt();
   443       if(!pmtpid) {
   444         SI::PAT pat(Data,false);
   445         if(pat.CheckCRCAndParse()) {
   446           SI::PAT::Association assoc;
   447           int idx=0;
   448           for(SI::Loop::Iterator it; pat.associationLoop.getNext(assoc,it);) {
   449             if(!assoc.isNITPid()) {
   450               if(idx++==pmtidx) {
   451                 pmtpid=assoc.getPid();
   452                 pmtsid=assoc.getServiceId();
   453                 Add(pmtpid,0x02);
   454                 pmtnext=now+PMT_SCAN_TIMEOUT;
   455                 d(printf("PMT pid now 0x%04x (idx=%d)\n",pmtpid,pmtidx))
   456                 break;
   457                 }
   458               }
   459             }
   460           if(!pmtpid) {
   461             pmtidx=0;
   462             pmtnext=now+PMT_SCAN_IDLE;
   463             d(printf("PMT scan idle\n"))
   464             }
   465           }
   466         }
   467       }
   468     }
   469   else if(pmtpid>0 && Pid==pmtpid && Tid==SI::TableIdPMT && Source() && Transponder()) {
   470     SI::PMT pmt(Data,false);
   471     if(pmt.CheckCRCAndParse() && pmt.getServiceId()==pmtsid) {
   472       SI::PMT::Stream stream;
   473       for(SI::Loop::Iterator it; pmt.streamLoop.getNext(stream,it); ) {
   474         if(stream.getStreamType()==0x05) {
   475           SI::CharArray data=stream.getData();
   476           if((data[1]&0xE0)==0xE0 && (data[3]&0xF0)==0xF0) {
   477             bool prvData=false, usrData=false;
   478             SI::Descriptor *d;
   479             for(SI::Loop::Iterator it; (d=stream.streamDescriptors.getNext(it)); ) {
   480               switch(d->getDescriptorTag()) {
   481                 case SI::PrivateDataSpecifierDescriptorTag:
   482                   d(printf("prv: %d %08x\n",d->getLength(),d->getData().FourBytes(2)))
   483                   if(d->getLength()==6 && d->getData().FourBytes(2)==0x000000be)
   484                     prvData=true;
   485                   break;
   486                 case 0x90:
   487                   d(printf("usr: %d %08x\n",d->getLength(),d->getData().FourBytes(2)))
   488                   if(d->getLength()==6 && d->getData().FourBytes(2)==0x0000ffff)
   489                     usrData=true;
   490                   break;
   491                 default:
   492                   break;
   493                 }
   494               delete d;
   495               }
   496             if(prvData && usrData) {
   497               int pid=stream.getPid();
   498               d(printf("found citpid 0x%04x",pid))
   499               if(!Matches(pid,0xA0)) {
   500                 Add(pid,0xA0);
   501                 d(printf(" (added)"))
   502                 }
   503               d(printf("\n"))
   504               }
   505             }
   506           }
   507         }
   508       NextPmt(); pmtnext=0;
   509       }
   510     }
   511   else if(Tid==0xA0 && Source()) {
   512     SI::PremiereCIT cit(Data,false);
   513     if(cit.CheckCRCAndParse()) {
   514       cSchedulesLock SchedulesLock(true,10);
   515       cSchedules *Schedules=(cSchedules *)cSchedules::Schedules(SchedulesLock);
   516       if(Schedules) {
   517         int nCount=0;
   518         SI::ExtendedEventDescriptors *ExtendedEventDescriptors=0;
   519         SI::ShortEventDescriptor *ShortEventDescriptor=0;
   520         char *order=0, *rating=0;
   521         {
   522         time_t firstTime=0;
   523         SI::Descriptor *d;
   524         bool UseExtendedEventDescriptor=false;
   525         int LanguagePreferenceShort=-1;
   526         int LanguagePreferenceExt=-1;
   527         for(SI::Loop::Iterator it; (d=cit.eventDescriptors.getNext(it)); ) {
   528           switch(d->getDescriptorTag()) {
   529             case 0xF0: // order information
   530               if(SetupPE.OrderInfo) {
   531                 static const char *text[] = {
   532                   trNOOP("Ordernumber"),
   533                   trNOOP("Price"),
   534                   trNOOP("Ordering"),
   535                   trNOOP("SMS"),
   536                   trNOOP("WWW")
   537                   };
   538                 char buff[512];
   539                 int p=0;
   540                 const unsigned char *data=d->getData().getData()+2;
   541                 for(int i=0; i<5; i++) {
   542                   int l=data[0]; 
   543                   if(l>0) p+=snprintf(&buff[p],sizeof(buff)-p,"\n%s: %.*s",tr(text[i]),l,&data[1]);
   544                   data+=l+1;
   545                   }
   546                 if(p>0) order=strdup(buff);
   547                 }
   548               break;
   549             case 0xF1: // parental rating
   550               if(SetupPE.RatingInfo) {
   551                 char buff[512];
   552                 int p=0;
   553                 const unsigned char *data=d->getData().getData()+2;
   554                 p+=snprintf(&buff[p],sizeof(buff)-p,"\n%s: %d %s",tr("Rating"),data[0]+3,tr("years"));
   555                 data+=7;
   556                 int l=data[0]; 
   557                 if(l>0) p+=snprintf(&buff[p],sizeof(buff)-p," (%.*s)",l,&data[1]);
   558                 if(p>0) rating=strdup(buff);
   559                 }
   560               break;
   561             case SI::PremiereContentTransmissionDescriptorTag:
   562               if(nCount>=0) {
   563                 SI::PremiereContentTransmissionDescriptor *pct=(SI::PremiereContentTransmissionDescriptor *)d;
   564                 nCount++;
   565                 SI::PremiereContentTransmissionDescriptor::StartDayEntry sd;
   566                 SI::Loop::Iterator it;
   567                 if(pct->startDayLoop.getNext(sd,it)) {
   568                   SI::PremiereContentTransmissionDescriptor::StartDayEntry::StartTimeEntry st;
   569                   SI::Loop::Iterator it2;
   570                   if(sd.startTimeLoop.getNext(st,it2)) {
   571                     time_t StartTime=st.getStartTime(sd.getMJD());
   572                     if(nCount==1) firstTime=StartTime;
   573                     else if(firstTime<StartTime-5*50 || firstTime>StartTime+5*60)
   574                       nCount=-1;
   575                     }
   576                   }
   577                 }
   578               break;
   579             case SI::ExtendedEventDescriptorTag:
   580               {
   581               SI::ExtendedEventDescriptor *eed=(SI::ExtendedEventDescriptor *)d;
   582               if(I18nIsPreferredLanguage(Setup.EPGLanguages,eed->languageCode, LanguagePreferenceExt) || !ExtendedEventDescriptors) {
   583                  delete ExtendedEventDescriptors;
   584                  ExtendedEventDescriptors=new SI::ExtendedEventDescriptors;
   585                  UseExtendedEventDescriptor=true;
   586                  }
   587               if(UseExtendedEventDescriptor) {
   588                  ExtendedEventDescriptors->Add(eed);
   589                  d=NULL; // so that it is not deleted
   590                  }
   591               if(eed->getDescriptorNumber()==eed->getLastDescriptorNumber())
   592                  UseExtendedEventDescriptor=false;
   593               }
   594               break;
   595             case SI::ShortEventDescriptorTag:
   596               {
   597               SI::ShortEventDescriptor *sed=(SI::ShortEventDescriptor *)d;
   598               if(I18nIsPreferredLanguage(Setup.EPGLanguages,sed->languageCode, LanguagePreferenceShort) || !ShortEventDescriptor) {
   599                  delete ShortEventDescriptor;
   600                  ShortEventDescriptor=sed;
   601                  d=NULL; // so that it is not deleted
   602                  }
   603               }
   604               break;
   605             default:
   606               break;
   607             }
   608           delete d;
   609           }
   610         }
   611 
   612         {
   613         bool Modified=false;
   614         int optCount=0;
   615         unsigned int crc[3];
   616         crc[0]=cit.getContentId();
   617         SI::PremiereContentTransmissionDescriptor *pct;
   618         for(SI::Loop::Iterator it; (pct=(SI::PremiereContentTransmissionDescriptor *)cit.eventDescriptors.getNext(it,SI::PremiereContentTransmissionDescriptorTag)); ) {
   619           int nid=pct->getOriginalNetworkId();
   620           int tid=pct->getTransportStreamId();
   621           int sid=pct->getServiceId();
   622           if(SetupPE.FixEpg) {
   623             if(nid==133) {
   624 	      if     (tid==0x03 && sid==0xf0) { tid=0x02; sid=0xe0; }
   625 	      else if(tid==0x03 && sid==0xf1) { tid=0x02; sid=0xe1; }
   626 	      else if(tid==0x03 && sid==0xf5) { tid=0x03; sid=0xdc; }
   627 	      else if(tid==0x04 && sid==0xd2) { tid=0x11; sid=0xe2; }
   628 	      else if(tid==0x11 && sid==0xd3) { tid=0x11; sid=0xe3; }
   629               }
   630             }
   631           tChannelID channelID(Source(),nid,tid,sid);
   632           cChannel *channel=Channels.GetByChannelID(channelID,true);
   633           if(!channel) continue;
   634 
   635           cSchedule *pSchedule=(cSchedule *)Schedules->GetSchedule(channelID);
   636           if(!pSchedule) {
   637              pSchedule=new cSchedule(channelID);
   638              Schedules->Add(pSchedule);
   639              }
   640 
   641           optCount++;
   642           SI::PremiereContentTransmissionDescriptor::StartDayEntry sd;
   643           int index=0;
   644           for(SI::Loop::Iterator it; pct->startDayLoop.getNext(sd,it); ) {
   645             int mjd=sd.getMJD();
   646             SI::PremiereContentTransmissionDescriptor::StartDayEntry::StartTimeEntry st;
   647             for(SI::Loop::Iterator it2; sd.startTimeLoop.getNext(st,it2); ) {
   648               time_t StartTime=st.getStartTime(mjd);
   649               time_t EndTime=StartTime+cit.getDuration();
   650               int runningStatus=(StartTime<now && now<EndTime) ? SI::RunningStatusRunning : ((StartTime-30<now && now<StartTime) ? SI::RunningStatusStartsInAFewSeconds : SI::RunningStatusNotRunning);
   651               bool isOpt=false;
   652               if(index++==0 && nCount>1) isOpt=true;
   653               crc[1]=isOpt ? optCount : 0;
   654               crc[2]=StartTime / STARTTIME_BIAS;
   655               tEventID EventId=((('P'<<8)|'W')<<16) | crc16(0,(unsigned char *)crc,sizeof(crc));
   656 
   657               d2(printf("%s R%d %04x/%.4x %d %d/%d %s +%d ",*channelID.ToString(),runningStatus,EventId&0xFFFF,cit.getContentId(),index,isOpt,optCount,stripspace(ctime(&StartTime)),(int)cit.getDuration()/60))
   658               if(EndTime+Setup.EPGLinger*60<now) {
   659                 d2(printf("(old)\n"))
   660                 continue;
   661                 }
   662 
   663               bool newEvent=false;
   664               cEvent *pEvent=(cEvent *)pSchedule->GetEvent(EventId,-1);
   665               if(!pEvent) {
   666                 d2(printf("(new)\n"))
   667                 pEvent=new cEvent(EventId);
   668                 if(!pEvent) continue;
   669                 newEvent=true;
   670                 }
   671               else {
   672                 d2(printf("(upd)\n"))
   673                 pEvent->SetSeen();
   674                 if(pEvent->TableID()==0x00 || pEvent->Version()==cit.getVersionNumber()) {
   675                   if(pEvent->RunningStatus()!=runningStatus)
   676                     pSchedule->SetRunningStatus(pEvent,runningStatus,channel);
   677                   continue;
   678                   }
   679                 }
   680               pEvent->SetEventID(EventId);
   681               pEvent->SetTableID(Tid);
   682               pEvent->SetVersion(cit.getVersionNumber());
   683               pEvent->SetStartTime(StartTime);
   684               pEvent->SetDuration(cit.getDuration());
   685 
   686               if(ShortEventDescriptor) {
   687                 char buffer[256];
   688                 ShortEventDescriptor->name.getText(buffer,sizeof(buffer));
   689                 if(isOpt) {
   690                   char buffer2[sizeof(buffer)+32];
   691                   snprintf(buffer2,sizeof(buffer2),optPats[SetupPE.OptPat],buffer,optCount);
   692                   pEvent->SetTitle(buffer2);
   693                   }
   694                 else
   695                   pEvent->SetTitle(buffer);
   696                 d2(printf("title: %s\n",pEvent->Title()))
   697                 pEvent->SetShortText(ShortEventDescriptor->text.getText(buffer,sizeof(buffer)));
   698                 }
   699               if(ExtendedEventDescriptors) {
   700                 char buffer[ExtendedEventDescriptors->getMaximumTextLength(": ")+1];
   701                 pEvent->SetDescription(ExtendedEventDescriptors->getText(buffer,sizeof(buffer),": "));
   702                 }
   703               if(order || rating) {
   704                 int len=(pEvent->Description() ? strlen(pEvent->Description()) : 0) +
   705                         (order                 ? strlen(order) : 0) +
   706                         (rating                ? strlen(rating) : 0);
   707                 char buffer[len+32];
   708                 buffer[0]=0;
   709                 if(pEvent->Description()) strcat(buffer,pEvent->Description());
   710                 if(rating)                strcat(buffer,rating);
   711                 if(order)                 strcat(buffer,order);
   712                 pEvent->SetDescription(buffer);
   713                 }
   714 
   715               if(newEvent) pSchedule->AddEvent(pEvent);
   716               pEvent->SetComponents(NULL);
   717               pEvent->FixEpgBugs();
   718               if(pEvent->RunningStatus()!=runningStatus)
   719                 pSchedule->SetRunningStatus(pEvent,runningStatus,channel);
   720               pSchedule->DropOutdated(StartTime,EndTime,Tid,cit.getVersionNumber());
   721               Modified=true;
   722               }
   723             }
   724           if(Modified) {
   725             pSchedule->Sort();
   726             Schedules->SetModified(pSchedule);
   727             }
   728           delete pct;
   729           }
   730         }
   731         delete ExtendedEventDescriptors;
   732         delete ShortEventDescriptor;
   733         free(order);
   734         free(rating);
   735         }
   736       }
   737     }
   738 }
   739 
   740 // --- cPluginPremiereEpg ------------------------------------------------------
   741 
   742 class cPluginPremiereEpg : public cPlugin {
   743 private:
   744   struct {
   745     cFilterPremiereEpg *filter;
   746     cDevice *device;
   747     } epg[MAXDVBDEVICES];
   748 public:
   749   cPluginPremiereEpg(void);
   750   virtual const char *Version(void) { return VERSION; }
   751   virtual const char *Description(void) { return tr(DESCRIPTION); }
   752   virtual bool Start(void);
   753   virtual void Stop(void);
   754   virtual cMenuSetupPage *SetupMenu(void);
   755   virtual bool SetupParse(const char *Name, const char *Value);
   756   };
   757 
   758 cPluginPremiereEpg::cPluginPremiereEpg(void)
   759 {
   760   memset(epg,0,sizeof(epg));
   761 }
   762 
   763 bool cPluginPremiereEpg::Start(void)
   764 {
   765 #if APIVERSNUM < 10507
   766   RegisterI18n(Phrases);
   767 #endif
   768   for(int i=0; i<MAXDVBDEVICES; i++) {
   769     cDevice *dev=cDevice::GetDevice(i);
   770     if(dev) {
   771       epg[i].device=dev;
   772       dev->AttachFilter(epg[i].filter=new cFilterPremiereEpg);
   773       isyslog("Attached premiere EPG filter to device %d",i);
   774       }
   775     }
   776   return true;
   777 }
   778 
   779 void cPluginPremiereEpg::Stop(void)
   780 {
   781   for(int i=0; i<MAXDVBDEVICES; i++) {
   782     cDevice *dev=epg[i].device;
   783     if(dev) dev->Detach(epg[i].filter);
   784     delete epg[i].filter;
   785     epg[i].device=0;
   786     epg[i].filter=0;
   787     }
   788 }
   789 
   790 cMenuSetupPage *cPluginPremiereEpg::SetupMenu(void)
   791 {
   792   return new cMenuSetupPremiereEpg;
   793 }
   794 
   795 bool cPluginPremiereEpg::SetupParse(const char *Name, const char *Value)
   796 {
   797   if      (!strcasecmp(Name, "OptionPattern")) SetupPE.OptPat     = atoi(Value);
   798   else if (!strcasecmp(Name, "OrderInfo"))     SetupPE.OrderInfo  = atoi(Value);
   799   else if (!strcasecmp(Name, "RatingInfo"))    SetupPE.RatingInfo = atoi(Value);
   800   else if (!strcasecmp(Name, "FixEpg"))        SetupPE.FixEpg     = atoi(Value);
   801   else return false;
   802   return true;
   803 }
   804 
   805 VDRPLUGINCREATOR(cPluginPremiereEpg); // Don't touch this!