[vlc-devel] [PATCH 06/12] move ignore-filetypes option from directory access to directory demux

Thomas Guillem thomas at gllm.fr
Tue May 19 10:27:46 CEST 2015


---
 modules/access/directory.c         | 46 --------------------------------------
 modules/access/fs.c                |  9 --------
 modules/demux/playlist/directory.c | 44 +++++++++++++++++++++++++++++++++++-
 modules/demux/playlist/playlist.c  |  9 ++++++++
 4 files changed, 52 insertions(+), 56 deletions(-)

diff --git a/modules/access/directory.c b/modules/access/directory.c
index 4728fa4..2b4f6a9 100644
--- a/modules/access/directory.c
+++ b/modules/access/directory.c
@@ -80,7 +80,6 @@ struct directory
 struct access_sys_t
 {
     directory *current;
-    char      *ignored_exts;
     char       mode;
 };
 
@@ -90,45 +89,6 @@ static int visible (const char *name)
     return name[0] != '.';
 }
 
-/**
- * Does the provided URI/path/stuff has one of the extension provided ?
- *
- * \param psz_exts A comma separated list of extension without dot, or only
- * one ext (ex: "avi,mkv,webm")
- * \param psz_uri The uri/path to check (ex: "file:///home/foo/bar.avi"). If
- * providing an URI, it must not contain a query string.
- *
- * \return true if the uri/path has one of the provided extension
- * false otherwise.
- */
-static bool has_ext (const char *psz_exts, const char *psz_uri)
-{
-    if (psz_exts == NULL)
-        return false;
-
-    const char *ext = strrchr (psz_uri, '.');
-    if (ext == NULL)
-        return false;
-
-    size_t extlen = strlen (++ext);
-
-    for (const char *type = psz_exts, *end; type[0]; type = end + 1)
-    {
-        end = strchr (type, ',');
-        if (end == NULL)
-            end = type + strlen (type);
-
-        if (type + extlen == end && !strncasecmp (ext, type, extlen))
-            return true;
-
-        if (*end == '\0')
-            break;
-    }
-
-    return false;
-}
-
-
 #ifdef HAVE_OPENAT
 /* Detect directories that recurse into themselves. */
 static bool has_inode_loop (const directory *dir, dev_t dev, ino_t inode)
@@ -298,7 +258,6 @@ int DirInit (access_t *p_access, DIR *handle)
     free (uri);
 
     p_access->p_sys = p_sys;
-    p_sys->ignored_exts = var_InheritString (p_access, "ignore-filetypes");
 
     p_access->pf_readdir = DirRead;
 
@@ -320,7 +279,6 @@ void DirClose( vlc_object_t * p_this )
     while (directory_pop (p_sys))
         ;
 
-    free (p_sys->ignored_exts);
     free (p_sys);
 }
 
@@ -345,10 +303,6 @@ input_item_t* DirRead (access_t *p_access)
         /* Check if it is a directory or even readable */
         i_res = directory_open (p_current, psz_entry, &handle);
 
-        if (i_res == ENTRY_EACCESS
-            || (i_res == ENTRY_ENOTDIR && has_ext (p_sys->ignored_exts, psz_entry)))
-            continue;
-
         /* Create an input item for the current entry */
         psz_uri = encode_URI_component (psz_entry);
         if (psz_uri == NULL
diff --git a/modules/access/fs.c b/modules/access/fs.c
index ec19c21..0c9b547 100644
--- a/modules/access/fs.c
+++ b/modules/access/fs.c
@@ -30,13 +30,6 @@
 #include "fs.h"
 #include <vlc_plugin.h>
 
-#define IGNORE_TEXT N_("Ignored extensions")
-#define IGNORE_LONGTEXT N_( \
-        "Files with these extensions will not be added to playlist when " \
-        "opening a directory.\n" \
-        "This is useful if you add directories that contain playlist files " \
-        "for instance. Use a comma-separated list of extensions." )
-
 vlc_module_begin ()
     set_description( N_("File input") )
     set_shortname( N_("File") )
@@ -50,8 +43,6 @@ vlc_module_begin ()
     add_submodule()
     set_section( N_("Directory" ), NULL )
     set_capability( "access", 55 )
-    add_string( "ignore-filetypes", "m3u,db,nfo,ini,jpg,jpeg,ljpg,gif,png,pgm,pgmyuv,pbm,pam,tga,bmp,pnm,xpm,xcf,pcx,tif,tiff,lbm,sfv,txt,sub,idx,srt,cue,ssa",
-                IGNORE_TEXT, IGNORE_LONGTEXT, false )
 #ifndef HAVE_FDOPENDIR
     add_shortcut( "file", "directory", "dir" )
 #else
diff --git a/modules/demux/playlist/directory.c b/modules/demux/playlist/directory.c
index c56e29e..869f555 100644
--- a/modules/demux/playlist/directory.c
+++ b/modules/demux/playlist/directory.c
@@ -68,6 +68,44 @@ void Close_Dir ( vlc_object_t *p_this )
     free( p_demux->p_sys );
 }
 
+/**
+ * Does the provided URI/path/stuff has one of the extension provided ?
+ *
+ * \param psz_exts A comma separated list of extension without dot, or only
+ * one ext (ex: "avi,mkv,webm")
+ * \param psz_uri The uri/path to check (ex: "file:///home/foo/bar.avi"). If
+ * providing an URI, it must not contain a query string.
+ *
+ * \return true if the uri/path has one of the provided extension
+ * false otherwise.
+ */
+static bool has_ext( const char *psz_exts, const char *psz_uri )
+{
+    if( psz_exts == NULL )
+        return false;
+
+    const char *ext = strrchr( psz_uri, '.' );
+    if( ext == NULL )
+        return false;
+
+    size_t extlen = strlen( ++ext );
+
+    for( const char *type = psz_exts, *end; type[0]; type = end + 1 )
+    {
+        end = strchr( type, ',' );
+        if( end == NULL )
+            end = type + strlen( type );
+
+        if( type + extlen == end && !strncasecmp( ext, type, extlen ) )
+            return true;
+
+        if( *end == '\0' )
+            break;
+    }
+
+    return false;
+}
+
 static int compar_type( input_item_t *p1, input_item_t *p2 )
 {
     if( p1->i_type != p2->i_type )
@@ -111,11 +149,13 @@ static int Demux( demux_t *p_demux )
     input_item_node_t *p_node;
     input_item_t *p_item;
     input_item_compar_cb compar_cb = NULL;
+    char *psz_ignored_exts;
 
     p_input = GetCurrentItem( p_demux );
     p_node = input_item_node_Create( p_input );
     input_item_Release(p_input);
 
+    psz_ignored_exts = var_InheritString( p_demux, "ignore-filetypes" );
     if( !p_demux->p_sys->b_dir_sorted )
     {
         char *psz_sort = var_InheritString( p_demux, "directory-sort" );
@@ -137,7 +177,8 @@ static int Demux( demux_t *p_demux )
         /* skip "." and ".." items */
         if( ( i_name_len == 1 && p_item->psz_name[0] == '.' ) ||
             ( i_name_len == 2 && p_item->psz_name[0] == '.' &&
-              p_item->psz_name[1] == '.' ) )
+              p_item->psz_name[1] == '.' ) ||
+            has_ext( psz_ignored_exts, p_item->psz_name ))
             goto skip_item;
 
         input_item_CopyOptions( p_node->p_item, p_item );
@@ -146,6 +187,7 @@ static int Demux( demux_t *p_demux )
 skip_item:
         input_item_Release( p_item );
     }
+    free( psz_ignored_exts );
 
     if( i_ret )
     {
diff --git a/modules/demux/playlist/playlist.c b/modules/demux/playlist/playlist.c
index 04eb90d..4d2ae03 100644
--- a/modules/demux/playlist/playlist.c
+++ b/modules/demux/playlist/playlist.c
@@ -61,6 +61,13 @@ static const char *const psz_sort_list_text[] = {
 #define SORT_LONGTEXT N_( \
     "Define the sort algorithm used when adding items from a directory." )
 
+#define IGNORE_TEXT N_("Ignored extensions")
+#define IGNORE_LONGTEXT N_( \
+        "Files with these extensions will not be added to playlist when " \
+        "opening a directory.\n" \
+        "This is useful if you add directories that contain playlist files " \
+        "for instance. Use a comma-separated list of extensions." )
+
 vlc_module_begin ()
     add_shortcut( "playlist" )
     set_category( CAT_INPUT )
@@ -155,6 +162,8 @@ vlc_module_begin ()
         add_shortcut( "playlist", "directory" )
         set_capability( "demux", 10 )
         set_callbacks( Import_Dir, Close_Dir )
+        add_string( "ignore-filetypes", "m3u,db,nfo,ini,jpg,jpeg,ljpg,gif,png,pgm,pgmyuv,pbm,pam,tga,bmp,pnm,xpm,xcf,pcx,tif,tiff,lbm,sfv,txt,sub,idx,srt,cue,ssa",
+                    IGNORE_TEXT, IGNORE_LONGTEXT, false )
         add_string( "directory-sort", "collate", SORT_TEXT, SORT_LONGTEXT, false )
           change_string_list( psz_sort_list, psz_sort_list_text )
 vlc_module_end ()
-- 
2.1.4




More information about the vlc-devel mailing list