From 05b5e92785fdd6a724e882626770432b15e859ce Mon Sep 17 00:00:00 2001 From: "E.Smith" <31170571+azlm8t@users.noreply.github.com> Date: Wed, 15 Nov 2017 14:03:28 +0000 Subject: [PATCH] channel: Allow merging on bouquet. (#4714). Previously the merging of channels with the same name on a bouquet did not work since we explicitly excluded these channels from the merge logic. So we now allow finding channels on a specific bouquet and merging and fuzzy merging them. Issue: #4714. --- src/channels.c | 12 +++++++++--- src/channels.h | 4 +++- src/service_mapper.c | 17 +++++++++++++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/channels.c b/src/channels.c index aa77961f7..5195246fd 100644 --- a/src/channels.c +++ b/src/channels.c @@ -562,7 +562,7 @@ const idclass_t channel_class = { // Note: since channel names are no longer unique this method will simply // return the first entry encountered, so could be somewhat random channel_t * -channel_find_by_name ( const char *name ) +channel_find_by_name_and_bouquet ( const char *name, const struct bouquet *bq ) { channel_t *ch; const char *s; @@ -573,11 +573,17 @@ channel_find_by_name ( const char *name ) if (!ch->ch_enabled) continue; s = channel_get_name(ch, NULL); if (s == NULL) continue; + if (bq && ch->ch_bouquet != bq) continue; if (strcmp(s, name) == 0) break; } return ch; } +channel_t * +channel_find_by_name(const char *name) +{ + return channel_find_by_name_and_bouquet(name, NULL); +} /// Copy name without space and HD suffix, lowercase in to a new /// buffer @@ -605,7 +611,7 @@ channel_make_fuzzy_name(const char *name) } channel_t * -channel_find_by_name_fuzzy ( const char *name ) +channel_find_by_name_bouquet_fuzzy ( const char *name, const struct bouquet *bq ) { channel_t *ch; const char *s; @@ -617,6 +623,7 @@ channel_find_by_name_fuzzy ( const char *name ) CHANNEL_FOREACH(ch) { if (!ch->ch_enabled) continue; + if (bq && ch->ch_bouquet != bq) continue; s = channel_get_name(ch, NULL); if (s == NULL) continue; /* We need case insensitive since historical constraints means we @@ -1629,7 +1636,6 @@ channel_tag_find_by_name(const char *name, int create) return ct; } - /** * */ diff --git a/src/channels.h b/src/channels.h index 5257aa737..44fd95216 100644 --- a/src/channels.h +++ b/src/channels.h @@ -129,6 +129,7 @@ channel_t *channel_create0 void channel_delete(channel_t *ch, int delconf); +channel_t *channel_find_by_name_and_bouquet(const char *name, const struct bouquet *bq); channel_t *channel_find_by_name(const char *name); /// Apply fuzzy matching when finding a channel such as ignoring /// whitespace, case, and stripping HD suffix. This means that @@ -136,7 +137,8 @@ channel_t *channel_find_by_name(const char *name); /// 'Channel 5 +1HD' can all be merged together. /// Since channel names aren't unique, this returns the /// first match (similar to channel_find_by_name). -channel_t *channel_find_by_name_fuzzy(const char *name); +/// @param bouquet - Bouquet to use: can be NULL +channel_t *channel_find_by_name_bouquet_fuzzy(const char *name, const struct bouquet *bq); #define channel_find_by_uuid(u)\ (channel_t*)idnode_find(u, &channel_class, NULL) diff --git a/src/service_mapper.c b/src/service_mapper.c index 65f462a04..4d30dc683 100644 --- a/src/service_mapper.c +++ b/src/service_mapper.c @@ -224,14 +224,23 @@ service_mapper_process /* Find existing channel */ name = service_get_channel_name(s); - if (!bq && conf->merge_same_name && name && *name) { + if (conf->merge_same_name && name && *name) { /* Try exact match first */ - chn = channel_find_by_name(name); + chn = channel_find_by_name_and_bouquet(name, bq); if (!chn && conf->merge_same_name_fuzzy) { - chn = channel_find_by_name_fuzzy(name); + chn = channel_find_by_name_bouquet_fuzzy(name, bq); } } - if (!chn) { + /* If using bouquets then we want to only merge + * with channels on the same bouquet. This is because + * you can disable all channels on a bouquet through + * the bouquet menu so if we merged between bouquets then + * you'd get odd results. + * + * The chn should already be for the correct bouquet + * but we'll safety-check here. + */ + if (!chn || (bq && chn->ch_bouquet != bq)) { chn = channel_create(NULL, NULL, NULL); chn->ch_bouquet = bq; } -- 2.47.3