[Tracker] [PATCH] Add iso extractor using libosinfo



---
 configure.ac                              |   35 ++++++++
 data/ontologies/33-nfo.ontology           |    9 ++-
 data/ontologies/93-libosinfo.description  |   13 +++
 data/ontologies/93-libosinfo.ontology     |   32 +++++++
 data/ontologies/Makefile.am               |    3 +-
 src/tracker-extract/11-iso.rule.in        |    4 +
 src/tracker-extract/Makefile.am           |   19 +++++
 src/tracker-extract/tracker-extract-iso.c |  127 +++++++++++++++++++++++++++++
 8 files changed, 240 insertions(+), 2 deletions(-)
 create mode 100644 data/ontologies/93-libosinfo.description
 create mode 100644 data/ontologies/93-libosinfo.ontology
 create mode 100644 src/tracker-extract/11-iso.rule.in
 create mode 100644 src/tracker-extract/tracker-extract-iso.c

diff --git a/configure.ac b/configure.ac
index de0b6f8..9b6f85d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -175,6 +175,7 @@ LIBVORBIS_REQUIRED=0.22
 LIBFLAC_REQUIRED=1.2.1
 LIBEXIF_REQUIRED=0.6
 LIBGSF_REQUIRED=1.13
+LIBOSINFO_REQUIRED=0.0.2
 EXEMPI_REQUIRED=2.1.0
 EVO_REQUIRED=2.32.0
 EVO_SHELL_REQUIRED=2.32.0
@@ -1811,6 +1812,39 @@ fi
 AM_CONDITIONAL(HAVE_LIBGSF, test "x$have_libgsf" = "xyes")
 
 ##################################################################
+# Check for tracker-extract: libosinfo
+##################################################################
+
+AC_ARG_ENABLE(libosinfo,
+              AS_HELP_STRING([--enable-libosinfo],
+                             [enable extractor for ISO data [[default=auto]]]),,
+              [enable_libosinfo=auto])
+
+if test "x$enable_libosinfo" != "xno" ; then
+   PKG_CHECK_MODULES(LIBOSINFO,
+                     [libosinfo-1.0 >= $LIBOSINFO_REQUIRED],
+                    [have_libosinfo=yes],
+                    [have_libosinfo=no])
+
+   AC_SUBST(LIBOSINFO_CFLAGS)
+   AC_SUBST(LIBOSINFO_LIBS)
+
+   if test "x$have_libosinfo" = "xyes"; then
+      AC_DEFINE(HAVE_LIBOSINFO, [], [Define if we have libosinfo])
+   fi
+else
+   have_libosinfo="no  (disabled)"
+fi
+
+if test "x$enable_libosinfo" = "xyes"; then
+   if test "x$have_libosinfo" != "xyes"; then
+      AC_MSG_ERROR([Couldn't find libosinfo >= $LIBOSINFO_REQUIRED.])
+   fi
+fi
+
+AM_CONDITIONAL(HAVE_LIBOSINFO, test "x$have_libosinfo" = "xyes")
+
+##################################################################
 # Check for tracker-extract: libgif
 ##################################################################
 
@@ -2329,6 +2363,7 @@ Metadata Extractors:
        Support media art processing:           $selected_for_media_art
        Support cue sheet parsing:              $have_libcue
        Support playlists (w/ Totem):           $have_playlist
+       Support ISO image parsing:              $have_libosinfo
 
 Data Miners:
 
diff --git a/data/ontologies/33-nfo.ontology b/data/ontologies/33-nfo.ontology
index 65e4fb9..1006def 100644
--- a/data/ontologies/33-nfo.ontology
+++ b/data/ontologies/33-nfo.ontology
@@ -12,7 +12,7 @@
 
 nfo: a tracker:Namespace, tracker:Ontology ;
        tracker:prefix "nfo" ;
-       nao:lastModified "2011-12-06T15:40:00Z" .
+       nao:lastModified "2011-12-15T18:51:25Z" .
 
 nfo:Document a rdfs:Class ;
        rdfs:label "Document" ;
@@ -926,6 +926,13 @@ nfo:isContentEncrypted a rdf:Property ;
        rdfs:domain nie:InformationElement ;
        rdfs:range xsd:boolean .
 
+# This change must be proposed upstream
+nfo:isBootable a rdf:Property ;
+       rdfs:label "Is content bootable" ;
+       rdfs:comment "Might change (IE of DataObject property?)" ;
+       nrl:maxCardinality 1 ;
+       rdfs:domain nie:InformationElement ;
+       rdfs:range xsd:boolean .
 
 # Ontology request by Alexander Bokovoy, replaces nfo:device
 # These classes and properties need to be submitted to NEPOMUK
diff --git a/data/ontologies/93-libosinfo.description b/data/ontologies/93-libosinfo.description
new file mode 100644
index 0000000..edb5035
--- /dev/null
+++ b/data/ontologies/93-libosinfo.description
@@ -0,0 +1,13 @@
+ prefix dsc: <http://www.tracker-project.org/temp/dsc#> .
+
+<virtual-ontology-uri:93-libosinfo.ontology> a dsc:Ontology ;
+       dsc:title "libosinfo-specific annotations Ontology" ;
+       dsc:description "Libosinf properties" ;
+
+       dsc:author "Red Hat, Inc" ;
+       dsc:editor "Red Hat, Inc" ;
+       dsc:gitlog "http://git.gnome.org/cgit/tracker/log/data/ontologies/93-libosinfo.ontology";;
+
+       dsc:localPrefix "osinfo" ;
+       dsc:baseUrl "http://www.tracker-project.org/ontologies/osinfo#";;
+       dsc:relativePath "./93-libosinfo.ontology" .
diff --git a/data/ontologies/93-libosinfo.ontology b/data/ontologies/93-libosinfo.ontology
new file mode 100644
index 0000000..be5c1c8
--- /dev/null
+++ b/data/ontologies/93-libosinfo.ontology
@@ -0,0 +1,32 @@
+ prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> .
+ prefix nie: <http://www.semanticdesktop.org/ontologies/2007/01/19/nie#> .
+ prefix nrl: <http://www.semanticdesktop.org/ontologies/2007/08/15/nrl#> .
+ prefix osinfo: <http://www.tracker-project.org/ontologies/osinfo#> .
+ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ prefix tracker: <http://www.tracker-project.org/ontologies/tracker#> .
+ prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+osinfo: a tracker:Namespace, tracker:Ontology ;
+       tracker:prefix "osinfo" ;
+       nao:lastModified "2011-12-16T08:00:00Z" .
+
+osinfo:isInstaller a rdf:Property ;
+       nrl:maxCardinality 1 ;
+       rdfs:domain nie:InformationElement ;
+       rdfs:range xsd:boolean .
+
+osinfo:isLiveCD a rdf:Property ;
+       nrl:maxCardinality 1 ;
+       rdfs:domain nie:InformationElement ;
+       rdfs:range xsd:boolean .
+
+osinfo:osName a rdf:Property ;
+       nrl:maxCardinality 1 ;
+       rdfs:domain nie:InformationElement ;
+       rdfs:range xsd:string .
+
+osinfo:id a rdf:Property ;
+       nrl:maxCardinality 1 ;
+       rdfs:domain nie:InformationElement ;
+       rdfs:range xsd:string .
diff --git a/data/ontologies/Makefile.am b/data/ontologies/Makefile.am
index b86440d..63ddbd2 100644
--- a/data/ontologies/Makefile.am
+++ b/data/ontologies/Makefile.am
@@ -24,7 +24,8 @@ config_DATA =                                          \
        41-mfo.ontology     41-mfo.description         \
        89-mtp.ontology     89-mtp.description         \
        92-slo.ontology     92-slo.description         \
-       90-tracker.ontology 90-tracker.description
+       90-tracker.ontology 90-tracker.description     \
+       93-libosinfo.ontology 93-libosinfo.description
 
 if HAVE_MAEMO
 config_DATA +=                                         \
diff --git a/src/tracker-extract/11-iso.rule.in b/src/tracker-extract/11-iso.rule.in
new file mode 100644
index 0000000..30d0ff6
--- /dev/null
+++ b/src/tracker-extract/11-iso.rule.in
@@ -0,0 +1,4 @@
+[ExtractorRule]
+ModulePath= modulesdir@/libextract-iso.so
+MimeTypes=application/x-cd-image
+
diff --git a/src/tracker-extract/Makefile.am b/src/tracker-extract/Makefile.am
index 105899d..39203e9 100644
--- a/src/tracker-extract/Makefile.am
+++ b/src/tracker-extract/Makefile.am
@@ -34,6 +34,7 @@ rules_in_files = \
        10-tiff.rule.in \
        10-vorbis.rule.in \
        10-xmp.rule.in \
+       11-iso.rule.in \
        11-msoffice-xml.rule.in \
        15-gstreamer-guess.rule.in \
        15-playlist.rule.in \
@@ -141,6 +142,11 @@ modules_LTLIBRARIES += libextract-playlist.la
 rules_DATA += 15-playlist.rule
 endif
 
+if HAVE_LIBOSINFO
+modules_LTLIBRARIES += libextract-iso.la
+rules_DATA += 11-iso.rule
+endif
+
 # ABW
 libextract_abw_la_SOURCES = tracker-extract-abw.c
 libextract_abw_la_CFLAGS = $(TRACKER_EXTRACT_MODULES_CFLAGS)
@@ -422,6 +428,19 @@ libextract_icon_la_LIBADD = \
        $(BUILD_LIBS) \
        $(TRACKER_EXTRACT_MODULES_LIBS)
 
+# ISO
+libextract_iso_la_SOURCES = tracker-extract-iso.c
+libextract_iso_la_CFLAGS = \
+       $(TRACKER_EXTRACT_MODULES_CFLAGS) \
+       $(LIBOSINFO_CFLAGS)
+
+libextract_iso_la_LDFLAGS = $(module_flags)
+libextract_iso_la_LIBADD = \
+       $(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
+       $(BUILD_LIBS) \
+       $(TRACKER_EXTRACT_MODULES_LIBS) \
+       $(LIBOSINFO_LIBS)
+
 #
 # Binaries
 #
diff --git a/src/tracker-extract/tracker-extract-iso.c b/src/tracker-extract/tracker-extract-iso.c
new file mode 100644
index 0000000..17f577e
--- /dev/null
+++ b/src/tracker-extract/tracker-extract-iso.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2011, Red Hat, Inc
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ *
+ * Author: Christophe Fergeau <cfergeau redhat com>
+ */
+
+#include <stdio.h>
+
+#include <osinfo/osinfo.h>
+
+#include <gio/gio.h>
+
+#include <libtracker-extract/tracker-extract.h>
+#include <libtracker-sparql/tracker-sparql.h>
+
+G_MODULE_EXPORT gboolean
+tracker_extract_get_metadata (TrackerExtractInfo *info_)
+{
+       /* NOTE: This function has to exist, tracker-extract checks
+        * the symbole table for this function and if it doesn't
+        * exist, the module is not loaded to be used as an extractor.
+        */
+
+       /* File information */
+       GFile *file;
+       GError *error = NULL;
+       gchar *filename;
+       OsinfoLoader *loader;
+       OsinfoMedia *media;
+       OsinfoMedia *matched_media;
+       OsinfoDb *db;
+       OsinfoOs *os;
+
+       /* Data input */
+       gboolean bootable;
+       gboolean has_installer;
+       gboolean is_live;
+       gchar *id;
+       gchar *name;
+       TrackerSparqlBuilder *metadata;
+
+       metadata = tracker_extract_info_get_metadata_builder (info_);
+
+       file = tracker_extract_info_get_file (info_);
+       filename = g_file_get_path (file);
+
+
+       media = osinfo_media_create_from_location (filename, NULL, &error);
+       if (error != NULL) {
+               if (error->code != OSINFO_MEDIA_ERROR_NOT_BOOTABLE) {
+                       g_message ("Could not extract iso info from '%s': %s",
+                                  filename, error->message);
+                       g_free (filename);
+                       g_error_free (error);
+                       return FALSE;
+               }
+               bootable = FALSE;
+       } else {
+               bootable = TRUE;
+       }
+       g_free (filename);
+
+       loader = osinfo_loader_new ();
+       osinfo_loader_process_default_path (loader, &error);
+       if (error != NULL) {
+               g_message ("Error loading libosinfo OS data: %s",
+                          error->message);
+               g_error_free (error);
+               g_object_unref (G_OBJECT(loader));
+               g_object_unref (G_OBJECT(media));
+               return FALSE;
+       }
+       db = osinfo_loader_get_db (loader);
+       os = osinfo_db_guess_os_from_media(db, media, &matched_media);
+
+       has_installer = osinfo_media_get_installer (media);
+       is_live = osinfo_media_get_live (media);
+
+       id = g_strdup (osinfo_entity_get_id (OSINFO_ENTITY (os)));
+       name = g_strdup (osinfo_product_get_name (OSINFO_PRODUCT (os)));
+
+       g_object_unref (G_OBJECT (media));
+       g_object_unref (G_OBJECT (loader));
+
+       if (is_live || has_installer) {
+           tracker_sparql_builder_predicate (metadata, "a");
+           tracker_sparql_builder_object (metadata, "nfo:OperatingSystem");
+       }
+
+       tracker_sparql_builder_predicate (metadata, "nfo:duration");
+       tracker_sparql_builder_object_int64 (metadata, 75);
+
+       tracker_sparql_builder_predicate (metadata, "nfo:isBootable");
+       tracker_sparql_builder_object_boolean (metadata, bootable);
+
+       tracker_sparql_builder_predicate (metadata, "osinfo:isInstaller");
+       tracker_sparql_builder_object_boolean (metadata, has_installer);
+
+       tracker_sparql_builder_predicate (metadata, "osinfo:isLiveCD");
+       tracker_sparql_builder_object_boolean (metadata, is_live);
+
+       tracker_sparql_builder_predicate (metadata, "osinfo:id");
+       tracker_sparql_builder_object_string (metadata, id);
+
+       tracker_sparql_builder_predicate (metadata, "osinfo:osName");
+       tracker_sparql_builder_object_string (metadata, name);
+
+       g_free (id);
+       g_free (name);
+
+       return TRUE;
+}
-- 
1.7.7.4




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