From ade2efec3a2e857e56dfcd42b0068d1de3bcfae7 Mon Sep 17 00:00:00 2001 From: Jochen Dolze Date: Mon, 9 Jul 2012 15:43:49 +0200 Subject: Added support for two titles (e.g. 'Mein cooler Onkel Charlie' vs. 'Two and a half men') --- event.cpp | 38 ++++++++++++++++++++++++++++++++++++- event.h | 6 ++---- import.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- parse.cpp | 28 ++++++++++++++++++++++++++- 4 files changed, 125 insertions(+), 11 deletions(-) diff --git a/event.cpp b/event.cpp index 4f081c7..73fda7f 100644 --- a/event.cpp +++ b/event.cpp @@ -79,7 +79,19 @@ void cXMLTVEvent::SetChannelID(const char *ChannelID) void cXMLTVEvent::SetTitle(const char *Title) { - title=strcpyrealloc(title, Title); + if (title) + { + if (strncasecmp(Title,title,3)) + { + title=strcatrealloc(title,"|"); + title=strcatrealloc(title,Title); + } + } + else + { + title=strcpyrealloc(title, Title); + } + if (title) { title=removechar(title,'\''); @@ -89,6 +101,24 @@ void cXMLTVEvent::SetTitle(const char *Title) } } +const char *cXMLTVEvent::Title(bool Second) +{ + char *p=strchr(title,'|'); + if (!p && Second) return NULL; + if (!p) return title; + + if (!Second) + { + return p++; + } + if (title2) free(title2); + title2=strdup(title); + if (!title2) return NULL; + p=strchr(title2,'|'); + if (p) *p=0; + return title2; +} + void cXMLTVEvent::SetOrigTitle(const char *OrigTitle) { origtitle=strcpyrealloc(origtitle, OrigTitle); @@ -561,6 +591,11 @@ void cXMLTVEvent::Clear() free(title); title=NULL; } + if (title2) + { + free(title2); + title2=NULL; + } if (shorttext) { free(shorttext); @@ -622,6 +657,7 @@ cXMLTVEvent::cXMLTVEvent() source=NULL; channelid=NULL; title=NULL; + title2=NULL; shorttext=NULL; description=eitdescription=NULL; country=NULL; diff --git a/event.h b/event.h index 473e9d0..fb160f4 100644 --- a/event.h +++ b/event.h @@ -33,6 +33,7 @@ class cXMLTVEvent { private: char *title; + char *title2; char *shorttext; char *description; char *eitdescription; @@ -180,10 +181,7 @@ public: { return source; } - const char *Title(void) const - { - return title; - } + const char *Title(bool Second=false); const char *ShortText(void) const { return shorttext; diff --git a/import.cpp b/import.cpp index b29d8b0..fb318bf 100644 --- a/import.cpp +++ b/import.cpp @@ -101,16 +101,27 @@ cEvent *cImport::SearchVDREvent(cEPGSource *source, cSchedule* schedule, cXMLTVE return f; } - const char *cxTitle=conv->Convert(xevent->Title()); + char *cxTitle1=strdup(conv->Convert(xevent->Title())); + char *cxTitle2=NULL; + if (xevent->Title(true)) cxTitle2=strdup(conv->Convert(xevent->Title(true))); // 2nd with StartTime f=(cEvent *) schedule->GetEvent((tEventID) 0,xevent->StartTime()+hint); if (f) { - if (!strcasecmp(f->Title(),cxTitle)) + if (!strcasecmp(f->Title(),cxTitle1)) { + free((void *) cxTitle1); + if (cxTitle2) free((void *) cxTitle2); return f; } + if (cxTitle2 && (!strcasecmp(f->Title(),cxTitle2))) + { + free((void *) cxTitle1); + free((void *) cxTitle2); + return f; + } + } // 3rd with StartTime +/- TimeDiff int maxdiff=INT_MAX; @@ -124,7 +135,7 @@ cEvent *cImport::SearchVDREvent(cEPGSource *source, cSchedule* schedule, cXMLTVE if (diff<=eventTimeDiff) { // found event with exact the same title - if (!strcasecmp(p->Title(),cxTitle)) + if (!strcasecmp(p->Title(),cxTitle1) || (cxTitle2 && !strcasecmp(p->Title(),cxTitle2))) { if (diff<=maxdiff) { @@ -144,7 +155,7 @@ cEvent *cImport::SearchVDREvent(cEPGSource *source, cSchedule* schedule, cXMLTVE // 0x20,0x30-0x39,0x41-0x5A,0x61-0x7A int wfound=0; char *s1=RemoveNonASCII(p->Title()); - char *s2=RemoveNonASCII(cxTitle); + char *s2=RemoveNonASCII(cxTitle1); if (s1 && s2) { if (!strcmp(s1,s2)) @@ -170,15 +181,54 @@ cEvent *cImport::SearchVDREvent(cEPGSource *source, cSchedule* schedule, cXMLTVE } } } + + char *s3=NULL; + if (cxTitle2) s3=RemoveNonASCII(cxTitle2); + if (s1 && s3 && !wfound) + { + if (!strcmp(s1,s3)) + { + wfound++; + } + else + { + struct split w1 = split(s1,' '); + struct split w3 = split(s3,' '); + if ((w1.count) && (w3.count)) + { + for (int i1=0; i13) wfound++; + } + } + } + } + } + } + if (s1) free(s1); if (s2) free(s2); + if (s3) free(s3); if (wfound) { if (diff<=maxdiff) { if (!WasChanged(p)) - tsyslogs(source,"found '%s' for '%s'",p->Title(),cxTitle); + { + if (cxTitle2) + { + tsyslogs(source,"found '%s' for '%s' or '%s'",p->Title(),cxTitle1,cxTitle2); + } + else + { + tsyslogs(source,"found '%s' for '%s'",p->Title(),cxTitle1); + } + } f=p; maxdiff=diff; } @@ -186,6 +236,10 @@ cEvent *cImport::SearchVDREvent(cEPGSource *source, cSchedule* schedule, cXMLTVE } } } + + free((void *) cxTitle1); + if (cxTitle2) free((void *) cxTitle2); + return f; } diff --git a/parse.cpp b/parse.cpp index 2162be3..45832a2 100644 --- a/parse.cpp +++ b/parse.cpp @@ -222,6 +222,32 @@ bool cParse::FetchSeasonEpisode(iconv_t cEP2ASCII, iconv_t cUTF2ASCII, const cha return false; } + char dname[2048]=""; + if (readlink(epfile,dname,sizeof(dname)-1)!=-1) + { + char *ls=strrchr(dname,'/'); + if (ls) + { + ls++; + memmove(dname,ls,strlen(ls)); + } + char *pt=strrchr(dname,'.'); + if (pt) + { + *pt=0; + } + else + { + dname[0]=0; + } + } + else + { + dname[0]=0; + } + + if (dname[0]==0) strn0cpy(dname,dirent->d_name,sizeof(dname)-1); + size_t dlen=4*slen; char *dshorttext=(char *) calloc(dlen,1); if (!dshorttext) @@ -275,7 +301,7 @@ bool cParse::FetchSeasonEpisode(iconv_t cEP2ASCII, iconv_t cUTF2ASCII, const cha { found=true; if (EPShortText) *EPShortText=strdup(epshorttext); - if (EPTitle) *EPTitle=strdup(dirent->d_name); + if (EPTitle) *EPTitle=strdup(dname); break; } } -- cgit v1.2.3