From 7c31cf3a7db315bc33ad2fc051419414bbc4a288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Thu, 21 Feb 2008 21:12:21 +0000 Subject: [PATCH] Instead of having the xmltv parser load a preconfigured file, execute the grabbers directly and parse output. We no longer need to rely on any cronjobs, etc for loading the xmltv db. --- epg_xmltv.c | 45 ++++++++++++++++++++++++++++++++------------- main.c | 12 +++--------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/epg_xmltv.c b/epg_xmltv.c index d03d27ab..d376adf6 100644 --- a/epg_xmltv.c +++ b/epg_xmltv.c @@ -36,6 +36,7 @@ #include "epg.h" #include "epg_xmltv.h" #include "refstr.h" +#include "spawn.h" extern int xmltvreload; @@ -252,13 +253,25 @@ xmltv_load(void) { xmlDoc *doc = NULL; xmlNode *root_element = NULL; - const char *filename = config_get_str("xmltv", "/tmp/tv.xml"); + const char *prog; + char *outbuf; + int outlen; + prog = config_get_str("xmltvgrabber", NULL); + if(prog == NULL) + return; - syslog(LOG_INFO, "Loading xmltv file \"%s\"", filename); + syslog(LOG_INFO, "xmltv: Starting grabber \"%s\"", prog); - doc = xmlParseFile(filename); + outlen = spawn_and_store_stdout(prog, &outbuf); + if(outlen < 1) { + syslog(LOG_ERR, "xmltv: Cannot parse output from \"%s\"", prog); + return; + } + + doc = xmlParseMemory(outbuf, outlen); if(doc == NULL) { - syslog(LOG_ERR, "Error while loading xmltv file \"%s\"", filename); + syslog(LOG_ERR, "xmltv: Error while parsing output from \"%s\"", prog); + free(outbuf); return; } @@ -268,6 +281,8 @@ xmltv_load(void) xmltv_parse_root(root_element); xmlFreeDoc(doc); xmlCleanupParser(); + syslog(LOG_INFO, "xmltv: EPG sucessfully loaded and parsed"); + free(outbuf); } /* @@ -374,17 +389,15 @@ xmltv_transfer(void) static void * xmltv_thread(void *aux) { - xmltvreload = 1; + int sleeptime; + + /* Default to 12 hours */ + sleeptime = atoi(config_get_str("xmltvinterval", "43200")); + while(1) { - - if(xmltvreload) { - xmltvreload = 0; - xmltv_load(); - } - + xmltv_load(); xmltv_transfer(); - sleep(10); - + sleep(sleeptime); } } @@ -396,5 +409,11 @@ void xmltv_init(void) { pthread_t ptid; + + if(config_get_str("xmltvgrabber", NULL) == NULL) { + syslog(LOG_INFO, "xmltv: No grabber configured, xmltv subsystem disabled"); + return; + } + pthread_create(&ptid, NULL, xmltv_thread, NULL); } diff --git a/main.c b/main.c index 2ad877ff..b6ca39a8 100644 --- a/main.c +++ b/main.c @@ -57,11 +57,11 @@ #include "file_input.h" #include "cwc.h" #include "autorec.h" +#include "spawn.h" #include int running; -int xmltvreload; int startupcounter; const char *settings_dir; const char *sys_warning; @@ -84,13 +84,6 @@ tag_get(void) } - -static void -xmltvdoreload(int x) -{ - xmltvreload = 1; -} - static void doexit(int x) { @@ -212,10 +205,11 @@ main(int argc, char **argv) htsparachute_init(pull_chute); - signal(SIGUSR1, xmltvdoreload); signal(SIGTERM, doexit); signal(SIGINT, doexit); + spawn_init(); + av_register_all(); av_log_set_level(AV_LOG_INFO);