diff options
author | Jochen Dolze <vdr@dolze.de> | 2012-07-09 15:43:49 +0200 |
---|---|---|
committer | Jochen Dolze <vdr@dolze.de> | 2012-07-09 15:43:49 +0200 |
commit | ade2efec3a2e857e56dfcd42b0068d1de3bcfae7 (patch) | |
tree | 508b0597d0ec4ddd585cfd691840d8cd389c45c0 | |
parent | f166663a354d07676f22879dbbbb3baa018d5a7c (diff) | |
download | vdr-plugin-xmltv2vdr-ade2efec3a2e857e56dfcd42b0068d1de3bcfae7.tar.gz vdr-plugin-xmltv2vdr-ade2efec3a2e857e56dfcd42b0068d1de3bcfae7.tar.bz2 |
Added support for two titles (e.g. 'Mein cooler Onkel Charlie' vs. 'Two and a half men')
-rw-r--r-- | event.cpp | 38 | ||||
-rw-r--r-- | event.h | 6 | ||||
-rw-r--r-- | import.cpp | 64 | ||||
-rw-r--r-- | parse.cpp | 28 |
4 files changed, 125 insertions, 11 deletions
@@ -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; @@ -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; @@ -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; i1<w1.count; i1++) + { + for (int i3=0; i3<w3.count; i3++) + { + if (!strcmp(w1.pointers[i1],w3.pointers[i3])) + { + if (strlen(w1.pointers[i1])>3) 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; } @@ -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; } } |