summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Lehtimäki <matti.lehtimaki@gmail.com>2012-04-13 23:24:02 +0300
committerMatti Lehtimäki <matti.lehtimaki@gmail.com>2012-04-13 23:24:02 +0300
commit827dc1da7b18c57102cff7d3785041542c3e76e4 (patch)
tree2a77dbed08a9162aec727b27a2efbb50ee7eb21a
parent9adbd81f5cbf42dc3fc45bad3d3376cdfbb7563f (diff)
downloadvdr-plugin-epgfixer-827dc1da7b18c57102cff7d3785041542c3e76e4.tar.gz
vdr-plugin-epgfixer-827dc1da7b18c57102cff7d3785041542c3e76e4.tar.bz2
Add support for channel IDs. Cleaning up code.
-rw-r--r--.description1
-rw-r--r--HISTORY4
-rw-r--r--README2
-rw-r--r--epghandler.c16
-rw-r--r--regexp.c88
-rw-r--r--regexp.h16
6 files changed, 75 insertions, 52 deletions
diff --git a/.description b/.description
new file mode 100644
index 0000000..d4efd47
--- /dev/null
+++ b/.description
@@ -0,0 +1 @@
+VDR EPGFixer plugin
diff --git a/HISTORY b/HISTORY
index 30da194..fa2e55e 100644
--- a/HISTORY
+++ b/HISTORY
@@ -1,6 +1,10 @@
VDR Plugin 'epgfixer' Revision History
--------------------------------------
+2012-04-13: Version 0.0.5
+
+- Support using channel IDs in channel list in addition to channel numbers.
+
2012-04-12: Version 0.0.4
- Allow enabling regular expressions for only selected channels.
diff --git a/README b/README
index f75fbff..d7e8c11 100644
--- a/README
+++ b/README
@@ -33,6 +33,8 @@ Syntax of regexp.conf line is "Channel_list:Parsed_epg_field=Regexp" with:
- Channel_list is optional comma separated list of channels for which the
regular expression is used. If no list of channels is given the regular
expression is used for all channels.
+- Channel_list for a regular expression can contain either channel IDs
+ (e.g. S19.2E-1-1089-12003-0) or numbers but not both.
- Parsed_epg_field is the EPG field for which the regular expression is applied
with available field names title, shorttext and description.
- Regular expressions use named backreferences with either title, shorttext,
diff --git a/epghandler.c b/epghandler.c
index cf84838..d01fadf 100644
--- a/epghandler.c
+++ b/epghandler.c
@@ -130,13 +130,10 @@ void cEpgfixerEpgHandler::FixOriginalEpgBugs(cEvent *event)
// Some channels put the same information into ShortText and Description.
// In that case we delete one of them:
if (EpgfixerSetup.equalshorttextanddescription && event->ShortText() && event->Description() && strcmp(event->ShortText(), event->Description()) == 0) {
- if (strlen(event->ShortText()) > MAX_USEFUL_EPISODE_LENGTH) {
+ if (strlen(event->ShortText()) > MAX_USEFUL_EPISODE_LENGTH)
event->SetShortText(NULL);
- }
- else {
+ else
event->SetDescription(NULL);
-
- }
}
// Some channels use the ` ("backtick") character, where a ' (single quote)
@@ -246,14 +243,15 @@ bool cEpgfixerEpgHandler::ApplyRegexp(cRegexp *regexp, cEvent *Event, const char
if (regexp->NumChannels() > 0) {
bool found = false;
int i = 0;
- while (i < regexp->NumChannels()) {
- if (Channels.GetByChannelID(Event->ChannelID())->Number() == regexp->GetChannel(i))
+ while (i < regexp->NumChannels() && !found) {
+ if (Channels.GetByChannelID(Event->ChannelID())->Number() == regexp->GetChannelNum(i))
+ found = true;
+ if (regexp->GetChannelID(i) && strcmp(*(Event->ChannelID().ToString()), regexp->GetChannelID(i)) == 0)
found = true;
i++;
}
- if (!found) {
+ if (!found)
active = false;
- }
}
if (active && regexp->Enabled() && regexp->GetRe()) {
const char *string;
diff --git a/regexp.c b/regexp.c
index ee4073a..0b64ca9 100644
--- a/regexp.c
+++ b/regexp.c
@@ -16,15 +16,14 @@ const char *strSources[] = { "title","shorttext","description","undefined" };
cRegexp::cRegexp()
{
enabled = false;
- error = NULL;
- erroffset = -1;
regexp = NULL;
string = NULL;
source = REGEXP_UNDEFINED;
re = NULL;
sd = NULL;
numchannels = 0;
- channels = NULL;
+ channels_num = NULL;
+ channels_str = NULL;
}
cRegexp::~cRegexp(void)
@@ -34,23 +33,40 @@ cRegexp::~cRegexp(void)
void cRegexp::Free(void)
{
- free(channels);
+ free(channels_num);
+ if (channels_str) {
+ int i = 0;
+ while (i < numchannels) {
+ free(channels_str[i]);
+ i++;
+ }
+ }
+ free(channels_str);
free(regexp);
free(string);
- channels = NULL;
+ channels_num = NULL;
+ channels_str = NULL;
regexp = NULL;
string = NULL;
FreeCompiled();
}
-int cRegexp::GetChannel(int index)
+int cRegexp::GetChannelNum(int index)
{
- if (index >= 0 && index < numchannels)
- return channels[index];
+ if (channels_num && index >= 0 && index < numchannels)
+ return channels_num[index];
else
return -1;
}
+const char *cRegexp::GetChannelID(int index)
+{
+ if (channels_str && index >= 0 && index < numchannels)
+ return channels_str[index];
+ else
+ return NULL;
+}
+
void cRegexp::ToggleEnabled(void)
{
enabled = enabled ? 0 : 1;
@@ -75,28 +91,34 @@ void cRegexp::SetFromString(char *s, bool Enabled, bool Precompile)
regexp = strdup(p + 1);
char *chanfield = (s[0] == '!') ? s+1 : s;
char *field = chanfield;
- if (atoi(chanfield)) {
- char *f = strchr(chanfield, ':');
- if (f) {
- *f = 0;
- field = f+1;
- char *c = chanfield;
- numchannels = 0;
- while (c) {
- numchannels++;
- c = strchr(c+1, ',');
- }
- if (numchannels > 0) {
- c = chanfield;
- channels = (int *)malloc(sizeof(int)*numchannels);
- int i = 1;
- channels[i] = atoi(c);
- while (i < numchannels) {
- c = strchr(c+1, ',');
- channels[i] = atoi(c+1);
- i++;
- }
+ char *f = strchr(chanfield, ':');
+ if (f) {
+ *f = 0;
+ field = f+1;
+ char *c = chanfield;
+ numchannels = 0;
+ while (c) {
+ numchannels++;
+ c = strchr(c+1, ',');
}
+ if (numchannels > 0) {
+ c = chanfield;
+ // Use channel numbers
+ if (atoi(chanfield))
+ channels_num = (int *)malloc(sizeof(int)*numchannels);
+ else// use channel IDs
+ channels_str = (char **)malloc(sizeof(char *)*numchannels);
+ int i = 0;
+ char *pc = strtok(c, ",");
+ while (i < numchannels) {
+ // Use channel numbers
+ if (atoi(chanfield))
+ channels_num[i] = atoi(pc);
+ else// use channel IDs
+ channels_str[i] = strdup(pc);
+ pc = strtok(NULL, ",");
+ i++;
+ }
}
}
if (strcmp(field, "title") == 0)
@@ -106,7 +128,7 @@ void cRegexp::SetFromString(char *s, bool Enabled, bool Precompile)
if (strcmp(field, "description") == 0)
source = REGEXP_DESCRIPTION;
if (precompile)
- Compile();
+ Compile();
}
}
}
@@ -130,7 +152,9 @@ void cRegexp::FreeCompiled()
void cRegexp::Compile()
{
FreeCompiled();
- re = pcre_compile(regexp, 0, (const char **)&error, &erroffset, NULL);
+ const char *error;
+ int erroffset;
+ re = pcre_compile(regexp, 0, &error, &erroffset, NULL);
if (error) {
esyslog("PCRE compile error: %s at offset %i", error, erroffset);
enabled = false;
@@ -177,10 +201,8 @@ bool cEpgfixerRegexps::LoadRegexps(const char *FileName, bool AllowComments, boo
FILE *f = fopen(FileName, "r");
if (f) {
char *s;
- int line = 0;
cReadLine ReadLine;
while ((s = ReadLine.Read(f)) != NULL) {
- line++;
if (!isempty(s)) {
regexps->Add(new cRegexp());
regexps->Last()->SetFromString(s, true, Precompile);
diff --git a/regexp.h b/regexp.h
index 1062133..57d69ba 100644
--- a/regexp.h
+++ b/regexp.h
@@ -21,15 +21,14 @@ class cRegexp : public cListObject
{
private:
bool enabled;
- char *error;
- int erroffset;
char *regexp;
char *string;
+ int *channels_num;
+ char **channels_str;
+ int numchannels;
int source;
pcre *re;
pcre_extra *sd;
- int numchannels;
- int *channels;
void Free();
public:
cRegexp();
@@ -42,7 +41,8 @@ public:
bool Enabled(void) { return enabled; }
void ToggleEnabled(void);
int NumChannels() { return numchannels; }
- int GetChannel(int index);
+ int GetChannelNum(int index);
+ const char *GetChannelID(int index);
int GetSource(void) { return source; }
pcre *GetRe(void) { return re; }
pcre_extra *GetSd(void) { return sd; }
@@ -51,10 +51,7 @@ public:
class cRegexpList : public cList<cRegexp>
{
public:
- void Clear(void)
- {
- cList<cRegexp>::Clear();
- }
+ void Clear(void) { cList<cRegexp>::Clear(); }
cRegexpList(void) {}
};
@@ -65,7 +62,6 @@ private:
char *fileName;
public:
cRegexpList *regexps;
-
cEpgfixerRegexps();
~cEpgfixerRegexps();
void SetRegexpConfigFile(const char *FileName);