]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
xmltv: Parse atsc style numbers. (#4615)
authorE.Smith <31170571+azlm8t@users.noreply.github.com>
Sat, 23 Sep 2017 11:31:55 +0000 (12:31 +0100)
committerJaroslav Kysela <perex@perex.cz>
Sun, 24 Sep 2017 07:02:20 +0000 (09:02 +0200)
Previously we only parsed numbers of the format "445" and
forced the minor number to be zero. However atsc numbers
have a major and a minor so we now parse "39.1" as
major=39 minor=1.

Issue: #4615

src/epggrab/module/xmltv.c

index 0c58f1f8e9dac4d441563029d915ce388502a8ba..522f9698b1ab78e5800771e679290a0e63d95e2b 100644 (file)
@@ -661,21 +661,43 @@ static int _xmltv_parse_channel
   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");
-      if (chnum && name) {
-        while (isdigit(*(name + n))) n++;
-        if (n > 0) {
-          if (*(name + n) == 0 || (*(name + n) == ' ' && chnum == 1)) {
-            save |= epggrab_channel_set_number(ch, atoi(name), 0);
-            name += n;
-            while (*name == ' ') name++;
-          }
-        }
+      int major = 0;
+      int minor = 0;
+      const char *cur = name;
+
+      /* Some xmltv providers supply a display-name that is the
+       * channel number. So attempt to grab it.
+       */
+
+      /* Check and grab major part of channel number */
+      while (isdigit(*cur))
+        major = (major * 10) + *cur++ - '0';
+
+      /* If a period then it's an atsc-style number of major.minor.
+       * So skip the period and parse the minor.
+       */
+      if (major && *cur == '.') {
+        ++cur;
+        while (isdigit(*cur))
+          minor = (minor * 10) + *cur++ - '0';
       }
-      if (name && *name)
-        htsmsg_add_str_exclusive(dnames, name);
+
+      /* If we have a channel number and then either end of string
+       * or (if chnum is 'first words') a space, then save the channel.
+       * The space is necessary to avoid channels such as "4Music"
+       * being treated as channel number 4.
+       *
+       * We assume channel number has to be >0.
+       */
+      if (major && (!*cur || (*cur == ' ' && chnum == 1))) {
+        save |= epggrab_channel_set_number(ch, major, minor);
+        /* Skip extra spaces between channel number and actual name */
+        while (*cur == ' ') ++cur;
+      }
+
+      if (cur && *cur)
+        htsmsg_add_str_exclusive(dnames, cur);
     }
     else if (strcmp(f->hmf_name, "icon") == 0) {
       if ((attribs = htsmsg_get_map(subtag,  "attrib")) != NULL &&