[tracker/guarantee: 2/2] libtracker-extract: Added -guarantee module
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/guarantee: 2/2] libtracker-extract: Added -guarantee module
- Date: Fri, 10 Dec 2010 13:21:56 +0000 (UTC)
commit 8f934a6971408d571c54d337ecc98aa1b302bbd9
Author: Martyn Russell <martyn lanedo com>
Date: Fri Dec 10 12:19:30 2010 +0000
libtracker-extract: Added -guarantee module
This is designed to use an existing value or guarantee a value from
the file in some way (in most cases).
For now this module just does the guessing, next will come the
checking existing values
src/libtracker-extract/Makefile.am | 3 +
src/libtracker-extract/tracker-extract.h | 1 +
src/libtracker-extract/tracker-guarantee.c | 93 ++++++++++++++++++++++
src/libtracker-extract/tracker-guarantee.h | 36 ++++++++
src/tracker-extract/tracker-extract-flac.c | 17 +---
src/tracker-extract/tracker-extract-gif.c | 17 +---
src/tracker-extract/tracker-extract-gstreamer.c | 30 ++------
src/tracker-extract/tracker-extract-gupnp-dlna.c | 30 ++------
src/tracker-extract/tracker-extract-jpeg.c | 17 +---
src/tracker-extract/tracker-extract-mp3.c | 18 +----
src/tracker-extract/tracker-extract-png.c | 22 +-----
src/tracker-extract/tracker-extract-tiff.c | 17 +---
12 files changed, 165 insertions(+), 136 deletions(-)
---
diff --git a/src/libtracker-extract/Makefile.am b/src/libtracker-extract/Makefile.am
index de9f2f5..e4b691e 100644
--- a/src/libtracker-extract/Makefile.am
+++ b/src/libtracker-extract/Makefile.am
@@ -15,6 +15,8 @@ libtracker_extract_ TRACKER_API_VERSION@_la_SOURCES = \
tracker-data.h \
tracker-exif.c \
tracker-exif.h \
+ tracker-guarantee.c \
+ tracker-guarantee.h \
tracker-iptc.c \
tracker-iptc.h \
tracker-utils.c \
@@ -27,6 +29,7 @@ libtracker_extractinc_HEADERS = \
tracker-data.h \
tracker-exif.h \
tracker-extract.h \
+ tracker-guarantee.h \
tracker-iptc.h \
tracker-utils.h \
tracker-xmp.h
diff --git a/src/libtracker-extract/tracker-extract.h b/src/libtracker-extract/tracker-extract.h
index 835fda2..ad25fdc 100644
--- a/src/libtracker-extract/tracker-extract.h
+++ b/src/libtracker-extract/tracker-extract.h
@@ -26,6 +26,7 @@
#include "tracker-data.h"
#include "tracker-exif.h"
+#include "tracker-guarantee.h"
#include "tracker-iptc.h"
#include "tracker-utils.h"
#include "tracker-xmp.h"
diff --git a/src/libtracker-extract/tracker-guarantee.c b/src/libtracker-extract/tracker-guarantee.c
new file mode 100644
index 0000000..bb5374a
--- /dev/null
+++ b/src/libtracker-extract/tracker-guarantee.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2009, Nokia <ivan frade nokia com>
+ *
+ * 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.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <glib.h>
+
+#include <libtracker-common/tracker-common.h>
+
+#include "tracker-guarantee.h"
+
+/**
+ * tracker_guarantee_title_from_filename:
+ * @uri: a string representing a URI to use
+ *
+ * Parses the filename pointed to by @uri and uses the basename
+ * (before the "." and extension of the file) as the title. If the
+ * title has any "_" characters, they are also converted into spaces.
+ *
+ * Returns: A newly allocated string which must be freed with g_free()
+ * or %NULL on error.
+ *
+ * Since: 0.10
+ **/
+gchar *
+tracker_guarantee_title_from_filename (const gchar *uri)
+{
+ gchar *filename;
+ gchar *basename;
+ gchar *p;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ filename = g_filename_from_uri (uri, NULL, NULL);
+ basename = g_filename_display_basename (filename);
+ g_free (filename);
+
+ p = strchr (basename, '.');
+ if (p) {
+ *p = '\0';
+ }
+
+ return g_strdelimit (basename, "_", ' ');
+
+}
+
+/**
+ * tracker_guarantee_date_from_filename_mtime:
+ * @uri: a string representing a URI to use
+ *
+ * Calls stat() on the filename pointed to by @uri to create a date
+ * based on the file's mtime.
+ *
+ * Returns: A newly allocated string which must be freed with g_free()
+ * or %NULL on error. The string represents the date in ISO8160.
+ *
+ * Since: 0.10
+ **/
+gchar *
+tracker_guarantee_date_from_filename_mtime (const gchar *uri)
+{
+ gchar *filename;
+ gchar *date;
+ guint64 mtime;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ filename = g_filename_from_uri (uri, NULL, NULL);
+ mtime = tracker_file_get_mtime (filename);
+ g_free (filename);
+
+ date = tracker_date_to_string ((time_t) mtime);
+
+ return date;
+}
diff --git a/src/libtracker-extract/tracker-guarantee.h b/src/libtracker-extract/tracker-guarantee.h
new file mode 100644
index 0000000..a215ccc
--- /dev/null
+++ b/src/libtracker-extract/tracker-guarantee.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2009, Nokia <ivan frade nokia com>
+ *
+ * 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.
+ */
+
+#include <stdio.h>
+
+#ifndef __LIBTRACKER_EXTRACT_GUARANTEE__
+#define __LIBTRACKER_EXTRACT_GUARANTEE_H__
+
+#if !defined (__LIBTRACKER_EXTRACT_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-extract/tracker-extract.h> must be included directly."
+#endif
+
+G_BEGIN_DECLS
+
+gchar *tracker_guarantee_title_from_filename (const gchar *uri);
+gchar *tracker_guarantee_date_from_filename_mtime (const gchar *uri);
+
+G_END_DECLS
+
+#endif /* __LIBTRACKER_EXTRACT_GUARANTEE_H__ */
diff --git a/src/tracker-extract/tracker-extract-flac.c b/src/tracker-extract/tracker-extract-flac.c
index 4cbb63a..9d5cc1f 100644
--- a/src/tracker-extract/tracker-extract-flac.c
+++ b/src/tracker-extract/tracker-extract-flac.c
@@ -326,17 +326,10 @@ extract_flac (const gchar *uri,
add_tuple (metadata, "nie:title", fd.title);
#ifdef GUARANTEE_METADATA
if (!fd.title) {
- gchar *basename = g_filename_display_basename (filename);
- gchar **parts = g_strsplit (basename, ".", -1);
- gchar *title = g_strdup (parts[0]);
-
- g_strfreev (parts);
- g_free (basename);
-
- title = g_strdelimit (title, "_", ' ');
+ gchar *title;
+ title = tracker_guarantee_title_from_filename (uri);
add_tuple (metadata, "nie:title", title);
-
g_free (title);
}
#endif
@@ -394,13 +387,9 @@ extract_flac (const gchar *uri,
#ifdef GUARANTEE_METADATA
if (!fd.date) {
gchar *date;
- guint64 mtime;
-
- mtime = tracker_file_get_mtime (filename);
- date = tracker_date_to_string ((time_t) mtime);
+ date = tracker_guarantee_date_from_filename_mtime (uri);
add_tuple (metadata, "nie:contentCreated", date);
-
g_free (date);
}
#endif
diff --git a/src/tracker-extract/tracker-extract-gif.c b/src/tracker-extract/tracker-extract-gif.c
index 08ee8ec..545f59f 100644
--- a/src/tracker-extract/tracker-extract-gif.c
+++ b/src/tracker-extract/tracker-extract-gif.c
@@ -236,14 +236,10 @@ read_metadata (TrackerSparqlBuilder *preupdate,
#ifdef GUARANTEE_METADATA
else {
gchar *date;
- guint64 mtime;
-
- mtime = tracker_file_get_mtime (filename);
- date = tracker_date_to_string ((time_t) mtime);
+ date = tracker_guarantee_date_from_filename_mtime (uri);
tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
tracker_sparql_builder_object_unvalidated (metadata, date);
-
g_free (date);
}
#endif
@@ -289,18 +285,11 @@ read_metadata (TrackerSparqlBuilder *preupdate,
}
#ifdef GUARANTEE_METADATA
else {
- gchar *basename = g_filename_display_basename (filename);
- gchar **parts = g_strsplit (basename, ".", -1);
- gchar *title = g_strdup (parts[0]);
-
- g_strfreev (parts);
- g_free (basename);
-
- title = g_strdelimit (title, "_", ' ');
+ gchar *title;
+ title = tracker_guarantee_title_from_filename (uri);
tracker_sparql_builder_predicate (metadata, "nie:title");
tracker_sparql_builder_object_unvalidated (metadata, title);
-
g_free (title);
}
#endif
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index 324d3c9..648f392 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -312,19 +312,12 @@ add_y_date_gst_tag (TrackerSparqlBuilder *metadata,
}
#ifdef GUARANTEE_METADATA
else {
- gchar *datestr;
- guint64 mtime;
-
- gchar *filename = g_filename_from_uri (uri, NULL, NULL);
-
- mtime = tracker_file_get_mtime (filename);
- datestr = tracker_date_to_string ((time_t) mtime);
+ gchar *date;
+ date = tracker_guarantee_date_from_filename_mtime (uri);
tracker_sparql_builder_predicate (metadata, key);
- tracker_sparql_builder_object_unvalidated (metadata, datestr);
-
- g_free (datestr);
- g_free (filename);
+ tracker_sparql_builder_object_unvalidated (metadata, date);
+ g_free (date);
}
#endif
@@ -788,20 +781,11 @@ extract_metadata (MetadataExtractor *extractor,
}
#ifdef GUARANTEE_METADATA
else {
- gchar *filename = g_filename_from_uri (uri, NULL, NULL);
- gchar *basename = g_filename_display_basename (filename);
- gchar **parts = g_strsplit (basename, ".", -1);
- gchar *title = g_strdup (parts[0]);
-
- g_strfreev (parts);
- g_free (basename);
- g_free (filename);
-
- title = g_strdelimit (title, "_", ' ');
-
+ gchar *title;
+
+ title = tracker_guarantee_title_from_filename (uri);
tracker_sparql_builder_predicate (metadata, "nie:title");
tracker_sparql_builder_object_unvalidated (metadata, title);
-
g_free (title);
}
#endif
diff --git a/src/tracker-extract/tracker-extract-gupnp-dlna.c b/src/tracker-extract/tracker-extract-gupnp-dlna.c
index f690a79..4b1b0de 100644
--- a/src/tracker-extract/tracker-extract-gupnp-dlna.c
+++ b/src/tracker-extract/tracker-extract-gupnp-dlna.c
@@ -294,19 +294,12 @@ add_y_date_gst_tag (TrackerSparqlBuilder *metadata,
}
#ifdef GUARANTEE_METADATA
else {
- gchar *datestr;
- guint64 mtime;
-
- gchar *filename = g_filename_from_uri (uri, NULL, NULL);
-
- mtime = tracker_file_get_mtime (filename);
- datestr = tracker_date_to_string ((time_t) mtime);
+ gchar *date;
+ date = tracker_guarantee_date_from_filename_mtime (uri);
tracker_sparql_builder_predicate (metadata, key);
- tracker_sparql_builder_object_unvalidated (metadata, datestr);
-
- g_free (datestr);
- g_free (filename);
+ tracker_sparql_builder_object_unvalidated (metadata, date);
+ g_free (date);
}
#endif
}
@@ -629,20 +622,11 @@ extract_metadata (MetadataExtractor *extractor,
}
#ifdef GUARANTEE_METADATA
else {
- gchar *filename = g_filename_from_uri (uri, NULL, NULL);
- gchar *basename = g_filename_display_basename (filename);
- gchar **parts = g_strsplit (basename, ".", -1);
- gchar *title = g_strdup (parts[0]);
-
- g_strfreev (parts);
- g_free (basename);
- g_free (filename);
-
- title = g_strdelimit (title, "_", ' ');
-
+ gchar *title;
+
+ title = tracker_guarantee_title_from_filename (uri);
tracker_sparql_builder_predicate (metadata, "nie:title");
tracker_sparql_builder_object_unvalidated (metadata, title);
-
g_free (title);
}
#endif
diff --git a/src/tracker-extract/tracker-extract-jpeg.c b/src/tracker-extract/tracker-extract-jpeg.c
index 7047ee3..133eb11 100644
--- a/src/tracker-extract/tracker-extract-jpeg.c
+++ b/src/tracker-extract/tracker-extract-jpeg.c
@@ -409,18 +409,11 @@ extract_jpeg (const gchar *uri,
}
#ifdef GUARANTEE_METADATA
else {
- gchar *basename = g_filename_display_basename (filename);
- gchar **parts = g_strsplit (basename, ".", -1);
- gchar *title = g_strdup (parts[0]);
-
- g_strfreev (parts);
- g_free (basename);
-
- title = g_strdelimit (title, "_", ' ');
+ gchar *title;
+ title = tracker_guarantee_title_from_filename (uri);
tracker_sparql_builder_predicate (metadata, "nie:title");
tracker_sparql_builder_object_unvalidated (metadata, title);
-
g_free (title);
}
#endif
@@ -499,14 +492,10 @@ extract_jpeg (const gchar *uri,
#ifdef GUARANTEE_METADATA
else {
gchar *date;
- guint64 mtime;
-
- mtime = tracker_file_get_mtime (filename);
- date = tracker_date_to_string ((time_t) mtime);
+ date = tracker_guarantee_date_from_filename_mtime (uri);
tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
tracker_sparql_builder_object_unvalidated (metadata, date);
-
g_free (date);
}
#endif
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index 71e821d..6d72ad0 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -2275,18 +2275,11 @@ extract_mp3 (const gchar *uri,
}
#ifdef GUARANTEE_METADATA
else {
- gchar *basename = g_filename_display_basename (filename);
- gchar **parts = g_strsplit (basename, ".", -1);
- gchar *title = g_strdup (parts[0]);
-
- g_strfreev (parts);
- g_free (basename);
-
- title = g_strdelimit (title, "_", ' ');
+ gchar *title;
+ title = tracker_guarantee_title_from_filename (uri);
tracker_sparql_builder_predicate (metadata, "nie:title");
tracker_sparql_builder_object_unvalidated (metadata, title);
-
g_free (title);
}
#endif
@@ -2321,19 +2314,14 @@ extract_mp3 (const gchar *uri,
#ifdef GUARANTEE_METADATA
else {
gchar *date;
- guint64 mtime;
-
- mtime = tracker_file_get_mtime (filename);
- date = tracker_date_to_string ((time_t) mtime);
+ date = tracker_guarantee_date_from_filename_mtime (uri);
tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
tracker_sparql_builder_object_unvalidated (metadata, date);
-
g_free (date);
}
#endif
-
if (md.genre) {
tracker_sparql_builder_predicate (metadata, "nfo:genre");
tracker_sparql_builder_object_unvalidated (metadata, md.genre);
diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c
index 080754d..f747ad3 100644
--- a/src/tracker-extract/tracker-extract-png.c
+++ b/src/tracker-extract/tracker-extract-png.c
@@ -248,18 +248,11 @@ read_metadata (TrackerSparqlBuilder *preupdate,
#ifdef GUARANTEE_METADATA
else {
gchar *date;
- guint64 mtime;
-
- gchar *filename = g_filename_from_uri (uri, NULL, NULL);
-
- mtime = tracker_file_get_mtime (filename);
- date = tracker_date_to_string ((time_t) mtime);
+ date = tracker_guarantee_date_from_filename_mtime (uri);
tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
tracker_sparql_builder_object_unvalidated (metadata, date);
-
g_free (date);
- g_free (filename);
}
#endif
if (md.description) {
@@ -278,20 +271,11 @@ read_metadata (TrackerSparqlBuilder *preupdate,
}
#ifdef GUARANTEE_METADATA
else {
- gchar *filename = g_filename_from_uri (uri, NULL, NULL);
- gchar *basename = g_filename_display_basename (filename);
- gchar **parts = g_strsplit (basename, ".", -1);
- gchar *title = g_strdup (parts[0]);
-
- g_strfreev (parts);
- g_free (basename);
- g_free (filename);
-
- title = g_strdelimit (title, "_", ' ');
+ gchar *title;
+ title = tracker_guarantee_title_from_filename (uri);
tracker_sparql_builder_predicate (metadata, "nie:title");
tracker_sparql_builder_object_unvalidated (metadata, title);
-
g_free (title);
}
#endif
diff --git a/src/tracker-extract/tracker-extract-tiff.c b/src/tracker-extract/tracker-extract-tiff.c
index 5c743da..2191047 100644
--- a/src/tracker-extract/tracker-extract-tiff.c
+++ b/src/tracker-extract/tracker-extract-tiff.c
@@ -604,18 +604,11 @@ extract_tiff (const gchar *uri,
}
#ifdef GUARANTEE_METADATA
else {
- gchar *basename = g_filename_display_basename (filename);
- gchar **parts = g_strsplit (basename, ".", -1);
- gchar *title = g_strdup (parts[0]);
-
- g_strfreev (parts);
- g_free (basename);
-
- title = g_strdelimit (title, "_", ' ');
+ gchar *title;
+ title = tracker_guarantee_title_from_filename (uri);
tracker_sparql_builder_predicate (metadata, "nie:title");
tracker_sparql_builder_object_unvalidated (metadata, title);
-
g_free (title);
}
#endif
@@ -682,14 +675,10 @@ extract_tiff (const gchar *uri,
#ifdef GUARANTEE_METADATA
else {
gchar *date;
- guint64 mtime;
-
- mtime = tracker_file_get_mtime (filename);
- date = tracker_date_to_string ((time_t) mtime);
+ date = tracker_guarantee_date_from_filename_mtime (uri);
tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
tracker_sparql_builder_object_unvalidated (metadata, date);
-
g_free (date);
}
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]