From 608f3f902ca6539de1b6db47412d9184135cee60 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Thu, 2 Apr 2009 02:40:35 +0000 Subject: [PATCH] * 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. --- inotify.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- scanner.c | 3 ++- scanner.h | 9 +++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/inotify.c b/inotify.c index 0cbbe2d..0d22a2f 100644 --- a/inotify.c +++ b/inotify.c @@ -264,7 +264,44 @@ 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 */ sql = sqlite3_mprintf("SELECT ID from DETAILS where PATH = '%q'", path); @@ -562,9 +599,14 @@ start_inotify() i = 0; while( i < length ) { - struct inotify_event * event = ( struct inotify_event * ) &buffer[ i ]; - if ( event->len ) + 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), "&", "&amp;", 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; } diff --git a/scanner.c b/scanner.c index 8eb4d44..e41316e 100644 --- a/scanner.c +++ b/scanner.c @@ -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 diff --git a/scanner.h b/scanner.h index 82f44a6..d835dd5 100644 --- a/scanner.h +++ b/scanner.h @@ -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);