From: axfree Date: Sun, 3 Apr 2016 22:24:55 +0000 (+0900) Subject: extract channel names and channel number from multiple elements. X-Git-Tag: v4.2.1~745 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3fe8012fccb2daf6d9821dbc74d234684bcdf5d;p=thirdparty%2Ftvheadend.git extract channel names and channel number from multiple elements. --- diff --git a/src/epggrab/module/xmltv.c b/src/epggrab/module/xmltv.c index eb40b5ace..5c9301847 100644 --- a/src/epggrab/module/xmltv.c +++ b/src/epggrab/module/xmltv.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -635,6 +636,8 @@ static int _xmltv_parse_channel htsmsg_t *attribs, *tags, *subtag; const char *id, *name, *icon; epggrab_channel_t *ch; + htsmsg_field_t *f; + htsmsg_t *dnames; if(body == NULL) return 0; @@ -646,15 +649,41 @@ static int _xmltv_parse_channel stats->channels.total++; if (save) stats->channels.created++; - if((name = htsmsg_xml_get_cdata_str(tags, "display-name")) != NULL) { - save |= epggrab_channel_set_name(ch, name); + dnames = htsmsg_create_list(); + + HTSMSG_FOREACH(f, tags) { + if (!(subtag = htsmsg_field_get_map(f))) continue; + if (strcmp(f->hmf_name, "display-name") == 0) { + 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 (*name) + htsmsg_add_str_exclusive(dnames, name); + } + else if (strcmp(f->hmf_name, "icon") == 0) { + if ((attribs = htsmsg_get_map(subtag, "attrib")) != NULL && + (icon = htsmsg_get_str(attribs, "src")) != NULL) { + save |= epggrab_channel_set_icon(ch, icon); + } + } } - if((subtag = htsmsg_get_map(tags, "icon")) != NULL && - (attribs = htsmsg_get_map(subtag, "attrib")) != NULL && - (icon = htsmsg_get_str(attribs, "src")) != NULL) { - save |= epggrab_channel_set_icon(ch, icon); + HTSMSG_FOREACH(f, dnames) { + const char *s; + + if ((s = htsmsg_field_get_str(f)) != NULL) + save |= epggrab_channel_set_name(ch, s); } + htsmsg_destroy(dnames); + if (save) stats->channels.modified++; return save;