summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartyn Russell <martyn@lanedo.com>2014-02-06 18:58:21 +0000
committerMartyn Russell <martyn@lanedo.com>2014-02-06 18:58:21 +0000
commit87e54e21fc5b281dea34c0b554ca783a2bc638d4 (patch)
tree96ed257d89382317b94abec60f604ae0740bd829
parent187dfd467fa0e9611cdf116990f1eb2a3e8dbc3a (diff)
parent356b2700eeb602c01c08a04fc07c7ba9c26069c2 (diff)
downloadtracker-87e54e21fc5b281dea34c0b554ca783a2bc638d4.tar.gz
Merge branch 'use-libmediaart'
-rw-r--r--configure.ac18
-rw-r--r--src/libtracker-common/Makefile.am6
-rw-r--r--src/libtracker-common/tracker-common.h1
-rw-r--r--src/libtracker-common/tracker-media-art.c322
-rw-r--r--src/libtracker-common/tracker-media-art.h42
-rw-r--r--src/libtracker-miner/tracker-media-art.c19
-rw-r--r--src/tracker-extract/Makefile.am15
-rw-r--r--src/tracker-extract/tracker-extract-gstreamer.c41
-rw-r--r--src/tracker-extract/tracker-extract-libav.c14
-rw-r--r--src/tracker-extract/tracker-extract-mp3.c18
-rw-r--r--src/tracker-extract/tracker-extract-vorbis.c18
-rw-r--r--src/tracker-extract/tracker-main.c19
-rw-r--r--src/tracker-extract/tracker-media-art-dummy.c49
-rw-r--r--src/tracker-extract/tracker-media-art-generic.h42
-rw-r--r--src/tracker-extract/tracker-media-art-pixbuf.c176
-rw-r--r--src/tracker-extract/tracker-media-art-qt.cpp199
-rw-r--r--src/tracker-extract/tracker-media-art.c1128
-rw-r--r--src/tracker-extract/tracker-media-art.h47
-rw-r--r--tests/libtracker-common/Makefile.am3
-rw-r--r--tests/libtracker-common/tracker-media-art-test.c178
20 files changed, 83 insertions, 2272 deletions
diff --git a/configure.ac b/configure.ac
index a8d3175b8..98cf9960a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -200,6 +200,7 @@ NETWORK_MANAGER_REQUIRED=0.8
GSTREAMER_REQUIRED=0.10.31
GUPNP_DLNA_REQUIRED=0.9.4
LIBPNG_REQUIRED=0.89
+LIBMEDIAART_REQUIRED=0.1.0
# 3.6.11 for sqlite_backup API
# 3.6.16 to fix test failures
@@ -228,8 +229,9 @@ LIBTRACKER_BUS_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
PKG_CHECK_MODULES(LIBTRACKER_BUS, [$LIBTRACKER_BUS_REQUIRED])
# Check requirements for libtracker-common
-LIBTRACKER_COMMON_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
- gio-unix-2.0 >= $GLIB_REQUIRED"
+LIBTRACKER_COMMON_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
+ gio-unix-2.0 >= $GLIB_REQUIRED
+ libmediaart-1.0 >= $LIBMEDIAART_REQUIRED"
PKG_CHECK_MODULES(LIBTRACKER_COMMON, [$LIBTRACKER_COMMON_REQUIRED])
@@ -269,8 +271,9 @@ LIBTRACKER_FTS_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
PKG_CHECK_MODULES(LIBTRACKER_FTS, [$LIBTRACKER_FTS_REQUIRED])
# Check requirements for libtracker-miner
-LIBTRACKER_MINER_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
- gio-unix-2.0 >= $GLIB_REQUIRED"
+LIBTRACKER_MINER_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
+ gio-unix-2.0 >= $GLIB_REQUIRED
+ libmediaart-1.0 >= $LIBMEDIAART_REQUIRED"
PKG_CHECK_MODULES(LIBTRACKER_MINER, [$LIBTRACKER_MINER_REQUIRED])
@@ -306,9 +309,10 @@ PKG_CHECK_MODULES(TRACKER_STORE, [$TRACKER_STORE_REQUIRED])
TRACKER_STORE_LIBS="$TRACKER_STORE_LIBS -lz -lm"
# Check requirements for tracker-extract
-TRACKER_EXTRACT_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
- gio-unix-2.0 >= $GLIB_REQUIRED
- gmodule-2.0 >= $GLIB_REQUIRED"
+TRACKER_EXTRACT_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
+ gio-unix-2.0 >= $GLIB_REQUIRED
+ gmodule-2.0 >= $GLIB_REQUIRED
+ libmediaart-1.0 >= $LIBMEDIAART_REQUIRED"
PKG_CHECK_MODULES(TRACKER_EXTRACT, [$TRACKER_EXTRACT_REQUIRED])
diff --git a/src/libtracker-common/Makefile.am b/src/libtracker-common/Makefile.am
index 1ef66bf60..69b9ce128 100644
--- a/src/libtracker-common/Makefile.am
+++ b/src/libtracker-common/Makefile.am
@@ -29,8 +29,7 @@ libtracker_common_la_SOURCES = \
tracker-type-utils.c \
tracker-utils.c \
tracker-crc32.c \
- tracker-locale.c \
- tracker-media-art.c
+ tracker-locale.c
noinst_HEADERS = \
tracker-dbus.h \
@@ -48,8 +47,7 @@ noinst_HEADERS = \
tracker-type-utils.h \
tracker-utils.h \
tracker-crc32.h \
- tracker-locale.h \
- tracker-media-art.h
+ tracker-locale.h
if HAVE_TRACKER_FTS
libtracker_common_la_SOURCES += tracker-language.c
diff --git a/src/libtracker-common/tracker-common.h b/src/libtracker-common/tracker-common.h
index cc183e716..e5616b027 100644
--- a/src/libtracker-common/tracker-common.h
+++ b/src/libtracker-common/tracker-common.h
@@ -36,7 +36,6 @@
#include "tracker-keyfile-object.h"
#include "tracker-language.h"
#include "tracker-log.h"
-#include "tracker-media-art.h"
#include "tracker-ontologies.h"
#include "tracker-os-dependant.h"
#include "tracker-sched.h"
diff --git a/src/libtracker-common/tracker-media-art.c b/src/libtracker-common/tracker-media-art.c
deleted file mode 100644
index c59982d19..000000000
--- a/src/libtracker-common/tracker-media-art.c
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * Copyright (C) 2008, 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 <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <utime.h>
-#include <time.h>
-
-#include <glib.h>
-#include <glib/gprintf.h>
-#include <glib/gstdio.h>
-#include <gio/gio.h>
-
-#include "tracker-file-utils.h"
-#include "tracker-date-time.h"
-#include "tracker-media-art.h"
-
-static gboolean
-media_art_strip_find_next_block (const gchar *original,
- const gunichar open_char,
- const gunichar close_char,
- gint *open_pos,
- gint *close_pos)
-{
- const gchar *p1, *p2;
-
- if (open_pos) {
- *open_pos = -1;
- }
-
- if (close_pos) {
- *close_pos = -1;
- }
-
- p1 = g_utf8_strchr (original, -1, open_char);
- if (p1) {
- if (open_pos) {
- *open_pos = p1 - original;
- }
-
- p2 = g_utf8_strchr (g_utf8_next_char (p1), -1, close_char);
- if (p2) {
- if (close_pos) {
- *close_pos = p2 - original;
- }
-
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-/**
- * tracker_media_art_strip_invalid_entities:
- * @original: original string
- *
- * Strip a albumname or artistname string to prepare it for calculating the
- * media art path with it. Certain characters and charactersets will be stripped
- * and a newly allocated string returned which you must free with g_free.
- *
- * Returns: copy of original but then stripped
- *
- * Since: 0.10.14
- */
-gchar *
-tracker_media_art_strip_invalid_entities (const gchar *original)
-{
- GString *str_no_blocks;
- gchar **strv;
- gchar *str;
- gboolean blocks_done = FALSE;
- const gchar *p;
- const gchar *invalid_chars = "()[]<>{}_!@#$^&*+=|\\/\"'?~";
- const gchar *invalid_chars_delimiter = "*";
- const gchar *convert_chars = "\t";
- const gchar *convert_chars_delimiter = " ";
- const gunichar blocks[5][2] = {
- { '(', ')' },
- { '{', '}' },
- { '[', ']' },
- { '<', '>' },
- { 0, 0 }
- };
-
- str_no_blocks = g_string_new ("");
-
- p = original;
-
- while (!blocks_done) {
- gint pos1, pos2, i;
-
- pos1 = -1;
- pos2 = -1;
-
- for (i = 0; blocks[i][0] != 0; i++) {
- gint start, end;
-
- /* Go through blocks, find the earliest block we can */
- if (media_art_strip_find_next_block (p, blocks[i][0], blocks[i][1], &start, &end)) {
- if (pos1 == -1 || start < pos1) {
- pos1 = start;
- pos2 = end;
- }
- }
- }
-
- /* If either are -1 we didn't find any */
- if (pos1 == -1) {
- /* This means no blocks were found */
- g_string_append (str_no_blocks, p);
- blocks_done = TRUE;
- } else {
- /* Append the test BEFORE the block */
- if (pos1 > 0) {
- g_string_append_len (str_no_blocks, p, pos1);
- }
-
- p = g_utf8_next_char (p + pos2);
-
- /* Do same again for position AFTER block */
- if (*p == '\0') {
- blocks_done = TRUE;
- }
- }
- }
-
- /* Now convert chars to lower case */
- str = g_utf8_strdown (str_no_blocks->str, -1);
- g_string_free (str_no_blocks, TRUE);
-
- /* Now strip invalid chars */
- g_strdelimit (str, invalid_chars, *invalid_chars_delimiter);
- strv = g_strsplit (str, invalid_chars_delimiter, -1);
- g_free (str);
- str = g_strjoinv (NULL, strv);
- g_strfreev (strv);
-
- /* Now convert chars */
- g_strdelimit (str, convert_chars, *convert_chars_delimiter);
- strv = g_strsplit (str, convert_chars_delimiter, -1);
- g_free (str);
- str = g_strjoinv (convert_chars_delimiter, strv);
- g_strfreev (strv);
-
- while (g_strrstr (str, " ") != NULL) {
- /* Now remove double spaces */
- strv = g_strsplit (str, " ", -1);
- g_free (str);
- str = g_strjoinv (" ", strv);
- g_strfreev (strv);
- }
-
- /* Now strip leading/trailing white space */
- g_strstrip (str);
-
- return str;
-}
-
-static gchar *
-media_art_checksum_for_data (GChecksumType checksum_type,
- const guchar *data,
- gsize length)
-{
- GChecksum *checksum;
- gchar *retval;
-
- checksum = g_checksum_new (checksum_type);
- if (!checksum) {
- return NULL;
- }
-
- g_checksum_update (checksum, data, length);
- retval = g_strdup (g_checksum_get_string (checksum));
- g_checksum_free (checksum);
-
- return retval;
-}
-
-/**
- * tracker_media_art_get_path:
- * @artist: the artist
- * @title: the title
- * @prefix: For example "album"
- * @uri: NULL or the uri of the file
- * @path: the location to store the local path
- * @local_uri: the location to store the local uri or NULL
- *
- * Get the path to media art for a given resource. Newly allocated data in
- * @path and @local_uri must be freed with g_free.
- *
- * Since: 0.10.14
- */
-void
-tracker_media_art_get_path (const gchar *artist,
- const gchar *title,
- const gchar *prefix,
- const gchar *uri,
- gchar **path,
- gchar **local_uri)
-{
- const gchar *space_checksum = "7215ee9c7d9dc229d2921a40e899ec5f";
-
- gchar *art_filename;
- gchar *dir;
- gchar *artist_down, *title_down;
- gchar *artist_stripped, *title_stripped;
- gchar *artist_norm, *title_norm;
- gchar *artist_checksum = NULL, *title_checksum = NULL;
-
- /* http://live.gnome.org/MediaArtStorageSpec */
-
- if (path) {
- *path = NULL;
- }
-
- if (local_uri) {
- *local_uri = NULL;
- }
-
- if (!artist && !title) {
- return;
- }
-
- if (artist) {
- artist_stripped = tracker_media_art_strip_invalid_entities (artist);
- artist_norm = g_utf8_normalize (artist_stripped, -1, G_NORMALIZE_NFKD);
- artist_down = g_utf8_strdown (artist_norm, -1);
- artist_checksum = media_art_checksum_for_data (G_CHECKSUM_MD5,
- (const guchar *) artist_down,
- strlen (artist_down));
- }
-
- if (title) {
- title_stripped = tracker_media_art_strip_invalid_entities (title);
- title_norm = g_utf8_normalize (title_stripped, -1, G_NORMALIZE_NFKD);
- title_down = g_utf8_strdown (title_norm, -1);
- title_checksum = media_art_checksum_for_data (G_CHECKSUM_MD5,
- (const guchar *) title_down,
- strlen (title_down));
- }
-
- dir = g_build_filename (g_get_user_cache_dir (),
- "media-art",
- NULL);
-
- if (!g_file_test (dir, G_FILE_TEST_EXISTS)) {
- g_mkdir_with_parents (dir, 0770);
- }
-
- art_filename = g_strdup_printf ("%s-%s-%s.jpeg",
- prefix ? prefix : "album",
- artist ? artist_checksum : space_checksum,
- title ? title_checksum : space_checksum);
-
- if (artist) {
- g_free (artist_checksum);
- g_free (artist_stripped);
- g_free (artist_down);
- g_free (artist_norm);
- }
-
- if (title) {
- g_free (title_checksum);
- g_free (title_stripped);
- g_free (title_down);
- g_free (title_norm);
- }
-
- if (path) {
- *path = g_build_filename (dir, art_filename, NULL);
- }
-
- if (local_uri) {
- gchar *local_dir;
- GFile *file, *parent;
-
- if (strstr (uri, "://")) {
- file = g_file_new_for_uri (uri);
- } else {
- file = g_file_new_for_path (uri);
- }
-
- parent = g_file_get_parent (file);
- if (parent) {
- local_dir = g_file_get_uri (parent);
-
- /* This is a URI, don't use g_build_filename here */
- *local_uri = g_strdup_printf ("%s/.mediaartlocal/%s", local_dir, art_filename);
-
- g_free (local_dir);
- g_object_unref (parent);
- }
- g_object_unref (file);
- }
-
- g_free (dir);
- g_free (art_filename);
-}
diff --git a/src/libtracker-common/tracker-media-art.h b/src/libtracker-common/tracker-media-art.h
deleted file mode 100644
index 73ffa0c97..000000000
--- a/src/libtracker-common/tracker-media-art.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2010 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.
- */
-
-#ifndef __LIBTRACKER_COMMON_MEDIA_ART_H__
-#define __LIBTRACKER_COMMON_MEDIA_ART_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION)
-#error "only <libtracker-common/tracker-common.h> must be included directly."
-#endif
-
-gchar * tracker_media_art_strip_invalid_entities (const gchar *original);
-void tracker_media_art_get_path (const gchar *artist,
- const gchar *album,
- const gchar *prefix,
- const gchar *uri,
- gchar **path,
- gchar **local_uri);
-
-
-G_END_DECLS
-
-#endif /* __LIBTRACKER_COMMON_MEDIA_ART_H__ */
diff --git a/src/libtracker-miner/tracker-media-art.c b/src/libtracker-miner/tracker-media-art.c
index fb92d24d5..b1abefc5a 100644
--- a/src/libtracker-miner/tracker-media-art.c
+++ b/src/libtracker-miner/tracker-media-art.c
@@ -24,7 +24,8 @@
#include <glib.h>
#include <glib/gstdio.h>
-#include <libtracker-common/tracker-media-art.h>
+#include <libmediaart/mediaart.h>
+
#include <libtracker-sparql/tracker-sparql.h>
#include "tracker-media-art.h"
@@ -90,18 +91,18 @@ on_query_finished (GObject *source_object,
artist = tracker_sparql_cursor_get_value_type (cursor, 1) != TRACKER_SPARQL_VALUE_TYPE_UNBOUND ? tracker_sparql_cursor_get_string (cursor, 1, NULL) : NULL;
/* The get_path API does stripping itself */
- tracker_media_art_get_path (artist,
- album,
- "album", NULL,
- &target, NULL);
+ media_art_get_path (artist,
+ album,
+ "album", NULL,
+ &target, NULL);
g_hash_table_replace (table, target, target);
/* Also add the file to which the symlinks are made */
- tracker_media_art_get_path (NULL,
- album,
- "album", NULL,
- &album_path, NULL);
+ media_art_get_path (NULL,
+ album,
+ "album", NULL,
+ &album_path, NULL);
g_hash_table_replace (table, album_path, album_path);
diff --git a/src/tracker-extract/Makefile.am b/src/tracker-extract/Makefile.am
index b8da1517c..feb296e8d 100644
--- a/src/tracker-extract/Makefile.am
+++ b/src/tracker-extract/Makefile.am
@@ -526,13 +526,10 @@ tracker_extract_SOURCES = \
tracker-extract.h \
tracker-extract-decorator.c \
tracker-extract-decorator.h \
- tracker-media-art.c \
- tracker-media-art.h \
tracker-read.c \
tracker-read.h \
tracker-main.c \
- tracker-main.h \
- tracker-media-art-generic.h
+ tracker-main.h
tracker_extract_LDADD = \
$(top_builddir)/src/libtracker-extract/libtracker-extract-@TRACKER_API_VERSION@.la \
@@ -553,15 +550,5 @@ if HAVE_LIBSTREAMANALYZER
tracker_extract_SOURCES += tracker-topanalyzer.cpp tracker-topanalyzer.h
endif
-if HAVE_GDKPIXBUF
-tracker_extract_SOURCES += tracker-media-art-pixbuf.c
-else
-if HAVE_QT
-tracker_extract_SOURCES += tracker-media-art-qt.cpp
-else
-tracker_extract_SOURCES += tracker-media-art-dummy.c
-endif
-endif
-
EXTRA_DIST = \
$(rules_files)
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index 59826ee0b..6a7a909ab 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -51,10 +51,11 @@
#include <gst/gst.h>
#include <gst/tag/tag.h>
+#include <libmediaart/mediaart.h>
+
#include <libtracker-common/tracker-common.h>
#include <libtracker-extract/tracker-extract.h>
-#include "tracker-media-art.h"
#include "tracker-cue-sheet.h"
/* We wait this long (seconds) for NULL state before freeing */
@@ -106,13 +107,13 @@ typedef struct {
GSList *artist_list;
- TrackerMediaArtType media_art_type;
- gchar *media_art_artist;
- gchar *media_art_title;
+ MediaArtType media_art_type;
+ gchar *media_art_artist;
+ gchar *media_art_title;
- unsigned char *media_art_buffer;
- guint media_art_buffer_size;
- const gchar *media_art_buffer_mime;
+ unsigned char *media_art_buffer;
+ guint media_art_buffer_size;
+ const gchar *media_art_buffer_mime;
GstSample *sample;
GstMapInfo info;
@@ -727,7 +728,7 @@ extractor_apply_general_metadata (MetadataExtractor *extractor,
add_string_gst_tag (metadata, "dc:coverage", tag_list, GST_TAG_LOCATION);
add_string_gst_tag (metadata, "nie:comment", tag_list, GST_TAG_COMMENT);
- if (extractor->media_art_type == TRACKER_MEDIA_ART_VIDEO) {
+ if (extractor->media_art_type == MEDIA_ART_VIDEO) {
extractor->media_art_title = title_guaranteed;
} else {
g_free (title_guaranteed);
@@ -1103,7 +1104,7 @@ extract_metadata (MetadataExtractor *extractor,
g_return_if_fail (postupdate != NULL);
g_return_if_fail (metadata != NULL);
- extractor->media_art_type = TRACKER_MEDIA_ART_NONE;
+ extractor->media_art_type = MEDIA_ART_NONE;
if (extractor->toc) {
gst_tag_list_insert (extractor->tagcache,
@@ -1148,11 +1149,11 @@ extract_metadata (MetadataExtractor *extractor,
if (extractor->toc == NULL || extractor->toc->entry_list == NULL)
tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
- extractor->media_art_type = TRACKER_MEDIA_ART_ALBUM;
+ extractor->media_art_type = MEDIA_ART_ALBUM;
} else if (extractor->mime == EXTRACT_MIME_VIDEO) {
tracker_sparql_builder_object (metadata, "nmm:Video");
- extractor->media_art_type = TRACKER_MEDIA_ART_VIDEO;
+ extractor->media_art_type = MEDIA_ART_VIDEO;
} else {
tracker_sparql_builder_object (metadata, "nfo:Image");
@@ -2039,7 +2040,7 @@ tracker_extract_gstreamer (const gchar *uri,
extractor = g_slice_new0 (MetadataExtractor);
extractor->mime = type;
extractor->tagcache = gst_tag_list_new_empty ();
- extractor->media_art_type = TRACKER_MEDIA_ART_NONE;
+ extractor->media_art_type = MEDIA_ART_NONE;
g_debug ("GStreamer backend in use:");
@@ -2074,14 +2075,14 @@ tracker_extract_gstreamer (const gchar *uri,
metadata,
graph);
- if (extractor->media_art_type != TRACKER_MEDIA_ART_NONE) {
- tracker_media_art_process (extractor->media_art_buffer,
- extractor->media_art_buffer_size,
- extractor->media_art_buffer_mime,
- extractor->media_art_type,
- extractor->media_art_artist,
- extractor->media_art_title,
- uri);
+ if (extractor->media_art_type != MEDIA_ART_NONE) {
+ media_art_process (extractor->media_art_buffer,
+ extractor->media_art_buffer_size,
+ extractor->media_art_buffer_mime,
+ extractor->media_art_type,
+ extractor->media_art_artist,
+ extractor->media_art_title,
+ uri);
}
}
diff --git a/src/tracker-extract/tracker-extract-libav.c b/src/tracker-extract/tracker-extract-libav.c
index 43f3ba1f7..fea30a389 100644
--- a/src/tracker-extract/tracker-extract-libav.c
+++ b/src/tracker-extract/tracker-extract-libav.c
@@ -327,13 +327,13 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
g_free (album_uri);
}
- tracker_media_art_process (NULL,
- 0,
- NULL,
- TRACKER_MEDIA_ART_ALBUM,
- album_artist,
- album_title,
- uri);
+ media_art_process (NULL,
+ 0,
+ NULL,
+ MEDIA_ART_ALBUM,
+ album_artist,
+ album_title,
+ uri);
g_free(performer_uri);
}
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index 04084e48a..da4a87a07 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -40,12 +40,12 @@
#include <sys/mman.h>
#endif /* G_OS_WIN32 */
+#include <libmediaart/mediaart.h>
+
#include <libtracker-common/tracker-common.h>
#include <libtracker-extract/tracker-extract.h>
-#include "tracker-media-art.h"
-
#ifdef FRAME_ENABLE_TRACE
#warning Frame traces enabled
#endif /* FRAME_ENABLE_TRACE */
@@ -2487,13 +2487,13 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
/* Get mp3 stream info */
mp3_parse (buffer, buffer_size, audio_offset, uri, metadata, &md);
- tracker_media_art_process (md.media_art_data,
- md.media_art_size,
- md.media_art_mime,
- TRACKER_MEDIA_ART_ALBUM,
- md.performer,
- md.album,
- uri);
+ media_art_process (md.media_art_data,
+ md.media_art_size,
+ md.media_art_mime,
+ MEDIA_ART_ALBUM,
+ md.performer,
+ md.album,
+ uri);
g_free (md.media_art_data);
g_free (md.media_art_mime);
diff --git a/src/tracker-extract/tracker-extract-vorbis.c b/src/tracker-extract/tracker-extract-vorbis.c
index 175008e89..27df41364 100644
--- a/src/tracker-extract/tracker-extract-vorbis.c
+++ b/src/tracker-extract/tracker-extract-vorbis.c
@@ -28,12 +28,12 @@
#include <vorbis/vorbisfile.h>
+#include <libmediaart/mediaart.h>
+
#include <libtracker-common/tracker-common.h>
#include <libtracker-extract/tracker-extract.h>
-#include "tracker-media-art.h"
-
typedef struct {
const gchar *creator;
gchar *creator_uri;
@@ -512,13 +512,13 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
}
uri = g_file_get_uri (file);
- tracker_media_art_process (NULL,
- 0,
- NULL,
- TRACKER_MEDIA_ART_ALBUM,
- vd.album_artist ? vd.album_artist : vd.artist,
- vd.album,
- uri);
+ media_art_process (NULL,
+ 0,
+ NULL,
+ MEDIA_ART_ALBUM,
+ vd.album_artist ? vd.album_artist : vd.artist,
+ vd.album,
+ uri);
g_free (uri);
g_free (vd.artist);
diff --git a/src/tracker-extract/tracker-main.c b/src/tracker-extract/tracker-main.c
index ac7bd3266..a41607f5c 100644
--- a/src/tracker-extract/tracker-main.c
+++ b/src/tracker-extract/tracker-main.c
@@ -38,6 +38,8 @@
#include <sys/resource.h>
#endif
+#include <libmediaart/mediaart.h>
+
#include <libtracker-common/tracker-log.h>
#include <libtracker-common/tracker-dbus.h>
#include <libtracker-common/tracker-os-dependant.h>
@@ -47,7 +49,6 @@
#include <libtracker-data/tracker-db-manager.h>
-#include "tracker-media-art.h"
#include "tracker-config.h"
#include "tracker-main.h"
#include "tracker-extract.h"
@@ -270,7 +271,10 @@ run_standalone (TrackerConfig *config)
}
tracker_locale_init ();
- tracker_media_art_init ();
+
+ if (!media_art_init ()) {
+ g_warning ("Could not initialize media art, will not be available");
+ }
/* This makes sure we don't steal all the system's resources */
initialize_priority_and_scheduling (tracker_config_get_sched_idle (config),
@@ -286,7 +290,7 @@ run_standalone (TrackerConfig *config)
if (!object) {
g_object_unref (file);
g_free (uri);
- tracker_media_art_shutdown ();
+ media_art_shutdown ();
tracker_locale_shutdown ();
return EXIT_FAILURE;
}
@@ -299,7 +303,7 @@ run_standalone (TrackerConfig *config)
g_object_unref (file);
g_free (uri);
- tracker_media_art_shutdown ();
+ media_art_shutdown ();
tracker_locale_shutdown ();
return EXIT_SUCCESS;
@@ -420,7 +424,10 @@ main (int argc, char *argv[])
#endif /* THREAD_ENABLE_TRACE */
tracker_locale_init ();
- tracker_media_art_init ();
+
+ if (!media_art_init ()) {
+ g_warning ("Could not initialize media art, will not be available");
+ }
tracker_miner_start (TRACKER_MINER (decorator));
@@ -435,7 +442,7 @@ main (int argc, char *argv[])
tracker_miner_stop (TRACKER_MINER (decorator));
/* Shutdown subsystems */
- tracker_media_art_shutdown ();
+ media_art_shutdown ();
tracker_locale_shutdown ();
g_object_unref (extract);
diff --git a/src/tracker-extract/tracker-media-art-dummy.c b/src/tracker-extract/tracker-media-art-dummy.c
deleted file mode 100644
index 64462b7d1..000000000
--- a/src/tracker-extract/tracker-media-art-dummy.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2008, 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.
- *
- * Authors:
- * Philip Van Hoof <philip@codeminded.be>
- */
-
-#include "tracker-media-art-generic.h"
-
-void
-tracker_media_art_plugin_init (void)
-{
-}
-
-void
-tracker_media_art_plugin_shutdown (void)
-{
-}
-
-gboolean
-tracker_media_art_file_to_jpeg (const gchar *filename,
- const gchar *target)
-{
- return FALSE;
-}
-
-gboolean
-tracker_media_art_buffer_to_jpeg (const unsigned char *buffer,
- size_t len,
- const gchar *buffer_mime,
- const gchar *target)
-{
- return FALSE;
-}
diff --git a/src/tracker-extract/tracker-media-art-generic.h b/src/tracker-extract/tracker-media-art-generic.h
deleted file mode 100644
index 53bbab620..000000000
--- a/src/tracker-extract/tracker-media-art-generic.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2008, 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.
- *
- * Authors:
- * Philip Van Hoof <philip@codeminded.be>
- */
-
-#ifndef __TRACKER_MEDIA_ART_GENERIC_H__
-#define __TRACKER_MEDIA_ART_GENERIC_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-void tracker_media_art_plugin_init (void);
-void tracker_media_art_plugin_shutdown (void);
-
-gboolean tracker_media_art_file_to_jpeg (const gchar *filename,
- const gchar *target);
-gboolean tracker_media_art_buffer_to_jpeg (const unsigned char *buffer,
- size_t len,
- const gchar *buffer_mime,
- const gchar *target);
-
-G_END_DECLS
-
-#endif /* __TRACKER_MEDIA_ART_GENERIC_H__ */
diff --git a/src/tracker-extract/tracker-media-art-pixbuf.c b/src/tracker-extract/tracker-media-art-pixbuf.c
deleted file mode 100644
index 3ed7684f3..000000000
--- a/src/tracker-extract/tracker-media-art-pixbuf.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright (C) 2008, 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.
- *
- * Authors:
- * Philip Van Hoof <philip@codeminded.be>
- */
-
-#include <gdk-pixbuf/gdk-pixbuf.h>
-
-#include "tracker-media-art-generic.h"
-
-#include "tracker-main.h"
-
-void
-tracker_media_art_plugin_init (void)
-{
-}
-
-void
-tracker_media_art_plugin_shutdown (void)
-{
-}
-
-gboolean
-tracker_media_art_file_to_jpeg (const gchar *filename,
- const gchar *target)
-{
- GdkPixbuf *pixbuf;
- GError *error = NULL;
- TrackerConfig *config = tracker_main_get_config ();
- gint max_media_art_width = tracker_config_get_max_media_art_width (config);
-
- if (max_media_art_width < 0) {
- g_debug ("Not saving album art from file, disabled in config");
- return TRUE;
- }
-
- /* TODO: Add resizing support */
-
- pixbuf = gdk_pixbuf_new_from_file (filename, &error);
-
- if (error) {
- g_clear_error (&error);
-
- return FALSE;
- } else {
- gdk_pixbuf_save (pixbuf, target, "jpeg", &error, NULL);
- g_object_unref (pixbuf);
-
- if (error) {
- g_clear_error (&error);
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-static void
-size_prepared_cb (GdkPixbufLoader *loader,
- gint width,
- gint height,
- gpointer user_data)
-{
- TrackerConfig *config = tracker_main_get_config ();
- gint max_media_art_width = tracker_config_get_max_media_art_width (config);
- gfloat scale;
-
- if (max_media_art_width < 1 || width <= max_media_art_width) {
- return;
- }
-
- g_debug ("Resizing media art to %d width", max_media_art_width);
-
- scale = width / (gfloat) max_media_art_width;
-
- gdk_pixbuf_loader_set_size (loader, (gint) (width / scale), (gint) (height / scale));
-}
-
-gboolean
-tracker_media_art_buffer_to_jpeg (const unsigned char *buffer,
- size_t len,
- const gchar *buffer_mime,
- const gchar *target)
-{
- TrackerConfig *config = tracker_main_get_config ();
- gint max_media_art_width = tracker_config_get_max_media_art_width (config);
-
- if (max_media_art_width < 0) {
- g_debug ("Not saving album art from buffer, disabled in config");
- return TRUE;
- }
-
- /* FF D8 FF are the three first bytes of JPeg images */
- if (max_media_art_width == 0 &&
- (g_strcmp0 (buffer_mime, "image/jpeg") == 0 ||
- g_strcmp0 (buffer_mime, "JPG") == 0) &&
- (buffer && len > 2 && buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff)) {
- g_debug ("Saving album art using raw data as uri:'%s'", target);
- g_file_set_contents (target, buffer, (gssize) len, NULL);
- } else {
- GdkPixbuf *pixbuf;
- GdkPixbufLoader *loader;
- GError *error = NULL;
-
- g_debug ("Saving album art using GdkPixbufLoader for uri:'%s' (max width:%d)",
- target,
- max_media_art_width);
-
- loader = gdk_pixbuf_loader_new ();
- if (max_media_art_width > 0) {
- g_signal_connect (loader,
- "size-prepared",
- G_CALLBACK (size_prepared_cb),
- NULL);
- }
-
- if (!gdk_pixbuf_loader_write (loader, buffer, len, &error)) {
- g_warning ("Could not write with GdkPixbufLoader when setting album art, %s",
- error ? error->message : "no error given");
-
- g_clear_error (&error);
- gdk_pixbuf_loader_close (loader, NULL);
- g_object_unref (loader);
-
- return FALSE;
- }
-
- pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
-
- if (pixbuf == NULL) {
- g_warning ("Could not get pixbuf from GdkPixbufLoader when setting album art");
-
- gdk_pixbuf_loader_close (loader, NULL);
- g_object_unref (loader);
-
- return FALSE;
- }
-
- if (!gdk_pixbuf_save (pixbuf, target, "jpeg", &error, NULL)) {
- g_warning ("Could not save GdkPixbuf when setting album art, %s",
- error ? error->message : "no error given");
-
- g_clear_error (&error);
- gdk_pixbuf_loader_close (loader, NULL);
- g_object_unref (loader);
-
- return FALSE;
- }
-
- if (!gdk_pixbuf_loader_close (loader, &error)) {
- g_warning ("Could not close GdkPixbufLoader when setting album art, %s",
- error ? error->message : "no error given");
- g_clear_error (&error);
- }
-
- g_object_unref (loader);
- }
-
- return TRUE;
-}
diff --git a/src/tracker-extract/tracker-media-art-qt.cpp b/src/tracker-extract/tracker-media-art-qt.cpp
deleted file mode 100644
index 47a3ef516..000000000
--- a/src/tracker-extract/tracker-media-art-qt.cpp
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright (C) 2010, Nokia
- *
- * 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.
- *
- * Authors:
- * Philip Van Hoof <philip@codeminded.be>
- */
-
-#include "config.h"
-
-#include "tracker-main.h"
-
-#include <QFile>
-#include <QBuffer>
-#include <QImageReader>
-#include <QImageWriter>
-#ifdef HAVE_QT5
-#include <QGuiApplication>
-#else
-#include <QApplication>
-#endif
-#include <QColor>
-#include <QPainter>
-
-#include <glib.h>
-
-#ifdef HAVE_NEMO
-#include <stdlib.h>
-#endif
-
-#include "tracker-media-art-generic.h"
-
-G_BEGIN_DECLS
-
-#ifdef HAVE_QT5
-static QGuiApplication *app = NULL;
-#else /* HAVE_QT4 */
-static QApplication *app = NULL
-#endif
-
-void
-tracker_media_art_plugin_init (void)
-{
- int argc = 1;
- char *argv[2] = { (char*) "tracker-extract", NULL };
-
-#ifdef HAVE_QT5
-
-#ifdef HAVE_NEMO
- g_setenv("QT_QPA_PLATFORM", "minimal", 1);
-#endif
-
- app = new QGuiApplication (argc, argv);
-#else /* HAVE_QT4 */
- app = new QApplication (argc, argv, QApplication::Tty);
-#endif
-}
-
-void
-tracker_media_art_plugin_shutdown (void)
-{
- // Apparently isn't destructing a QApplication something you should do, as
- // QApplication is designed to work on stack of the main() function.
-
- // delete app;
-}
-
-gboolean
-tracker_media_art_file_to_jpeg (const gchar *filename,
- const gchar *target)
-{
- TrackerConfig *config = tracker_main_get_config ();
- gint max_media_art_width = tracker_config_get_max_media_art_width (config);
-
- if (max_media_art_width < 0) {
- g_debug ("Not saving album art from file, disabled in config");
- return TRUE;
- }
-
- /* TODO: Add resizing support */
-
- QFile file (filename);
-
- if (!file.open (QIODevice::ReadOnly)) {
- g_message ("Could not get QFile from file: '%s'", filename);
- return FALSE;
- }
-
- QByteArray array = file.readAll ();
- QBuffer buffer (&array);
-
- buffer.open (QIODevice::ReadOnly);
-
- QImageReader reader (&buffer);
-
- if (!reader.canRead ()) {
- g_message ("Could not get QImageReader from file: '%s', reader.canRead was FALSE",
- filename);
- return FALSE;
- }
-
- QImage image1;
- image1 = reader.read ();
-
- if (image1.hasAlphaChannel ()) {
- QImage image2 (image1.size(), QImage::Format_RGB32);
- image2.fill (QColor(Qt::black).rgb());
- QPainter painter (&image2);
- painter.drawImage (0, 0, image1);
- image2.save (QString (target), "jpeg");
- } else {
- image1.save (QString (target), "jpeg");
- }
-
- return TRUE;
-}
-
-gboolean
-tracker_media_art_buffer_to_jpeg (const unsigned char *buffer,
- size_t len,
- const gchar *buffer_mime,
- const gchar *target)
-{
- TrackerConfig *config = tracker_main_get_config ();
- gint max_media_art_width = tracker_config_get_max_media_art_width (config);
-
- if (max_media_art_width < 0) {
- g_debug ("Not saving album art from buffer, disabled in config");
- return TRUE;
- }
-
- /* FF D8 FF are the three first bytes of JPeg images */
- if (max_media_art_width == 0 &&
- (g_strcmp0 (buffer_mime, "image/jpeg") == 0 ||
- g_strcmp0 (buffer_mime, "JPG") == 0) &&
- (buffer && len > 2 && buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff)) {
- g_debug ("Saving album art using raw data as uri:'%s'",
- target);
- g_file_set_contents (target, (const gchar*) buffer, (gssize) len, NULL);
- } else {
- QImageReader *reader = NULL;
- QByteArray array;
-
- /* TODO: Add resizing support */
-
- array = QByteArray ((const char *) buffer, (int) len);
-
- QBuffer qbuffer (&array);
- qbuffer.open (QIODevice::ReadOnly);
-
- if (buffer_mime != NULL) {
- reader = new QImageReader (&qbuffer, QByteArray (buffer_mime));
- } else {
- QByteArray format = QImageReader::imageFormat (&qbuffer);
-
- if (!format.isEmpty ()) {
- reader = new QImageReader (&qbuffer, format);
- }
- }
-
- if (!reader) {
- g_message ("Could not get QImageReader from buffer");
- return FALSE;
- }
-
- QImage image1;
- image1 = reader->read ();
-
- if (image1.hasAlphaChannel ()) {
- QImage image2 (image1.size(), QImage::Format_RGB32);
- image2.fill (QColor(Qt::black).rgb());
- QPainter painter (&image2);
- painter.drawImage (0, 0, image1);
- image2.save (QString (target), "jpeg");
- } else {
- image1.save (QString (target), "jpeg");
- }
-
- delete reader;
- }
-
- return TRUE;
-}
-
-G_END_DECLS
diff --git a/src/tracker-extract/tracker-media-art.c b/src/tracker-extract/tracker-media-art.c
deleted file mode 100644
index b438b63df..000000000
--- a/src/tracker-extract/tracker-media-art.c
+++ /dev/null
@@ -1,1128 +0,0 @@
-/*
- * Copyright (C) 2008, 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 <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <utime.h>
-#include <time.h>
-#include <errno.h>
-
-#include <glib.h>
-#include <glib/gprintf.h>
-#include <glib/gstdio.h>
-#include <gio/gio.h>
-
-#include <libtracker-miner/tracker-miner.h>
-#include <libtracker-common/tracker-file-utils.h>
-#include <libtracker-common/tracker-date-time.h>
-#include <libtracker-common/tracker-media-art.h>
-
-#include "tracker-media-art.h"
-#include "tracker-extract.h"
-#include "tracker-media-art-generic.h"
-
-#define ALBUMARTER_SERVICE "com.nokia.albumart"
-#define ALBUMARTER_PATH "/com/nokia/albumart/Requester"
-#define ALBUMARTER_INTERFACE "com.nokia.albumart.Requester"
-
-static const gchar *media_art_type_name[TRACKER_MEDIA_ART_TYPE_COUNT] = {
- "invalid",
- "album",
- "video"
-};
-
-typedef struct {
- TrackerStorage *storage;
- gchar *art_path;
- gchar *local_uri;
-} GetFileInfo;
-
-typedef struct {
- gchar *uri;
- TrackerMediaArtType type;
- gchar *artist_strdown;
- gchar *title_strdown;
-} TrackerMediaArtSearch;
-
-typedef enum {
- IMAGE_MATCH_EXACT = 0,
- IMAGE_MATCH_EXACT_SMALL = 1,
- IMAGE_MATCH_SAME_DIRECTORY = 2,
- IMAGE_MATCH_TYPE_COUNT
-} ImageMatchType;
-
-static gboolean initialized = FALSE;
-static gboolean disable_requests;
-static TrackerStorage *media_art_storage;
-static GHashTable *media_art_cache;
-static GDBusConnection *connection;
-
-static void
-media_art_queue_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data);
-
-
-static GDir *
-get_parent_g_dir (const gchar *uri,
- gchar **dirname,
- GError **error)
-{
- GFile *file, *dirf;
- GDir *dir;
-
- g_return_val_if_fail (dirname != NULL, NULL);
-
- *dirname = NULL;
-
- file = g_file_new_for_uri (uri);
- dirf = g_file_get_parent (file);
- if (dirf) {
- *dirname = g_file_get_path (dirf);
- g_object_unref (dirf);
- }
- g_object_unref (file);
-
- if (*dirname == NULL) {
- *error = g_error_new (G_FILE_ERROR,
- G_FILE_ERROR_EXIST,
- "No parent directory found for '%s'",
- uri);
- return NULL;
- }
-
- dir = g_dir_open (*dirname, 0, error);
-
- return dir;
-}
-
-
-static gchar *
-checksum_for_data (GChecksumType checksum_type,
- const guchar *data,
- gsize length)
-{
- GChecksum *checksum;
- gchar *retval;
-
- checksum = g_checksum_new (checksum_type);
- if (!checksum) {
- return NULL;
- }
-
- g_checksum_update (checksum, data, length);
- retval = g_strdup (g_checksum_get_string (checksum));
- g_checksum_free (checksum);
-
- return retval;
-}
-
-static gboolean
-file_get_checksum_if_exists (GChecksumType checksum_type,
- const gchar *path,
- gchar **md5,
- gboolean check_jpeg,
- gboolean *is_jpeg)
-{
- GFile *file = g_file_new_for_path (path);
- GFileInputStream *stream;
- GChecksum *checksum;
- gboolean retval;
-
- checksum = g_checksum_new (checksum_type);
-
- if (!checksum) {
- g_debug ("Can't create checksum engine");
- g_object_unref (file);
- return FALSE;
- }
-
- stream = g_file_read (file, NULL, NULL);
-
- if (stream) {
- gssize rsize;
- guchar buffer[1024];
-
- /* File exists & readable always means true retval */
- retval = TRUE;
-
- if (check_jpeg) {
- if (g_input_stream_read_all (G_INPUT_STREAM (stream), buffer, 3, &rsize, NULL, NULL)) {
- if (rsize >= 3 && buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff) {
- if (is_jpeg) {
- *is_jpeg = TRUE;
- }
- /* Add the read bytes to the checksum */
- g_checksum_update (checksum, buffer, rsize);
- } else {
- /* Larger than 3 bytes but incorrect jpeg header */
- if (is_jpeg) {
- *is_jpeg = FALSE;
- }
- goto end;
- }
- } else {
- /* Smaller than 3 bytes, not a jpeg */
- if (is_jpeg) {
- *is_jpeg = FALSE;
- }
- goto end;
- }
- }
-
- while ((rsize = g_input_stream_read (G_INPUT_STREAM (stream), buffer, 1024, NULL, NULL)) > 0) {
- g_checksum_update (checksum, buffer, rsize);
- }
-
- if (md5) {
- *md5 = g_strdup (g_checksum_get_string (checksum));
- }
-
- } else {
- g_debug ("%s isn't readable while calculating MD5 checksum", path);
- /* File doesn't exist or isn't readable */
- retval = FALSE;
- }
-
-end:
-
- if (stream) {
- g_object_unref (stream);
- }
- g_checksum_free (checksum);
- g_object_unref (file);
-
- return retval;
-}
-
-static gboolean
-convert_from_other_format (const gchar *found,
- const gchar *target,
- const gchar *album_path,
- const gchar *artist)
-{
- gboolean retval;
- gchar *sum1 = NULL;
- gchar *target_temp;
-
- target_temp = g_strdup_printf ("%s-tmp", target);
-
- retval = tracker_media_art_file_to_jpeg (found, target_temp);
-
- if (retval && (artist == NULL || g_strcmp0 (artist, " ") == 0)) {
- if (g_rename (target_temp, album_path) == -1) {
- g_debug ("rename(%s, %s) error: %s", target_temp, album_path, g_strerror (errno));
- }
- } else if (retval && file_get_checksum_if_exists (G_CHECKSUM_MD5, target_temp, &sum1, FALSE, NULL)) {
- gchar *sum2 = NULL;
- if (file_get_checksum_if_exists (G_CHECKSUM_MD5, album_path, &sum2, FALSE, NULL)) {
- if (g_strcmp0 (sum1, sum2) == 0) {
-
- /* If album-space-md5.jpg is the same as found,
- * make a symlink */
-
- if (symlink (album_path, target) != 0) {
- g_debug ("symlink(%s, %s) error: %s", album_path, target, g_strerror (errno));
- retval = FALSE;
- } else {
- retval = TRUE;
- }
-
- g_unlink (target_temp);
-
- } else {
-
- /* If album-space-md5.jpg isn't the same as found,
- * make a new album-md5-md5.jpg (found -> target) */
-
- if (g_rename (target_temp, album_path) == -1) {
- g_debug ("rename(%s, %s) error: %s", target_temp, album_path, g_strerror (errno));
- }
- }
- g_free (sum2);
- } else {
-
- /* If there's not yet a album-space-md5.jpg, make one,
- * and symlink album-md5-md5.jpg to it */
-
- g_rename (target_temp, album_path);
-
- if (symlink (album_path, target) != 0) {
- g_debug ("symlink(%s,%s) error: %s", album_path, target, g_strerror (errno));
- retval = FALSE;
- } else {
- retval = TRUE;
- }
-
- }
-
- g_free (sum1);
- } else if (retval) {
- g_debug ("Can't read %s while calculating checksum", target_temp);
- /* Can't read the file that it was converted to, strange ... */
- g_unlink (target_temp);
- }
-
- g_free (target_temp);
-
- return retval;
-}
-
-static TrackerMediaArtSearch *
-tracker_media_art_search_new (const gchar *uri,
- TrackerMediaArtType type,
- const gchar *artist,
- const gchar *title)
-{
- TrackerMediaArtSearch *search;
- gchar *temp;
-
- search = g_slice_new0 (TrackerMediaArtSearch);
- search->uri = g_strdup (uri);
- search->type = type;
-
- if (artist) {
- temp = tracker_media_art_strip_invalid_entities (artist);
- search->artist_strdown = g_utf8_strdown (temp, -1);
- g_free (temp);
- }
-
- temp = tracker_media_art_strip_invalid_entities (title);
- search->title_strdown = g_utf8_strdown (temp, -1);
- g_free (temp);
-
- return search;
-}
-
-static void
-tracker_media_art_search_free (TrackerMediaArtSearch *search)
-{
- g_free (search->uri);
- g_free (search->artist_strdown);
- g_free (search->title_strdown);
-
- g_slice_free (TrackerMediaArtSearch, search);
-}
-
-static ImageMatchType
-classify_image_file (TrackerMediaArtSearch *search,
- const gchar *file_name_strdown)
-{
- if ((search->artist_strdown && search->artist_strdown[0] != '\0' &&
- strstr (file_name_strdown, search->artist_strdown)) ||
- (search->title_strdown && search->title_strdown[0] != '\0' &&
- strstr (file_name_strdown, search->title_strdown))) {
- return IMAGE_MATCH_EXACT;
- }
-
- if (search->type == TRACKER_MEDIA_ART_ALBUM) {
- /* Accept cover, front, folder, AlbumArt_{GUID}_Large (first choice)
- * second choice is AlbumArt_{GUID}_Small and AlbumArtSmall. We
- * don't support just AlbumArt. (it must have a Small or Large) */
-
- if (strstr (file_name_strdown, "cover") ||
- strstr (file_name_strdown, "front") ||
- strstr (file_name_strdown, "folder")) {
- return IMAGE_MATCH_EXACT;
- }
-
- if (strstr (file_name_strdown, "albumart")) {
- if (strstr (file_name_strdown, "large")) {
- return IMAGE_MATCH_EXACT;
- } else if (strstr (file_name_strdown, "small")) {
- return IMAGE_MATCH_EXACT_SMALL;
- }
- }
- }
-
- if (search->type == TRACKER_MEDIA_ART_VIDEO) {
- if (strstr (file_name_strdown, "folder") ||
- strstr (file_name_strdown, "poster")) {
- return IMAGE_MATCH_EXACT;
- }
- }
-
- /* Lowest priority for other images, but we still might use it for videos */
- return IMAGE_MATCH_SAME_DIRECTORY;
-}
-
-static gchar *
-tracker_media_art_find_by_artist_and_title (const gchar *uri,
- TrackerMediaArtType type,
- const gchar *artist,
- const gchar *title)
-{
- TrackerMediaArtSearch *search;
- GDir *dir;
- GError *error = NULL;
- gchar *dirname = NULL;
- const gchar *name;
- gchar *name_utf8, *name_strdown;
- guint i;
- gchar *art_file_name;
- gchar *art_file_path;
- gint priority;
-
- GList *image_list[IMAGE_MATCH_TYPE_COUNT] = { NULL, };
-
- g_return_val_if_fail (type > TRACKER_MEDIA_ART_NONE && type < TRACKER_MEDIA_ART_TYPE_COUNT, FALSE);
- g_return_val_if_fail (title != NULL, FALSE);
-
- dir = get_parent_g_dir (uri, &dirname, &error);
-
- if (!dir) {
- g_debug ("Media art directory could not be opened: %s",
- error ? error->message : "no error given");
-
- g_clear_error (&error);
- g_free (dirname);
-
- return NULL;
- }
-
- /* First, classify each file in the directory as either an image, relevant
- * to the media object in question, or irrelevant. We use this information
- * to decide if the image is a cover or if the file is in a random directory.
- */
-
- search = tracker_media_art_search_new (uri, type, artist, title);
-
- for (name = g_dir_read_name (dir);
- name != NULL;
- name = g_dir_read_name (dir)) {
-
- name_utf8 = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
-
- if (!name_utf8) {
- g_debug ("Could not convert filename '%s' to UTF-8", name);
- continue;
- }
-
- name_strdown = g_utf8_strdown (name_utf8, -1);
-
- if (g_str_has_suffix (name_strdown, "jpeg") ||
- g_str_has_suffix (name_strdown, "jpg") ||
- g_str_has_suffix (name_strdown, "png")) {
-
- priority = classify_image_file (search, name_strdown);
- image_list[priority] = g_list_prepend (image_list[priority], name_strdown);
- } else {
- g_free (name_strdown);
- }
-
- g_free (name_utf8);
- }
-
- /* Use the results to pick a media art image */
-
- art_file_name = NULL;
- art_file_path = NULL;
-
- if (g_list_length (image_list[IMAGE_MATCH_EXACT]) > 0) {
- art_file_name = g_strdup (image_list[IMAGE_MATCH_EXACT]->data);
- } else if (g_list_length (image_list[IMAGE_MATCH_EXACT_SMALL]) > 0) {
- art_file_name = g_strdup (image_list[IMAGE_MATCH_EXACT_SMALL]->data);
- } else {
- if (type == TRACKER_MEDIA_ART_VIDEO && g_list_length (image_list[IMAGE_MATCH_SAME_DIRECTORY]) == 1) {
- art_file_name = g_strdup (image_list[IMAGE_MATCH_SAME_DIRECTORY]->data);
- }
- }
-
- for (i = 0; i < IMAGE_MATCH_TYPE_COUNT; i ++) {
- g_list_foreach (image_list[i], (GFunc)g_free, NULL);
- g_list_free (image_list[i]);
- }
-
- if (art_file_name) {
- art_file_path = g_build_filename (dirname, art_file_name, NULL);
- g_free (art_file_name);
- } else {
- g_debug ("Album art NOT found in same directory");
- art_file_path = NULL;
- }
-
- tracker_media_art_search_free (search);
- g_dir_close (dir);
- g_free (dirname);
-
- return art_file_path;
-}
-
-static gboolean
-media_art_heuristic (const gchar *artist,
- const gchar *title,
- TrackerMediaArtType type,
- const gchar *filename_uri,
- const gchar *local_uri)
-{
- gchar *art_file_path = NULL;
- gchar *album_art_file_path = NULL;
- gchar *target = NULL;
- gchar *artist_stripped = NULL;
- gchar *title_stripped = NULL;
- gboolean retval = FALSE;
-
- if (title == NULL || title[0] == '\0') {
- g_debug ("Unable to fetch media art, no title specified");
- return FALSE;
- }
-
- if (artist) {
- artist_stripped = tracker_media_art_strip_invalid_entities (artist);
- }
- title_stripped = tracker_media_art_strip_invalid_entities (title);
-
- tracker_media_art_get_path (artist_stripped,
- title_stripped,
- media_art_type_name[type],
- NULL,
- &target,
- NULL);
-
- /* Copy from local album art (.mediaartlocal) to spec */
- if (local_uri) {
- GFile *local_file, *file;
-
- local_file = g_file_new_for_uri (local_uri);
-
- if (g_file_query_exists (local_file, NULL)) {
- g_debug ("Album art being copied from local (.mediaartlocal) file:'%s'",
- local_uri);
-
- file = g_file_new_for_path (target);
-
- g_file_copy_async (local_file, file, 0, 0,
- NULL, NULL, NULL, NULL, NULL);
-
- g_object_unref (file);
- g_object_unref (local_file);
-
- g_free (target);
- g_free (artist_stripped);
- g_free (title_stripped);
-
- return TRUE;
- }
-
- g_object_unref (local_file);
- }
-
- art_file_path = tracker_media_art_find_by_artist_and_title (filename_uri, type, artist, title);
-
- if (art_file_path != NULL) {
- if (g_str_has_suffix (art_file_path, "jpeg") ||
- g_str_has_suffix (art_file_path, "jpg")) {
-
- gboolean is_jpeg = FALSE;
- gchar *sum1 = NULL;
-
- if (type != TRACKER_MEDIA_ART_ALBUM || (artist == NULL || g_strcmp0 (artist, " ") == 0)) {
- GFile *art_file;
- GFile *target_file;
- GError *err = NULL;
-
- g_debug ("Album art (JPEG) found in same directory being used:'%s'", art_file_path);
-
- target_file = g_file_new_for_path (target);
- art_file = g_file_new_for_path (art_file_path);
-
- g_file_copy (art_file, target_file, 0, NULL, NULL, NULL, &err);
- if (err) {
- g_debug ("%s", err->message);
- g_clear_error (&err);
- }
- g_object_unref (art_file);
- g_object_unref (target_file);
- } else if (file_get_checksum_if_exists (G_CHECKSUM_MD5, art_file_path, &sum1, TRUE, &is_jpeg)) {
- /* Avoid duplicate artwork for each track in an album */
- tracker_media_art_get_path (NULL,
- title_stripped,
- media_art_type_name [type],
- NULL,
- &album_art_file_path,
- NULL);
-
- if (is_jpeg) {
- gchar *sum2 = NULL;
-
- g_debug ("Album art (JPEG) found in same directory being used:'%s'", art_file_path);
-
- if (file_get_checksum_if_exists (G_CHECKSUM_MD5, album_art_file_path, &sum2, FALSE, NULL)) {
- if (g_strcmp0 (sum1, sum2) == 0) {
- /* If album-space-md5.jpg is the same as found,
- * make a symlink */
-
- if (symlink (album_art_file_path, target) != 0) {
- g_debug ("symlink(%s, %s) error: %s", album_art_file_path, target, g_strerror (errno));
- retval = FALSE;
- } else {
- retval = TRUE;
- }
- } else {
- GFile *art_file;
- GFile *target_file;
- GError *err = NULL;
-
- /* If album-space-md5.jpg isn't the same as found,
- * make a new album-md5-md5.jpg (found -> target) */
-
- target_file = g_file_new_for_path (target);
- art_file = g_file_new_for_path (art_file_path);
- retval = g_file_copy (art_file, target_file, 0, NULL, NULL, NULL, &err);
- if (err) {
- g_debug ("%s", err->message);
- g_clear_error (&err);
- }
- g_object_unref (art_file);
- g_object_unref (target_file);
- }
- g_free (sum2);
- } else {
- GFile *art_file;
- GFile *album_art_file;
- GError *err = NULL;
-
- /* If there's not yet a album-space-md5.jpg, make one,
- * and symlink album-md5-md5.jpg to it */
-
- album_art_file = g_file_new_for_path (album_art_file_path);
- art_file = g_file_new_for_path (art_file_path);
- retval = g_file_copy (art_file, album_art_file, 0, NULL, NULL, NULL, &err);
-
- if (err == NULL) {
- if (symlink (album_art_file_path, target) != 0) {
- g_debug ("symlink(%s, %s) error: %s", album_art_file_path, target, g_strerror (errno));
- retval = FALSE;
- } else {
- retval = TRUE;
- }
- } else {
- g_debug ("%s", err->message);
- g_clear_error (&err);
- retval = FALSE;
- }
-
- g_object_unref (album_art_file);
- g_object_unref (art_file);
- }
- } else {
- g_debug ("Album art found in same directory but not a real JPEG file (trying to convert): '%s'", art_file_path);
- retval = convert_from_other_format (art_file_path, target, album_art_file_path, artist);
- }
-
- g_free (sum1);
- } else {
- /* Can't read contents of the cover.jpg file ... */
- retval = FALSE;
- }
- } else if (g_str_has_suffix (art_file_path, "png")) {
- if (!album_art_file_path) {
- tracker_media_art_get_path (NULL,
- title_stripped,
- media_art_type_name[type],
- NULL,
- &album_art_file_path,
- NULL);
- }
-
- g_debug ("Album art (PNG) found in same directory being used:'%s'", art_file_path);
- retval = convert_from_other_format (art_file_path, target, album_art_file_path, artist);
- }
-
- g_free (art_file_path);
- g_free (album_art_file_path);
- }
-
- g_free (target);
- g_free (artist_stripped);
- g_free (title_stripped);
-
- return retval;
-}
-
-static gboolean
-media_art_set (const unsigned char *buffer,
- size_t len,
- const gchar *mime,
- TrackerMediaArtType type,
- const gchar *artist,
- const gchar *title,
- const gchar *uri)
-{
- gchar *local_path;
- gboolean retval = FALSE;
-
- g_return_val_if_fail (type > TRACKER_MEDIA_ART_NONE && type < TRACKER_MEDIA_ART_TYPE_COUNT, FALSE);
-
- if (!artist && !title) {
- g_warning ("Could not save embedded album art, not enough metadata supplied");
- return FALSE;
- }
-
- tracker_media_art_get_path (artist, title, media_art_type_name[type], NULL, &local_path, NULL);
-
- if (type != TRACKER_MEDIA_ART_ALBUM || (artist == NULL || g_strcmp0 (artist, " ") == 0)) {
- retval = tracker_media_art_buffer_to_jpeg (buffer, len, mime, local_path);
- } else {
- gchar *album_path;
-
- tracker_media_art_get_path (NULL, title, media_art_type_name[type], NULL, &album_path, NULL);
-
- if (!g_file_test (album_path, G_FILE_TEST_EXISTS)) {
- retval = tracker_media_art_buffer_to_jpeg (buffer, len, mime, album_path);
-
- /* If album-space-md5.jpg doesn't exist, make one and make a symlink
- * to album-md5-md5.jpg */
-
- if (retval && symlink (album_path, local_path) != 0) {
- g_debug ("symlink(%s, %s) error: %s", album_path, local_path, g_strerror (errno));
- retval = FALSE;
- } else {
- retval = TRUE;
- }
- } else {
- gchar *sum2 = NULL;
-
- if (file_get_checksum_if_exists (G_CHECKSUM_MD5, album_path, &sum2, FALSE, NULL)) {
- if ( !(g_strcmp0 (mime, "image/jpeg") == 0 || g_strcmp0 (mime, "JPG") == 0) ||
- ( !(len > 2 && buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff) )) {
- gchar *sum1 = NULL;
- gchar *temp = g_strdup_printf ("%s-tmp", album_path);
-
- /* If buffer isn't a JPEG */
-
- retval = tracker_media_art_buffer_to_jpeg (buffer, len, mime, temp);
-
- if (retval && file_get_checksum_if_exists (G_CHECKSUM_MD5, temp, &sum1, FALSE, NULL)) {
- if (g_strcmp0 (sum1, sum2) == 0) {
-
- /* If album-space-md5.jpg is the same as buffer, make a symlink
- * to album-md5-md5.jpg */
-
- g_unlink (temp);
- if (symlink (album_path, local_path) != 0) {
- g_debug ("symlink(%s, %s) error: %s", album_path, local_path, g_strerror (errno));
- retval = FALSE;
- } else {
- retval = TRUE;
- }
- } else {
- /* If album-space-md5.jpg isn't the same as buffer, make a
- * new album-md5-md5.jpg */
- if (g_rename (temp, local_path) == -1) {
- g_debug ("rename(%s, %s) error: %s", temp, local_path, g_strerror (errno));
- }
- }
- g_free (sum1);
- } else {
- /* Can't read temp file ... */
- g_unlink (temp);
- }
-
- g_free (temp);
- } else {
- gchar *sum1 = NULL;
-
- sum1 = checksum_for_data (G_CHECKSUM_MD5, buffer, len);
- /* If album-space-md5.jpg is the same as buffer, make a symlink
- * to album-md5-md5.jpg */
-
- if (g_strcmp0 (sum1, sum2) == 0) {
- if (symlink (album_path, local_path) != 0) {
- g_debug ("symlink(%s, %s) error: %s", album_path, local_path, g_strerror (errno));
- retval = FALSE;
- } else {
- retval = TRUE;
- }
- } else {
- /* If album-space-md5.jpg isn't the same as buffer, make a
- * new album-md5-md5.jpg */
- retval = tracker_media_art_buffer_to_jpeg (buffer, len, mime, local_path);
- }
- g_free (sum1);
- }
- g_free (sum2);
- }
- g_free (album_path);
- }
- }
-
- g_free (local_path);
-
- return retval;
-}
-
-static void
-media_art_request_download (TrackerStorage *storage,
- TrackerMediaArtType type,
- const gchar *album,
- const gchar *artist,
- const gchar *local_uri,
- const gchar *art_path)
-{
- if (connection) {
- GetFileInfo *info;
-
- if (disable_requests) {
- return;
- }
-
- if (type != TRACKER_MEDIA_ART_ALBUM) {
- return;
- }
-
- info = g_slice_new (GetFileInfo);
-
- info->storage = storage ? g_object_ref (storage) : NULL;
-
- info->local_uri = g_strdup (local_uri);
- info->art_path = g_strdup (art_path);
-
- g_dbus_connection_call (connection,
- ALBUMARTER_SERVICE,
- ALBUMARTER_PATH,
- ALBUMARTER_INTERFACE,
- "Queue",
- g_variant_new ("(sssu)",
- artist ? artist : "",
- album ? album : "",
- "album",
- 0),
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- media_art_queue_cb,
- info);
- }
-}
-
-static void
-media_art_copy_to_local (TrackerStorage *storage,
- const gchar *filename,
- const gchar *local_uri)
-{
- GSList *roots, *l;
- gboolean on_removable_device = FALSE;
- guint flen;
-
- /* Determining if we are on a removable device */
- if (!storage) {
- /* This is usually because we are running on the
- * command line, so we don't error here with
- * g_return_if_fail().
- */
- return;
- }
-
- roots = tracker_storage_get_device_roots (storage, TRACKER_STORAGE_REMOVABLE, FALSE);
- flen = strlen (filename);
-
- for (l = roots; l; l = l->next) {
- guint len;
-
- len = strlen (l->data);
-
- if (flen >= len && strncmp (filename, l->data, len)) {
- on_removable_device = TRUE;
- break;
- }
- }
-
- g_slist_foreach (roots, (GFunc) g_free, NULL);
- g_slist_free (roots);
-
- if (on_removable_device) {
- GFile *local_file, *from;
-
- from = g_file_new_for_path (filename);
- local_file = g_file_new_for_uri (local_uri);
-
- /* We don't try to overwrite, but we also ignore all errors.
- * Such an error could be that the removable device is
- * read-only. Well that's fine then ... ignore */
-
- if (!g_file_query_exists (local_file, NULL)) {
- GFile *dirf;
-
- dirf = g_file_get_parent (local_file);
- if (dirf) {
- /* Parent file may not exist, as if the file is in the
- * root of a gvfs mount. In this case we won't try to
- * create the parent directory, just try to copy the
- * file there. */
- g_file_make_directory_with_parents (dirf, NULL, NULL);
- g_object_unref (dirf);
- }
-
- g_debug ("Copying media art from:'%s' to:'%s'",
- filename, local_uri);
-
- g_file_copy_async (from, local_file, 0, 0,
- NULL, NULL, NULL, NULL, NULL);
- }
-
- g_object_unref (local_file);
- g_object_unref (from);
- }
-}
-
-static void
-media_art_queue_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- GError *error = NULL;
- GetFileInfo *info;
- GVariant *v;
-
- info = user_data;
-
- v = g_dbus_connection_call_finish ((GDBusConnection *) source_object, res, &error);
-
- if (error) {
- if (error->code == G_DBUS_ERROR_SERVICE_UNKNOWN) {
- disable_requests = TRUE;
- } else {
- g_warning ("%s", error->message);
- }
- g_clear_error (&error);
- }
-
- if (v) {
- g_variant_unref (v);
- }
-
- if (info->storage && info->art_path &&
- g_file_test (info->art_path, G_FILE_TEST_EXISTS)) {
-
- media_art_copy_to_local (info->storage,
- info->art_path,
- info->local_uri);
- }
-
- g_free (info->art_path);
- g_free (info->local_uri);
-
- if (info->storage) {
- g_object_unref (info->storage);
- }
-
- g_slice_free (GetFileInfo, info);
-}
-
-gboolean
-tracker_media_art_init (void)
-{
- GError *error = NULL;
-
- g_return_val_if_fail (initialized == FALSE, FALSE);
-
- tracker_media_art_plugin_init ();
-
- media_art_storage = tracker_storage_new ();
-
- /* Cache to know if we have already handled uris */
- media_art_cache = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- NULL);
-
- /* Signal handler for new album art from the extractor */
- connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
-
- if (!connection) {
- g_critical ("Could not connect to the D-Bus session bus, %s",
- error ? error->message : "no error given.");
- g_clear_error (&error);
- return FALSE;
- }
-
- initialized = TRUE;
-
- return TRUE;
-}
-
-void
-tracker_media_art_shutdown (void)
-{
- g_return_if_fail (initialized == TRUE);
-
- if (connection) {
- g_object_unref (connection);
- }
-
- if (media_art_cache) {
- g_hash_table_unref (media_art_cache);
- }
-
- if (media_art_storage) {
- g_object_unref (media_art_storage);
- }
-
- tracker_media_art_plugin_shutdown ();
-
- initialized = FALSE;
-}
-
-static void
-set_mtime (const gchar *filename, guint64 mtime)
-{
-
- struct utimbuf buf;
-
- buf.actime = buf.modtime = mtime;
- utime (filename, &buf);
-}
-
-gboolean
-tracker_media_art_process (const unsigned char *buffer,
- size_t len,
- const gchar *mime,
- TrackerMediaArtType type,
- const gchar *artist,
- const gchar *title,
- const gchar *uri)
-{
- gchar *art_path;
- gchar *local_art_uri = NULL;
- gboolean processed = TRUE, a_exists, created = FALSE;
- guint64 mtime, a_mtime = 0;
-
- g_return_val_if_fail (type > TRACKER_MEDIA_ART_NONE && type < TRACKER_MEDIA_ART_TYPE_COUNT, FALSE);
-
- g_debug ("Processing media art: artist:'%s', title:'%s', type:'%s', uri:'%s'. Buffer is %ld bytes, mime:'%s'",
- artist ? artist : "",
- title ? title : "",
- media_art_type_name[type],
- uri,
- (long int) len,
- mime);
-
- /* TODO: We can definitely work with GFiles better here */
-
- mtime = tracker_file_get_mtime_uri (uri);
-
- tracker_media_art_get_path (artist,
- title,
- media_art_type_name[type],
- uri,
- &art_path,
- &local_art_uri);
-
- if (!art_path) {
- g_debug ("Album art path could not be obtained, not processing any further");
-
- g_free (local_art_uri);
-
- return FALSE;
- }
-
- a_exists = g_file_test (art_path, G_FILE_TEST_EXISTS);
-
- if (a_exists) {
- a_mtime = tracker_file_get_mtime (art_path);
- }
-
- if ((buffer && len > 0) && ((!a_exists) || (a_exists && mtime > a_mtime))) {
- processed = media_art_set (buffer, len, mime, type, artist, title, uri);
- set_mtime (art_path, mtime);
- created = TRUE;
- }
-
- if ((!created) && ((!a_exists) || (a_exists && mtime > a_mtime))) {
- /* If not, we perform a heuristic on the dir */
- gchar *key;
- gchar *dirname = NULL;
- GFile *file, *dirf;
-
- file = g_file_new_for_uri (uri);
- dirf = g_file_get_parent (file);
- if (dirf) {
- dirname = g_file_get_path (dirf);
- g_object_unref (dirf);
- }
- g_object_unref (file);
-
- key = g_strdup_printf ("%i-%s-%s-%s",
- type,
- artist ? artist : "",
- title ? title : "",
- dirname ? dirname : "");
-
- g_free (dirname);
-
- if (!g_hash_table_lookup (media_art_cache, key)) {
- if (!media_art_heuristic (artist,
- title,
- type,
- uri,
- local_art_uri)) {
- /* If the heuristic failed, we
- * request the download the
- * media-art to the media-art
- * downloaders
- */
- media_art_request_download (media_art_storage,
- type,
- artist,
- title,
- local_art_uri,
- art_path);
- }
-
- set_mtime (art_path, mtime);
-
- g_hash_table_insert (media_art_cache,
- key,
- GINT_TO_POINTER(TRUE));
- } else {
- g_free (key);
- }
- } else {
- if (!created) {
- g_debug ("Album art already exists for uri:'%s' as '%s'",
- uri,
- art_path);
- }
- }
-
- if (local_art_uri && !g_file_test (local_art_uri, G_FILE_TEST_EXISTS)) {
- /* We can't reuse art_exists here because the
- * situation might have changed
- */
- if (g_file_test (art_path, G_FILE_TEST_EXISTS)) {
- media_art_copy_to_local (media_art_storage,
- art_path,
- local_art_uri);
- }
- }
-
- g_free (art_path);
- g_free (local_art_uri);
-
- return processed;
-}
diff --git a/src/tracker-extract/tracker-media-art.h b/src/tracker-extract/tracker-media-art.h
deleted file mode 100644
index 980239af6..000000000
--- a/src/tracker-extract/tracker-media-art.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2008, 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.
- */
-
-#ifndef __TRACKER_EXTRACT_MEDIA_ART_H__
-#define __TRACKER_EXTRACT_MEDIA_ART_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-typedef enum {
- TRACKER_MEDIA_ART_NONE,
- TRACKER_MEDIA_ART_ALBUM,
- TRACKER_MEDIA_ART_VIDEO,
- TRACKER_MEDIA_ART_TYPE_COUNT
-} TrackerMediaArtType;
-
-gboolean tracker_media_art_init (void);
-void tracker_media_art_shutdown (void);
-
-gboolean tracker_media_art_process (const unsigned char *buffer,
- size_t len,
- const gchar *mime,
- TrackerMediaArtType type,
- const gchar *artist,
- const gchar *title,
- const gchar *uri);
-
-G_END_DECLS
-
-#endif /* __TRACKER_EXTRACT_MEDIA_ART_H__ */
diff --git a/tests/libtracker-common/Makefile.am b/tests/libtracker-common/Makefile.am
index ad2662eae..4c80160ab 100644
--- a/tests/libtracker-common/Makefile.am
+++ b/tests/libtracker-common/Makefile.am
@@ -7,7 +7,6 @@ TEST_PROGS += \
tracker-dbus \
tracker-file-utils \
tracker-utils \
- tracker-media-art-test \
tracker-sched-test \
tracker-crc32-test \
tracker-date-time-test
@@ -35,8 +34,6 @@ tracker_file_utils_SOURCES = tracker-file-utils-test.c
tracker_utils_SOURCES = tracker-utils-test.c
-tracker_media_art = tracker-media-art-test.c
-
tracker_sched_test_SOURCES = tracker-sched-test.c
tracker_crc32_test_SOURCES = tracker-crc32-test.c
diff --git a/tests/libtracker-common/tracker-media-art-test.c b/tests/libtracker-common/tracker-media-art-test.c
deleted file mode 100644
index cc5df0530..000000000
--- a/tests/libtracker-common/tracker-media-art-test.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (C) 2011, Nokia <ivan.frade@nokia.com>
- *
- * 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.
- */
-
-#include <glib-object.h>
-
-#include <libtracker-common/tracker-common.h>
-
-struct {
- const gchar *input;
- const gchar *expected_output;
-} strip_test_cases [] = {
- { "nothing to strip here", "nothing to strip here" },
- { "Upper Case gOEs dOwN", "upper case goes down"},
- { "o", "o"},
- { "A", "a"},
- { "cool album (CD1)", "cool album"},
- { "cool album [CD1]", "cool album"},
- { "cool album {CD1}", "cool album"},
- { "cool album <CD1>", "cool album"},
- { " ", ""},
- { " a ", "a"},
- { "messy #title & stuff?", "messy title stuff"},
- { "Unbalanced [brackets", "unbalanced brackets" },
- { "Unbalanced (brackets", "unbalanced brackets" },
- { "Unbalanced <brackets", "unbalanced brackets" },
- { "Unbalanced brackets)", "unbalanced brackets" },
- { "Unbalanced brackets]", "unbalanced brackets" },
- { "Unbalanced brackets>", "unbalanced brackets" },
- { "Live at *WEMBLEY* dude!", "live at wembley dude" },
- { NULL, NULL}
-};
-
-static void
-test_albumart_stripping (void)
-{
- gint i;
- gchar *result;
-
- for (i = 0; strip_test_cases[i].input != NULL; i++) {
- result = tracker_media_art_strip_invalid_entities (strip_test_cases[i].input);
- g_assert_cmpstr (result, ==, strip_test_cases[i].expected_output);
- g_free (result);
- }
-
- g_print ("(%d test cases) ", i);
-}
-
-static void
-test_albumart_stripping_null (void)
-{
- // FIXME: Decide what is the expected behaviour here...
- // a. Return NULL
- // b. Return ""
- //g_assert (!tracker_albumart_strip_invalid_entities (NULL));
-}
-
-struct {
- const gchar *artist;
- const gchar *album;
- const gchar *filename;
-} albumart_test_cases [] = {
- {"Beatles", "Sgt. Pepper",
- "album-2a9ea35253dbec60e76166ec8420fbda-cfba4326a32b44b8760b3a2fc827a634.jpeg"},
-
- { "", "sgt. pepper",
- "album-d41d8cd98f00b204e9800998ecf8427e-cfba4326a32b44b8760b3a2fc827a634.jpeg"},
-
- { " ", "sgt. pepper",
- "album-d41d8cd98f00b204e9800998ecf8427e-cfba4326a32b44b8760b3a2fc827a634.jpeg"},
-
- { NULL, "sgt. pepper",
- "album-7215ee9c7d9dc229d2921a40e899ec5f-cfba4326a32b44b8760b3a2fc827a634.jpeg"},
-
- { "Beatles", NULL,
- "album-2a9ea35253dbec60e76166ec8420fbda-7215ee9c7d9dc229d2921a40e899ec5f.jpeg"},
-
- { NULL, NULL, NULL }
-};
-
-static void
-test_albumart_location (void)
-{
- gchar *path = NULL, *local_uri = NULL;
- gchar *expected;
- gint i;
-
- for (i = 0; albumart_test_cases[i].filename != NULL; i++) {
- tracker_media_art_get_path (albumart_test_cases[i].artist,
- albumart_test_cases[i].album,
- "album",
- "file:///home/test/a.mp3",
- &path,
- &local_uri);
- expected = g_build_path (G_DIR_SEPARATOR_S,
- g_get_user_cache_dir (),
- "media-art",
- albumart_test_cases[i].filename,
- NULL);
- g_assert_cmpstr (path, ==, expected);
-
- g_free (expected);
- g_free (path);
- g_free (local_uri);
- }
- g_print ("(%d test cases) ", i);
-
-
-}
-
-static void
-test_albumart_location_null (void)
-{
- gchar *path = NULL, *local_uri = NULL;
-
- /* NULL parameters */
- tracker_media_art_get_path (NULL, NULL, "album", "file:///a/b/c.mp3", &path, &local_uri);
- g_assert (!path && !local_uri);
-}
-
-static void
-test_albumart_location_path (void)
-{
- gchar *path = NULL, *local_uri = NULL;
- gchar *expected;
-
- /* Use path instead of URI */
- tracker_media_art_get_path (albumart_test_cases[0].artist,
- albumart_test_cases[0].album,
- "album",
- "/home/test/a.mp3",
- &path,
- &local_uri);
- expected = g_build_path (G_DIR_SEPARATOR_S,
- g_get_user_cache_dir (),
- "media-art",
- albumart_test_cases[0].filename,
- NULL);
- g_assert_cmpstr (path, ==, expected);
-
- g_free (expected);
- g_free (path);
- g_free (local_uri);
-}
-
-gint
-main (gint argc, gchar **argv)
-{
- g_test_init (&argc, &argv, NULL);
-
- g_test_add_func ("/libtracker-common/albumart/stripping",
- test_albumart_stripping);
- g_test_add_func ("/libtracker-common/albumart/stripping_null",
- test_albumart_stripping_null);
- g_test_add_func ("/libtracker-common/albumart/location",
- test_albumart_location);
- g_test_add_func ("/libtracker-common/albumart/location_null",
- test_albumart_location_null);
- g_test_add_func ("/libtracker_common/albumart/location_path",
- test_albumart_location_path);
-
- return g_test_run ();
-}