Copy freesat to non-freesat database
This commit is contained in:
parent
5e468f5857
commit
b3ea751561
17
epgsql.c
17
epgsql.c
|
@ -112,6 +112,23 @@ int ExecSQLStatement(char *SQL, sqlite3 *db)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int ExecSQLStatementRowCount(char *SQL, sqlite3 *db)
|
||||
{
|
||||
int rc;
|
||||
char *zErrMsg = 0;
|
||||
|
||||
rc = sqlite3_exec(db, SQL, 0, 0, &zErrMsg);
|
||||
|
||||
if( rc!=SQLITE_OK ){
|
||||
fprintf(stderr, "SQL error executing script : %s\n", zErrMsg);
|
||||
fprintf(stderr, "RC : %i\n", rc);
|
||||
fprintf(stderr, "SQL : %s\n", SQL);
|
||||
sqlite3_free(zErrMsg);
|
||||
return -1;
|
||||
}
|
||||
return sqlite3_changes(db);
|
||||
}
|
||||
|
||||
/*int GetFileTimestamp(sqlite3 *db, char *res)*/
|
||||
void GetFileTimestamp(unsigned int * TS)
|
||||
{
|
||||
|
|
1
epgsql.h
1
epgsql.h
|
@ -5,6 +5,7 @@ int OpenCreateDB(char * DBFile, sqlite3 **db);
|
|||
int CloseDB(sqlite3 *db);
|
||||
int InitDB(char * InitScript, sqlite3 *db);
|
||||
int ExecSQLStatement(char *SQL, sqlite3 *db);
|
||||
int ExecSQLStatementRowCount(char *SQL, sqlite3 *db);
|
||||
void GetFileTimestamp(unsigned int *);
|
||||
|
||||
|
||||
|
|
84
main.c
84
main.c
|
@ -21,14 +21,14 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
int debug = 0;
|
||||
const char *version = "1.3";
|
||||
const char *version = "1.8";
|
||||
unsigned long sysopts = 0;
|
||||
unsigned long filterflags = 0;
|
||||
|
||||
int
|
||||
syntax()
|
||||
{
|
||||
fprintf(stderr, "Humax Foxsat EPG Tool v%s, by adrianf36, 2011-2016.\n", version);
|
||||
fprintf(stderr, "Humax Foxsat EPG Tool v%s, by adrianf36, 2011-2016, MofTot 2018-20.\n", version);
|
||||
fprintf(stderr, "based on the Humax (T2) EPG Tool from af123 v1.0.2, 2011.\n\n");
|
||||
|
||||
fprintf(stderr,
|
||||
|
@ -111,10 +111,10 @@ unsigned int NeedToProcess (char * epgFile)
|
|||
|
||||
void SwapEPGFiles()
|
||||
{
|
||||
/*
|
||||
Having built the new EPG file as epgnew.db delete the old one
|
||||
and replace it with the new one. Handle the case where the old
|
||||
one can't be deleted because it's being accessed
|
||||
/*
|
||||
Having built the new EPG file as epgnew.db delete the old one
|
||||
and replace it with the new one. Handle the case where the old
|
||||
one can't be deleted because it's being accessed
|
||||
|
||||
First thing make sure that the size of the new file looks sensible.
|
||||
Expect this to be > 10MB ..... usually it's about 12MB
|
||||
|
@ -140,7 +140,7 @@ FILE * fp;
|
|||
}
|
||||
} else {
|
||||
/* epgnew.db is smaller than we expected and is probably incomplete.
|
||||
Delete it and output a warning.
|
||||
Delete it and output a warning.
|
||||
*/
|
||||
fprintf(stderr, "Error. epgnew.db file size too small. Probably corrupt.\n");
|
||||
remove("/opt/epg/epgnew.db");
|
||||
|
@ -202,7 +202,7 @@ void EscapeChars(char ** InString, unsigned int *Len)
|
|||
/* at least one ' character - process string */
|
||||
/* count them so we know how much space to allocate */
|
||||
for (i=0; i<*Len; i++) {
|
||||
if (originalstring[i]==0x27) {
|
||||
if (originalstring[i]==0x27) {
|
||||
charcount++;
|
||||
}
|
||||
}
|
||||
|
@ -210,8 +210,8 @@ void EscapeChars(char ** InString, unsigned int *Len)
|
|||
j=0;
|
||||
for (i=0; i<*Len; i++) {
|
||||
new[j++]=originalstring[i];
|
||||
if (originalstring[i]==0x27)
|
||||
new[j++]=0x27;
|
||||
if (originalstring[i]==0x27)
|
||||
new[j++]=0x27;
|
||||
}
|
||||
new[j]='\0';
|
||||
|
||||
|
@ -254,8 +254,8 @@ dumpsql(struct epg *epg __attribute__((unused)),
|
|||
*/
|
||||
sprintf(SQLStatement,"insert into epg (serviceid, eventid, starttime, duration, encrypted, name,"\
|
||||
"descr, warning, contentcode, contenttype, ECRID, SCRID, RCRID) values (");
|
||||
sprintf(SQLStatement, "%s%d,%d,%ld,%d,%d,", SQLStatement,
|
||||
s->service_id, d->event_id, tm,
|
||||
sprintf(SQLStatement, "%s%d,%d,%ld,%d,%d,", SQLStatement,
|
||||
s->service_id, d->event_id, tm,
|
||||
d->dur_hour * 3600 + d->dur_min * 60 + d->dur_sec,
|
||||
d->u1.u.free_CA_mode);
|
||||
if (ds[PARSER_SHORT_EVENT])
|
||||
|
@ -293,7 +293,7 @@ dumpsql(struct epg *epg __attribute__((unused)),
|
|||
}
|
||||
else
|
||||
sprintf(SQLStatement,"%s'',",SQLStatement);
|
||||
|
||||
|
||||
if (ds[PARSER_CRID_SERIES])
|
||||
{
|
||||
struct descriptor *d = ds[PARSER_CRID_SERIES];
|
||||
|
@ -347,6 +347,8 @@ void dosqldump(char * epgpath,struct epgfilter *filter, int Continuous)
|
|||
|
||||
rc = ExecSQLStatement("COMMIT;", db);
|
||||
|
||||
copy_freesat_to_non_freesat(db);
|
||||
|
||||
sprintf(SQL, "replace into epgtimestamp (lastfileprocessed) values (%i);", FileTS);
|
||||
rc = ExecSQLStatement("Delete from epgtimestamp;", db);
|
||||
rc = ExecSQLStatement(SQL, db);
|
||||
|
@ -359,7 +361,7 @@ void dosqldump(char * epgpath,struct epgfilter *filter, int Continuous)
|
|||
}
|
||||
} else {
|
||||
|
||||
FileTS = NeedToProcess(epgpath);
|
||||
FileTS = NeedToProcess(epgpath);
|
||||
|
||||
if (FileTS != 0) {
|
||||
|
||||
|
@ -377,13 +379,15 @@ void dosqldump(char * epgpath,struct epgfilter *filter, int Continuous)
|
|||
|
||||
rc = ExecSQLStatement("COMMIT;", db);
|
||||
|
||||
copy_freesat_to_non_freesat(db);
|
||||
|
||||
sprintf(SQL, "replace into epgtimestamp (lastfileprocessed) values (%i);", FileTS);
|
||||
rc = ExecSQLStatement("Delete from epgtimestamp;", db);
|
||||
rc = ExecSQLStatement(SQL, db);
|
||||
|
||||
if (db != NULL) CloseDB(db);
|
||||
SwapEPGFiles();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -415,7 +419,7 @@ dump(struct epg *epg __attribute__((unused)),
|
|||
* event CRID, series CRID, rec CRID
|
||||
*/
|
||||
printf("%d\t%d\t%ld\t%d\t%d\t",
|
||||
s->service_id, d->event_id, tm,
|
||||
s->service_id, d->event_id, tm,
|
||||
d->dur_hour * 3600 + d->dur_min * 60 + d->dur_sec,
|
||||
d->u1.u.free_CA_mode);
|
||||
if (ds[PARSER_SHORT_EVENT])
|
||||
|
@ -484,7 +488,7 @@ dump(struct epg *epg __attribute__((unused)),
|
|||
if (sysopts & SYSOPT_BRIEF)
|
||||
{
|
||||
safeprintf("%d/%d: %s+%d\n",
|
||||
s->service_id, d->event_id, ctime_nl(&tm),
|
||||
s->service_id, d->event_id, ctime_nl(&tm),
|
||||
d->dur_hour * 3600 + d->dur_min * 60 + d->dur_sec);
|
||||
if (ds[PARSER_SHORT_EVENT])
|
||||
{
|
||||
|
@ -568,6 +572,47 @@ dump(struct epg *epg __attribute__((unused)),
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
copy_freesat_to_non_freesat(sqlite3 * db)
|
||||
{
|
||||
int rc;
|
||||
|
||||
ExecSQLStatement(
|
||||
"attach database '/opt/webif/plugin/epg/epgsettings.db' as epgsettings",
|
||||
db
|
||||
);
|
||||
|
||||
ExecSQLStatement("BEGIN;", db);
|
||||
|
||||
rc = ExecSQLStatementRowCount(
|
||||
"insert into epg "
|
||||
"select epgmappings.nonfreesatserviceid, "
|
||||
"eventid, "
|
||||
"starttime, "
|
||||
"duration, "
|
||||
"encrypted, "
|
||||
"name, "
|
||||
"descr, "
|
||||
"warning, "
|
||||
"contentcode, "
|
||||
"contenttype, "
|
||||
"ECRID, "
|
||||
"SCRID, "
|
||||
"RCRID "
|
||||
"from epgsettings.epgmappings join epg on epg.serviceid = epgsettings.epgmappings.freesatserviceid "
|
||||
"except "
|
||||
"select epg.* "
|
||||
"from epgsettings.epgmappings join epg on epg.serviceid = epgsettings.epgmappings.freesatserviceid",
|
||||
db
|
||||
);
|
||||
|
||||
ExecSQLStatement("COMMIT;", db);
|
||||
|
||||
printf("%d EPG event(s) copied from Freesat to non-Freesat\n", rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void
|
||||
search(struct epg *epg __attribute__((unused)),
|
||||
struct section *s, struct data *d, struct descriptor **ds,
|
||||
|
@ -759,12 +804,9 @@ nextopt:
|
|||
{
|
||||
dosqldump(epgpath, filter, 1);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
syntax();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue