$OpenBSD: patch-src_support_c,v 1.14 2013/07/12 09:20:04 dcoppa Exp $

Escape the name when obtained from the URI
(upstream svn revisions r2444 and r2445)

--- src/support.c.orig	Mon Feb 18 15:58:47 2013
+++ src/support.c	Thu Jul 11 17:13:59 2013
@@ -1028,6 +1028,8 @@ MetaData *get_basic_metadata(gchar * uri)
     gchar *length = NULL;
     gchar *name = NULL;
     gchar *basename = NULL;
+    gchar *escaped_name = NULL;
+    gchar *escaped_basename = NULL;
     gchar *audio_codec = NULL;
     gchar *video_codec = NULL;
     gchar *demuxer = NULL;
@@ -1051,16 +1053,25 @@ MetaData *get_basic_metadata(gchar * uri)
 #ifdef GIO_ENABLED
         file = g_file_new_for_uri(uri);
         if (file != NULL) {
-            name = g_file_get_path(file);
-            basename = g_file_get_basename(file);
+            escaped_name = g_file_get_path(file);
+            escaped_basename = g_file_get_basename(file);
             g_object_unref(file);
         }
 #else
-        name = g_filename_from_uri(uri, NULL, NULL);
-        basename = g_filename_display_basename(name);
+        escaped_name = g_filename_from_uri(uri, NULL, NULL);
+        escaped_basename = g_filename_display_basename(name);
 #endif
     }
 
+    if (escaped_name == NULL) {
+        if (ret != NULL)
+            g_free(ret);
+        return NULL;
+    }
+
+    name = g_uri_unescape_string(escaped_name, NULL);
+    basename = g_uri_unescape_string(escaped_basename, NULL);
+
     if (name == NULL) {
         if (ret != NULL)
             g_free(ret);
@@ -1068,11 +1079,12 @@ MetaData *get_basic_metadata(gchar * uri)
     }
 
     if (title == NULL || strlen(title) == 0) {
-        localuri = g_strdup(uri);
+        localuri = g_uri_unescape_string(uri, NULL);
         p = g_strrstr(localuri, ".");
         if (p)
             p[0] = '\0';
         p = g_strrstr(localuri, "/");
+        p = g_strrstr(p - 1, "/");
         if (p) {
             artist = g_strdup(p + 1);
             p = strstr(artist, " - ");
@@ -1414,11 +1426,12 @@ MetaData *get_metadata(gchar * uri)
 
 
     if (title == NULL || strlen(title) == 0) {
-        localuri = g_strdup(uri);
+        localuri = g_uri_unescape_string(uri, NULL);
         p = g_strrstr(localuri, ".");
         if (p)
             p[0] = '\0';
         p = g_strrstr(localuri, "/");
+        p = g_strrstr(p - 1, "/");
         if (p) {
             artist = g_strdup(p + 1);
             p = strstr(artist, " - ");
@@ -1669,7 +1682,7 @@ gboolean add_item_to_playlist(const gchar * uri, gbool
 
     gm_log(verbose, G_LOG_LEVEL_INFO, "adding %s to playlist (cancel = %s)", uri,
            gm_bool_to_string(cancel_folder_load));
-    local_uri = g_strdup(uri);
+    local_uri = g_uri_unescape_string(uri, NULL);
 #ifdef LIBGDA_ENABLED
     data = get_db_metadata(db_connection, uri);
 #endif
