[rygel] media-export: Create factory method for extractors



commit 5b9dfeb2ffb7d417a57a1c6a6e10417184026b79
Author: Jens Georg <mail jensge org>
Date:   Fri May 13 16:15:27 2016 +0200

    media-export: Create factory method for extractors
    
    Signed-off-by: Jens Georg <mail jensge org>

 .../media-export/rygel-media-export-extract.vala   |   17 ++----------
 .../media-export/rygel-media-export-extractor.vala |   26 +++++++++++++++++++-
 2 files changed, 28 insertions(+), 15 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-extract.vala 
b/src/plugins/media-export/rygel-media-export-extract.vala
index 28ee4ea..dad622f 100644
--- a/src/plugins/media-export/rygel-media-export-extract.vala
+++ b/src/plugins/media-export/rygel-media-export-extract.vala
@@ -79,22 +79,11 @@ async void run () {
 
                 try {
                     var file = File.new_for_uri (parts[0]);
-                    Extractor extractor;
                     // Copy current URI to statically allocated memory area to
                     // dump to fd in the signal handler
-                    if (metadata) {
-                        var is_text = parts[1].has_prefix ("text/") ||
-                                      parts[1].has_suffix ("xml");
-                        if (parts[1] == "application/x-cd-image") {
-                            extractor = new DVDParser (file);
-                        } else if (!is_text) {
-                            extractor = new GenericExtractor (file);
-                        } else {
-                            extractor = new PlaylistExtractor (file);
-                        }
-                    } else {
-                        extractor = new Extractor (file);
-                    }
+                    var extractor = Extractor.create_for_file (file,
+                                                               parts[1],
+                                                               metadata);
                     yield extractor.run ();
 
                     send_extraction_done (file, extractor.get ());
diff --git a/src/plugins/media-export/rygel-media-export-extractor.vala 
b/src/plugins/media-export/rygel-media-export-extractor.vala
index e669cc0..3f1fc83 100644
--- a/src/plugins/media-export/rygel-media-export-extractor.vala
+++ b/src/plugins/media-export/rygel-media-export-extractor.vala
@@ -51,7 +51,31 @@ public class Rygel.MediaExport.Extractor : Object {
 
     protected VariantDict serialized_info;
 
-    public Extractor (File file) {
+    /**
+     * Factory method for creating specific extractors depending on the
+     * content type of the file
+     */
+    public static Extractor create_for_file (File   file,
+                                             string content_type,
+                                             bool   extract_metadata) {
+        if (!extract_metadata) {
+            return new Extractor (file);
+        }
+
+        var is_text = content_type.has_prefix ("text/") ||
+                      content_type.has_suffix ("xml");
+        if (content_type == "application/x-cd-image") {
+            return new DVDParser (file);
+        }
+
+        if (is_text) {
+            return new PlaylistExtractor (file);
+        }
+
+        return new GenericExtractor (file);
+    }
+
+    private Extractor (File file) {
         Object (file: file);
     }
 


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