diff --git a/src/channels.c b/src/channels.c index 521a6e0f5..f8c15a946 100644 --- a/src/channels.c +++ b/src/channels.c @@ -622,7 +622,7 @@ channel_find_by_name(const char *name) /// Copy name without space and (U)HD suffix, lowercase in to a new /// buffer -static char * +char * channel_make_fuzzy_name(const char *name) { if (!name) return NULL; @@ -632,17 +632,27 @@ channel_make_fuzzy_name(const char *name) const char *ch = name; for (; *ch ; ++ch) { + /* Strip trailing 'SD'. */ + if (*ch == 'S' && *(ch+1) == 'D' && *(ch+2) == 0) + break; /* Strip trailing 'HD'. */ if (*ch == 'H' && *(ch+1) == 'D' && *(ch+2) == 0) break; + /* Strip trailing 'FHD'. */ + if (*ch == 'F' && *(ch+1) == 'H' && *(ch+2) == 'D' && *(ch+3) == 0) + break; /* Strip trailing 'UHD'. */ if (*ch == 'U' && *(ch+1) == 'H' && *(ch+2) == 'D' && *(ch+3) == 0) break; - /* Strip trailing 'FHD'. */ - if (*ch == 'F' && *(ch+1) == 'H' && *(ch+2) == 'D' && *(ch+3) == 0) + /* Strip trailing '4K'. */ + if (*ch == '4' && *(ch+1) == 'K' && *(ch+2) == 0) break; + /* Strip trailing '8K'. */ + if (*ch == '8' && *(ch+1) == 'K' && *(ch+2) == 0) + break; + - if (!isspace(*ch)) { + if (!isspace(*ch) && *ch!='.' && *ch!=':' && *ch!=';' && *ch!=',' && *ch!='_' && *ch!='-' ) { *ch_fuzzy++ = tolower(*ch); } } diff --git a/src/channels.h b/src/channels.h index 7b377487d..bfd83a17a 100644 --- a/src/channels.h +++ b/src/channels.h @@ -212,6 +212,8 @@ int channel_set_icon ( channel_t *ch, const char *icon ); const char *channel_get_epgid ( channel_t *ch ); +char *channel_make_fuzzy_name(const char *name); + #define channel_get_uuid(ch,ub) idnode_uuid_as_str(&(ch)->ch_id, ub) #define channel_get_id(ch) idnode_get_short_uuid((&(ch)->ch_id)) diff --git a/src/epggrab/channel.c b/src/epggrab/channel.c index 2bda67fd8..102ac8fd0 100644 --- a/src/epggrab/channel.c +++ b/src/epggrab/channel.c @@ -82,14 +82,25 @@ int epggrab_channel_match_name ( epggrab_channel_t *ec, channel_t *ch ) if (name == NULL) return 0; - if (ec->name && !strcasecmp(ec->name, name)) - return 1; + char *ch_fuzzy_name = channel_make_fuzzy_name(name); + const char *chid = channel_get_epgid(ch); + char *chid_fuzzy_name = chid ? channel_make_fuzzy_name(chid) : NULL; + + if (ec->name) + { + char *ec_fuzzy_name = channel_make_fuzzy_name(ec->name); + if(!strcmp(ec_fuzzy_name, ch_fuzzy_name)) return 1; + if(chid_fuzzy_name && !strcmp(ec_fuzzy_name, chid_fuzzy_name) ) return 1; //macth chid with ec->name + } if (ec->names) HTSMSG_FOREACH(f, ec->names) if ((s = htsmsg_field_get_str(f)) != NULL) - if (!strcasecmp(s, name)) - return 1; + { + char *s_fuzzy_name = channel_make_fuzzy_name(s); + if(!strcmp(s_fuzzy_name, ch_fuzzy_name)) return 1; + if(chid_fuzzy_name && !strcmp(s_fuzzy_name, chid_fuzzy_name) ) return 1; //macth chid with ec->names + } return 0; } @@ -195,6 +206,7 @@ epggrab_channel_map ( idnode_t *ec, idnode_t *ch, void *origin ) return epggrab_channel_link((epggrab_channel_t *)ec, (channel_t *)ch, origin); } + /* Set name */ int epggrab_channel_set_name ( epggrab_channel_t *ec, const char *name ) { @@ -288,20 +300,16 @@ static int epggrab_channel_autolink( epggrab_channel_t *ec ) { channel_t *ch; + int found=1; CHANNEL_FOREACH(ch) - if (epggrab_channel_match_epgid(ec, ch)) + if (epggrab_channel_match_epgid(ec, ch) + || epggrab_channel_match_name(ec, ch) + || epggrab_channel_match_number(ec, ch)) if (epggrab_channel_link(ec, ch, NULL)) - return 1; - CHANNEL_FOREACH(ch) - if (epggrab_channel_match_name(ec, ch)) - if (epggrab_channel_link(ec, ch, NULL)) - return 1; - CHANNEL_FOREACH(ch) - if (epggrab_channel_match_number(ec, ch)) - if (epggrab_channel_link(ec, ch, NULL)) - return 1; - return 0; + found=1; + + return found; } /* Channel settings updated */