]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
channel icons: add '%U' to pass UTF-8 filenames, fixes #4755
authorJaroslav Kysela <perex@perex.cz>
Sun, 3 Dec 2017 08:47:44 +0000 (09:47 +0100)
committerJaroslav Kysela <perex@perex.cz>
Sun, 3 Dec 2017 08:47:44 +0000 (09:47 +0100)
docs/property/config_channelicon_path.md
src/channels.c
src/tvheadend.h
src/utils.c

index 33ee5b6b2d730cc0700afbbac8c6c0e047c06306..2c6f2aadcc801cc0ef17086bc3701aff55803b70 100644 (file)
@@ -4,8 +4,9 @@ The following placeholders are available:
 
 Placeholder | Function
 :----------:| --------
-**%C**      | The transliterated channel name in in URL encoded ASCII with safe characters only - `WDR Köln :<>|*?'"` will be `WDR%20Koln%20________`
-**%c**      | The channel name (URL encoded UTF-8)
+**%C**      | The transliterated channel name in URL encoded ASCII with safe characters only - `WDR Köln :<>*?'"` will be `WDR%20Koln%20________`
+**%c**      | The transliterated channel name in URL encoded ASCII
+**%U**      | UTF-8 encoded URL
 
 Example: `file:///tmp/icons/%C.png` or `http://example.com/%c.png`
 
index d7fb45388dd6a6babaab8b3a58dd6df2b4749fd9..b9d8b08da36a6acb1bf2199a39a695d073e8cd67 100644 (file)
@@ -941,8 +941,7 @@ channel_get_icon ( channel_t *ch )
       chi = strdup(chicon);
 
       /* Check for and replace placeholders */
-      if ((send = strstr(chi, "%C"))) {
-
+      if ((send = strstr(chi, "%C")) || (send = strstr(chi, "%c"))) {
         sname = intlconv_utf8safestr(intlconv_charset_id("ASCII", 1, 1),
                                      chname, strlen(chname) * 2);
         if (sname == NULL)
@@ -957,34 +956,24 @@ channel_get_icon ( channel_t *ch )
           s = sname;
           while (s && *s) {
             c = *s;
-            if (c > 122 || strchr(":<>|*?'\"", c) != NULL)
+            if (send[1] == 'C' && (c > 122 || strchr(":<>|*?'\"", c) != NULL))
               *(char *)s = '_';
             else if (config.chicon_scheme == CHICON_LOWERCASE && c >= 'A' && c <= 'Z')
               *(char *)s = c - 'A' + 'a';
             s++;
           }
         }
-
-      } else if ((send = strstr(chi, "%c"))) {
-
-        sname = intlconv_utf8safestr(intlconv_charset_id("ASCII", 1, 1),
-                                     chname, strlen(chname) * 2);
-
+      } else if ((send = strstr(chi, "%U"))) {
         if (sname == NULL)
           sname = strdup(chname);
 
         if (config.chicon_scheme == CHICON_LOWERCASE) {
-          for (s = sname; *s; s++) {
-            c = *s;
-            if (c >= 'A' && c <= 'Z')
-              *(char *)s = c - 'A' + 'a';
-          }
+          utf8_lowercase_inplace((char *)sname);
         } else if (config.chicon_scheme == CHICON_SVCNAME) {
           s = svcnamepicons(sname);
           free((char *)sname);
           sname = (char *)s;
         }
-
       } else {
         buf[0] = '\0';
         sname = NULL;
index 306a37b9f49a6fc2f9795c54479a1355e1f3b4a3..ece6ee43350075fe957da2b6fd34c2618e0c8bdd 100644 (file)
@@ -765,6 +765,8 @@ char *base64_encode(char *out, int out_size, const uint8_t *in, int in_size);
 
 int put_utf8(char *out, int c);
 
+char *utf8_lowercase_inplace(char *s);
+
 static inline int64_t ts_rescale(int64_t ts, int tb)
 {
   //  return (ts * tb + (tb / 2)) / 90000LL;
index 45d03e4786966067797d48cc5b3be4472009532a..2fd26761beb94c55cbc18f7b90678dde794fa2e8 100644 (file)
@@ -291,6 +291,38 @@ put_utf8(char *out, int c)
   return 6;
 }
 
+char *utf8_lowercase_inplace(char *s)
+{
+  char *r = s;
+  uint8_t c;
+
+  for ( ; *s; s++) {
+    /* FIXME: this is really wrong version of lowercase for utf-8 */
+    /* but it's a deep issue with the different locale handling */
+    c = (uint8_t)*s;
+    if (c & 0x80) {
+      if ((c & 0xe0) == 0xc0) {
+        s++;
+        continue;
+      } else if ((c & 0xf0) == 0xe0) {
+        s++;
+        if (*s) s++;
+      } else if ((c & 0xf8) == 0xf0) {
+        s++;
+        if (*s) s++;
+        if (*s) s++;
+      }
+    }
+    if (c >= 'A' && c <= 'Z')
+      *(char *)s = c - 'A' + 'a';
+  }
+  return r;
+}
+
+/**
+ *
+ */
+
 static void
 sbuf_alloc_fail(int len)
 {