* 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:
Justin Maggard 2009-04-02 02:40:35 +00:00
parent ea70f079f2
commit 608f3f902c
3 changed files with 56 additions and 4 deletions

View File

@ -264,6 +264,43 @@ inotify_insert_file(char * name, const char * path)
char * parent_buf = NULL;
char * id = NULL;
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.
* TODO: compare modify timestamps */
@ -565,6 +602,11 @@ start_inotify()
struct inotify_event * event = (struct inotify_event *) &buffer[i];
if( event->len )
{
if( *(event->name) == '.' )
{
i += EVENT_SIZE + event->len;
continue;
}
esc_name = modifyString(strdup(event->name), "&", "&", 0);
asprintf(&path_buf, "%s/%s", get_path_from_wd(event->wd), event->name);
if ( (event->mask & IN_CREATE && event->mask & IN_ISDIR) ||
@ -600,5 +642,5 @@ start_inotify()
inotify_remove_watches(fd);
close(fd);
exit( 0 );
return NULL;
}

View File

@ -46,12 +46,13 @@ int
is_video(const char * file)
{
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, ".mp4") || ends_with(file, ".m4v") ||
ends_with(file, ".mts") || ends_with(file, ".m2ts") ||
ends_with(file, ".m2t") || ends_with(file, ".mkv") ||
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

View File

@ -15,6 +15,15 @@
#define VIDEO_DIR_ID "2$15"
#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
get_next_available_id(const char * table, const char * parentID);