tracker r2433 - in trunk: . src/tracker-extract
- From: pvanhoof svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2433 - in trunk: . src/tracker-extract
- Date: Thu, 30 Oct 2008 11:40:05 +0000 (UTC)
Author: pvanhoof
Date: Thu Oct 30 11:40:05 2008
New Revision: 2433
URL: http://svn.gnome.org/viewvc/tracker?rev=2433&view=rev
Log:
2008-10-30 Philip Van Hoof <philip codeminded be>
* src/tracker-extract/tracker-albumart.c: Stripping album and artist
strings
Modified:
trunk/ChangeLog
trunk/src/tracker-extract/tracker-albumart.c
Modified: trunk/src/tracker-extract/tracker-albumart.c
==============================================================================
--- trunk/src/tracker-extract/tracker-albumart.c (original)
+++ trunk/src/tracker-extract/tracker-albumart.c Thu Oct 30 11:40:05 2008
@@ -82,6 +82,81 @@
#endif /* HAVE_STRCASESTR */
+
+static gchar*
+strip_characters (const gchar *original)
+{
+ const gchar *foo = "()[]<>{}_! #$^&*+=|\\/\"'?~";
+ guint osize = strlen (original);
+ gchar *retval = (gchar *) g_malloc0 (sizeof (gchar *) * osize);
+ guint i = 0, y = 0;
+
+ while (i < osize) {
+
+ /* Remove (anything) */
+
+ if (original[i] == '(') {
+ gchar *loc = strchr (original+i, ')');
+ if (loc) {
+ i = loc - original + 1;
+ continue;
+ }
+ }
+
+ /* Remove [anything] */
+
+ if (original[i] == '[') {
+ gchar *loc = strchr (original+i, ']');
+ if (loc) {
+ i = loc - original + 1;
+ continue;
+ }
+ }
+
+ /* Remove {anything} */
+
+ if (original[i] == '{') {
+ gchar *loc = strchr (original+i, '}');
+ if (loc) {
+ i = loc - original + 1;
+ continue;
+ }
+ }
+
+ /* Remove <anything> */
+
+ if (original[i] == '<') {
+ gchar *loc = strchr (original+i, '>');
+ if (loc) {
+ i = loc - original + 1;
+ continue;
+ }
+ }
+
+ /* Remove double whitespaces */
+
+ if ((y > 0) &&
+ (original[i] == ' ' || original[i] == '\t') &&
+ (retval[y-1] == ' ' || retval[y-1] == '\t')) {
+ i++;
+ continue;
+ }
+
+ /* Remove strange characters */
+
+ if (!strchr (foo, original[i])) {
+ retval[y] = original[i]!='\t'?original[i]:' ';
+ y++;
+ }
+
+ i++;
+ }
+
+ retval[y] = 0;
+
+ return retval;
+}
+
static void
perhaps_copy_to_local (const gchar *filename, const gchar *local_uri)
{
@@ -102,8 +177,8 @@
}
static gboolean
-heuristic_albumart (const gchar *artist,
- const gchar *album,
+heuristic_albumart (const gchar *artist_,
+ const gchar *album_,
const gchar *tracks_str,
const gchar *filename)
{
@@ -116,7 +191,9 @@
gboolean retval;
gint tracks;
gint count;
-
+ gchar *artist = NULL;
+ gchar *album = NULL;
+
file = g_file_new_for_path (filename);
basename = g_file_get_basename (file);
g_object_unref (file);
@@ -143,7 +220,12 @@
} else {
tracks = -1;
}
-
+
+ if (artist_)
+ artist = strip_characters (artist_);
+ if (album_)
+ album = strip_characters (album_);
+
if ((tracks != -1 && tracks < count + 3 && tracks > count - 3) ||
(tracks == -1 && count > 8 && count < 50)) {
gchar *found = NULL;
@@ -229,9 +311,11 @@
if (file) {
g_object_unref (file);
}
-
+
g_free (target);
g_free (basename);
+ g_free (artist);
+ g_free (album);
return retval;
}
@@ -286,10 +370,12 @@
gchar **path,
gchar **local)
{
+
gchar *art_filename;
gchar *dir;
gchar *str;
gchar *down;
+ gchar *f_a = NULL, *f_b = NULL;
*path = NULL;
@@ -297,10 +383,20 @@
return;
}
- str = g_strconcat (a ? a : "",
+ if (a)
+ f_a = strip_characters (a);
+
+ if (b)
+ f_b = strip_characters (b);
+
+ str = g_strconcat (a ? f_a : "",
" ",
- b ? b : "",
+ b ? f_b : "",
NULL);
+
+ g_free (f_a);
+ g_free (f_b);
+
down = g_utf8_strdown (str, -1);
g_free (str);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]