[rygel] media-export: Re-add simple harvesting mode



commit 2dc5585d95155d0508cb15b222ebcd5ef4f3a44d
Author: Jens Georg <mail jensge org>
Date:   Wed Jul 21 22:30:09 2010 +0300

    media-export: Re-add simple harvesting mode
    
    The simple mode got lost somehow in the transition to
    gupnp-dlna-discoverer. This is configurable with the config entry
    extract-metadata and defaults to "true".

 data/rygel-default.conf                            |    1 +
 data/rygel-maemo.conf                              |    1 +
 .../media-export/rygel-media-export-harvester.vala |   22 +++++--
 .../media-export/rygel-media-export-item.vala      |   23 +++++++
 .../rygel-media-export-metadata-extractor.vala     |   61 +++++++++++++++----
 5 files changed, 89 insertions(+), 19 deletions(-)
---
diff --git a/data/rygel-default.conf b/data/rygel-default.conf
index 774179c..baadd1b 100644
--- a/data/rygel-default.conf
+++ b/data/rygel-default.conf
@@ -79,6 +79,7 @@ uris=
 #
 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
+extract-metadata=true
 
 [GstRenderer]
 enabled=true
diff --git a/data/rygel-maemo.conf b/data/rygel-maemo.conf
index 2a69cbc..0fe10cc 100644
--- a/data/rygel-maemo.conf
+++ b/data/rygel-maemo.conf
@@ -79,6 +79,7 @@ uris=
 #
 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
+extract-metadata=true
 
 [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 c079e81..4d0376d 100644
--- a/src/plugins/media-export/rygel-media-export-harvester.vala
+++ b/src/plugins/media-export/rygel-media-export-harvester.vala
@@ -284,11 +284,11 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
         }
     }
 
-    private void on_extracted_cb (File                  file,
-                                  GUPnP.DLNAInformation dlna,
-                                  string                mime,
-                                  uint64                size,
-                                  uint64                mtime) {
+    private void on_extracted_cb (File                   file,
+                                  GUPnP.DLNAInformation? dlna,
+                                  string                 mime,
+                                  uint64                 size,
+                                  uint64                 mtime) {
         if (this.cancellable.is_cancelled ()) {
             harvested (this.origin);
         }
@@ -300,12 +300,22 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
            return;
         }
         if (file == entry) {
-            var item = Item.create_from_info (this.containers.peek_head (),
+            MediaItem item;
+            if (dlna == null) {
+                item = new Item.simple (this.containers.peek_head (),
+                                        file,
+                                        mime,
+                                        size,
+                                        mtime);
+            } else {
+                item = Item.create_from_info (this.containers.peek_head (),
                                               file,
                                               dlna,
                                               mime,
                                               size,
                                               mtime);
+            }
+
             if (item != null) {
                 item.parent_ref = this.containers.peek_head ();
                 try {
diff --git a/src/plugins/media-export/rygel-media-export-item.vala b/src/plugins/media-export/rygel-media-export-item.vala
index 4cf4710..ede7b53 100644
--- a/src/plugins/media-export/rygel-media-export-item.vala
+++ b/src/plugins/media-export/rygel-media-export-item.vala
@@ -28,6 +28,29 @@ using Gst;
  * Represents MediaExport item.
  */
 public class Rygel.MediaExport.Item : Rygel.MediaItem {
+    public Item.simple (MediaContainer parent,
+                        File           file,
+                        string         mime,
+                        uint64         size,
+                        uint64         mtime) {
+        string id = Checksum.compute_for_string (ChecksumType.MD5,
+                                                 file.get_uri ());
+        var title = file.get_basename ();
+        string upnp_class;
+
+        if (mime.has_prefix ("video/")) {
+            upnp_class = MediaItem.VIDEO_CLASS;
+        } else if (mime.has_prefix ("image/")) {
+            upnp_class = MediaItem.PHOTO_CLASS;
+        } else {
+            upnp_class = MediaItem.AUDIO_CLASS;
+        }
+
+        base (id, parent, title, upnp_class);
+        this.mime_type = mime;
+        this.add_uri (file.get_uri (), null);
+    }
+
     public static Item? create_from_info (MediaContainer        parent,
                                           File                  file,
                                           GUPnP.DLNAInformation dlna_info,
diff --git a/src/plugins/media-export/rygel-media-export-metadata-extractor.vala b/src/plugins/media-export/rygel-media-export-metadata-extractor.vala
index 02ae121..720673c 100644
--- a/src/plugins/media-export/rygel-media-export-metadata-extractor.vala
+++ b/src/plugins/media-export/rygel-media-export-metadata-extractor.vala
@@ -34,11 +34,11 @@ using GUPnP;
  */
 public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
     /* Signals */
-    public signal void extraction_done (File                  file,
-                                        GUPnP.DLNAInformation info,
-                                        string                mime,
-                                        uint64                size,
-                                        uint64                mtime);
+    public signal void extraction_done (File                   file,
+                                        GUPnP.DLNAInformation? info,
+                                        string                 mime,
+                                        uint64                 size,
+                                        uint64                 mtime);
 
     /**
      * Signalize that an error occured during metadata extraction
@@ -54,6 +54,8 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
     private HashMap<string, File> file_hash;
     private uint64 timeout = 10; /* seconds */
 
+    private bool extract_metadata;
+
     public static MetadataExtractor? create () {
         return new MetadataExtractor ();
     }
@@ -61,14 +63,26 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
     public MetadataExtractor () {
         this.file_hash = new HashMap<string, File> ();
 
-        this.discoverer = new GUPnP.DLNADiscoverer ((ClockTime)
-                                              (this.timeout * 1000000000ULL));
-        this.discoverer.done.connect (on_done);
-        this.discoverer.start ();
+        var config = MetaConfig.get_default ();
+        try {
+            this.extract_metadata = config.get_bool ("MediaExport",
+                                                     "extract-metadata");
+        } catch (Error error) {
+            this.extract_metadata = true;
+        }
+
+        if (this.extract_metadata) {
+            var gst_timeout = (ClockTime) (this.timeout * Gst.SECOND);
+            this.discoverer = new GUPnP.DLNADiscoverer (gst_timeout);
+            this.discoverer.done.connect (on_done);
+            this.discoverer.start ();
+        }
     }
 
     ~MetadataExtractor () {
-        this.discoverer.stop ();
+        if (this.extract_metadata) {
+            this.discoverer.stop ();
+        }
     }
 
     private void on_done (GUPnP.DLNAInformation dlna,
@@ -103,9 +117,30 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
     }
 
     public void extract (File file) {
-        string uri = file.get_uri ();
-        this.file_hash.set (uri, file);
-        this.discoverer.discover_uri (uri);
+        if (this.extract_metadata) {
+            string uri = file.get_uri ();
+            this.file_hash.set (uri, file);
+            this.discoverer.discover_uri (uri);
+        } else {
+            try {
+                string mime;
+                uint64 size;
+                uint64 mtime;
+
+                extract_file_info (file,
+                                   out mime,
+                                   out size,
+                                   out mtime);
+
+                this.extraction_done (file,
+                                      null,
+                                      mime,
+                                      size,
+                                      mtime);
+            } catch (Error error) {
+                this.error (file, error);
+            }
+        }
     }
 
     private void extract_file_info (File       file,



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