From 929517e8f1b9bad347119d7640ac59aa9c74e49e Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 5 Apr 2016 08:48:41 +0200 Subject: [PATCH] xmltv grabber: parse channel numbers only on request - cleanup the PyEPG / XMLTV module registration - create different classes for help and additional configs --- docs/markdown/toc.md | 6 ++-- src/epggrab.c | 4 +++ src/epggrab.h | 2 ++ src/epggrab/module.c | 4 +-- src/epggrab/module/pyepg.c | 19 ++++++++++-- src/epggrab/module/xmltv.c | 63 ++++++++++++++++++++++++++++++++------ src/epggrab/private.h | 6 +++- 7 files changed, 87 insertions(+), 17 deletions(-) diff --git a/docs/markdown/toc.md b/docs/markdown/toc.md index 2117ba9b4..a22c6f306 100644 --- a/docs/markdown/toc.md +++ b/docs/markdown/toc.md @@ -59,8 +59,10 @@ Web Interface Configuration Guide - [EPG Grabber](class/epggrab) - EPG Grabber Modules - [OTA Module](class/epggrab_mod_ota) - - [Internal Module](class/epggrab_mod_int) - - [External Module](class/epggrab_mod_ext) + - [Internal PyEPG](class/epggrab_mod_int_pyepg) + - [Internal XMLTV](class/epggrab_mod_int_xmltv) + - [External PyEPG](class/epggrab_mod_ext_pyepg) + - [External XMLTV](class/epggrab_mod_ext_xmltv) * Stream diff --git a/src/epggrab.c b/src/epggrab.c index f957e3452..dc7acbd6d 100644 --- a/src/epggrab.c +++ b/src/epggrab.c @@ -402,7 +402,11 @@ void epggrab_init ( void ) idclass_register(&epggrab_class); idclass_register(&epggrab_mod_class); idclass_register(&epggrab_mod_int_class); + idclass_register(&epggrab_mod_int_pyepg_class); + idclass_register(&epggrab_mod_int_xmltv_class); idclass_register(&epggrab_mod_ext_class); + idclass_register(&epggrab_mod_ext_pyepg_class); + idclass_register(&epggrab_mod_ext_xmltv_class); idclass_register(&epggrab_mod_ota_class); epggrab_channel_init(); diff --git a/src/epggrab.h b/src/epggrab.h index 73e37476a..20e101eff 100644 --- a/src/epggrab.h +++ b/src/epggrab.h @@ -172,6 +172,8 @@ struct epggrab_module_int const char *path; ///< Path for the command const char *args; ///< Extra arguments + int xmltv_chnum; + /* Handle data */ char* (*grab) ( void *mod ); htsmsg_t* (*trans) ( void *mod, char *data ); diff --git a/src/epggrab/module.c b/src/epggrab/module.c index f4ffe4ea4..cd4247749 100644 --- a/src/epggrab/module.c +++ b/src/epggrab/module.c @@ -552,7 +552,7 @@ epggrab_module_activate_socket ( void *m, int a ) * Create a module */ epggrab_module_ext_t *epggrab_module_ext_create - ( epggrab_module_ext_t *skel, + ( epggrab_module_ext_t *skel, const idclass_t *cls, const char *id, const char *saveid, const char *name, int priority, const char *sockid, int (*parse) (void *m, htsmsg_t *data, epggrab_stats_t *sta), @@ -566,7 +566,7 @@ epggrab_module_ext_t *epggrab_module_ext_create /* Pass through */ hts_settings_buildpath(path, sizeof(path), "epggrab/%s.sock", sockid); epggrab_module_int_create((epggrab_module_int_t*)skel, - &epggrab_mod_ext_class, + cls ?: &epggrab_mod_ext_class, id, saveid, name, priority, path, NULL, parse, trans); diff --git a/src/epggrab/module/pyepg.c b/src/epggrab/module/pyepg.c index 4acfe7811..5994a2abb 100644 --- a/src/epggrab/module/pyepg.c +++ b/src/epggrab/module/pyepg.c @@ -458,18 +458,33 @@ static int _pyepg_parse * Module Setup * ***********************************************************************/ +const idclass_t epggrab_mod_int_pyepg_class = { + .ic_super = &epggrab_mod_int_class, + .ic_class = "epggrab_mod_int_pyepg", + .ic_caption = N_("Internal PyEPG grabber"), +}; + + +const idclass_t epggrab_mod_ext_pyepg_class = { + .ic_super = &epggrab_mod_ext_class, + .ic_class = "epggrab_mod_ext_pyepg", + .ic_caption = N_("External PyEPG grabber"), +}; + + void pyepg_init ( void ) { char buf[256]; /* Internal module */ if (find_exec("pyepg", buf, sizeof(buf)-1)) - epggrab_module_int_create(NULL, NULL, + epggrab_module_int_create(NULL, &epggrab_mod_int_pyepg_class, "pyepg-internal", "pyepg", "PyEPG", 4, buf, NULL, _pyepg_parse, NULL); /* External module */ - epggrab_module_ext_create(NULL, "pyepg", "pyepg", "PyEPG", 4, "pyepg", + epggrab_module_ext_create(NULL, &epggrab_mod_ext_pyepg_class, + "pyepg", "pyepg", "PyEPG", 4, "pyepg", _pyepg_parse, NULL); } diff --git a/src/epggrab/module/xmltv.c b/src/epggrab/module/xmltv.c index 5c9301847..1d31b9c0d 100644 --- a/src/epggrab/module/xmltv.c +++ b/src/epggrab/module/xmltv.c @@ -657,12 +657,14 @@ static int _xmltv_parse_channel int n = 0; name = htsmsg_get_str(subtag, "cdata"); - while (isdigit(*(name + n))) n++; - if (n > 0) { - if (*(name + n) == 0 || *(name + n) == ' ') { - save |= epggrab_channel_set_number(ch, atoi(name), 0); - name += n; - while (*name == ' ') name++; + if (((epggrab_module_ext_t *)mod)->xmltv_chnum) { + while (isdigit(*(name + n))) n++; + if (n > 0) { + if (*(name + n) == 0 || *(name + n) == ' ') { + save |= epggrab_channel_set_number(ch, atoi(name), 0); + name += n; + while (*name == ' ') name++; + } } } if (*name) @@ -746,6 +748,45 @@ static int _xmltv_parse * Module Setup * ***********************************************************************/ +#define DN_CHNUM_NAME N_("Channel numbers (heuristic)") +#define DN_CHNUM_DESC \ + N_("Try to obtain channel numbers from the display-name xml tag. " \ + "If the first word is number, it is used as the channel number.") + +const idclass_t epggrab_mod_int_xmltv_class = { + .ic_super = &epggrab_mod_int_class, + .ic_class = "epggrab_mod_int_xmltv", + .ic_caption = N_("Internal XMLTV EPG grabber"), + .ic_properties = (const property_t[]){ + { + .type = PT_BOOL, + .id = "dn_chnum", + .name = DN_CHNUM_NAME, + .desc = DN_CHNUM_DESC, + .off = offsetof(epggrab_module_int_t, xmltv_chnum), + .group = 1 + }, + {} + } +}; + +const idclass_t epggrab_mod_ext_xmltv_class = { + .ic_super = &epggrab_mod_ext_class, + .ic_class = "epggrab_mod_ext_xmltv", + .ic_caption = N_("External XMLTV EPG grabber"), + .ic_properties = (const property_t[]){ + { + .type = PT_BOOL, + .id = "dn_chnum", + .name = DN_CHNUM_NAME, + .desc = DN_CHNUM_DESC, + .off = offsetof(epggrab_module_ext_t, xmltv_chnum), + .group = 1 + }, + {} + } +}; + static void _xmltv_load_grabbers ( void ) { int outlen = -1, rd = -1; @@ -767,7 +808,8 @@ static void _xmltv_load_grabbers ( void ) if ( outbuf[i] == '\n' || outbuf[i] == '\0' ) { outbuf[i] = '\0'; sprintf(name, "XMLTV: %s", &outbuf[n]); - epggrab_module_int_create(NULL, NULL, &outbuf[p], "xmltv", + epggrab_module_int_create(NULL, &epggrab_mod_int_xmltv_class, + &outbuf[p], "xmltv", name, 3, &outbuf[p], NULL, _xmltv_parse, NULL); p = n = i + 1; @@ -814,7 +856,8 @@ static void _xmltv_load_grabbers ( void ) close(rd); if (outbuf[outlen-1] == '\n') outbuf[outlen-1] = '\0'; snprintf(name, sizeof(name), "XMLTV: %s", outbuf); - epggrab_module_int_create(NULL, NULL, bin, "xmltv", name, 3, bin, + epggrab_module_int_create(NULL, &epggrab_mod_int_xmltv_class, + bin, "xmltv", name, 3, bin, NULL, _xmltv_parse, NULL); free(outbuf); } else { @@ -833,8 +876,8 @@ static void _xmltv_load_grabbers ( void ) void xmltv_init ( void ) { /* External module */ - epggrab_module_ext_create(NULL, "xmltv", "xmltv", - "XMLTV", 3, "xmltv", + epggrab_module_ext_create(NULL, &epggrab_mod_ext_xmltv_class, + "xmltv", "xmltv", "XMLTV", 3, "xmltv", _xmltv_parse, NULL); /* Standard modules */ diff --git a/src/epggrab/private.h b/src/epggrab/private.h index 73edc6240..8e6290e04 100644 --- a/src/epggrab/private.h +++ b/src/epggrab/private.h @@ -87,7 +87,7 @@ epggrab_module_int_t *epggrab_module_int_create * *************************************************************************/ epggrab_module_ext_t *epggrab_module_ext_create - ( epggrab_module_ext_t *skel, + ( epggrab_module_ext_t *skel, const idclass_t *cls, const char *id, const char *saveid, const char *name, int priority, const char *sockid, @@ -188,7 +188,11 @@ size_t freesat_huffman_decode extern const idclass_t epggrab_mod_class; extern const idclass_t epggrab_mod_int_class; +extern const idclass_t epggrab_mod_int_pyepg_class; +extern const idclass_t epggrab_mod_int_xmltv_class; extern const idclass_t epggrab_mod_ext_class; +extern const idclass_t epggrab_mod_ext_pyepg_class; +extern const idclass_t epggrab_mod_ext_xmltv_class; extern const idclass_t epggrab_mod_ota_class; /* ************************************************************************** -- 2.47.3