Commit 703a4ae2 authored by Philip Van Hoof's avatar Philip Van Hoof Committed by Philip Van Hoof

src/tracker-extract/tracker-extract-mp3.c

2009-02-11  Philip Van Hoof  <philip@codeminded.be>

	* src/tracker-extract/tracker-extract-mp3.c
	* src/tracker-extract/tracker-extract-gstreamer-helix.c
	* src/tracker-extract/tracker-extract-gstreamer.c
	* src/tracker-extract/Makefile.am
	* src/libtracker-common/Makefile.am
	* src/tracker-extract/tracker-extract-albumart.c
	* src/tracker-extract/tracker-extract-albumart.h
	* src/libtracker-common/tracker-albumart.c
	* src/libtracker-common/tracker-albumart.h
	* src/tracker-extract/tracker-albumart.c
	* src/tracker-extract/tracker-albumart.h: Made a library for the album-art
	code, because other processes (tracker-indexer and trackerd) will soon
	have to perform album-art use-cases and requests too (not only the 
	tracker-extract will have to do it anymore)


svn path=/trunk/; revision=2914
parent 4c191dea
2009-02-11 Philip Van Hoof <philip@codeminded.be>
* src/tracker-extract/tracker-extract-mp3.c
* src/tracker-extract/tracker-extract-gstreamer-helix.c
* src/tracker-extract/tracker-extract-gstreamer.c
* src/tracker-extract/Makefile.am
* src/libtracker-common/Makefile.am
* src/tracker-extract/tracker-extract-albumart.c
* src/tracker-extract/tracker-extract-albumart.h
* src/libtracker-common/tracker-albumart.c
* src/libtracker-common/tracker-albumart.h
* src/tracker-extract/tracker-albumart.c
* src/tracker-extract/tracker-albumart.h: Made a library for the album-art
code, because other processes (tracker-indexer and trackerd) will soon
have to perform album-art use-cases and requests too (not only the
tracker-extract will have to do it anymore)
2009-02-11 Mikael Ottela <mikael.ottela@ixonos.com>
* src/trackerd/tracker-main.c: Crash fix for error freeing.
......
......@@ -5,13 +5,14 @@ INCLUDES = \
-DG_LOG_DOMAIN=\"Tracker\" \
-DTRACKER_COMPILATION \
-I$(top_srcdir)/src \
$(WARN_CFLAGS) \
$(WARN_CFLAGS) \
$(HAL_CFLAGS) \
$(DBUS_CFLAGS) \
$(UNAC_CFLAGS) \
$(PANGO_CFLAGS) \
$(GIO_CFLAGS) \
$(GLIB2_CFLAGS)
$(GLIB2_CFLAGS) \
$(GDKPIXBUF_CFLAGS)
libtracker_commondir = $(libdir)/tracker
libtracker_commonincludedir=$(includedir)/tracker-1.0/libtracker-common/
......@@ -48,7 +49,8 @@ libtracker_common_la_SOURCES = \
tracker-service.c \
tracker-type-utils.c \
tracker-utils.c \
tracker-thumbnailer.c
tracker-thumbnailer.c \
tracker-albumart.c
noinst_HEADERS = \
$(hal_headers) \
......@@ -57,7 +59,8 @@ noinst_HEADERS = \
tracker-log.h \
tracker-nfs-lock.h \
tracker-os-dependant.h \
tracker-thumbnailer.h
tracker-thumbnailer.h \
tracker-albumart.h
libtracker_commoninclude_HEADERS = \
tracker-common.h \
......@@ -80,7 +83,8 @@ libtracker_common_la_LIBADD = \
$(UNAC_LIBS) \
$(PANGO_LIBS) \
$(GIO_LIBS) \
$(GLIB2_LIBS)
$(GLIB2_LIBS) \
$(GDKPIXBUF_LIBS)
tracker-marshal.h: tracker-marshal.list
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc@gnome.org)
* Copyright (C) 2008, Nokia
*
* This program is free software; you can redistribute it and/or
* This library 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,
* 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
* 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
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* Authors: Philip Van Hoof <philip@codeminded.be>
*/
#include "config.h"
......@@ -30,17 +33,14 @@
#include <glib.h>
#include <glib/gprintf.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
#ifdef HAVE_GDKPIXBUF
#include <gdk-pixbuf/gdk-pixbuf.h>
#endif
#include <dbus/dbus-glib-bindings.h>
#include <libtracker-common/tracker-common.h>
#include <libtracker-common/tracker-thumbnailer.h>
#include "tracker-albumart.h"
......@@ -52,13 +52,10 @@
#define THUMBNAILER_PATH "/org/freedesktop/thumbnailer/Generic"
#define THUMBNAILER_INTERFACE "org.freedesktop.thumbnailer.Generic"
static void get_albumart_path (const gchar *a,
const gchar *b,
const gchar *prefix,
const gchar *uri,
gchar **path,
gchar **local);
typedef struct {
gchar *art_path;
gchar *local_uri;
} GetFileInfo;
static gchar *
my_compute_checksum_for_data (GChecksumType checksum_type,
......@@ -250,8 +247,8 @@ strip_characters (const gchar *original)
}
static void
perhaps_copy_to_local (const gchar *filename, const gchar *local_uri)
void
tracker_albumart_copy_to_local (const gchar *filename, const gchar *local_uri)
{
#ifdef HAVE_HAL
TrackerHal *hal;
......@@ -322,13 +319,13 @@ perhaps_copy_to_local (const gchar *filename, const gchar *local_uri)
}
}
static gboolean
heuristic_albumart (const gchar *artist_,
const gchar *album_,
const gchar *tracks_str,
const gchar *filename,
const gchar *local_uri,
gboolean *copied)
gboolean
tracker_albumart_heuristic (const gchar *artist_,
const gchar *album_,
const gchar *tracks_str,
const gchar *filename,
const gchar *local_uri,
gboolean *copied)
{
GFile *file;
GDir *dir;
......@@ -351,9 +348,9 @@ heuristic_albumart (const gchar *artist_,
if (g_file_query_exists (local_file, NULL)) {
get_albumart_path (artist, album,
"album", NULL,
&target, NULL);
tracker_albumart_get_path (artist, album,
"album", NULL,
&target, NULL);
file = g_file_new_for_path (target);
......@@ -424,9 +421,9 @@ heuristic_albumart (const gchar *artist_,
GFile *file_found;
if (!target) {
get_albumart_path (artist, album,
"album", NULL,
&target, NULL);
tracker_albumart_get_path (artist, album,
"album", NULL,
&target, NULL);
}
if (!file) {
......@@ -459,12 +456,12 @@ heuristic_albumart (const gchar *artist_,
retval = FALSE;
} else {
if (!target) {
get_albumart_path (artist,
album,
"album",
NULL,
&target,
NULL);
tracker_albumart_get_path (artist,
album,
"album",
NULL,
&target,
NULL);
}
gdk_pixbuf_save (pixbuf, target, "jpeg", &error, NULL);
......@@ -528,15 +525,11 @@ get_albumart_requester (void)
return albart_proxy;
}
typedef struct {
gchar *art_path, *local_uri;
} GetFileInfo;
static void
get_file_albumart_queue_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
tracker_albumart_queue_cb (DBusGProxy *proxy,
DBusGProxyCall *call,
gpointer user_data)
{
GError *error = NULL;
guint handle;
......@@ -552,7 +545,7 @@ get_file_albumart_queue_cb (DBusGProxy *proxy,
tracker_thumbnailer_get_file_thumbnail (asuri, "image/jpeg");
g_free (asuri);
perhaps_copy_to_local (info->art_path, info->local_uri);
tracker_albumart_copy_to_local (info->art_path, info->local_uri);
}
g_free (info->art_path);
......@@ -566,13 +559,13 @@ get_file_albumart_queue_cb (DBusGProxy *proxy,
}
}
static void
get_albumart_path (const gchar *a,
const gchar *b,
const gchar *prefix,
const gchar *uri,
gchar **path,
gchar **local)
void
tracker_albumart_get_path (const gchar *a,
const gchar *b,
const gchar *prefix,
const gchar *uri,
gchar **path,
gchar **local)
{
gchar *art_filename;
gchar *dir;
......@@ -625,158 +618,26 @@ get_albumart_path (const gchar *a,
g_free (str2);
}
#ifdef HAVE_GDKPIXBUF
static gboolean
set_albumart (const unsigned char *buffer,
size_t len,
const gchar *artist,
const gchar *album,
const gchar *uri)
void
tracker_albumart_request_download (gchar *album,
gchar *artist,
gchar *local_uri,
gchar *art_path)
{
GdkPixbufLoader *loader;
GdkPixbuf *pixbuf = NULL;
gchar *filename;
GError *error = NULL;
g_type_init ();
if (!artist && !album) {
g_warning ("No identification data for embedded image");
return FALSE;
}
get_albumart_path (artist, album, "album", NULL, &filename, NULL);
loader = gdk_pixbuf_loader_new ();
if (!gdk_pixbuf_loader_write (loader, buffer, len, &error)) {
g_warning ("%s\n", error->message);
g_error_free (error);
gdk_pixbuf_loader_close (loader, NULL);
g_free (filename);
return FALSE;
}
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
if (!gdk_pixbuf_save (pixbuf, filename, "jpeg", &error, NULL)) {
g_warning ("%s\n", error->message);
g_error_free (error);
g_free (filename);
g_object_unref (pixbuf);
gdk_pixbuf_loader_close (loader, NULL);
return FALSE;
}
g_object_unref (pixbuf);
if (!gdk_pixbuf_loader_close (loader, &error)) {
g_warning ("%s\n", error->message);
g_error_free (error);
}
tracker_thumbnailer_get_file_thumbnail (filename, "image/jpeg");
g_free (filename);
return TRUE;
}
#endif /* HAVE_GDKPIXBUF */
gboolean
tracker_process_albumart (const unsigned char *buffer,
size_t len,
const gchar *artist,
const gchar *album,
const gchar *trackercnt_str,
const gchar *filename)
{
gchar *art_path;
gboolean retval = TRUE;
gchar *local_uri = NULL;
gchar *filename_uri;
gboolean lcopied = FALSE;
if (strchr (filename, ':'))
filename_uri = g_strdup (filename);
else
filename_uri = g_filename_to_uri (filename, NULL, NULL);
get_albumart_path (artist, album, "album", filename_uri,
&art_path, &local_uri);
if (!g_file_test (art_path, G_FILE_TEST_EXISTS)) {
#ifdef HAVE_GDKPIXBUF
/* If we have embedded album art */
if (buffer && len) {
retval = set_albumart (buffer, len,
artist,
album,
filename);
lcopied = !retval;
} else {
#endif /* HAVE_GDK_PIXBUF */
/* If not, we perform a heuristic on the dir */
if (!heuristic_albumart (artist, album, trackercnt_str, filename, local_uri, &lcopied)) {
GetFileInfo *info;
/* If the heuristic failed, we request the download
* of the media-art to the media-art downloaders */
lcopied = TRUE;
info = g_slice_new (GetFileInfo);
info->local_uri = g_strdup (local_uri);
info->art_path = g_strdup (art_path);
dbus_g_proxy_begin_call (get_albumart_requester (),
"Queue",
get_file_albumart_queue_cb,
info, NULL,
G_TYPE_STRING, artist,
G_TYPE_STRING, album,
G_TYPE_STRING, "album",
G_TYPE_UINT, 0,
G_TYPE_INVALID);
}
#ifdef HAVE_GDKPIXBUF
}
#endif /* HAVE_GDKPIXBUF */
/* If the heuristic didn't copy from the .mediaartlocal, then
* we'll perhaps copy it to .mediaartlocal (perhaps because this
* only copies in case the media is located on a removable
* device */
if (g_file_test (art_path, G_FILE_TEST_EXISTS)) {
gchar *asuri = g_filename_to_uri (art_path, NULL, NULL);
tracker_thumbnailer_get_file_thumbnail (asuri, "image/jpeg");
g_free (asuri);
}
if (!lcopied && g_file_test (art_path, G_FILE_TEST_EXISTS))
perhaps_copy_to_local (art_path, local_uri);
}
g_free (art_path);
g_free (filename_uri);
g_free (local_uri);
return retval;
GetFileInfo *info;
info = g_slice_new (GetFileInfo);
info->local_uri = g_strdup (local_uri);
info->art_path = g_strdup (art_path);
dbus_g_proxy_begin_call (get_albumart_requester (),
"Queue",
tracker_albumart_queue_cb,
info, NULL,
G_TYPE_STRING, artist,
G_TYPE_STRING, album,
G_TYPE_STRING, "album",
G_TYPE_UINT, 0,
G_TYPE_INVALID);
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc@gnome.org)
* Copyright (C) 2008, Nokia
* This library 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 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
* General Public License for more details.
*
* You should have received a copy of the GNU 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.
*
* Authors: Philip Van Hoof <philip@codeminded.be>
*/
#ifndef __TRACKER_ALBUMART_H__
#define __TRACKER_ALBUMART_H__
G_BEGIN_DECLS
gboolean tracker_albumart_heuristic (const gchar *artist_,
const gchar *album_,
const gchar *tracks_str,
const gchar *filename,
const gchar *local_uri,
gboolean *copied);
void tracker_albumart_copy_to_local (const gchar *filename,
const gchar *local_uri);
void tracker_albumart_get_path (const gchar *a,
const gchar *b,
const gchar *prefix,
const gchar *uri,
gchar **path,
gchar **local);
void tracker_albumart_request_download (gchar *album,
gchar *artist,
gchar *local_uri,
gchar *art_path);
G_END_DECLS
#endif /* __TRACKER_THUMBNAILER_H__ */
......@@ -96,8 +96,8 @@ xmp_sources = \
albumart_libs =
albumart_flags =
albumart_sources = \
tracker-albumart.c \
tracker-albumart.h
tracker-extract-albumart.c \
tracker-extract-albumart.h
if HAVE_GDKPIXBUF
albumart_flags += $(DBUS_CFLAGS)
......@@ -234,4 +234,4 @@ dbus_sources = \
BUILT_SOURCES = \
$(dbus_sources)
CLEANFILES = $(BUILT_SOURCES)
\ No newline at end of file
CLEANFILES = $(BUILT_SOURCES)
/* -*- 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 <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <ctype.h>
#include <glib.h>
#include <glib/gprintf.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
#ifdef HAVE_GDKPIXBUF
#include <gdk-pixbuf/gdk-pixbuf.h>
#endif
#include <libtracker-common/tracker-common.h>
#include <libtracker-common/tracker-thumbnailer.h>
#include "tracker-extract-albumart.h"
#ifdef HAVE_GDKPIXBUF
static gboolean
set_albumart (const unsigned char *buffer,
size_t len,
const gchar *artist,
const gchar *album,
const gchar *uri)
{
GdkPixbufLoader *loader;
GdkPixbuf *pixbuf = NULL;
gchar *filename;
GError *error = NULL;
g_type_init ();
if (!artist && !album) {
g_warning ("No identification data for embedded image");
return FALSE;
}
tracker_albumart_get_path (artist, album, "album", NULL, &filename, NULL);
loader = gdk_pixbuf_loader_new ();
if (!gdk_pixbuf_loader_write (loader, buffer, len, &error)) {
g_warning ("%s\n", error->message);
g_error_free (error);
gdk_pixbuf_loader_close (loader, NULL);
g_free (filename);
return FALSE;
}
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
if (!gdk_pixbuf_save (pixbuf, filename, "jpeg", &error, NULL)) {
g_warning ("%s\n", error->message);
g_error_free (error);
g_free (filename);
g_object_unref (pixbuf);
gdk_pixbuf_loader_close (loader, NULL);
return FALSE;
}
g_object_unref (pixbuf);
if (!gdk_pixbuf_loader_close (loader, &error)) {
g_warning ("%s\n", error->message);
g_error_free (error);
}
tracker_thumbnailer_get_file_thumbnail (filename, "image/jpeg");
g_free (filename);
return TRUE;
}
#endif /* HAVE_GDKPIXBUF */
gboolean
tracker_process_albumart (const unsigned char *buffer,
size_t len,
const gchar *artist,
const gchar *album,
const gchar *trackercnt_str,
const gchar *filename)
{
gchar *art_path;
gboolean retval = TRUE;
gchar *local_uri = NULL;
gchar *filename_uri;
gboolean lcopied = FALSE;
if (strchr (filename, ':'))
filename_uri = g_strdup (filename);
else
filename_uri = g_filename_to_uri (filename, NULL, NULL);
tracker_albumart_get_path (artist, album, "album", filename_uri,
&art_path, &local_uri);
if (!g_file_test (art_path, G_FILE_TEST_EXISTS)) {
#ifdef HAVE_GDKPIXBUF
/* If we have embedded album art */
if (buffer && len) {
retval = set_albumart (buffer, len,
artist,
album,
filename);
lcopied = !retval;
} else {
#endif /* HAVE_GDK_PIXBUF */
/* If not, we perform a heuristic on the dir */
if (!tracker_albumart_heuristic (artist, album, trackercnt_str, filename, local_uri, &lcopied)) {
/* If the heuristic failed, we request the download
* of the media-art to the media-art downloaders */
lcopied = TRUE;
tracker_albumart_request_download (artist,
album,
local_uri,
art_path);
}
#ifdef HAVE_GDKPIXBUF
}
#endif /* HAVE_GDKPIXBUF */
/* If the heuristic didn't copy from the .mediaartlocal, then
* we'll perhaps copy it to .mediaartlocal (perhaps because this
* only copies in case the media is located on a removable
* device */
if (g_file_test (art_path, G_FILE_TEST_EXISTS)) {
gchar *asuri = g_filename_to_uri (art_path, NULL, NULL);
tracker_thumbnailer_get_file_thumbnail (asuri, "image/jpeg");
g_free (asuri);
}
if (!lcopied && g_file_test (art_path, G_FILE_TEST_EXISTS))
tracker_albumart_copy_to_local (art_path, local_uri);
}
g_free (art_path);
g_free (filename_uri);
g_free (local_uri);
return retval;
}
......@@ -22,6 +22,8 @@
#include <glib.h>
#include <libtracker-common/tracker-albumart.h>
G_BEGIN_DECLS
gboolean tracker_process_albumart (const unsigned char *buffer,
......
......@@ -34,7 +34,7 @@
#include <gst/tag/tag.h>
#include "tracker-main.h"
#include "tracker-albumart.h"
#include "tracker-extract-albumart.h"
typedef enum {
EXTRACT_MIME_UNDEFINED=0,
......
......@@ -65,7 +65,7 @@
#include <libtracker-common/tracker-type-utils.h>
#include "tracker-main.h"
#include "tracker-albumart.h"
#include "tracker-extract-albumart.h"
/*
* Some fluendo plugins use non-standard tag names currently which cause
......
......@@ -40,7 +40,7 @@
#endif /* G_OS_WIN32 */
#include "tracker-main.h"
#include "tracker-albumart.h"
#include "tracker-extract-albumart.h"
#include "tracker-escape.h"
/* FIXME The max file read is not a good idea as basic
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment