/* * event.cpp: A plugin for the Video Disk Recorder * * See the README file for copyright information and how to reach the author. * */ #include #include #include #include #include #include "event.h" extern char *strcatrealloc(char *, const char*); cXMLTVStringList::~cXMLTVStringList(void) { free(buf); Clear(); } void cXMLTVStringList::Clear(void) { for (int i=0; i::Clear(); } const char* cXMLTVStringList::toString() { free(buf); buf=NULL; for (int i=0; i0 && r<=18) && (r>parentalRating)) parentalRating=r; } tok=strtok_r(NULL,delim,&sp); } rating.Sort(); free(c); } void cXMLTVEvent::SetVideo(const char *Video) { if (!Video) return; char *c=strdup(Video); if (!c) return; char *sp,*tok; char delim[]="@"; tok=strtok_r(c,delim,&sp); while (tok) { video.Append(strdup(tok)); tok=strtok_r(NULL,delim,&sp); } free(c); } void cXMLTVEvent::SetStarRating(const char *StarRating) { if (!StarRating) return; char *c=strdup(StarRating); if (!c) return; char *sp,*tok; char delim[]="@"; tok=strtok_r(c,delim,&sp); while (tok) { starrating.Append(strdup(tok)); tok=strtok_r(NULL,delim,&sp); } starrating.Sort(); free(c); } void cXMLTVEvent::AddReview(const char *Review) { review.Append(compactspace(strdup(Review))); } void cXMLTVEvent::AddVideo(const char *VType, const char *VContent) { char *value=NULL; if (asprintf(&value,"%s|%s",VType,VContent)==-1) return; video.Append(value); } 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(); } void cXMLTVEvent::AddStarRating(const char *System, const char *Rating) { char *value=NULL; if (System) { if (asprintf(&value,"%s|%s",System,Rating)==-1) return; } else { if (asprintf(&value,"*|%s",Rating)==-1) return; } starrating.Append(value); } void cXMLTVEvent::AddCategory(const char *Category) { category.Append(compactspace(strdup(Category))); category.Sort(); } void cXMLTVEvent::AddCredits(const char *CreditType, const char *Credit, const char *Addendum) { char *value=NULL; if (Addendum) { if (asprintf(&value,"%s|%s (%s)",CreditType,Credit,Addendum)==-1) return; } else { if (asprintf(&value,"%s|%s",CreditType,Credit)==-1) return; } credits.Append(value); credits.Sort(); } const char *cXMLTVEvent::GetSQL(const char *Source, int SrcIdx, const char *ChannelID) { if (sql) free(sql); const char *cr=credits.toString(); const char *ca=category.toString(); const char *re=review.toString(); const char *ra=rating.toString(); const char *sr=starrating.toString(); const char *vi=video.toString(); 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,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);"\ "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, "\ "picexists=%i,srcidx=%i " \ " where changes()=0 and src=^%s^ and channelid=^%s^ and eventid=%i" , Source,ChannelID,eventid,starttime,duration,title, origtitle ? origtitle : "NULL", shorttext ? shorttext : "NULL", description ? description : "NULL", country ? country : "NULL", year, cr,ca,re,ra,sr,vi, audio ? audio : "NULL", season, episode, picexists, SrcIdx, duration,starttime,title, origtitle ? origtitle : "NULL", shorttext ? shorttext : "NULL", description ? description : "NULL", country ? country : "NULL", year, cr,ca,re,ra,sr,vi, audio ? audio : "NULL", season, episode, picexists, SrcIdx, Source,ChannelID,eventid )==-1) return NULL; string s=sql; int reps; reps=pcrecpp::RE("'").GlobalReplace("''",&s); reps+=pcrecpp::RE("\\^").GlobalReplace("'",&s); reps+=pcrecpp::RE("'NULL'").GlobalReplace("NULL",&s); if (reps) { sql=(char *) realloc(sql,s.size()+1); strcpy(sql,s.c_str()); } return sql; } void cXMLTVEvent::Clear() { if (source) { free(source); source=NULL; } if (sql) { free(sql); sql=NULL; } if (title) { free(title); title=NULL; } if (shorttext) { free(shorttext); shorttext=NULL; } if (description) { free(description); description=NULL; } if (eitdescription) { free(eitdescription); eitdescription=NULL; } if (country) { free(country); country=NULL; } if (origtitle) { free(origtitle); origtitle=NULL; } if (audio) { free(audio); audio=NULL; } if (channelid) { free(channelid); channelid=NULL; } year=0; starttime = 0; duration = 0; eventid=eiteventid=0; video.Clear(); credits.Clear(); category.Clear(); review.Clear(); rating.Clear(); starrating.Clear(); season=0; episode=0; parentalRating=0; memset(&contents,0,sizeof(contents)); picexists=false; } cXMLTVEvent::cXMLTVEvent() { sql=NULL; source=NULL; channelid=NULL; title=NULL; shorttext=NULL; description=eitdescription=NULL; country=NULL; origtitle=NULL; audio=NULL; Clear(); } cXMLTVEvent::~cXMLTVEvent() { Clear(); }