[rygel/wip/dvd: 93/103] media-export: Query DVD structure information



commit 7e0f59b3912b0e1d17732b537f7632e672c13488
Author: Jens Georg <jensg openismus com>
Date:   Sun Jul 14 14:55:12 2013 +0200

    media-export: Query DVD structure information
    
    Use lsdvd binary and its XML output for this to avoid effective GPL
    relicensing by using libdvdread explicitly.
    
    The output is cached so we only have to do this once ideally.

 configure.ac                                       |    1 +
 src/plugins/media-export/Makefile.am               |    1 +
 .../rygel-media-export-dvd-parser.vala             |  126 ++++++++++++++++++++
 .../media-export/rygel-media-export-harvester.vala |    2 +-
 4 files changed, 129 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c71a701..a8dc902 100644
--- a/configure.ac
+++ b/configure.ac
@@ -261,6 +261,7 @@ AS_IF([test "x$with_media_engine" = "xgstreamer"],
                                libsoup-2.4 >= $LIBSOUP_REQUIRED
                                sqlite3 >= $LIBSQLITE3_REQUIRED
                                libmediaart-2.0 >= $MEDIAART_REQUIRED])
+                               libxml-2.0 >= $LIBXML_REQUIRED
             RYGEL_PLUGIN_MEDIA_EXPORT_DEPS_VALAFLAGS="$RYGEL_COMMON_MODULES_VALAFLAGS --pkg gupnp-dlna-2.0 
--pkg gupnp-dlna-gst-2.0 --pkg gstreamer-tag-1.0 --pkg gstreamer-app-1.0 --pkg gstreamer-pbutils-1.0 --pkg 
sqlite3 --pkg libmediaart-2.0"
             AC_SUBST([RYGEL_PLUGIN_MEDIA_EXPORT_DEPS_VALAFLAGS])
           ])
diff --git a/src/plugins/media-export/Makefile.am b/src/plugins/media-export/Makefile.am
index 978cb9c..adf651b 100644
--- a/src/plugins/media-export/Makefile.am
+++ b/src/plugins/media-export/Makefile.am
@@ -33,6 +33,7 @@ plugin_DATA = media-export.plugin
 
 librygel_media_export_la_SOURCES = \
        rygel-media-export-plugin.vala \
+       rygel-media-export-dvd-parser.vala \
        rygel-media-export-db-container.vala \
        rygel-media-export-sql-factory.vala \
        rygel-media-export-media-cache.vala \
diff --git a/src/plugins/media-export/rygel-media-export-dvd-parser.vala 
b/src/plugins/media-export/rygel-media-export-dvd-parser.vala
new file mode 100644
index 0000000..b4a4fef
--- /dev/null
+++ b/src/plugins/media-export/rygel-media-export-dvd-parser.vala
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2013 Jens Georg <mail jensge org>.
+ *
+ * Author: Jens Georg <mail jensge org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+internal class Rygel.MediaExport.DVDParser : GLib.Object {
+    /// URI to the image / toplevel directory
+    public File file { private get; construct; }
+
+    private File cache_file;
+
+    public DVDParser (File file) {
+        Object (file : file);
+    }
+
+    public override void constructed () {
+        unowned string user_cache = Environment.get_user_cache_dir ();
+        var cache_folder = Path.build_filename (user_cache,
+                                                "rygel",
+                                                "dvd-content");
+        DirUtils.create_with_parents (cache_folder, 0700);
+        var cache_path = Path.build_filename (cache_folder,
+                                              MediaCache.get_id (this.file));
+
+        this.cache_file = File.new_for_path (cache_path);
+    }
+
+    public async void run () {
+        var doc = yield this.get_information ();
+        if (doc != null) {
+            doc->children;
+        }
+    }
+
+    public async Xml.Doc* get_information () {
+        if (this.cache_file.query_exists ()) {
+            return Xml.Parser.read_file (this.cache_file.get_path (),
+                                         null,
+                                         Xml.ParserOption.NOERROR |
+                                         Xml.ParserOption.NOWARNING);
+        }
+
+        Pid pid;
+        int stdout_fd;
+
+        try {
+            Process.spawn_async_with_pipes (null,
+                                            { "/usr/bin/lsdvd",
+                                              "-Ox",
+                                              "-x",
+                                              "-q",
+                                              this.file.get_path (),
+                                              null },
+                                            null,
+                                            SpawnFlags.DO_NOT_REAP_CHILD |
+                                            SpawnFlags.STDERR_TO_DEV_NULL,
+                                            null,
+                                            out pid,
+                                            null,
+                                            out stdout_fd);
+            var data = new StringBuilder ();
+            var io_channel = new IOChannel.unix_new (stdout_fd);
+            var io_watch = io_channel.add_watch (IOCondition.IN |
+                                                 IOCondition.PRI,
+                                                 () => {
+                string line;
+
+                try {
+                    io_channel.read_to_end (out line, null);
+                    data.append (line);
+                } catch (Error error) { }
+
+                return true;
+            });
+
+            uint child_watch = 0;
+            child_watch = ChildWatch.add (pid, () => {
+                Source.remove (child_watch);
+                Source.remove (io_watch);
+                Process.close_pid (pid);
+
+                get_information.callback ();
+            });
+
+            yield;
+
+            try {
+                this.cache_file.replace_contents (data.str.data,
+                                                  null,
+                                                  false,
+                                                  FileCreateFlags.NONE,
+                                                  null);
+            } catch (Error rc_error) {
+                debug ("Failed to cache lsdvd output: %s", rc_error.message);
+            }
+
+            return Xml.Parser.read_memory (data.str,
+                                           (int) data.len,
+                                           null,
+                                           null,
+                                           Xml.ParserOption.NOERROR |
+                                           Xml.ParserOption.NOWARNING);
+        } catch (SpawnError error) {
+            debug ("Failed to run lsdvd: %s", error.message);
+        }
+
+        return null;
+    }
+}
diff --git a/src/plugins/media-export/rygel-media-export-harvester.vala 
b/src/plugins/media-export/rygel-media-export-harvester.vala
index e0b0ee7..34a0667 100644
--- a/src/plugins/media-export/rygel-media-export-harvester.vala
+++ b/src/plugins/media-export/rygel-media-export-harvester.vala
@@ -75,7 +75,7 @@ internal class Rygel.MediaExport.Harvester : GLib.Object {
             info.get_content_type () == "application/xml" ||
             info.get_content_type () == "text/xml" ||
             info.get_content_type () == "text/plain";
-
+            info.get_content_type () == "application/x-cd-image";
         var cache = MediaCache.get_default ();
         var is_blacklisted = cache.is_blacklisted (file);
 


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