diff options
-rw-r--r-- | import.cpp | 120 | ||||
-rw-r--r-- | import.h | 11 | ||||
-rw-r--r-- | parse.cpp | 25 | ||||
-rw-r--r-- | po/de_DE.po | 7 | ||||
-rw-r--r-- | po/it_IT.po | 5 | ||||
-rw-r--r-- | setup.cpp | 16 | ||||
-rw-r--r-- | setup.h | 2 | ||||
-rw-r--r-- | source.cpp | 22 | ||||
-rw-r--r-- | source.h | 2 | ||||
-rw-r--r-- | xmltv2vdr.cpp | 41 |
10 files changed, 163 insertions, 88 deletions
@@ -242,13 +242,13 @@ char *cImport::AddEOT2Description(char *description) return description; } -bool cImport::WasChanged(cEvent* event) +bool cImport::WasChanged(cEvent* Event) { - if (!event) return false; - if (!event->Description()) return false; - int len=strlen(event->Description()); + if (!Event) return false; + if (!Event->Description()) return false; + int len=strlen(Event->Description()); if (len<1) return false; - if ((uchar)(event->Description()[len-1])==0xA0) return true; + if ((uchar)(Event->Description()[len-1])==0xA0) return true; return false; } @@ -259,12 +259,17 @@ bool cImport::PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule, if (!schedule) return false; if (!xevent) return false; +#define CHANGED_NOTHING 0 +#define CHANGED_SHORTTEXT 1 +#define CHANGED_DESCRIPTION 2 +#define CHANGED_ALL 3 + struct tm tm; char from[80]; char till[80]; time_t start,end; - bool changed=false; + int changed=CHANGED_NOTHING; bool append=false; if ((Flags & OPT_APPEND)==OPT_APPEND) append=true; @@ -398,7 +403,6 @@ bool cImport::PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule, { source->Dlog("title and subtitle equal, clearing subtitle"); event->SetShortText(""); - changed=true; } else { @@ -406,7 +410,7 @@ bool cImport::PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule, if (!event->ShortText() || strcmp(event->ShortText(),dp)) { event->SetShortText(dp); - changed=true; + changed|=CHANGED_SHORTTEXT; // shorttext really changed } } } @@ -431,8 +435,8 @@ bool cImport::PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule, if (!description && event->Description() && (strlen(event->Description())>0)) { if (WasChanged(event)) return true; - UpdateXMLTVEvent(source->EPGFile(),db,source->Name(),xevent->EventID(),event->EventID(), - event->Description()); + UpdateXMLTVEvent(source,source->EPGFile(),db,event,source->Name(),xevent->EventID(), + event->EventID(),event->Description()); description=strdup(event->Description()); } @@ -706,7 +710,7 @@ bool cImport::PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule, if (!event->Description() || strcmp(event->Description(),dp)) { event->SetDescription(dp); - changed=true; + changed|=CHANGED_DESCRIPTION; } free(description); } @@ -722,9 +726,18 @@ bool cImport::PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule, strftime(from,sizeof(from)-1,"%b %d %H:%M",&tm); localtime_r(&end,&tm); strftime(till,sizeof(till)-1,"%b %d %H:%M",&tm); - source->Dlog("changing %s%s'%s'@%s-%s",xevent->EITDescription() ? "old " : "", - (Option==IMPORT_SHORTTEXT) ? "shorttext " : "description ", - event->Title(),from,till); + switch (changed) + { + case CHANGED_SHORTTEXT: + source->Dlog("changing shorttext of '%s'@%s-%s",event->Title(),from,till); + break; + case CHANGED_DESCRIPTION: + source->Dlog("changing description of '%s'@%s-%s",event->Title(),from,till); + break; + case CHANGED_ALL: + source->Dlog("changing stext+descr of '%s'@%s-%s",event->Title(),from,till); + break; + } } return true; } @@ -920,15 +933,17 @@ cXMLTVEvent *cImport::AddXMLTVEvent(const char *EPGFile, const char *ChannelID, return xevent; } -void cImport::UpdateXMLTVEvent(const char *EPGFile, sqlite3 *db, const char *Source, tEventID EventID, - tEventID EITEventID, const char *EITDescription) +void cImport::UpdateXMLTVEvent(cEPGSource *Source, const char *EPGFile, sqlite3 *Db, const cEvent *Event, + const char *SourceName, tEventID EventID, tEventID EITEventID, + const char *EITDescription) { + if (!Source) return; bool closedb=false; - if (!db) + if (!Db) { - if (sqlite3_open_v2(EPGFile,&db,SQLITE_OPEN_READWRITE,NULL)!=SQLITE_OK) + if (sqlite3_open_v2(EPGFile,&Db,SQLITE_OPEN_READWRITE,NULL)!=SQLITE_OK) { - esyslog("epghandler: failed to open %s",EPGFile); + Source->Elog("failed to open %s",EPGFile); return; } closedb=true; @@ -940,8 +955,8 @@ void cImport::UpdateXMLTVEvent(const char *EPGFile, sqlite3 *db, const char *Sou char *eitdescription=strdup(EITDescription); if (!eitdescription) { - esyslog("epghandler: out of memory"); - if (closedb) sqlite3_close(db); + Source->Elog("out of memory"); + if (closedb) sqlite3_close(Db); return; } @@ -956,45 +971,60 @@ void cImport::UpdateXMLTVEvent(const char *EPGFile, sqlite3 *db, const char *Sou } if (asprintf(&sql,"update epg set eiteventid=%li, eitdescription='%s' where eventid=%li and src='%s'", - (long int) EITEventID,eitdescription,(long int) EventID,Source)==-1) + (long int) EITEventID,eitdescription,(long int) EventID,SourceName)==-1) { free(eitdescription); - esyslog("epghandler: out of memory"); - if (closedb) sqlite3_close(db); + Source->Elog("out of memory"); + if (closedb) sqlite3_close(Db); return; } free(eitdescription); + + if (Event) + { + struct tm tm; + char from[80]; + char till[80]; + time_t start,end; + start=Event->StartTime(); + end=Event->EndTime(); + localtime_r(&start,&tm); + strftime(from,sizeof(from)-1,"%b %d %H:%M",&tm); + localtime_r(&end,&tm); + strftime(till,sizeof(till)-1,"%b %d %H:%M",&tm); + Source->Dlog("updating description of '%s'@%s-%s in db",Event->Title(),from,till); + } } else { if (asprintf(&sql,"update epg set eiteventid=%li where eventid=%li and src='%s'", - (long int) EITEventID,(long int) EventID,Source)==-1) + (long int) EITEventID,(long int) EventID,SourceName)==-1) { - esyslog("epghandler: out of memory"); - if (closedb) sqlite3_close(db); + Source->Elog("out of memory"); + if (closedb) sqlite3_close(Db); return; } } char *errmsg; - if (sqlite3_exec(db,sql,NULL,NULL,&errmsg)!=SQLITE_OK) + if (sqlite3_exec(Db,sql,NULL,NULL,&errmsg)!=SQLITE_OK) { - esyslog("epghandler: %s -> %s",sql,errmsg); + Source->Elog("%s -> %s",sql,errmsg); free(sql); sqlite3_free(errmsg); - if (closedb) sqlite3_close(db); + if (closedb) sqlite3_close(Db); return; } free(sql); - if (closedb) sqlite3_close(db); + if (closedb) sqlite3_close(Db); return; } -cXMLTVEvent *cImport::SearchXMLTVEvent(const char *EPGFile, const char *ChannelID, const cEvent *event) +cXMLTVEvent *cImport::SearchXMLTVEvent(const char *EPGFile, const char *ChannelID, const cEvent *Event) { - if (!event) return NULL; + if (!Event) return NULL; if (!EPGFile) return NULL; cXMLTVEvent *xevent=NULL; @@ -1011,7 +1041,7 @@ cXMLTVEvent *cImport::SearchXMLTVEvent(const char *EPGFile, const char *ChannelI if (asprintf(&sql,"select channelid,eventid,starttime,duration,title,origtitle,shorttext,description," \ "country,year,credits,category,review,rating,starrating,video,audio,season,episode," \ "mixing,src,eiteventid,eitdescription from epg where eiteventid=%li and channelid='%s' " \ - "order by srcidx asc limit 1",(long int) event->EventID(),ChannelID)==-1) + "order by srcidx asc limit 1",(long int) Event->EventID(),ChannelID)==-1) { sqlite3_close(db); esyslog("epghandler: out of memory"); @@ -1026,10 +1056,16 @@ cXMLTVEvent *cImport::SearchXMLTVEvent(const char *EPGFile, const char *ChannelI } int eventTimeDiff=0; - if (event->Duration()) eventTimeDiff=event->Duration()/4; + if (Event->Duration()) eventTimeDiff=Event->Duration()/4; if (eventTimeDiff<780) eventTimeDiff=780; - char *sqltitle=strdup(event->Title()); + char *sqltitle=strdup(Event->Title()); + if (!sqltitle) + { + sqlite3_close(db); + esyslog("epghandler: out of memory"); + return NULL; + } string st=sqltitle; @@ -1037,16 +1073,20 @@ cXMLTVEvent *cImport::SearchXMLTVEvent(const char *EPGFile, const char *ChannelI reps=pcrecpp::RE("'").GlobalReplace("''",&st); if (reps) { - sqltitle=(char *) realloc(sqltitle,st.size()+1); - strcpy(sqltitle,st.c_str()); + char *tmp_sqltitle=(char *) realloc(sqltitle,st.size()+1); + if (tmp_sqltitle) + { + sqltitle=tmp_sqltitle; + strcpy(sqltitle,st.c_str()); + } } if (asprintf(&sql,"select channelid,eventid,starttime,duration,title,origtitle,shorttext,description," \ "country,year,credits,category,review,rating,starrating,video,audio,season,episode," \ "mixing,src,eiteventid,eitdescription,abs(starttime-%li) as diff from epg where " \ " (starttime>=%li and starttime<=%li) and title='%s' and channelid='%s' " \ - " order by diff,srcidx asc limit 1",event->StartTime(),event->StartTime()-eventTimeDiff, - event->StartTime()+eventTimeDiff,sqltitle,ChannelID)==-1) + " order by diff,srcidx asc limit 1",Event->StartTime(),Event->StartTime()-eventTimeDiff, + Event->StartTime()+eventTimeDiff,sqltitle,ChannelID)==-1) { free(sqltitle); sqlite3_close(db); @@ -59,17 +59,18 @@ private: cEvent *SearchVDREvent(cSchedule* schedule, cXMLTVEvent *event); bool FetchXMLTVEvent(sqlite3_stmt *stmt, cXMLTVEvent *xevent); char *RemoveNonASCII(const char *src); - cXMLTVEvent *PrepareAndReturn(sqlite3 *db, char *sql, sqlite3_stmt *stmt); + cXMLTVEvent *PrepareAndReturn(sqlite3 *db, char *sql, sqlite3_stmt *stmt); public: cImport(cEPGSource *Source, cEPGMappings *Maps, cTEXTMappings *Texts); ~cImport(); int Process(cEPGExecutor &myExecutor); - bool WasChanged(cEvent *event); + bool WasChanged(cEvent *Event); bool PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule, cEvent *event, cXMLTVEvent *xevent, int Flags, int Option=IMPORT_ALL); - cXMLTVEvent *SearchXMLTVEvent(const char *EPGFile, const char *ChannelID, const cEvent *event); - void UpdateXMLTVEvent(const char *EPGFile, sqlite3 *db, const char *Source, tEventID EventID, - tEventID EITEventID, const char *EITDescription=NULL); + cXMLTVEvent *SearchXMLTVEvent(const char *EPGFile, const char *ChannelID, const cEvent *Event); + void UpdateXMLTVEvent(cEPGSource *Source, const char *EPGFile, sqlite3 *Db, const cEvent *Event, + const char *SourceName, tEventID EventID, tEventID EITEventID, + const char *EITDescription=NULL); cXMLTVEvent *AddXMLTVEvent(const char *EPGFile, const char *ChannelID, const cEvent *Event, const char *EITDescription); }; @@ -99,10 +99,19 @@ time_t cParse::ConvertXMLTVTime2UnixTime(char *xmltvtime) void cParse::RemoveNonAlphaNumeric(char *String) { if (!String) return; + + // remove " Teil " int len=strlen(String); - char *p=String; - int pos=0; + char *p=strstr(String," Teil "); + if (p) + { + memmove(p,p+6,len-6); + } + // remove non alphanumeric characters + len=strlen(String); + p=String; + int pos=0; while (*p) { // 0x30 - 0x39 @@ -135,6 +144,7 @@ void cParse::RemoveNonAlphaNumeric(char *String) break; } } + return; } @@ -143,6 +153,8 @@ bool cParse::FetchSeasonEpisode(iconv_t Conv, const char *EPDir, const char *Tit { if (!EPDir) return false; if (!ShortText) return false; + size_t slen=strlen(ShortText); + if (!slen) return false; if (!Title) return false; if (Conv==(iconv_t) -1) return false; @@ -176,7 +188,6 @@ bool cParse::FetchSeasonEpisode(iconv_t Conv, const char *EPDir, const char *Tit return false; } - size_t slen=strlen(ShortText); size_t dlen=4*slen; char *dshorttext=(char *) calloc(dlen,1); if (!dshorttext) @@ -197,7 +208,13 @@ bool cParse::FetchSeasonEpisode(iconv_t Conv, const char *EPDir, const char *Tit } RemoveNonAlphaNumeric(dshorttext); - + if (!strlen(dshorttext)) + { + free(dshorttext); + fclose(f); + free(epfile); + return false; + } char *line=NULL; size_t length; diff --git a/po/de_DE.po b/po/de_DE.po index d6a6fff..f64ca30 100644 --- a/po/de_DE.po +++ b/po/de_DE.po @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: vdr\n" "Report-Msgid-Bugs-To: <see README>\n" -"POT-Creation-Date: 2012-04-01 18:24+0200\n" +"POT-Creation-Date: 2012-04-06 17:02+0200\n" "PO-Revision-Date: 2010-12-23 23:59+0100\n" "Last-Translator: Jochen Dolze <vdr@dolze.de>\n" "Language-Team: <vdr@linuxtv.org>\n" @@ -85,8 +85,8 @@ msgstr "Staffel und Episode" msgid "overview" msgstr "Übersicht" -msgid "last execution" -msgstr "Letzte Ausführung" +msgid "next execution" +msgstr "Nächste Ausführung" msgid "active" msgstr "aktiv" @@ -264,4 +264,3 @@ msgstr "xmltv2vdr plugin ist noch aktiv" msgid "Imports xmltv epg into vdr" msgstr "Importiert xmltv epg in den VDR" - diff --git a/po/it_IT.po b/po/it_IT.po index bd360cf..78ea021 100644 --- a/po/it_IT.po +++ b/po/it_IT.po @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: vdr\n" "Report-Msgid-Bugs-To: <see README>\n" -"POT-Creation-Date: 2012-04-01 18:24+0200\n" +"POT-Creation-Date: 2012-04-06 17:02+0200\n" "PO-Revision-Date: 2011-03-05 15:45+0100\n" "Last-Translator: Diego Pierotto <vdr-italian@tiscali.it>\n" "Language-Team: <vdr@linuxtv.org>\n" @@ -88,7 +88,7 @@ msgstr "" msgid "overview" msgstr "" -msgid "last execution" +msgid "next execution" msgstr "" msgid "active" @@ -267,4 +267,3 @@ msgstr "Plugin XMLTV2VDR ancora in esecuzione" msgid "Imports xmltv epg into vdr" msgstr "Importa EPG di XMLTV in VDR" - @@ -515,23 +515,23 @@ void cMenuSetupXmltv2vdrLog::output(void) int cur=Current(); Clear(); Add(NewTitle(tr("overview"))); - time_t lastexec=src->LastExecution(); - if (lastexec) + time_t nextrun=src->NextRunTime(); + if (nextrun) { struct tm tm; - localtime_r(&lastexec,&tm); - strftime(lastexec_str,sizeof(lastexec_str)-1,"%d %b %H:%M:%S",&tm); + localtime_r(&nextrun,&tm); + strftime(nextrun_str,sizeof(nextrun_str)-1,"%d %b %H:%M:%S",&tm); } cString last; if (src->Active()) { - last=cString::sprintf("%s:\t%s",tr("last execution"), + last=cString::sprintf("%s:\t%s",tr("next execution"), tr("active")); } else { - last=cString::sprintf("%s:\t%s",tr("last execution"), - lastexec ? lastexec_str : "-"); + last=cString::sprintf("%s:\t%s",tr("next execution"), + nextrun ? nextrun_str : "-"); } Add(new cOsdItem(last,osUnknown,true)); @@ -616,6 +616,8 @@ cMenuSetupXmltv2vdrLog::cMenuSetupXmltv2vdrLog(cPluginXmltv2vdr *Plugin, cEPGSou width=0; lastrefresh=(time_t) 0; font=NULL; + nextrun_str[0]=0; + cSkinDisplayMenu *disp=DisplayMenu(); if (disp) { @@ -178,7 +178,7 @@ private: }; int level; cEPGSource *src; - char lastexec_str[30]; + char nextrun_str[30]; void output(void); int width; time_t lastrefresh; @@ -147,20 +147,28 @@ cEPGSource::~cEPGSource() if (import) delete import; } -time_t cEPGSource::NextRunTime() +time_t cEPGSource::NextRunTime(time_t Now) { if (disabled) return 0; // never! if (exec_upstart) return 0; // only once! - time_t t,now=time(NULL); - t=cTimer::SetTime(now,cTimer::TimeToInt(exec_time)); + time_t t; + if (!Now) + { + Now=(time(NULL)/60)*60; + } + t=cTimer::SetTime(Now,cTimer::TimeToInt(exec_time)); while ((exec_weekday & (1<<cTimer::GetWDay(t)))==0) { t=cTimer::IncDay(t,1); } - if (t<now) t=cTimer::IncDay(t,1); + if (t<Now) + { + t=cTimer::IncDay(t,1); + lastexec=(time_t) 0; + } return t; } @@ -178,10 +186,10 @@ bool cEPGSource::RunItNow() } else { - time_t t=time(NULL); - time_t nrt=NextRunTime(); + time_t t=(time(NULL)/60)*60; + time_t nrt=NextRunTime(t); if (!nrt) return false; - if ((t>nrt) && t<(nrt+5)) return true; + if (t==nrt) return true; return false; } } @@ -79,7 +79,7 @@ public: int Execute(cEPGExecutor &myExecutor); int Import(cEPGExecutor &myExecutor); bool RunItNow(); - time_t NextRunTime(); + time_t NextRunTime(time_t Now=(time_t) 0); void Store(void); void ChangeChannelSelection(int *Selection); char *Log; diff --git a/xmltv2vdr.cpp b/xmltv2vdr.cpp index 6e00925..f0d83f9 100644 --- a/xmltv2vdr.cpp +++ b/xmltv2vdr.cpp @@ -98,13 +98,15 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description) if (xevent->EITDescription() && Description && strcasecmp(xevent->EITDescription(),Description)) update=true; + cEPGSource *source=sources->GetSource(xevent->Source()); + if (update) { - import->UpdateXMLTVEvent(epgfile,NULL,xevent->Source(), + import->UpdateXMLTVEvent(source,epgfile,NULL,Event,xevent->Source(), xevent->EventID(),Event->EventID(),Description); } - bool ret=import->PutEvent(sources->GetSource(xevent->Source()),NULL, + bool ret=import->PutEvent(source,NULL, (cSchedule *) Event->Schedule(), Event,xevent,Flags,IMPORT_DESCRIPTION); delete xevent; @@ -140,11 +142,12 @@ bool cEPGHandler::SetShortText(cEvent* Event, const char* UNUSED(ShortText)) cXMLTVEvent *xevent=import->SearchXMLTVEvent(epgfile,map->ChannelName(),Event); if (!xevent) return false; - if (!xevent->EITEventID()) import->UpdateXMLTVEvent(epgfile,NULL,xevent->Source(), + cEPGSource *source=sources->GetSource(xevent->Source()); + + if (!xevent->EITEventID()) import->UpdateXMLTVEvent(source,epgfile,NULL,Event,xevent->Source(), xevent->EventID(),Event->EventID()); - bool ret=import->PutEvent(sources->GetSource(xevent->Source()),NULL, - (cSchedule *) Event->Schedule(),Event,xevent, + bool ret=import->PutEvent(source,NULL,(cSchedule *) Event->Schedule(),Event,xevent, map->Flags(),IMPORT_SHORTTEXT); delete xevent; if (!ret) @@ -181,9 +184,10 @@ void cEPGTimer::Action() for (cTimer *Timer = Timers.First(); Timer; Timer = Timers.Next(Timer)) { - const cEvent *event=Timer->Event(); + cEvent *event=(cEvent *) Timer->Event(); if (!event) continue; if (!event->ShortText()) continue; // no short text -> no episode + if (!strlen(event->ShortText())) continue; // empty short text -> no episode if (maps->ProcessChannel(event->ChannelID())) continue; // already processed by xmltv2vdr cChannel *chan=Channels.GetByChannelID(event->ChannelID()); @@ -201,7 +205,7 @@ void cEPGTimer::Action() if (schedule) { import->PutEvent(sources->GetSource(EITSOURCE),NULL,schedule, - (cEvent *) event,xevent,USE_SEASON,IMPORT_DESCRIPTION); + event,xevent,USE_SEASON,IMPORT_DESCRIPTION); } delete xevent; } @@ -307,8 +311,9 @@ bool cPluginXmltv2vdr::EPGSourceMove(int From, int To) const char *cPluginXmltv2vdr::CommandLineHelp(void) { // Return a string that describes all known command line options. - return " -E FILE, --epgfile=FILE write the EPG data into the given FILE(default is\n" - " 'epg.db' in the video directory)\n"; + return " -E FILE, --epgfile=FILE write the EPG data into the given FILE (default is\n" + " 'epg.db' in the video directory) - best performance\n" + " if located on a ramdisk\n"; } bool cPluginXmltv2vdr::ProcessArgs(int argc, char *argv[]) @@ -418,8 +423,12 @@ void cPluginXmltv2vdr::Housekeeping(void) } else { - isyslog("xmltv2vdr: removed %i old entries from db",sqlite3_changes(db)); - sqlite3_exec(db,"VACCUM;",NULL,NULL,NULL); + int changes=sqlite3_changes(db); + if (changes) + { + isyslog("xmltv2vdr: removed %i old entries from db",changes); + sqlite3_exec(db,"VACCUM;",NULL,NULL,NULL); + } } free(sql); } @@ -428,7 +437,7 @@ void cPluginXmltv2vdr::Housekeeping(void) } } } - last_housetime_t=now; + last_housetime_t=(now / 3600)*3600; } } @@ -437,23 +446,23 @@ void cPluginXmltv2vdr::MainThreadHook(void) // Perform actions in the context of the main program thread. // WARNING: Use with great care - see PLUGINS.html! time_t now=time(NULL); - if (now>(last_maintime_t+60)) + if (now>=(last_maintime_t+60)) { if (!epgexecutor.Active()) { if (epgsources.RunItNow()) epgexecutor.Start(); } - last_maintime_t=now; + last_maintime_t=(now/60)*60; } if (epall) { - if (now>(last_epcheck_t+600)) + if (now>=(last_epcheck_t+600)) { if (IsIdle()) { epgtimer->Start(); } - last_epcheck_t=now; + last_epcheck_t=(now/600)*600; } } } |