summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Dolze <vdr@dolze.de>2012-04-11 02:36:08 +0200
committerJochen Dolze <vdr@dolze.de>2012-04-11 02:36:08 +0200
commit5d943515babc18cba0576f21f4c89a389d5f60c0 (patch)
treee237a03b56a840b495c93af1dda9acbbb5938818
parent3539d1a5106f2bfeb9d25bc5c14b97d53c8fb81b (diff)
downloadvdr-plugin-xmltv2vdr-5d943515babc18cba0576f21f4c89a389d5f60c0.tar.gz
vdr-plugin-xmltv2vdr-5d943515babc18cba0576f21f4c89a389d5f60c0.tar.bz2
Added full parential rating support
-rw-r--r--event.cpp11
-rw-r--r--event.h8
-rw-r--r--import.cpp38
-rw-r--r--xmltv2vdr.cpp236
-rw-r--r--xmltv2vdr.h18
5 files changed, 217 insertions, 94 deletions
diff --git a/event.cpp b/event.cpp
index 19838c8..83ddb20 100644
--- a/event.cpp
+++ b/event.cpp
@@ -159,6 +159,13 @@ void cXMLTVEvent::SetRating(const char *Rating)
while (tok)
{
rating.Append(strdup(tok));
+ char *rval=strchr(tok,'|');
+ if (rval)
+ {
+ rval++;
+ int r=atoi(rval);
+ if ((r>0 && r<=18) && (r>parentalRating)) parentalRating=r;
+ }
tok=strtok_r(NULL,delim,&sp);
}
rating.Sort();
@@ -214,6 +221,8 @@ void cXMLTVEvent::AddRating(const char *System, const char *Rating)
{
char *value=NULL;
if (asprintf(&value,"%s|%s",System,Rating)==-1) return;
+ int r=atoi(Rating);
+ if ((r>0 && r<=18) && (r>parentalRating)) parentalRating=r;
rating.Append(value);
rating.Sort();
}
@@ -379,6 +388,8 @@ void cXMLTVEvent::Clear()
starrating.Clear();
season=0;
episode=0;
+ parentalRating=0;
+ memset(&contents,0,sizeof(contents));
mixing=false;
}
diff --git a/event.h b/event.h
index 082e8c1..14e8eb6 100644
--- a/event.h
+++ b/event.h
@@ -56,10 +56,8 @@ private:
cXMLTVStringList review;
cXMLTVStringList rating;
cXMLTVStringList starrating;
-#if VDRVERSNUM >= 10711
- uchar parentalRating;
+ int parentalRating;
uchar contents[MaxEventContents];
-#endif
public:
cXMLTVEvent();
~cXMLTVEvent();
@@ -142,6 +140,10 @@ public:
{
mixing=true;
}
+ int ParentalRating() const
+ {
+ return parentalRating;
+ }
int Duration() const
{
return duration;
diff --git a/import.cpp b/import.cpp
index efcd649..2e1330f 100644
--- a/import.cpp
+++ b/import.cpp
@@ -630,42 +630,36 @@ bool cImport::PutEvent(cEPGSource *source, sqlite3 *db, cSchedule* schedule,
if (((Flags & USE_RATING)==USE_RATING) && (xevent->Rating()->Size()))
{
- cXMLTVStringList *rating=xevent->Rating();
- int rv=0;
- for (int i=0; i<rating->Size(); i++)
+#if VDRVERSNUM < 10711 && !EPGHANDLER
+ Flags|=OPT_RATING_TEXT; // always add to text if we dont have the internal tag!
+#endif
+ if ((Flags & OPT_RATING_TEXT)==OPT_RATING_TEXT)
{
- char *rtype=strdup((*rating)[i]);
- if (rtype)
+ cXMLTVStringList *rating=xevent->Rating();
+ for (int i=0; i<rating->Size(); i++)
{
- char *rval=strchr(rtype,'|');
- if (rval)
+ char *rtype=strdup((*rating)[i]);
+ if (rtype)
{
- *rval=0;
- rval++;
-#if VDRVERSNUM < 10711 && !EPGHANDLER
- description=Add2Description(description,rtype);
- description=Add2Description(description,": ");
- description=Add2Description(description,rval);
- description=Add2Description(description,"\n");
-#else
- if ((Flags & OPT_RATING_TEXT)==OPT_RATING_TEXT)
+ char *rval=strchr(rtype,'|');
+ if (rval)
{
+ *rval=0;
+ rval++;
+
description=Add2Description(description,rtype);
description=Add2Description(description,": ");
description=Add2Description(description,rval);
description=Add2Description(description,"\n");
}
- int r=atoi(rval);
- if (r>rv) rv=r;
-#endif
+ free(rtype);
}
- free(rtype);
}
}
#if VDRVERSNUM >= 10711 || EPGHANDLER
- if ((rv>0) && (rv<=18))
+ if (xevent->ParentalRating())
{
- event->SetParentalRating(rv);
+ event->SetParentalRating(xevent->ParentalRating());
}
#endif
}
diff --git a/xmltv2vdr.cpp b/xmltv2vdr.cpp
index 08ff990..8fdc139 100644
--- a/xmltv2vdr.cpp
+++ b/xmltv2vdr.cpp
@@ -39,6 +39,50 @@ int ioprio_set(int which, int who, int ioprio)
// -------------------------------------------------------------
+cEPGHandlerState::cEPGHandlerState()
+{
+ xevent=NULL;
+ Clear();
+}
+
+cEPGHandlerState::~cEPGHandlerState()
+{
+ Clear();
+}
+
+void cEPGHandlerState::Clear()
+{
+ if (xevent)
+ {
+ delete xevent;
+ xevent=NULL;
+ }
+ source=NULL;
+ flags=0;
+}
+
+
+void cEPGHandlerState::Set(cEPGSource* Source, cXMLTVEvent* xEvent, int Flags)
+{
+ Clear();
+ source=Source;
+ xevent=xEvent;
+ flags=Flags;
+ if (ioprio_set(1,getpid(),7 | 3 << 13)==-1)
+ {
+ esyslog("xmltv2vdr: failed to set ioprio to 3,7");
+ }
+}
+
+bool cEPGHandlerState::isSame(tEventID EventID)
+{
+ if (!xevent) return false;
+ if (xevent->EITEventID()==EventID) return true;
+ return false;
+}
+
+// -------------------------------------------------------------
+
cEPGHandler::cEPGHandler(cPluginXmltv2vdr *Plugin, const char *EpgFile, cEPGSources *Sources,
cEPGMappings *Maps, cTEXTMappings *Texts)
{
@@ -74,70 +118,77 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description)
if (!import) return false;
if (!baseplugin) return false;
- bool special_epall_timer_handling=false;
- if (!maps->ProcessChannel(Event->ChannelID()))
+ if (!last.isSame(Event->EventID()))
{
- if (!epall) return false;
- if (!Event->HasTimer()) return false;
- if (!Event->ShortText()) return false;
- special_epall_timer_handling=true;
- }
+ last.Clear();
+ bool special_epall_timer_handling=false;
+ if (!maps->ProcessChannel(Event->ChannelID()))
+ {
+ if (!epall) return false;
+ if (!Event->HasTimer()) return false;
+ if (!Event->ShortText()) return false;
+ special_epall_timer_handling=true;
+ }
- if (!baseplugin->IsIdle())
- {
- if (import->WasChanged(Event)) return true;
- return false;
- }
+ if (!baseplugin->IsIdle())
+ {
+ if (import->WasChanged(Event)) return true;
+ return false;
+ }
- int Flags=0;
- const char *ChannelID;
+ int Flags=0;
+ const char *ChannelID;
- if (special_epall_timer_handling)
- {
- cChannel *chan=Channels.GetByChannelID(Event->ChannelID());
- if (!chan) return false;
- Flags=USE_SEASON;
- ChannelID=chan->Name();
- }
- else
- {
- cEPGMapping *map=maps->GetMap(Event->ChannelID());
- if (!map) return false;
- Flags=map->Flags();
- ChannelID=map->ChannelName();
- }
+ if (special_epall_timer_handling)
+ {
+ cChannel *chan=Channels.GetByChannelID(Event->ChannelID());
+ if (!chan) return false;
+ Flags=USE_SEASON;
+ ChannelID=chan->Name();
+ }
+ else
+ {
+ cEPGMapping *map=maps->GetMap(Event->ChannelID());
+ if (!map) return false;
+ Flags=map->Flags();
+ ChannelID=map->ChannelName();
+ }
- if (ioprio_set(1,getpid(),7 | 3 << 13)==-1)
- {
- esyslog("xmltv2vdr: failed to set ioprio to 3,7");
+ cXMLTVEvent *xevent=import->SearchXMLTVEvent(epgfile,ChannelID,Event);
+ if (!xevent)
+ {
+ if (!epall) return false;
+ xevent=import->AddXMLTVEvent(epgfile,ChannelID,Event,Description);
+ if (!xevent) return false;
+ }
+ cEPGSource *source=sources->GetSource(xevent->Source());
+ last.Set(source,xevent,Flags);
}
-
- cXMLTVEvent *xevent=import->SearchXMLTVEvent(epgfile,ChannelID,Event);
- if (!xevent)
+ else
{
- if (!epall) return false;
- xevent=import->AddXMLTVEvent(epgfile,ChannelID,Event,Description);
- if (!xevent) return false;
+ if (!baseplugin->IsIdle())
+ {
+ if (import->WasChanged(Event)) return true;
+ return false;
+ }
}
bool update=false;
- if (!xevent->EITEventID()) update=true;
- if (!xevent->EITDescription() && Description) update=true;
- if (xevent->EITDescription() && Description &&
- strcasecmp(xevent->EITDescription(),Description)) update=true;
- cEPGSource *source=sources->GetSource(xevent->Source());
+ if (!last.xEvent()->EITEventID()) update=true;
+ if (!last.xEvent()->EITDescription() && Description) update=true;
+ if (last.xEvent()->EITDescription() && Description &&
+ strcasecmp(last.xEvent()->EITDescription(),Description)) update=true;
if (update)
{
- import->UpdateXMLTVEvent(source,epgfile,NULL,Event,xevent->Source(),
- xevent->EventID(),Event->EventID(),Description);
+ import->UpdateXMLTVEvent(last.Source(),epgfile,NULL,Event,last.xEvent()->Source(),
+ last.xEvent()->EventID(),Event->EventID(),Description);
}
- bool ret=import->PutEvent(source,NULL,
+ bool ret=import->PutEvent(last.Source(),NULL,
(cSchedule *) Event->Schedule(),
- Event,xevent,Flags,IMPORT_DESCRIPTION);
- delete xevent;
+ Event,last.xEvent(),last.Flags(),IMPORT_DESCRIPTION);
if (!ret)
{
dsyslog("xmltv2vdr: failed to put event description!");
@@ -145,9 +196,48 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description)
return ret;
}
-bool cEPGHandler::SetParentalRating(cEvent* UNUSED(Event), int UNUSED(ParentalRating))
+bool cEPGHandler::SetParentalRating(cEvent* Event, int ParentalRating)
{
- return false;
+ if (!Event) return false;
+ if (!maps) return false;
+ if (!import) return false;
+
+ if (!last.isSame(Event->EventID()))
+ {
+ last.Clear();
+
+ if (!maps->ProcessChannel(Event->ChannelID())) return false;
+
+ if (!baseplugin->IsIdle())
+ {
+ if (import->WasChanged(Event)) return true;
+ return false;
+ }
+
+ cEPGMapping *map=maps->GetMap(Event->ChannelID());
+ if (!map) return false;
+
+ cXMLTVEvent *xevent=import->SearchXMLTVEvent(epgfile,map->ChannelName(),Event);
+ if (!xevent) return false;
+
+ cEPGSource *source=sources->GetSource(xevent->Source());
+
+ if (!xevent->EITEventID()) import->UpdateXMLTVEvent(source,epgfile,NULL,Event,xevent->Source(),
+ xevent->EventID(),Event->EventID());
+ last.Set(source,xevent,map->Flags());
+ }
+ else
+ {
+ if (!baseplugin->IsIdle())
+ {
+ if (import->WasChanged(Event)) return true;
+ return false;
+ }
+ }
+
+ if (ParentalRating>last.xEvent()->ParentalRating()) return false; // use dvb value
+ Event->SetParentalRating(last.xEvent()->ParentalRating());
+ return true;
}
bool cEPGHandler::SetShortText(cEvent* Event, const char* UNUSED(ShortText))
@@ -156,33 +246,41 @@ bool cEPGHandler::SetShortText(cEvent* Event, const char* UNUSED(ShortText))
if (!maps) return false;
if (!import) return false;
- if (!maps->ProcessChannel(Event->ChannelID())) return false;
-
- if (!baseplugin->IsIdle())
+ if (!last.isSame(Event->EventID()))
{
- if (import->WasChanged(Event)) return true;
- return false;
- }
+ last.Clear();
- cEPGMapping *map=maps->GetMap(Event->ChannelID());
- if (!map) return false;
+ if (!maps->ProcessChannel(Event->ChannelID())) return false;
- if (ioprio_set(1,getpid(),7 | 3 << 13)==-1)
- {
- esyslog("xmltv2vdr: failed to set ioprio to 3,7");
- }
+ if (!baseplugin->IsIdle())
+ {
+ if (import->WasChanged(Event)) return true;
+ return false;
+ }
- cXMLTVEvent *xevent=import->SearchXMLTVEvent(epgfile,map->ChannelName(),Event);
- if (!xevent) return false;
+ cEPGMapping *map=maps->GetMap(Event->ChannelID());
+ if (!map) return false;
- cEPGSource *source=sources->GetSource(xevent->Source());
+ cXMLTVEvent *xevent=import->SearchXMLTVEvent(epgfile,map->ChannelName(),Event);
+ if (!xevent) return false;
+
+ cEPGSource *source=sources->GetSource(xevent->Source());
- if (!xevent->EITEventID()) import->UpdateXMLTVEvent(source,epgfile,NULL,Event,xevent->Source(),
- xevent->EventID(),Event->EventID());
+ if (!xevent->EITEventID()) import->UpdateXMLTVEvent(source,epgfile,NULL,Event,xevent->Source(),
+ xevent->EventID(),Event->EventID());
+ last.Set(source,xevent,map->Flags());
+ }
+ else
+ {
+ if (!baseplugin->IsIdle())
+ {
+ if (import->WasChanged(Event)) return true;
+ return false;
+ }
+ }
- bool ret=import->PutEvent(source,NULL,(cSchedule *) Event->Schedule(),Event,xevent,
- map->Flags(),IMPORT_SHORTTEXT);
- delete xevent;
+ bool ret=import->PutEvent(last.Source(),NULL,(cSchedule *) Event->Schedule(),Event,last.xEvent(),
+ last.Flags(),IMPORT_SHORTTEXT);
if (!ret)
{
dsyslog("xmltv2vdr: failed to put event shorttext!");
diff --git a/xmltv2vdr.h b/xmltv2vdr.h
index f0da36a..693c0ac 100644
--- a/xmltv2vdr.h
+++ b/xmltv2vdr.h
@@ -58,6 +58,23 @@ class cEPGSources;
class cImport;
class cPluginXmltv2vdr;
+class cEPGHandlerState
+{
+ private:
+ cXMLTVEvent *xevent;
+ cEPGSource *source;
+ int flags;
+ public:
+ cEPGHandlerState();
+ ~cEPGHandlerState();
+ void Clear();
+ void Set(cEPGSource *Source, cXMLTVEvent *xEvent, int Flags);
+ bool isSame(tEventID EventID);
+ cXMLTVEvent *xEvent() { return xevent; }
+ cEPGSource *Source() { return source; }
+ int Flags() { return flags; }
+};
+
class cEPGHandler : public cEpgHandler
{
private:
@@ -67,6 +84,7 @@ private:
cEPGSources *sources;
cImport *import;
bool epall;
+ cEPGHandlerState last;
public:
cEPGHandler(cPluginXmltv2vdr *Plugin, const char *EpgFile, cEPGSources *Sources,
cEPGMappings *Maps, cTEXTMappings *Texts);