add JSON
This commit is contained in:
parent
5b98b8e21a
commit
c31dc7166f
5
Makefile
5
Makefile
|
@ -33,6 +33,10 @@ endif
|
||||||
|
|
||||||
all: tags epg
|
all: tags epg
|
||||||
|
|
||||||
|
install: epg
|
||||||
|
strip epg
|
||||||
|
cp epg /mod/bin/epg
|
||||||
|
|
||||||
epg: ${OBJS}
|
epg: ${OBJS}
|
||||||
@echo "Linking..."
|
@echo "Linking..."
|
||||||
@-[ -f $@ ] && mv $@ $@~ || exit 0
|
@-[ -f $@ ] && mv $@ $@~ || exit 0
|
||||||
|
@ -42,7 +46,6 @@ epg: ${OBJS}
|
||||||
${CFLAGS} -o $@ \
|
${CFLAGS} -o $@ \
|
||||||
${OBJS} \
|
${OBJS} \
|
||||||
${LIBS}
|
${LIBS}
|
||||||
@strip epg
|
|
||||||
@echo "Done..."
|
@echo "Done..."
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
106
main.c
106
main.c
|
@ -21,7 +21,7 @@
|
||||||
#include "lint.h"
|
#include "lint.h"
|
||||||
|
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
const char *version = "1.0.10";
|
const char *version = "1.0.11";
|
||||||
unsigned long sysopts = 0;
|
unsigned long sysopts = 0;
|
||||||
unsigned long filterflags = 0;
|
unsigned long filterflags = 0;
|
||||||
static time_t latest_stamp = 0;
|
static time_t latest_stamp = 0;
|
||||||
|
@ -68,6 +68,7 @@ syntax()
|
||||||
" dump Show a parsed summary of the EPG.\n"
|
" dump Show a parsed summary of the EPG.\n"
|
||||||
" dumpraw Show raw data from the EPG.\n"
|
" dumpraw Show raw data from the EPG.\n"
|
||||||
" sqldump Produce SQL statements from EPG data.\n"
|
" sqldump Produce SQL statements from EPG data.\n"
|
||||||
|
" json Produce JSON formatted EPG data.\n"
|
||||||
#ifdef HAVE_SQLITE3
|
#ifdef HAVE_SQLITE3
|
||||||
" sqlitedump <file> Create SQLite database from EPG data.\n"
|
" sqlitedump <file> Create SQLite database from EPG data.\n"
|
||||||
#endif
|
#endif
|
||||||
|
@ -326,6 +327,103 @@ sqlitedump(struct epg *epg __attribute__((unused)),
|
||||||
|
|
||||||
#endif /* HAVE_SQLITE3 */
|
#endif /* HAVE_SQLITE3 */
|
||||||
|
|
||||||
|
static int json_service_id = 0;
|
||||||
|
|
||||||
|
void
|
||||||
|
jsonstart()
|
||||||
|
{
|
||||||
|
printf("{\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
jsonend()
|
||||||
|
{
|
||||||
|
if (json_service_id)
|
||||||
|
printf("\n }\n");
|
||||||
|
printf("}\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
json(struct epg *epg __attribute__((unused)),
|
||||||
|
struct section *s, struct data *d, struct descriptor **ds,
|
||||||
|
void *var __attribute__((unused)))
|
||||||
|
{
|
||||||
|
time_t tm, dur;
|
||||||
|
|
||||||
|
tm = mjd(d->start_date, d->start_hour, d->start_min, d->start_sec);
|
||||||
|
dur = d->dur_hour * 3600 + d->dur_min * 60 + d->dur_sec;
|
||||||
|
|
||||||
|
if (s->service_id != json_service_id)
|
||||||
|
{
|
||||||
|
/* New service. */
|
||||||
|
if (json_service_id)
|
||||||
|
printf("\n },\n");
|
||||||
|
printf(" \"%d\": {\n", s->service_id);
|
||||||
|
json_service_id = s->service_id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf(",\n");
|
||||||
|
|
||||||
|
printf(" \"%d\": {\n", d->event_id);
|
||||||
|
printf(" \"start\": %ld,\n", tm);
|
||||||
|
printf(" \"end\": %ld,\n", tm + dur);
|
||||||
|
printf(" \"duration\": %ld", dur);
|
||||||
|
|
||||||
|
if (ds[PARSER_SHORT_EVENT])
|
||||||
|
{
|
||||||
|
struct descriptor *d = ds[PARSER_SHORT_EVENT];
|
||||||
|
|
||||||
|
DECOMPRESS(d->content.d77.name, d->content.d77.namelen);
|
||||||
|
DECOMPRESS(d->content.d77.text, d->content.d77.textlen);
|
||||||
|
|
||||||
|
printf(",\n \"name\": \"%.*s\"",
|
||||||
|
d->content.d77.namelen, d->content.d77.name);
|
||||||
|
printf(",\n \"text\": \"%.*s\"",
|
||||||
|
d->content.d77.textlen, d->content.d77.text);
|
||||||
|
}
|
||||||
|
if (ds[PARSER_USER_DEFINED])
|
||||||
|
{
|
||||||
|
struct descriptor *d = ds[PARSER_USER_DEFINED];
|
||||||
|
DECOMPRESS(d->content.d137.warning, d->content.d137.warninglen);
|
||||||
|
|
||||||
|
printf(",\n \"warning\": \"%.*s\"",
|
||||||
|
d->content.d137.warninglen, d->content.d137.warning);
|
||||||
|
}
|
||||||
|
if (ds[PARSER_CONTENT])
|
||||||
|
{
|
||||||
|
printf(",\n \"content_type\": \"%d\"",
|
||||||
|
ds[PARSER_CONTENT]->content.d84.level1);
|
||||||
|
printf(",\n \"content\": \"%s\"",
|
||||||
|
content_type(ds[PARSER_CONTENT]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ds[PARSER_CRID_EVENT])
|
||||||
|
{
|
||||||
|
struct descriptor *d = ds[PARSER_CRID_EVENT];
|
||||||
|
printf(",\n \"event_crid\": \"%.*s\"",
|
||||||
|
d->content.d118.crids[0].cridlen,
|
||||||
|
d->content.d118.crids[0].crid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ds[PARSER_CRID_SERIES])
|
||||||
|
{
|
||||||
|
struct descriptor *d = ds[PARSER_CRID_SERIES];
|
||||||
|
printf(",\n \"series_crid\": \"%.*s\"",
|
||||||
|
d->content.d118.crids[0].cridlen,
|
||||||
|
d->content.d118.crids[0].crid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ds[PARSER_CRID_REC])
|
||||||
|
{
|
||||||
|
struct descriptor *d = ds[PARSER_CRID_REC];
|
||||||
|
printf(",\n \"rec_crid\": \"%.*s\"",
|
||||||
|
d->content.d118.crids[0].cridlen,
|
||||||
|
d->content.d118.crids[0].crid);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n }");
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sqldumpstart()
|
sqldumpstart()
|
||||||
{
|
{
|
||||||
|
@ -823,6 +921,12 @@ nextopt:
|
||||||
parse(epgpath, sqldump, NULL, filter);
|
parse(epgpath, sqldump, NULL, filter);
|
||||||
sqldumpend();
|
sqldumpend();
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(argv[0], "json"))
|
||||||
|
{
|
||||||
|
jsonstart();
|
||||||
|
parse(epgpath, json, NULL, filter);
|
||||||
|
jsonend();
|
||||||
|
}
|
||||||
#ifdef HAVE_SQLITE3
|
#ifdef HAVE_SQLITE3
|
||||||
else if (!strcmp(argv[0], "sqlitedump") && argc == 2)
|
else if (!strcmp(argv[0], "sqlitedump") && argc == 2)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue