[rygel] media-export: Use a filter for files to harvest



commit 5cc4d69a7b0c1d9a3b0076640792f83993765334
Author: Jens Georg <mail jensge org>
Date:   Sat Jun 26 11:59:21 2010 +0200

    media-export: Use a filter for files to harvest
    
    The media-export plugin now uses a positive list for file extensions to
    include in the metadata extraction.
    
    The configuration key is named "include-filter". The default
    configuration is
    
    .mp3;.oga;.ogv;.ogg;.mkv;.avi;.mp4;.mpeg;.mpg;.ts;.flac;.jpeg;.jpg;.wav

 data/rygel-default.conf                            |    1 +
 data/rygel-maemo.conf                              |    1 +
 .../media-export/rygel-media-export-harvester.vala |   27 ++++++++++++++++++++
 3 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/data/rygel-default.conf b/data/rygel-default.conf
index 6b5f874..774179c 100644
--- a/data/rygel-default.conf
+++ b/data/rygel-default.conf
@@ -78,6 +78,7 @@ uris=
 # of a folder for each unique value of the metadata in question.
 #
 virtual-folders=Artists=upnp:artist,?,upnp:album,?;Albums=upnp:album,?,upnp:artist,?
+include-filter=.mp3;.oga;.ogv;.ogg;.mkv;.avi;.mp4;.mpeg;.mpg;.ts;.flac;.jpeg;.jpg;.wav
 
 [GstRenderer]
 enabled=true
diff --git a/data/rygel-maemo.conf b/data/rygel-maemo.conf
index b798274..2a69cbc 100644
--- a/data/rygel-maemo.conf
+++ b/data/rygel-maemo.conf
@@ -78,6 +78,7 @@ uris=
 # of a folder for each unique value of the metadata in question.
 #
 virtual-folders=Artists=upnp:artist,?,upnp:album,?;Albums=upnp:album,?,upnp:artist,?
+include-filter=.mp3;.oga;.ogv;.ogg;.mkv;.avi;.mp4;.mpeg;.mpg;.ts;.flac;.jpeg;.jpg;.wav
 
 [GstRenderer]
 enabled=true
diff --git a/src/plugins/media-export/rygel-media-export-harvester.vala b/src/plugins/media-export/rygel-media-export-harvester.vala
index 3721f20..4a2c2c0 100644
--- a/src/plugins/media-export/rygel-media-export-harvester.vala
+++ b/src/plugins/media-export/rygel-media-export-harvester.vala
@@ -29,6 +29,7 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
     private File origin;
     private MediaContainer parent;
     private RecursiveFileMonitor monitor;
+    private Regex file_filter;
     public Cancellable cancellable;
     private const string HARVESTER_ATTRIBUTES =
                                         FILE_ATTRIBUTE_STANDARD_NAME + "," +
@@ -51,6 +52,25 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
         this.origin = null;
         this.monitor = monitor;
         this.cancellable = new Cancellable ();
+        var config = MetaConfig.get_default ();
+
+        try {
+            var extensions = config.get_string_list ("MediaExport",
+                                                     "include-filter");
+
+            // never trust user input
+            string[] escaped_extensions = new string[0];
+            foreach (var extension in extensions) {
+                escaped_extensions += Regex.escape_string (extension);
+            }
+
+            var list = string.joinv ("|", escaped_extensions);
+            file_filter = new Regex ("(%s)$".printf (list),
+                                     RegexCompileFlags.CASELESS |
+                                     RegexCompileFlags.OPTIMIZE);
+        } catch (Error error) {
+            file_filter = null;
+        }
     }
 
     private bool push_if_changed_or_unknown (File       file,
@@ -120,6 +140,13 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
                 }
             } else {
                 string id;
+
+                // Let's see if the file is wanted
+                if (file_filter != null &&
+                    !file_filter.match (file.get_uri ())) {
+                    continue;
+                }
+
                 push_if_changed_or_unknown (file, info, out id);
                 parent_container.seen (id);
             }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]