[tracker/tracker-0.6] Fixes NB#128713, Period in media filenames



commit 63a0441ffcb1258167afafcf340d7db18ab38462
Author: Mikael Ottela <mikael ottela ixonos com>
Date:   Mon Jul 27 15:37:20 2009 +0300

    Fixes NB#128713, Period in media filenames
    
    Remove everything after the _last_ dot in the filename, and replace
    in the remaining string '.' and '_' with whitespaces.
    
    This is used to get a default title, when a media file doesn't have any.
    
    Author:    Mikael Ottela <mikael ottela ixonos com>

 src/tracker-extract/Makefile.am                    |   44 +++++++++---------
 .../tracker-extract-gstreamer-helix.c              |   37 +++------------
 src/tracker-extract/tracker-extract-gstreamer.c    |   37 +++------------
 src/tracker-extract/tracker-extract-mp3.c          |   24 ++--------
 src/tracker-extract/tracker-utils.c                |   48 ++++++++++++++++++++
 src/tracker-extract/tracker-utils.h                |   34 ++++++++++++++
 6 files changed, 123 insertions(+), 101 deletions(-)
---
diff --git a/src/tracker-extract/Makefile.am b/src/tracker-extract/Makefile.am
index 72247a9..2511c4f 100644
--- a/src/tracker-extract/Makefile.am
+++ b/src/tracker-extract/Makefile.am
@@ -115,17 +115,19 @@ albumart_libs += 							\
 	$(GDKPIXBUF_LIBS) $(DBUS_LIBS) $(GCOV_LIBS)
 endif
 
-escape_sources = 							\
+util_sources = 								\
 	tracker-escape.c						\
-	tracker-escape.h
+	tracker-escape.h						\
+	tracker-utils.c							\
+	tracker-utils.h
 
 # ABW
-libextract_abw_la_SOURCES = tracker-extract-abw.c $(escape_sources)
+libextract_abw_la_SOURCES = tracker-extract-abw.c $(util_sources)
 libextract_abw_la_LDFLAGS = $(module_flags)
 libextract_abw_la_LIBADD = $(GLIB2_LIBS) $(GCOV_LIBS)
 
 # MP3
-libextract_mp3_la_SOURCES = tracker-extract-mp3.c $(albumart_sources) $(escape_sources)
+libextract_mp3_la_SOURCES = tracker-extract-mp3.c $(albumart_sources) $(util_sources)
 libextract_mp3_la_LDFLAGS = $(module_flags) $(albumart_flags)
 libextract_mp3_la_LIBADD = $(albumart_libs) $(GLIB2_LIBS) $(GCOV_LIBS)
 
@@ -135,27 +137,27 @@ libextract_mp3_la_LIBADD += $(ENCA_LIBS)
 endif
 
 # Vorbis (OGG)
-libextract_vorbis_la_SOURCES = tracker-extract-vorbis.c $(escape_sources)
+libextract_vorbis_la_SOURCES = tracker-extract-vorbis.c $(util_sources)
 libextract_vorbis_la_LDFLAGS = $(module_flags)
 libextract_vorbis_la_LIBADD = $(GLIB2_LIBS) $(LIBVORBIS_LIBS) $(GCOV_LIBS)
 
 # MPlayer
-libextract_mplayer_la_SOURCES = tracker-extract-mplayer.c $(escape_sources)
+libextract_mplayer_la_SOURCES = tracker-extract-mplayer.c $(util_sources)
 libextract_mplayer_la_LDFLAGS = $(module_flags)
 libextract_mplayer_la_LIBADD = $(GLIB2_LIBS)
 
 # Oasis
-libextract_oasis_la_SOURCES = tracker-extract-oasis.c $(escape_sources)
+libextract_oasis_la_SOURCES = tracker-extract-oasis.c $(util_sources)
 libextract_oasis_la_LDFLAGS = $(module_flags)
 libextract_oasis_la_LIBADD = $(GLIB2_LIBS)  $(GCOV_LIBS)
 
 # PNG
-libextract_png_la_SOURCES = tracker-extract-png.c $(xmp_sources) $(escape_sources)
+libextract_png_la_SOURCES = tracker-extract-png.c $(xmp_sources) $(util_sources)
 libextract_png_la_LDFLAGS = $(module_flags)
 libextract_png_la_LIBADD = $(GLIB2_LIBS) $(LIBPNG_LIBS) $(EXEMPI_LIBS) $(GCOV_LIBS)
 
 # PS
-libextract_ps_la_SOURCES = tracker-extract-ps.c $(escape_sources)
+libextract_ps_la_SOURCES = tracker-extract-ps.c $(util_sources)
 libextract_ps_la_LDFLAGS = $(module_flags)
 libextract_ps_la_LIBADD = 						\
 	$(top_builddir)/src/libtracker-common/libtracker-common.la	\
@@ -163,63 +165,63 @@ libextract_ps_la_LIBADD = 						\
 	$(GCOV_LIBS)
 
 # Totem
-libextract_totem_la_SOURCES = tracker-extract-totem.c $(escape_sources)
+libextract_totem_la_SOURCES = tracker-extract-totem.c $(util_sources)
 libextract_totem_la_LDFLAGS = $(module_flags)
 libextract_totem_la_LIBADD = $(GLIB2_LIBS) $(GCOV_LIBS)
 
 # XMP
-libextract_xmp_la_SOURCES = tracker-extract-xmp.c $(xmp_sources) $(escape_sources)
+libextract_xmp_la_SOURCES = tracker-extract-xmp.c $(xmp_sources) $(util_sources)
 libextract_xmp_la_LDFLAGS = $(module_flags)
 libextract_xmp_la_LIBADD = $(GLIB2_LIBS) $(EXEMPI_LIBS) $(GCOV_LIBS)
 
 # HTML
-libextract_html_la_SOURCES = tracker-extract-html.c $(escape_sources)
+libextract_html_la_SOURCES = tracker-extract-html.c $(util_sources)
 libextract_html_la_LDFLAGS = $(module_flags)
 libextract_html_la_LIBADD = $(GLIB2_LIBS) $(LIBXML2_LIBS) $(GCOV_LIBS)
 
 # MS Office
-libextract_msoffice_la_SOURCES = tracker-extract-msoffice.c $(escape_sources)
+libextract_msoffice_la_SOURCES = tracker-extract-msoffice.c $(util_sources)
 libextract_msoffice_la_LDFLAGS = $(module_flags)
 libextract_msoffice_la_LIBADD = $(GLIB2_LIBS) $(LIBGSF_LIBS) $(GCOV_LIBS)
 
 # PDF
-libextract_pdf_la_SOURCES = tracker-extract-pdf.c $(xmp_sources) $(escape_sources)
+libextract_pdf_la_SOURCES = tracker-extract-pdf.c $(xmp_sources) $(util_sources)
 libextract_pdf_la_LDFLAGS = $(module_flags)
 libextract_pdf_la_LIBADD = $(GLIB2_LIBS) $(POPPLER_GLIB_LIBS) $(EXEMPI_LIBS) $(GCOV_LIBS)
 
 # GStreamer
-libextract_gstreamer_la_SOURCES = tracker-extract-gstreamer.c $(albumart_sources) $(escape_sources)
+libextract_gstreamer_la_SOURCES = tracker-extract-gstreamer.c $(albumart_sources) $(util_sources)
 libextract_gstreamer_la_CFLAGS = -std=c99
 libextract_gstreamer_la_LDFLAGS = $(module_flags) $(albumart_flags) -lm
 libextract_gstreamer_la_LIBADD = $(albumart_libs) $(GSTREAMER_LIBS) $(GLIB2_LIBS) $(GCOV_LIBS)
 
 # GStreamer helix
-libextract_gstreamer_helix_la_SOURCES = tracker-extract-gstreamer-helix.c $(albumart_sources) $(escape_sources)
+libextract_gstreamer_helix_la_SOURCES = tracker-extract-gstreamer-helix.c $(albumart_sources) $(util_sources)
 libextract_gstreamer_helix_la_LDFLAGS = $(module_flags) $(albumart_flags)
 libextract_gstreamer_helix_la_LIBADD = $(albumart_libs) $(GSTREAMER_LIBS) $(GLIB2_LIBS) $(GCOV_LIBS)
 
 # Xine
-libextract_xine_la_SOURCES = tracker-extract-libxine.c $(escape_sources)
+libextract_xine_la_SOURCES = tracker-extract-libxine.c $(util_sources)
 libextract_xine_la_LDFLAGS = $(module_flags)
 libextract_xine_la_LIBADD = $(GLIB2_LIBS) $(XINE_LIBS) $(GCOV_LIBS)
 
 # JPEG
-libextract_jpeg_la_SOURCES = tracker-extract-jpeg.c $(xmp_sources) $(iptc_sources) $(escape_sources)
+libextract_jpeg_la_SOURCES = tracker-extract-jpeg.c $(xmp_sources) $(iptc_sources) $(util_sources)
 libextract_jpeg_la_LDFLAGS = $(module_flags)
 libextract_jpeg_la_LIBADD = $(GLIB2_LIBS) $(LIBJPEG_LIBS) $(LIBEXIF_LIBS) $(LIBIPTCDATA_LIBS) $(EXEMPI_LIBS) $(GCOV_LIBS)
 
 # TIFF
-libextract_tiff_la_SOURCES = tracker-extract-tiff.c $(xmp_sources) $(iptc_sources) $(escape_sources)
+libextract_tiff_la_SOURCES = tracker-extract-tiff.c $(xmp_sources) $(iptc_sources) $(util_sources)
 libextract_tiff_la_LDFLAGS = $(module_flags)
 libextract_tiff_la_LIBADD = $(GLIB2_LIBS) $(LIBTIFF_LIBS) $(LIBIPTCDATA_LIBS) $(EXEMPI_LIBS) $(GCOV_LIBS)
 
 # MOCKUP
-libextract_mockup_la_SOURCES = tracker-extract-mockup.c $(escape_sources)
+libextract_mockup_la_SOURCES = tracker-extract-mockup.c $(util_sources)
 libextract_mockup_la_LDFLAGS = $(module_flags)
 libextract_mockup_la_LIBADD = $(GLIB2_LIBS) $(GCOV_LIBS)
 
 # Playlists using totem-pl-parser
-libextract_playlist_la_SOURCES = tracker-extract-playlist.c  $(escape_sources)
+libextract_playlist_la_SOURCES = tracker-extract-playlist.c  $(util_sources)
 libextract_playlist_la_LDFLAGS = $(module_flags)
 libextract_playlist_la_LIBADD = $(GLIB2_LIBS) $(TOTEM_PL_PARSER_LIBS) $(GCOV_LIBS)
 
diff --git a/src/tracker-extract/tracker-extract-gstreamer-helix.c b/src/tracker-extract/tracker-extract-gstreamer-helix.c
index 435aef4..1038de0 100644
--- a/src/tracker-extract/tracker-extract-gstreamer-helix.c
+++ b/src/tracker-extract/tracker-extract-gstreamer-helix.c
@@ -34,6 +34,7 @@
 #include <gst/tag/tag.h>
 
 #include "tracker-main.h"
+#include "tracker-utils.h"
 #include "tracker-extract-albumart.h"
 
 typedef enum {
@@ -838,37 +839,13 @@ tracker_extract_gstreamer_helix (const gchar *uri,
 	/* Check that we have the minimum data. FIXME We should not need to do this */
 
 	if (type == EXTRACT_MIME_VIDEO) {
-		if (!g_hash_table_lookup (metadata, "Video:Title")) {
-			gchar  *basename = g_filename_display_basename (uri);
-			gchar **parts    = g_strsplit (basename, ".", -1);
-			gchar  *title    = g_strdup (parts[0]);
-			
-			g_strfreev (parts);
-			g_free (basename);
-
-			title = g_strdelimit (title, "_", ' ');
-			
-			g_hash_table_insert (metadata,
-					     g_strdup ("Video:Title"),
-					     tracker_escape_metadata (title));
-			g_free (title);
-		}
+		tracker_utils_default_check_filename (metadata,
+						      "Video:Title",
+						      uri);
 	} else if (type == EXTRACT_MIME_AUDIO) {
-		if (!g_hash_table_lookup (metadata, "Audio:Title")) {
-			gchar  *basename = g_filename_display_basename (uri);
-			gchar **parts    = g_strsplit (basename, ".", -1);
-			gchar  *title    = g_strdup (parts[0]);
-			
-			g_strfreev (parts);
-			g_free (basename);
-			
-			title = g_strdelimit (title, "_", ' ');
-			
-			g_hash_table_insert (metadata,
-					     g_strdup ("Audio:Title"),
-					     tracker_escape_metadata (title));
-			g_free (title);
-		}
+		tracker_utils_default_check_filename (metadata,
+						      "Audio:Title",
+						      uri);
 	}
 
 	/* Also clean up */
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index b7d00fc..d26e129 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -37,6 +37,7 @@
 #include <libtracker-common/tracker-file-utils.h>
 
 #include "tracker-main.h"
+#include "tracker-utils.h"
 #include "tracker-extract-albumart.h"
 
 /* We wait this long (seconds) for NULL state before freeing */
@@ -923,37 +924,13 @@ fail:
 			g_free (date);
 		}
 	} else if (type == EXTRACT_MIME_VIDEO) {
-		if (!g_hash_table_lookup (metadata, "Video:Title")) {
-			gchar  *basename = g_filename_display_basename (uri);
-			gchar **parts    = g_strsplit (basename, ".", -1);
-			gchar  *title    = g_strdup (parts[0]);
-			
-			g_strfreev (parts);
-			g_free (basename);
-
-			title = g_strdelimit (title, "_", ' ');
-			
-			g_hash_table_insert (metadata,
-					     g_strdup ("Video:Title"),
-					     tracker_escape_metadata (title));
-			g_free (title);
-		}
+		tracker_utils_default_check_filename (metadata,
+						      "Video:Title",
+						      uri);
 	} else if (type == EXTRACT_MIME_AUDIO) {
-		if (!g_hash_table_lookup (metadata, "Audio:Title")) {
-			gchar  *basename = g_filename_display_basename (uri);
-			gchar **parts    = g_strsplit (basename, ".", -1);
-			gchar  *title    = g_strdup (parts[0]);
-			
-			g_strfreev (parts);
-			g_free (basename);
-			
-			title = g_strdelimit (title, "_", ' ');
-			
-			g_hash_table_insert (metadata,
-					     g_strdup ("Audio:Title"),
-					     tracker_escape_metadata (title));
-			g_free (title);
-		}
+		tracker_utils_default_check_filename (metadata,
+						      "Audio:Title",
+						      uri);
 	}
 }
 
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index 7dcde3b..e81d2a4 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -50,6 +50,7 @@
 #include "tracker-main.h"
 #include "tracker-extract-albumart.h"
 #include "tracker-escape.h"
+#include "tracker-utils.h"
 
 /* We mmap the beginning of the file and read separately the last 128
  * bytes for id3v1 tags. While these are probably cornercases the
@@ -2055,26 +2056,9 @@ extract_mp3 (const gchar *filename,
 	g_free (filedata.albumartmime);
 
 	/* Check that we have the minimum data. FIXME We should not need to do this */
-	if (!g_hash_table_lookup (metadata, "Audio:Title")) {
-		gchar  *basename;
-		gchar **parts;
-		gchar  *title;
-		
-		basename = g_filename_display_basename (filename);
-		parts = g_strsplit (basename, ".", -1);
-		title = g_strdup (parts[0]);
-
-		g_strfreev (parts);
-		g_free (basename);
-		
-		title = g_strdelimit (title, "_", ' ');
-		
-		g_hash_table_insert (metadata,
-				     g_strdup ("Audio:Title"),
-				     tracker_escape_metadata (title));
-
-		g_free (title);
-	}
+	tracker_utils_default_check_filename (metadata,
+					      "Audio:Title",
+					      filename);
 
 #ifndef G_OS_WIN32
 	munmap (buffer, buffer_size);
diff --git a/src/tracker-extract/tracker-utils.c b/src/tracker-extract/tracker-utils.c
new file mode 100644
index 0000000..b3f6ff4
--- /dev/null
+++ b/src/tracker-extract/tracker-utils.c
@@ -0,0 +1,48 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <glib.h>
+
+#include "tracker-escape.h"
+
+void
+tracker_utils_default_check_filename (GHashTable  *metadata,
+				      gchar       *key,
+				      const gchar *filename)
+{
+	if (!g_hash_table_lookup (metadata, key)) {
+		gchar  *name = g_filename_display_basename (filename);
+		gchar  *suffix = NULL;
+
+		suffix = g_strrstr (name, ".");
+		*suffix = '\0';
+		
+		g_strdelimit (name, "._", ' ');
+		
+		g_hash_table_insert (metadata,
+				     g_strdup (key),
+				     tracker_escape_metadata (name));
+		g_free (name);
+	}	
+}
diff --git a/src/tracker-extract/tracker-utils.h b/src/tracker-extract/tracker-utils.h
new file mode 100644
index 0000000..7645b2e
--- /dev/null
+++ b/src/tracker-extract/tracker-utils.h
@@ -0,0 +1,34 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
+#ifndef __TRACKER_UTILS_H__
+#define __TRACKER_UTILS_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+void           tracker_utils_default_check_filename (GHashTable  *metadata,
+						     gchar       *key,
+						     const gchar *filename);
+
+G_END_DECLS
+
+#endif /* __TRACKER_UTILS_H__ */



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