* Add file filters to inotify scanner. Now, for example, an audio-only directory should not have image or video files put in the database by the inotify auto-scanner.
This commit is contained in:
parent
ea70f079f2
commit
608f3f902c
48
inotify.c
48
inotify.c
@ -264,6 +264,43 @@ inotify_insert_file(char * name, const char * path)
|
|||||||
char * parent_buf = NULL;
|
char * parent_buf = NULL;
|
||||||
char * id = NULL;
|
char * id = NULL;
|
||||||
int depth = 1;
|
int depth = 1;
|
||||||
|
enum media_types type = ALL_MEDIA;
|
||||||
|
struct media_dir_s * media_path = media_dirs;
|
||||||
|
|
||||||
|
/* Check if we're supposed to be scanning for this file type in this directory */
|
||||||
|
while( media_path )
|
||||||
|
{
|
||||||
|
if( strncmp(path, media_path->path, strlen(media_path->path)) == 0 )
|
||||||
|
{
|
||||||
|
type = media_path->type;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
media_path = media_path->next;
|
||||||
|
}
|
||||||
|
switch( type )
|
||||||
|
{
|
||||||
|
case ALL_MEDIA:
|
||||||
|
if( !is_image(path) &&
|
||||||
|
!is_audio(path) &&
|
||||||
|
!is_video(path) )
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
case AUDIO_ONLY:
|
||||||
|
if( !is_audio(path) )
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
case VIDEO_ONLY:
|
||||||
|
if( !is_video(path) )
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
case IMAGES_ONLY:
|
||||||
|
if( !is_image(path) )
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* If it's already in the database, just skip it for now.
|
/* If it's already in the database, just skip it for now.
|
||||||
* TODO: compare modify timestamps */
|
* TODO: compare modify timestamps */
|
||||||
@ -562,9 +599,14 @@ start_inotify()
|
|||||||
i = 0;
|
i = 0;
|
||||||
while( i < length )
|
while( i < length )
|
||||||
{
|
{
|
||||||
struct inotify_event * event = ( struct inotify_event * ) &buffer[ i ];
|
struct inotify_event * event = (struct inotify_event *) &buffer[i];
|
||||||
if ( event->len )
|
if( event->len )
|
||||||
{
|
{
|
||||||
|
if( *(event->name) == '.' )
|
||||||
|
{
|
||||||
|
i += EVENT_SIZE + event->len;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
esc_name = modifyString(strdup(event->name), "&", "&amp;", 0);
|
esc_name = modifyString(strdup(event->name), "&", "&amp;", 0);
|
||||||
asprintf(&path_buf, "%s/%s", get_path_from_wd(event->wd), event->name);
|
asprintf(&path_buf, "%s/%s", get_path_from_wd(event->wd), event->name);
|
||||||
if ( (event->mask & IN_CREATE && event->mask & IN_ISDIR) ||
|
if ( (event->mask & IN_CREATE && event->mask & IN_ISDIR) ||
|
||||||
@ -600,5 +642,5 @@ start_inotify()
|
|||||||
inotify_remove_watches(fd);
|
inotify_remove_watches(fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
exit( 0 );
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -46,12 +46,13 @@ int
|
|||||||
is_video(const char * file)
|
is_video(const char * file)
|
||||||
{
|
{
|
||||||
return (ends_with(file, ".mpg") || ends_with(file, ".mpeg") ||
|
return (ends_with(file, ".mpg") || ends_with(file, ".mpeg") ||
|
||||||
|
ends_with(file, ".avi") || ends_with(file, ".divx") ||
|
||||||
ends_with(file, ".asf") || ends_with(file, ".wmv") ||
|
ends_with(file, ".asf") || ends_with(file, ".wmv") ||
|
||||||
ends_with(file, ".mp4") || ends_with(file, ".m4v") ||
|
ends_with(file, ".mp4") || ends_with(file, ".m4v") ||
|
||||||
ends_with(file, ".mts") || ends_with(file, ".m2ts") ||
|
ends_with(file, ".mts") || ends_with(file, ".m2ts") ||
|
||||||
ends_with(file, ".m2t") || ends_with(file, ".mkv") ||
|
ends_with(file, ".m2t") || ends_with(file, ".mkv") ||
|
||||||
ends_with(file, ".vob") || ends_with(file, ".ts") ||
|
ends_with(file, ".vob") || ends_with(file, ".ts") ||
|
||||||
ends_with(file, ".avi") || ends_with(file, ".xvid"));
|
ends_with(file, ".flv") || ends_with(file, ".xvid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -15,6 +15,15 @@
|
|||||||
#define VIDEO_DIR_ID "2$15"
|
#define VIDEO_DIR_ID "2$15"
|
||||||
#define IMAGE_DIR_ID "3$16"
|
#define IMAGE_DIR_ID "3$16"
|
||||||
|
|
||||||
|
int
|
||||||
|
is_video(const char * file);
|
||||||
|
|
||||||
|
int
|
||||||
|
is_audio(const char * file);
|
||||||
|
|
||||||
|
int
|
||||||
|
is_image(const char * file);
|
||||||
|
|
||||||
sqlite_int64
|
sqlite_int64
|
||||||
get_next_available_id(const char * table, const char * parentID);
|
get_next_available_id(const char * table, const char * parentID);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user