changeset 2215:9ddfa78b43a0

- now container plugins feed only valid uri to the core. - fix a bug in pls plugin which prevented writing pls playlist.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Fri, 07 Dec 2007 01:13:34 +0900
parents 9a869d4bb0d3
children 6a4d667a9183 d7acad3d50e8
files src/m3u/m3u.c src/pls/pls.c
diffstat 2 files changed, 39 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/m3u/m3u.c	Thu Dec 06 23:25:24 2007 +0900
+++ b/src/m3u/m3u.c	Fri Dec 07 01:13:34 2007 +0900
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+/* #define AUD_DEBUG 1 */
+
 #include <glib.h>
 #include <string.h>
 #include <glib.h>
@@ -84,14 +86,14 @@
     gint ext_len = -1;
     gboolean is_extm3u = FALSE;
     Playlist *playlist = aud_playlist_get_active();
-    gchar *uri;
+    gchar *uri = NULL;
     
     uri = g_filename_to_uri(filename, NULL, NULL);
 
     if ((file = aud_vfs_fopen(uri ? uri : filename, "rb")) == NULL)
         return;
 
-    g_free(uri);
+    g_free(uri); uri = NULL;
 
     line = g_malloc(line_len);
     while (aud_vfs_fgets(line, line_len, file)) {
@@ -130,15 +132,21 @@
             ext_info = NULL;
         }
 
-        uri = g_filename_to_uri(line, NULL, NULL);
-        aud_playlist_load_ins_file(playlist, uri ? uri : line, filename, pos, ext_title, ext_len);
+        uri = aud_construct_uri(line, filename);
+        AUDDBG("uri=%s\n", uri);
+
+        /* add file only if valid uri has been constructed */
+        if (uri) {
+            aud_playlist_load_ins_file(playlist, uri, filename, pos, ext_title, ext_len);
+
+            if (pos >= 0)
+                pos++;
+        }
+
         g_free(uri);
 
         aud_str_replace_in(&ext_title, NULL);
         ext_len = -1;
-
-        if (pos >= 0)
-            pos++;
     }
 
     aud_vfs_fclose(file);
--- a/src/pls/pls.c	Thu Dec 06 23:25:24 2007 +0900
+++ b/src/pls/pls.c	Fri Dec 07 01:13:34 2007 +0900
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+/* #define AUD_DEBUG 1 */
+
 #include <glib.h>
 #include <string.h>
 #include <glib.h>
@@ -65,30 +67,28 @@
         g_snprintf(line_key, sizeof(line_key), "File%d", i);
         if ((line = aud_read_ini_string(inifile, "playlist", line_key)))
         {
-            gchar *uri = g_filename_to_uri(line, NULL, NULL);
-
-            if (uri)
-                g_free(line);
-            else
-                uri = line;
+            gchar *uri = aud_construct_uri(line, filename);
+            g_free(line);
 
-            if (aud_cfg->use_pl_metadata)
-            {
-                g_snprintf(title_key, sizeof(title_key), "Title%d", i);
+            /* add file only if valid uri has been constructed */
+            if (uri) {
+                if (aud_cfg->use_pl_metadata)
+                {
+                    g_snprintf(title_key, sizeof(title_key), "Title%d", i);
 
-                if ((title = aud_read_ini_string(inifile, "playlist", title_key)))
-                    aud_playlist_load_ins_file(playlist, uri, filename, pos, title, -1);
+                    if ((title = aud_read_ini_string(inifile, "playlist", title_key)))
+                        aud_playlist_load_ins_file(playlist, uri, filename, pos, title, -1);
+                    else
+                        aud_playlist_load_ins_file(playlist, uri, filename, pos, NULL, -1);
+                }
                 else
                     aud_playlist_load_ins_file(playlist, uri, filename, pos, NULL, -1);
-            }
-            else
-                aud_playlist_load_ins_file(playlist, uri, filename, pos, NULL, -1);
+
+                added_count++;
 
-            added_count++;
-
-            if (pos >= 0)
-                pos++;
-
+                if (pos >= 0)
+                    pos++;
+            }
             g_free(uri);
         }
     }
@@ -99,10 +99,14 @@
 static void
 playlist_save_pls(const gchar *filename, gint pos)
 {
+    gchar *uri = g_filename_to_uri(filename, NULL, NULL);
     GList *node;
-    VFSFile *file = aud_vfs_fopen(filename, "wb");
+    VFSFile *file = aud_vfs_fopen(uri, "wb");
     Playlist *playlist = aud_playlist_get_active();
 
+    AUDDBG("filename=%s\n", filename);
+    AUDDBG("uri=%s\n", uri);
+
     g_return_if_fail(file != NULL);
     g_return_if_fail(playlist != NULL);