Commit b62156ba authored by Thomas Guillem's avatar Thomas Guillem

move ignore-filetypes option from directory access to directory demux

parent 50922179
......@@ -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
......
......@@ -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
......
......@@ -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 )
......@@ -110,11 +148,14 @@ static int Demux( demux_t *p_demux )
input_item_t *p_input;
input_item_node_t *p_node;
input_item_t *p_item;
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" );
while( !i_ret && ( p_item = stream_ReadDir( p_demux->s ) ) )
{
int i_name_len = p_item->psz_name ? strlen( p_item->psz_name ) : 0;
......@@ -122,7 +163,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 );
......@@ -131,6 +173,7 @@ static int Demux( demux_t *p_demux )
skip_item:
input_item_Release( p_item );
}
free( psz_ignored_exts );
if( i_ret )
{
......
......@@ -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 ()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment