]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
channel: Allow merging on bouquet. (#4714).
authorE.Smith <31170571+azlm8t@users.noreply.github.com>
Wed, 15 Nov 2017 14:03:28 +0000 (14:03 +0000)
committerJaroslav Kysela <perex@perex.cz>
Thu, 16 Nov 2017 13:53:06 +0000 (14:53 +0100)
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
src/channels.h
src/service_mapper.c

index aa77961f7ad64497ad2b848ad33eaf1859d5aaf0..5195246fdcbad4bce9f506bc2febc9ea1b41a696 100644 (file)
@@ -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;
 }
 
-
 /**
  *
  */
index 5257aa7371b3b8704b1113e79d8be2563d48c079..44fd95216547db631fdfab038ebf2131e37a4280 100644 (file)
@@ -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)
 
index 65f462a0421d50a753f8b8bd5467cf013eb5972b..4d30dc6836571c9fd04c957c0f09f2fb40f61e69 100644 (file)
@@ -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;
   }