Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
xmltv grabber: parse channel numbers only on request
- cleanup the PyEPG / XMLTV module registration
- create different classes for help and additional configs
  • Loading branch information
perexg committed Apr 5, 2016
1 parent cea0b2b commit 929517e
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 17 deletions.
6 changes: 4 additions & 2 deletions docs/markdown/toc.md
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/epggrab.c
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/epggrab.h
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/epggrab/module.c
Expand Up @@ -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),
Expand All @@ -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);

Expand Down
19 changes: 17 additions & 2 deletions src/epggrab/module/pyepg.c
Expand Up @@ -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);
}

Expand Down
63 changes: 53 additions & 10 deletions src/epggrab/module/xmltv.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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 */
Expand Down
6 changes: 5 additions & 1 deletion src/epggrab/private.h
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

/* **************************************************************************
Expand Down

0 comments on commit 929517e

Please sign in to comment.