[grilo-plugins/wip/carlosg/tracker3: 33/48] tracker3: Change title-from-filename handling




commit 87d12220753c88bc7365a9ed300522ec4c3693f9
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun May 24 16:07:06 2020 +0200

    tracker3: Change title-from-filename handling
    
    Set it afterwards, instead of relying on a second for the same
    metadata key. This is the only place where this is needed and
    can be easily handled in other ways.

 src/tracker3/grl-tracker-source-api.c | 26 ++++++++++++++++----------
 src/tracker3/grl-tracker-utils.c      | 21 ---------------------
 2 files changed, 16 insertions(+), 31 deletions(-)
---
diff --git a/src/tracker3/grl-tracker-source-api.c b/src/tracker3/grl-tracker-source-api.c
index 54c99f48..11143749 100644
--- a/src/tracker3/grl-tracker-source-api.c
+++ b/src/tracker3/grl-tracker-source-api.c
@@ -84,9 +84,13 @@ static void
 set_title_from_filename (GrlMedia *media)
 {
   const gchar *url;
-  gchar *path, *display_name, *ext, *title;
+  gchar *path, *display_name, *ext, *title = NULL;
   guint suffix_len;
 
+  /* Prefer the real title */
+  if (grl_media_get_title (media))
+    return;
+
   url = grl_media_get_url (media);
   if (url == NULL)
     return;
@@ -97,19 +101,21 @@ set_title_from_filename (GrlMedia *media)
   display_name = g_filename_display_basename (path);
   g_free (path);
   ext = strrchr (display_name, '.');
-  if (!ext)
-    goto out;
+  if (ext) {
+    suffix_len = strlen (ext);
+    if (suffix_len != 4 && suffix_len != 5)
+      goto out;
 
-  suffix_len = strlen (ext);
-  if (suffix_len != 4 && suffix_len != 5)
-    goto out;
+    title = g_strndup (display_name, ext - display_name);
+  } else {
+    title = g_strdup (display_name);
+  }
 
-  title = g_strndup (display_name, ext - display_name);
-  if (g_strcmp0 (grl_media_get_title (media), title) == 0)
-    grl_data_set_boolean (GRL_DATA (media), GRL_METADATA_KEY_TITLE_FROM_FILENAME, TRUE);
-  g_free (title);
+  grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_TITLE, title);
+  grl_data_set_boolean (GRL_DATA (media), GRL_METADATA_KEY_TITLE_FROM_FILENAME, TRUE);
 
 out:
+  g_free (title);
   g_free (display_name);
 }
 
diff --git a/src/tracker3/grl-tracker-utils.c b/src/tracker3/grl-tracker-utils.c
index 00310960..4550a210 100644
--- a/src/tracker3/grl-tracker-utils.c
+++ b/src/tracker3/grl-tracker-utils.c
@@ -107,19 +107,6 @@ set_favourite (TrackerSparqlCursor *cursor,
   grl_data_set_boolean (GRL_DATA (media), key, is_favourite);
 }
 
-static void
-set_title_from_filename (TrackerSparqlCursor *cursor,
-                         gint                 column,
-                         GrlMedia            *media,
-                         GrlKeyID             key)
-{
-  const gchar *str = tracker_sparql_cursor_get_string (cursor, column, NULL);
-  if (key == GRL_METADATA_KEY_TITLE) {
-    grl_data_set_boolean (GRL_DATA (media), GRL_METADATA_KEY_TITLE_FROM_FILENAME, TRUE);
-    grl_media_set_title (media, str);
-  }
-}
-
 static void
 set_title (TrackerSparqlCursor *cursor,
            gint                 column,
@@ -428,14 +415,6 @@ grl_tracker_setup_key_mappings (void)
                                   GRL_TYPE_FILTER_ALL,
                                   set_title);
 
-  insert_key_mapping_with_setter (GRL_METADATA_KEY_TITLE,
-                                  "fileName",
-                                  "nfo:fileName",
-                                  "nfo:fileName(?urn)",
-                                  "file",
-                                  GRL_TYPE_FILTER_ALL,
-                                  set_title_from_filename);
-
   insert_key_mapping (GRL_METADATA_KEY_URL,
                       "url",
                       "nie:isStoredAs",


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