tracker r2489 - in trunk: . src/tracker-extract



Author: ifrade
Date: Wed Nov 12 17:33:20 2008
New Revision: 2489
URL: http://svn.gnome.org/viewvc/tracker?rev=2489&view=rev

Log:
Extractor for playlists using totem-plparser. Deleted old m3u module

Added:
   trunk/src/tracker-extract/tracker-extract-playlist.c
Removed:
   trunk/src/tracker-extract/tracker-extract-m3u.c
Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/src/tracker-extract/Makefile.am

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Wed Nov 12 17:33:20 2008
@@ -976,6 +976,30 @@
    AC_DEFINE(HAVE_IMAGEMAGICK, 1, [Define if we have imagemagick])
 fi
 
+###############################################
+# Checking totem-pl-parser
+###############################################
+AC_ARG_ENABLE(playlist, 
+	      AS_HELP_STRING([--disable-playlist],
+			     [Disable playlist support]),
+			     [enable_playlist=no],
+			     [enable_playlist=yes])
+
+if test "x$enable_playlist" = "xyes"; then
+   PKG_CHECK_MODULES(TOTEM_PL_PARSER, 
+    	  	     [totem-plparser], 
+		     [have_playlist_parser=yes], 
+		     [have_playlist_parser=no 
+		      AC_MSG_ERROR(totem-plparser is not available in the system. You can try with --disable-playlist option.)])
+   AC_SUBST(TOTEM_PL_PARSER_CFLAGS)
+   AC_SUBST(TOTEM_PL_PARSER_LIBS)
+else
+   have_playlist_parser="no (disabled)"
+fi
+
+AM_CONDITIONAL(HAVE_TOTEM_PL_PARSER, test "x$have_playlist_parser" = "xyes")
+
+
 ##################################################
 # Checks for gtk-doc and docbook-tools
 ##################################################
@@ -1180,6 +1204,7 @@
 	Support embedded / sidecar XMP:		$have_exempi
 	Support video formats:			$have_video_handler ($have_video_handler_app)
 	Support MP3 album art (w/ GdkPixbuf):	$have_gdkpixbuf
+	Support Playlists:                      $have_playlist_parser
 
 Thumbnailers:
 

Modified: trunk/src/tracker-extract/Makefile.am
==============================================================================
--- trunk/src/tracker-extract/Makefile.am	(original)
+++ trunk/src/tracker-extract/Makefile.am	Wed Nov 12 17:33:20 2008
@@ -21,11 +21,11 @@
 	$(GDKPIXBUF_CFLAGS)						\
 	$(GMODULE_CFLAGS) 						\
 	$(DBUS_CFLAGS)							\
-	$(GLIB2_CFLAGS)
+	$(GLIB2_CFLAGS)							\
+	$(TOTEM_PL_PARSER_CFLAGS)
 
 modules_LTLIBRARIES = 							\
 	libextract-abw.la 						\
-	libextract-m3u.la						\
 	libextract-mp3.la				 		\
 	libextract-oasis.la 						\
 	libextract-png.la 						\
@@ -73,7 +73,9 @@
 			libextract-totem.la
 endif
 
-
+if HAVE_TOTEM_PL_PARSER
+modules_LTLIBRARIES += libextract-playlist.la
+endif
 
 # Common XMP Sources
 xmp_sources = 								\
@@ -104,11 +106,6 @@
 libextract_imagemagick_la_LDFLAGS = $(module_flags)
 libextract_imagemagick_la_LIBADD = $(GLIB2_LIBS) $(EXEMPI_LIBS)
 
-# M3U
-libextract_m3u_la_SOURCES = tracker-extract-m3u.c
-libextract_m3u_la_LDFLAGS = $(module_flags)
-libextract_m3u_la_LIBADD = $(GLIB2_LIBS)
-
 # MP3
 libextract_mp3_la_SOURCES = tracker-extract-mp3.c $(albumart_sources)
 libextract_mp3_la_LDFLAGS = $(module_flags) $(albumart_flags)
@@ -181,6 +178,11 @@
 libextract_tiff_la_LDFLAGS = $(module_flags)
 libextract_tiff_la_LIBADD = $(GLIB2_LIBS) $(LIBTIFF_LIBS) $(EXEMPI_LIBS)
 
+# Playlists using totem-pl-parser
+libextract_playlist_la_SOURCES = tracker-extract-playlist.c 
+libextract_playlist_la_LDFLAGS = $(module_flags)
+libextract_playlist_la_LIBADD = $(GLIB2_LIBS) $(TOTEM_PL_PARSER_LIBS)
+
 #
 # Binaries
 #

Added: trunk/src/tracker-extract/tracker-extract-playlist.c
==============================================================================
--- (empty file)
+++ trunk/src/tracker-extract/tracker-extract-playlist.c	Wed Nov 12 17:33:20 2008
@@ -0,0 +1,127 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2007, Mr Jamie McCracken (jamiemcc gnome org)
+ * 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"
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+
+#include "tracker-extract.h"
+#include <totem-pl-parser.h>
+
+#define PLAYLIST_PROPERTY_NO_TRACKS "Playlist:Songs"
+#define PLAYLIST_PROPERTY_DURATION  "Playlist:TotalLength"
+
+typedef struct {
+	gint        track_counter;
+	gint        total_time;
+} PlaylistMetadata;
+
+static void extract_playlist (const gchar *filename,
+			      GHashTable  *metadata);
+
+
+static TrackerExtractorData data[] = {
+	{ "audio/x-mpegurl", extract_playlist },
+	{ "audio/mpegurl", extract_playlist },
+	{ "audio/x-scpls", extract_playlist },
+	{ "audio/x-pn-realaudio", extract_playlist },
+	{ "application/ram", extract_playlist },
+	{ "application/vnd.ms-wpl", extract_playlist }, 
+	{ "application/smil", extract_playlist }, 
+	{ "audio/x-ms-asx", extract_playlist },
+	{ NULL, NULL }
+};
+
+static void
+entry_parsed (TotemPlParser *parser, const gchar *uri, GHashTable *metadata, gpointer user_data)
+{
+	gchar *duration;
+	PlaylistMetadata *data;
+
+	data = (PlaylistMetadata *)user_data;
+
+	data->track_counter += 1;
+
+	duration = g_hash_table_lookup (metadata, TOTEM_PL_PARSER_FIELD_DURATION);
+
+	if (duration == NULL) {
+		duration = g_hash_table_lookup (metadata, TOTEM_PL_PARSER_FIELD_DURATION_MS);
+	}
+
+	if (duration != NULL) {
+		gint secs = atoi (duration);
+		if (secs > 0) {
+			data->total_time += secs;
+		}
+	} 
+}
+
+static void
+extract_playlist (const gchar *filename,
+		  GHashTable  *metadata)
+{
+	TotemPlParser *pl;
+	PlaylistMetadata data = {0, 0};
+	gchar *proper_filename;
+
+	pl = totem_pl_parser_new ();
+
+        g_object_set (pl, "recurse", FALSE, "disable-unsafe", TRUE, NULL);
+
+        g_signal_connect (G_OBJECT (pl), "entry-parsed", 
+                          G_CALLBACK (entry_parsed), &data);
+
+	if (g_str_has_prefix (filename, "file://")) {
+		proper_filename = g_strdup (filename);
+	} else {
+		proper_filename = g_strconcat ("file://", filename, NULL);
+	}
+
+        if (totem_pl_parser_parse (pl, 
+                                   proper_filename, 
+                                   FALSE) != TOTEM_PL_PARSER_RESULT_SUCCESS)
+                g_error ("Playlist parsing failed.");
+
+	g_hash_table_insert (metadata, 
+			     g_strdup (PLAYLIST_PROPERTY_DURATION), 
+			     g_strdup_printf ("%d", data.total_time));
+
+	g_hash_table_insert (metadata, 
+			     g_strdup (PLAYLIST_PROPERTY_NO_TRACKS), 
+			     g_strdup_printf ("%d", data.track_counter));
+
+	g_free (proper_filename);
+        g_object_unref (pl);
+}
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}



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