summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Dolze <vdr@dolze.de>2012-04-24 00:31:18 +0200
committerJochen Dolze <vdr@dolze.de>2012-04-24 00:31:18 +0200
commit5f9d257b756d372a0033db0b17e87e573fefcbfd (patch)
tree505bdf316a565f697003ae87fbb5e0cfa91d568f
parent5a6f00a4048d5ad48e1676b485f778c2d9f44020 (diff)
downloadvdr-plugin-xmltv2vdr-5f9d257b756d372a0033db0b17e87e573fefcbfd.tar.gz
vdr-plugin-xmltv2vdr-5f9d257b756d372a0033db0b17e87e573fefcbfd.tar.bz2
Added support for mixing channels with different eventids (e.g. zdf,zdfhd)
Replaced mixing field with picexists Changed some debugging output
-rw-r--r--event.cpp10
-rw-r--r--event.h10
-rw-r--r--import.cpp58
-rw-r--r--import.h3
-rw-r--r--parse.cpp34
-rw-r--r--xmltv2vdr.cpp124
-rw-r--r--xmltv2vdr.h6
7 files changed, 135 insertions, 110 deletions
diff --git a/event.cpp b/event.cpp
index 83ddb20..09e9563 100644
--- a/event.cpp
+++ b/event.cpp
@@ -275,7 +275,7 @@ const char *cXMLTVEvent::GetSQL(const char *Source, int SrcIdx, const char *Chan
if (asprintf(&sql,"INSERT OR IGNORE INTO epg (src,channelid,eventid,starttime,duration,"\
"title,origtitle,shorttext,description,country,year,credits,category,"\
- "review,rating,starrating,video,audio,season,episode,mixing,srcidx) "\
+ "review,rating,starrating,video,audio,season,episode,picexists,srcidx) "\
"VALUES (^%s^,^%s^,%i,%li,%i,"\
"^%s^,^%s^,^%s^,^%s^,^%s^,%i,^%s^,^%s^,"\
"^%s^,^%s^,^%s^,^%s^,^%s^,%i,%i,%i,%i);"\
@@ -283,7 +283,7 @@ const char *cXMLTVEvent::GetSQL(const char *Source, int SrcIdx, const char *Chan
"UPDATE epg SET duration=%i,starttime=%li,title=^%s^,origtitle=^%s^,"\
"shorttext=^%s^,description=^%s^,country=^%s^,year=%i,credits=^%s^,category=^%s^,"\
"review=^%s^,rating=^%s^,starrating=^%s^,video=^%s^,audio=^%s^,season=%i,episode=%i, "\
- "mixing=%i,srcidx=%i " \
+ "picexists=%i,srcidx=%i " \
" where changes()=0 and src=^%s^ and channelid=^%s^ and eventid=%i"
,
Source,ChannelID,eventid,starttime,duration,title,
@@ -294,7 +294,7 @@ const char *cXMLTVEvent::GetSQL(const char *Source, int SrcIdx, const char *Chan
year,
cr,ca,re,ra,sr,vi,
audio ? audio : "NULL",
- season, episode, mixing, SrcIdx,
+ season, episode, picexists, SrcIdx,
duration,starttime,title,
origtitle ? origtitle : "NULL",
@@ -304,7 +304,7 @@ const char *cXMLTVEvent::GetSQL(const char *Source, int SrcIdx, const char *Chan
year,
cr,ca,re,ra,sr,vi,
audio ? audio : "NULL",
- season, episode, mixing, SrcIdx,
+ season, episode, picexists, SrcIdx,
Source,ChannelID,eventid
@@ -390,7 +390,7 @@ void cXMLTVEvent::Clear()
episode=0;
parentalRating=0;
memset(&contents,0,sizeof(contents));
- mixing=false;
+ picexists=false;
}
cXMLTVEvent::cXMLTVEvent()
diff --git a/event.h b/event.h
index 14e8eb6..c6ca6af 100644
--- a/event.h
+++ b/event.h
@@ -42,7 +42,7 @@ private:
char *sql;
char *channelid;
char *source;
- bool mixing;
+ bool picexists;
int year;
time_t starttime;
int duration;
@@ -136,9 +136,9 @@ public:
{
eiteventid=EventID;
}
- void SetMixing(void)
+ void SetPicExists(void)
{
- mixing=true;
+ picexists=true;
}
int ParentalRating() const
{
@@ -212,9 +212,9 @@ public:
{
return episode;
}
- bool Mixing(void)
+ bool PicExists(void)
{
- return mixing;
+ return picexists;
}
};
diff --git a/import.cpp b/import.cpp
index 479581a..e4b0271 100644
--- a/import.cpp
+++ b/import.cpp
@@ -82,7 +82,7 @@ char *cImport::RemoveNonASCII(const char *src)
return dst;
}
-cEvent *cImport::SearchVDREvent(cEPGSource *source, cSchedule* schedule, cXMLTVEvent *xevent)
+cEvent *cImport::SearchVDREvent(cEPGSource *source, cSchedule* schedule, cXMLTVEvent *xevent, bool append)
{
if (!source) return NULL;
if (!schedule) return NULL;
@@ -95,7 +95,7 @@ cEvent *cImport::SearchVDREvent(cEPGSource *source, cSchedule* schedule, cXMLTVE
if (xevent->EITEventID()) f=(cEvent *) schedule->GetEvent(xevent->EITEventID());
if (f) return f;
- if (xevent->EventID() && !xevent->Mixing()) f=(cEvent *) schedule->GetEvent(xevent->EventID());
+ if (xevent->EventID() && append) f=(cEvent *) schedule->GetEvent(xevent->EventID());
if (f) return f;
// 2nd with StartTime
@@ -298,6 +298,8 @@ bool cImport::PutEvent(cEPGSource *Source, sqlite3 *Db, cSchedule* Schedule,
int changed=CHANGED_NOTHING;
bool append=false;
+ bool retcode=false;
+
if ((Flags & OPT_APPEND)==OPT_APPEND) append=true;
if (append && !Event)
@@ -417,6 +419,7 @@ bool cImport::PutEvent(cEPGSource *Source, sqlite3 *Db, cSchedule* Schedule,
strftime(till,sizeof(till)-1,"%b %d %H:%M",&tm);
tsyslogs(Source,"adding '%s'@%s-%s",xEvent->Title(),from,till);
}
+ retcode=true;
}
else
{
@@ -462,7 +465,7 @@ bool cImport::PutEvent(cEPGSource *Source, sqlite3 *Db, cSchedule* Schedule,
if (!description && Event->Description() && (strlen(Event->Description())>0))
{
- if (WasChanged(Event)) return true;
+ if (WasChanged(Event)) return false;
UpdateXMLTVEvent(Source,Db,Event,xEvent);
description=strdup(Event->Description());
}
@@ -767,7 +770,7 @@ bool cImport::PutEvent(cEPGSource *Source, sqlite3 *Db, cSchedule* Schedule,
if ((changed==CHANGED_SHORTTEXT) && (WasChanged(Event)==false))
{
- description=strdup(Event->Description());
+ if (Event->Description()) description=strdup(Event->Description());
if (description)
{
description=AddEOT2Description(description,true);
@@ -801,8 +804,9 @@ bool cImport::PutEvent(cEPGSource *Source, sqlite3 *Db, cSchedule* Schedule,
break;
}
}
+ retcode=true;
}
- return true;
+ return retcode;
}
bool cImport::FetchXMLTVEvent(sqlite3_stmt *stmt, cXMLTVEvent *xevent)
@@ -873,7 +877,7 @@ bool cImport::FetchXMLTVEvent(sqlite3_stmt *stmt, cXMLTVEvent *xevent)
xevent->SetEpisode(sqlite3_column_int(stmt,col));
break;
case 19:
- if (sqlite3_column_int(stmt,col)==1) xevent->SetMixing();
+ if (sqlite3_column_int(stmt,col)==1) xevent->SetPicExists();
break;
case 20: // source
xevent->SetSource((const char *) sqlite3_column_text(stmt,col));
@@ -1040,8 +1044,9 @@ bool cImport::UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Ev
strcpy(eitdescription,ed.c_str());
}
- if (asprintf(&sql,"update epg set eiteventid=%li, eitdescription='%s' where eventid=%li and src='%s'",
- (long int) Event->EventID(),eitdescription,(long int) xEvent->EventID(),Source->Name())==-1)
+ if (asprintf(&sql,"update epg set eiteventid=%li, eitdescription='%s' where eventid=%li and "
+ "src='%s' and channelid='%s'",(long int) Event->EventID(),eitdescription,
+ (long int) xEvent->EventID(),Source->Name(),*Event->ChannelID().ToString())==-1)
{
free(eitdescription);
esyslogs(Source,"out of memory");
@@ -1051,8 +1056,9 @@ bool cImport::UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Ev
}
else
{
- if (asprintf(&sql,"update epg set eiteventid=%li where eventid=%li and src='%s'",
- (long int) Event->EventID(),(long int) xEvent->EventID(),Source->Name())==-1)
+ if (asprintf(&sql,"update epg set eiteventid=%li where eventid=%li and src='%s' and "
+ "channelid='%s'",(long int) Event->EventID(),(long int) xEvent->EventID(),
+ Source->Name(),*Event->ChannelID().ToString())==-1)
{
esyslogs(Source,"out of memory");
return false;
@@ -1109,7 +1115,7 @@ cXMLTVEvent *cImport::SearchXMLTVEvent(sqlite3 **Db,const char *ChannelID, const
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' " \
+ "picexists,src,eiteventid,eitdescription from epg where eiteventid=%li and channelid='%s' " \
"order by srcidx asc limit 1;",(long int) Event->EventID(),ChannelID)==-1)
{
esyslog("out of memory");
@@ -1146,7 +1152,7 @@ cXMLTVEvent *cImport::SearchXMLTVEvent(sqlite3 **Db,const char *ChannelID, const
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 " \
+ "picexists,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)
@@ -1248,7 +1254,7 @@ int cImport::Process(cEPGSource *Source, cEPGExecutor &myExecutor)
char *sql;
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 (starttime > %li or " \
+ "picexists,src,eiteventid,eitdescription from epg where (starttime > %li or " \
" (starttime + duration) > %li) and (starttime + duration) < %li "\
" and src='%s';",begin,begin,end,Source->Name())==-1)
{
@@ -1278,7 +1284,7 @@ int cImport::Process(cEPGSource *Source, cEPGExecutor &myExecutor)
cXMLTVEvent xevent;
if (FetchXMLTVEvent(stmt,&xevent))
{
- cEPGMapping *map=maps->GetMap(xevent.ChannelID());
+ cEPGMapping *map=maps->GetMap(tChannelID::FromString(xevent.ChannelID()));
if (!map)
{
if (lerr!=IMPORT_NOMAPPING)
@@ -1312,7 +1318,7 @@ int cImport::Process(cEPGSource *Source, cEPGExecutor &myExecutor)
continue;
}
- cEvent *event=SearchVDREvent(Source, schedule, &xevent);
+ cEvent *event=SearchVDREvent(Source, schedule, &xevent, addevents);
if (addevents && event && (event->EventID() != xevent.EventID()))
{
@@ -1325,8 +1331,7 @@ int cImport::Process(cEPGSource *Source, cEPGExecutor &myExecutor)
#if VDRVERSNUM < 10726 && (!EPGHANDLER)
if ((!addevents) && (xevent.StartTime()>endoneday)) continue;
#endif
- PutEvent(Source, db, schedule, event, &xevent, map->Flags());
- cnt++;
+ if (PutEvent(Source, db, schedule, event, &xevent, map->Flags())) cnt++;
}
}
}
@@ -1338,7 +1343,14 @@ int cImport::Process(cEPGSource *Source, cEPGExecutor &myExecutor)
if (Commit(Source,db))
{
- dsyslogs(Source,"processed %i xmltv events",cnt);
+ if (cnt)
+ {
+ dsyslogs(Source,"processed %i vdr events",cnt);
+ }
+ else
+ {
+ dsyslogs(Source,"processed no vdr events - all up to date?");
+ }
}
sqlite3_finalize(stmt);
@@ -1347,6 +1359,16 @@ int cImport::Process(cEPGSource *Source, cEPGExecutor &myExecutor)
return 0;
}
+bool cImport::DBExists()
+{
+ if (!epgfile) return true; // is this safe?
+ struct stat statbuf;
+ if (stat(epgfile,&statbuf)==-1) return false; // no database
+ if (!statbuf.st_size) return false; // no database
+ return true;
+}
+
+
cImport::cImport(const char *EPGFile, cEPGMappings* Maps, cTEXTMappings *Texts)
{
maps=Maps;
diff --git a/import.h b/import.h
index 5750fec..7864412 100644
--- a/import.h
+++ b/import.h
@@ -50,7 +50,7 @@ private:
char *AddEOT2Description(char *description, bool checkutf8=false);
struct split split(char *in, char delim);
cEvent *GetEventBefore(cSchedule* schedule, time_t start);
- cEvent *SearchVDREvent(cEPGSource *source, cSchedule* schedule, cXMLTVEvent *event);
+ cEvent *SearchVDREvent(cEPGSource *source, cSchedule* schedule, cXMLTVEvent *event, bool append);
bool FetchXMLTVEvent(sqlite3_stmt *stmt, cXMLTVEvent *xevent);
char *RemoveNonASCII(const char *src);
cXMLTVEvent *PrepareAndReturn(sqlite3 *db, char *sql);
@@ -60,6 +60,7 @@ public:
int Process(cEPGSource *Source, cEPGExecutor &myExecutor);
bool Begin(cEPGSource *Source, sqlite3 *Db);
bool Commit(cEPGSource *Source, sqlite3 *Db);
+ bool DBExists();
bool PutEvent(cEPGSource *Source, sqlite3 *Db, cSchedule* Schedule, cEvent *Event,
cXMLTVEvent *xEvent, int Flags);
bool UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Event, cXMLTVEvent *xEvent);
diff --git a/parse.cpp b/parse.cpp
index 31d45af..e48ea43 100644
--- a/parse.cpp
+++ b/parse.cpp
@@ -211,10 +211,7 @@ 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;
+ strcpy(dshorttext,ShortText); // ok lets try with the original text
}
char *line=NULL;
@@ -236,6 +233,10 @@ bool cParse::FetchSeasonEpisode(iconv_t Conv, const char *EPDir, const char *Tit
if (iconv(Conv,&FromPtr,&slen,&ToPtr,&dlen)!=(size_t) -1)
{
RemoveNonAlphaNumeric(depshorttext);
+ if (!strlen(depshorttext))
+ {
+ strcpy(depshorttext,epshorttext); // ok lets try with the original text
+ }
if (!strncasecmp(dshorttext,depshorttext,strlen(depshorttext)))
{
found=true;
@@ -500,6 +501,7 @@ bool cParse::FetchEvent(xmlNodePtr enode)
else if ((!xmlStrcasecmp(node->name, (const xmlChar *) "icon")))
{
// http-link inside -> just ignore
+ xevent.SetPicExists();
}
else if ((!xmlStrcasecmp(node->name, (const xmlChar *) "length")))
{
@@ -590,7 +592,7 @@ int cParse::Process(cEPGExecutor &myExecutor,char *buffer, int bufsize)
"shorttext nvarchar(255), description text, eitdescription text, " \
"country nvarchar(255), year int, " \
"credits text, category text, review text, rating text, " \
- "starrating text, video text, audio text, season int, episode int, mixing int," \
+ "starrating text, video text, audio text, season int, episode int, picexists int," \
"srcidx int," \
"PRIMARY KEY(src, channelid, eventid)" \
");" \
@@ -648,6 +650,7 @@ int cParse::Process(cEPGExecutor &myExecutor,char *buffer, int bufsize)
node=node->next;
continue;
}
+ xmlFree(channelid);
xmlChar *start,*stop;
time_t starttime=(time_t) 0;
@@ -673,14 +676,12 @@ int cParse::Process(cEPGExecutor &myExecutor,char *buffer, int bufsize)
if (lerr!=PARSE_XMLTVERR)
esyslogs(source,"no starttime, check xmltv file");
lerr=PARSE_XMLTVERR;
- xmlFree(channelid);
node=node->next;
continue;
}
if (starttime<begin)
{
- xmlFree(channelid);
node=node->next;
continue;
}
@@ -688,25 +689,22 @@ int cParse::Process(cEPGExecutor &myExecutor,char *buffer, int bufsize)
xevent.SetStartTime(starttime);
if (stoptime) xevent.SetDuration(stoptime-starttime);
- if ((map->Flags() & OPT_APPEND)!=OPT_APPEND) xevent.SetMixing();
-
if (!FetchEvent(node)) // sets xevent
{
tsyslogs(source,"failed to fetch event");
node=node->next;
- xmlFree(channelid);
continue;
}
-
- const char *sql=xevent.GetSQL(source->Name(),source->Index(),(const char *) channelid);
- if (sqlite3_exec(db,sql,NULL,NULL,&errmsg)!=SQLITE_OK)
+ for (int i=0; i<map->NumChannelIDs(); i++)
{
- tsyslogs(source,"sqlite3: %s",errmsg);
- sqlite3_free(errmsg);
- xmlFree(channelid);
- break;
+ const char *sql=xevent.GetSQL(source->Name(),source->Index(),map->ChannelIDs()[i].ToString());
+ if (sqlite3_exec(db,sql,NULL,NULL,&errmsg)!=SQLITE_OK)
+ {
+ tsyslogs(source,"sqlite3: %s",errmsg);
+ sqlite3_free(errmsg);
+ break;
+ }
}
- xmlFree(channelid);
cnt++;
node=node->next;
diff --git a/xmltv2vdr.cpp b/xmltv2vdr.cpp
index 4cbb7da..ad2a218 100644
--- a/xmltv2vdr.cpp
+++ b/xmltv2vdr.cpp
@@ -122,19 +122,12 @@ void logger(cEPGSource *source, char logtype, const char* format, ...)
// -------------------------------------------------------------
cEPGHandler::cEPGHandler(const char *EpgFile, cEPGSources *Sources,
- cEPGMappings *Maps, cTEXTMappings *Texts)
+ cEPGMappings *Maps, cTEXTMappings *Texts) : import(EpgFile,Maps,Texts)
{
epall=false;
maps=Maps;
sources=Sources;
db=NULL;
- epgfile = EpgFile;
- import = new cImport(EpgFile,Maps,Texts);
-}
-
-cEPGHandler::~cEPGHandler()
-{
- if (import) delete import;
}
bool cEPGHandler::IgnoreChannel(const cChannel* Channel)
@@ -147,16 +140,13 @@ bool cEPGHandler::IgnoreChannel(const cChannel* Channel)
bool cEPGHandler::check4proc(cEvent *event, bool &spth)
{
if (!event) return false;
- if (!import) return false;
/*
- if (import->WasChanged(event)) {
+ if (import.WasChanged(event)) {
tsyslog("{%i} already seen %s",Event->EventID(),Event->Title());
}
*/
if (!maps) return false;
- struct stat statbuf;
- if (stat(epgfile,&statbuf)==-1) return false; // no database? -> exit immediately
- if (!statbuf.st_size) return false; // no database? -> exit immediately
+ if (!import.DBExists()) return false;
spth=false;
if (!maps->ProcessChannel(event->ChannelID()))
@@ -171,31 +161,33 @@ bool cEPGHandler::check4proc(cEvent *event, bool &spth)
bool cEPGHandler::SetShortText(cEvent* Event, const char* ShortText)
{
- bool notused;
- if (!check4proc(Event,notused)) return false;
+ bool seth;
+ if (!check4proc(Event,seth)) return false;
- if (import->WasChanged(Event))
+ if (import.WasChanged(Event))
{
// ok we already changed this event!
- tsyslog("{%i} already seen stext '%s'",Event->EventID(),Event->Title());
+ tsyslog("{%i} %salready seen stext '%s'",Event->EventID(),seth ? "*" : "",
+ Event->Title());
return true;
}
// prevent setting empty shorttext
if (!ShortText) return true;
// prevent setting empty shorttext
if (!strlen(ShortText)) return true;
- // prevent setting shorttext equal
+ // prevent setting shorttext equal to title
if (Event->Title() && !strcasecmp(Event->Title(),ShortText)) return true;
- tsyslog("{%i} setting stext (%s) of '%s'",Event->EventID(),ShortText,Event->Title());
+ tsyslog("{%i} %ssetting stext (%s) of '%s'",Event->EventID(),seth ? "*" : "",
+ ShortText,Event->Title());
return false;
}
bool cEPGHandler::SetDescription(cEvent* Event, const char* Description)
{
- bool notused;
- if (!check4proc(Event,notused)) return false;
+ bool seth;
+ if (!check4proc(Event,seth)) return false;
- if (import->WasChanged(Event))
+ if (import.WasChanged(Event))
{
// ok we already changed this event!
if (!Description) return true; // prevent setting nothing to description
@@ -203,13 +195,16 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description)
if (strncasecmp(Event->Description(),Description,len))
{
// eit description changed -> set it
- tsyslog("{%i} changing descr of '%s'",Event->EventID(),Event->Title());
+ tsyslog("{%i} %schanging descr of '%s'",Event->EventID(),seth ? "*" : "",
+ Event->Title());
return false;
}
- tsyslog("{%i} already seen descr '%s'",Event->EventID(),Event->Title());
+ tsyslog("{%i} %salready seen descr '%s'",Event->EventID(),seth ? "*" : "",
+ Event->Title());
return true;
}
- tsyslog("{%i} setting descr of '%s'",Event->EventID(),Event->Title());
+ tsyslog("{%i} %ssetting descr of '%s'",Event->EventID(),seth ? "*" : "",
+ Event->Title());
return false;
}
@@ -220,29 +215,23 @@ bool cEPGHandler::HandleEvent(cEvent* Event)
if (!check4proc(Event,special_epall_timer_handling)) return false;
int Flags=0;
- const char *ChannelID;
+ const char *ChannelID=strdup(*Event->ChannelID().ToString());
+ if (!ChannelID) return false;
if (special_epall_timer_handling)
{
- cChannel *chan=Channels.GetByChannelID(Event->ChannelID());
- if (!chan)
- {
- tsyslog("no channel for %s",*Event->ChannelID().ToString());
- return false;
- }
Flags=USE_SEASON;
- ChannelID=chan->Name();
}
else
{
cEPGMapping *map=maps->GetMap(Event->ChannelID());
if (!map)
{
- tsyslog("no map for channel %s",*Event->ChannelID().ToString());
+ tsyslog("no map for channel %s",ChannelID);
+ free((void*)ChannelID);
return false;
}
Flags=map->Flags();
- ChannelID=map->ChannelName();
}
if (ioprio_set(1,getpid(),7 | 3 << 13)==-1)
@@ -251,19 +240,28 @@ bool cEPGHandler::HandleEvent(cEvent* Event)
}
cEPGSource *source=NULL;
- cXMLTVEvent *xevent=import->SearchXMLTVEvent(&db,ChannelID,Event);
+ cXMLTVEvent *xevent=import.SearchXMLTVEvent(&db,ChannelID,Event);
if (!xevent)
{
- if (!epall) return false;
+ if (!epall)
+ {
+ free((void*)ChannelID);
+ return false;
+ }
source=sources->GetSource(EITSOURCE);
if (!source) tsyslog("no source for %s",EITSOURCE);
- xevent=import->AddXMLTVEvent(source,db,ChannelID,Event,Event->Description());
- if (!xevent) return false;
+ xevent=import.AddXMLTVEvent(source,db,ChannelID,Event,Event->Description());
+ if (!xevent)
+ {
+ free((void*)ChannelID);
+ return false;
+ }
}
else
{
source=sources->GetSource(xevent->Source());
}
+ free((void*)ChannelID);
if (!source)
{
tsyslog("no source for %s",xevent->Source());
@@ -275,15 +273,15 @@ bool cEPGHandler::HandleEvent(cEvent* Event)
if (!xevent->EITEventID()) update=true;
if (!xevent->EITDescription() && Event->Description()) update=true;
- if (xevent->EITDescription() && Event->Description() && !import->WasChanged(Event) &&
+ if (xevent->EITDescription() && Event->Description() && !import.WasChanged(Event) &&
strcasecmp(xevent->EITDescription(),Event->Description())) update=true;
if (update)
{
- import->UpdateXMLTVEvent(source,db,Event,xevent); // ignore errors
+ import.UpdateXMLTVEvent(source,db,Event,xevent); // ignore errors
}
- import->PutEvent(source,db,(cSchedule *) Event->Schedule(),Event,xevent,Flags);
+ import.PutEvent(source,db,(cSchedule *) Event->Schedule(),Event,xevent,Flags);
delete xevent;
return false; // let VDR fix the bugs!
}
@@ -292,7 +290,7 @@ bool cEPGHandler::SortSchedule(cSchedule* UNUSED(Schedule))
{
if (db)
{
- import->Commit(NULL,db);
+ import.Commit(NULL,db);
sqlite3_close(db);
db=NULL;
}
@@ -347,14 +345,19 @@ void cEPGTimer::Action()
cChannel *chan=Channels.GetByChannelID(event->ChannelID());
if (!chan) continue;
- const char *ChannelID=chan->Name();
+ const char *ChannelID=strdup(*event->ChannelID().ToString());
cXMLTVEvent *xevent=import->SearchXMLTVEvent(&db,ChannelID,event);
if (!xevent)
{
xevent=import->AddXMLTVEvent(source,db,ChannelID,event,event->Description());
- if (!xevent) continue;
+ if (!xevent)
+ {
+ free((void*)ChannelID);
+ continue;
+ }
}
+ free((void*)ChannelID);
cSchedule* schedule = (cSchedule *) schedules->GetSchedule(chan,false);
if (schedule)
@@ -437,6 +440,7 @@ cPluginXmltv2vdr::cPluginXmltv2vdr(void) : epgexecutor(&epgsources)
last_housetime_t=0;
last_maintime_t=0;
last_epcheck_t=0;
+ nextruntime=0;
wakeup=0;
insetup=false;
SetEPAll(false);
@@ -565,9 +569,6 @@ bool cPluginXmltv2vdr::Start(void)
}
cParse::InitLibXML();
- dbmutex=sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
- if (!dbmutex) return false;
-
ReadInEPGSources();
epghandler = new cEPGHandler(epgfile,&epgsources,&epgmappings,&textmappings);
epgtimer = new cEPGTimer(epgfile,&epgsources,&epgmappings,&textmappings);
@@ -582,17 +583,24 @@ void cPluginXmltv2vdr::Stop(void)
// Stop any background activities the plugin is performing.
cSchedules::Cleanup(true);
epgtimer->Stop();
- if (epgtimer) delete epgtimer;
- if (housekeeping) delete housekeeping;
+ if (epgtimer) {
+ delete epgtimer;
+ epgtimer=NULL;
+ }
+ if (housekeeping) {
+ delete housekeeping;
+ housekeeping=NULL;
+ }
epgexecutor.Stop();
+ if (wakeup)
+ {
+ nextruntime=epgsources.NextRunTime();
+ if (nextruntime) nextruntime-=(time_t) 180;
+ }
epgsources.Remove();
epgmappings.Remove();
textmappings.Remove();
cParse::CleanupLibXML();
- if (dbmutex)
- {
- sqlite3_mutex_free(dbmutex);
- }
if (confdir)
{
free(confdir);
@@ -673,11 +681,9 @@ time_t cPluginXmltv2vdr::WakeupTime(void)
{
// Return custom wakeup time for shutdown script
if (!wakeup) return (time_t) 0;
-
- time_t nt=epgsources.NextRunTime();
- if (nt) nt-=(time_t) 180;
- tsyslog("reporting wakeuptime %s",ctime(&nt));
- return nt;
+ if (!nextruntime) return (time_t) 0;
+ tsyslog("reporting wakeuptime %s",ctime(&nextruntime));
+ return nextruntime;
}
const char *cPluginXmltv2vdr::MainMenuEntry(void)
diff --git a/xmltv2vdr.h b/xmltv2vdr.h
index 419e4cc..4731dde 100644
--- a/xmltv2vdr.h
+++ b/xmltv2vdr.h
@@ -64,8 +64,7 @@ class cEPGHandler : public cEpgHandler
private:
cEPGMappings *maps;
cEPGSources *sources;
- cImport *import;
- const char *epgfile;
+ cImport import;
bool epall;
sqlite3 *db;
void closedb(void);
@@ -81,7 +80,6 @@ public:
{
return (db!=NULL);
}
- virtual ~cEPGHandler();
virtual bool IgnoreChannel(const cChannel *Channel);
virtual bool SetShortText(cEvent *Event,const char *ShortText);
virtual bool SetDescription(cEvent *Event,const char *Description);
@@ -128,10 +126,10 @@ private:
cEPGMappings epgmappings;
cEPGSources epgsources;
cTEXTMappings textmappings;
- sqlite3_mutex *dbmutex;
time_t last_housetime_t;
time_t last_maintime_t;
time_t last_epcheck_t;
+ time_t nextruntime;
char *confdir;
char *epgfile;
char *srcorder;