[grilo-plugins/wip/carlosg/tracker3: 20/48] tracker3: Assign a sparql name to each metadata key




commit 4f2467b7e07b686bb73af0756e48234d6613eec3
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat May 23 18:50:21 2020 +0200

    tracker3: Assign a sparql name to each metadata key
    
    So it can be used to generate variable names in SPARQL queries, and
    parameter bindings for filters.

 src/tracker3/grl-tracker-utils.c | 62 ++++++++++++++++++++++++++++++++++++++++
 src/tracker3/grl-tracker-utils.h |  3 ++
 2 files changed, 65 insertions(+)
---
diff --git a/src/tracker3/grl-tracker-utils.c b/src/tracker3/grl-tracker-utils.c
index 67ae46c6..74ccc629 100644
--- a/src/tracker3/grl-tracker-utils.c
+++ b/src/tracker3/grl-tracker-utils.c
@@ -153,6 +153,7 @@ set_int_metadata_keys (TrackerSparqlCursor *cursor,
 
 static tracker_grl_sparql_t *
 insert_key_mapping (GrlKeyID     grl_key,
+                    const gchar *sparql_var_name,
                     const gchar *sparql_key_attr,
                     const gchar *sparql_key_attr_call,
                     const gchar *sparql_key_flavor)
@@ -169,6 +170,7 @@ insert_key_mapping (GrlKeyID     grl_key,
   canon_name = g_strdup (GRL_METADATA_KEY_GET_NAME (grl_key));
 
   assoc->grl_key               = grl_key;
+  assoc->sparql_var_name       = sparql_var_name;
   assoc->sparql_key_name       = build_flavored_key (canon_name,
                                                      sparql_key_flavor);
   assoc->sparql_key_name_canon = g_strdup (canon_name);
@@ -205,6 +207,7 @@ insert_key_mapping (GrlKeyID     grl_key,
 
 static tracker_grl_sparql_t *
 insert_key_mapping_with_setter (GrlKeyID                       grl_key,
+                                const gchar                   *sparql_var_name,
                                 const gchar                   *sparql_key_attr,
                                 const gchar                   *sparql_key_attr_call,
                                 const gchar                   *sparql_key_flavor,
@@ -213,6 +216,7 @@ insert_key_mapping_with_setter (GrlKeyID                       grl_key,
   tracker_grl_sparql_t *assoc;
 
   assoc = insert_key_mapping (grl_key,
+                              sparql_var_name,
                               sparql_key_attr,
                               sparql_key_attr_call,
                               sparql_key_flavor);
@@ -241,98 +245,117 @@ grl_tracker_setup_key_mappings (void)
   sparql_to_grl_mapping = g_hash_table_new (g_str_hash, g_str_equal);
 
   insert_key_mapping (grl_metadata_key_tracker_urn,
+                      "urn",
                       NULL,
                       "?urn",
                       "file");
 
   insert_key_mapping (GRL_METADATA_KEY_ALBUM,
+                      "album",
                       NULL,
                       "nie:title(nmm:musicAlbum(?urn))",
                       "audio");
 
   insert_key_mapping (GRL_METADATA_KEY_ALBUM_DISC_NUMBER,
+                      "albumDiscNumber",
                       NULL,
                       "nmm:setNumber(nmm:musicAlbumDisc(?urn))",
                       "audio");
 
   insert_key_mapping (GRL_METADATA_KEY_ARTIST,
+                      "artist",
                       NULL,
                       "nmm:artistName(nmm:performer(?urn))",
                       "audio");
 
   insert_key_mapping (GRL_METADATA_KEY_ALBUM_ARTIST,
+                      "albumArtist",
                       NULL,
                       "nmm:artistName(nmm:albumArtist(nmm:musicAlbum(?urn)))",
                       "audio");
 
   insert_key_mapping (GRL_METADATA_KEY_AUTHOR,
+                      "author",
                       NULL,
                       "nmm:artistName(nmm:performer(?urn))",
                       "audio");
 
   insert_key_mapping (GRL_METADATA_KEY_BITRATE,
+                      "bitrate",
                       "nfo:averageBitrate",
                       "nfo:averageBitrate(?urn)",
                       "audio");
 
   insert_key_mapping (GRL_METADATA_KEY_CHILDCOUNT,
+                      "childCount",
                       "nfo:entryCounter",
                       "nfo:entryCounter(?urn)",
                       "directory");
 
   insert_key_mapping (GRL_METADATA_KEY_COMPOSER,
+                      "composer",
                       NULL,
                       "nmm:artistName(nmm:composer(?urn))",
                       "audio");
 
   insert_key_mapping (GRL_METADATA_KEY_SIZE,
+                      "size",
                       NULL,
                       "nfo:fileSize(?urn)",
                       "file");
 
   insert_key_mapping (grl_metadata_key_gibest_hash,
+                      "gibestHash",
                       NULL,
                       "(select nfo:hashValue(?h) { ?urn nfo:hasHash ?h . ?h nfo:hashAlgorithm \"gibest\" })",
                       "video");
 
   insert_key_mapping_with_setter (GRL_METADATA_KEY_MODIFICATION_DATE,
+                                  "lastModified",
                                   "nfo:fileLastModified",
                                   "nfo:fileLastModified(?urn)",
                                   "file",
                                   set_date);
 
   insert_key_mapping (GRL_METADATA_KEY_DURATION,
+                      "duration",
                       "nfo:duration",
                       "nfo:duration(?urn)",
                       "audio");
 
   insert_key_mapping (GRL_METADATA_KEY_MB_TRACK_ID,
+                      "mbTrack",
                       NULL,
                       "(SELECT tracker:referenceIdentifier(?t) AS ?t_id { ?urn tracker:hasExternalReference 
?t . ?t tracker:referenceSource \"https://musicbrainz.org/doc/Track\"; })",
                      "audio");
 
   insert_key_mapping (GRL_METADATA_KEY_MB_ARTIST_ID,
+                      "mbArtist",
                       NULL,
                      "(SELECT tracker:referenceIdentifier(?a) AS ?a_id { ?urn nmm:performer ?artist . 
?artist tracker:hasExternalReference ?a . ?a tracker:referenceSource \"https://musicbrainz.org/doc/Artist\"; 
})",
                       "audio");
 
   insert_key_mapping (GRL_METADATA_KEY_MB_RECORDING_ID,
+                      "mbRecording",
                       NULL,
                      "(SELECT tracker:referenceIdentifier(?r) AS ?r_id { ?urn tracker:hasExternalReference 
?r . ?r tracker:referenceSource \"https://musicbrainz.org/doc/Recording\"; })",
                       "audio");
 
   insert_key_mapping (GRL_METADATA_KEY_MB_RELEASE_ID,
+                      "mbRelease",
                       NULL,
                      "(SELECT tracker:referenceIdentifier(?re) AS ?re_id { ?urn nmm:musicAlbum ?album . 
?album tracker:hasExternalReference ?re . ?re tracker:referenceSource \"https://musicbrainz.org/doc/Release\"; 
})",
                       "audio");
 
   insert_key_mapping (GRL_METADATA_KEY_MB_RELEASE_GROUP_ID,
+                      "mbReleaseGroup",
                       NULL,
                      "(SELECT tracker:referenceIdentifier(?rg) AS ?rg_id { ?urn nmm:musicAlbum ?album . 
?album tracker:hasExternalReference ?rg . ?rg tracker:referenceSource 
\"https://musicbrainz.org/doc/Release_Group\"; })",
                      "audio");
 
   if (grl_metadata_key_chromaprint != 0) {
     insert_key_mapping_with_setter (grl_metadata_key_chromaprint,
+                                    "chromaprint",
                                     NULL,
                                     "(select nfo:hashValue(?h) { ?urn nfo:hasHash ?h . ?h nfo:hashAlgorithm 
\"chromaprint\" })",
                                     "audio",
@@ -340,128 +363,152 @@ grl_tracker_setup_key_mappings (void)
   };
 
   insert_key_mapping (GRL_METADATA_KEY_FRAMERATE,
+                      "frameRate",
                       "nfo:frameRate",
                       "nfo:frameRate(?urn)",
                       "video");
 
   insert_key_mapping (GRL_METADATA_KEY_HEIGHT,
+                      "height",
                       "nfo:height",
                       "nfo:height(?urn)",
                       "video");
 
   insert_key_mapping (GRL_METADATA_KEY_ID,
+                      "id",
                       "tracker:id",
                       "tracker:id(?urn)",
                       "file");
 
   insert_key_mapping_with_setter (GRL_METADATA_KEY_LAST_PLAYED,
+                                  "fileLastAccessed",
                                   "nfo:fileLastAccessed",
                                   "nfo:fileLastAccessed(?urn)",
                                   "file",
                                   set_date);
 
   insert_key_mapping (GRL_METADATA_KEY_MIME,
+                      "mimeType",
                       "nie:mimeType",
                       "nie:mimeType(?urn)",
                       "file");
 
   insert_key_mapping (GRL_METADATA_KEY_SITE,
+                      "siteUrl",
                       "nie:url",
                       "nie:url(?urn)",
                       "file");
 
   insert_key_mapping_with_setter (GRL_METADATA_KEY_TITLE,
+                                  "title",
                                   "nie:title",
                                   "nie:title(?urn)",
                                   "audio",
                                   set_title);
 
   insert_key_mapping_with_setter (GRL_METADATA_KEY_TITLE,
+                                  "fileName",
                                   "nfo:fileName",
                                   "nfo:fileName(?urn)",
                                   "file",
                                   set_title_from_filename);
 
   insert_key_mapping (GRL_METADATA_KEY_URL,
+                      "url",
                       "nie:url",
                       "nie:url(?urn)",
                       "file");
 
   insert_key_mapping (GRL_METADATA_KEY_WIDTH,
+                      "width",
                       "nfo:width",
                       "nfo:width(?urn)",
                       "video");
 
   insert_key_mapping (GRL_METADATA_KEY_SEASON,
+                      "season",
                       NULL,
                       "nmm:seasonNumber(nmm:isPartOfSeason(?urn))",
                       "video");
 
   insert_key_mapping (GRL_METADATA_KEY_EPISODE,
+                      "episode",
                       "nmm:episodeNumber",
                       "nmm:episodeNumber(?urn)",
                       "video");
 
   insert_key_mapping_with_setter (GRL_METADATA_KEY_CREATION_DATE,
+                                  "creationDate",
                                   "nie:contentCreated",
                                   "nie:contentCreated(?urn)",
                                   "image",
                                   set_date);
 
   insert_key_mapping (GRL_METADATA_KEY_CAMERA_MODEL,
+                      "cameraModel",
                       NULL,
                       "nfo:model(nfo:equipment(?urn))",
                       "image");
 
   insert_key_mapping (GRL_METADATA_KEY_FLASH_USED,
+                      "flashUsed",
                       "nmm:flash",
                       "nmm:flash(?urn)",
                       "image");
 
   insert_key_mapping (GRL_METADATA_KEY_EXPOSURE_TIME,
+                      "exposureTime",
                       "nmm:exposureTime",
                       "nmm:exposureTime(?urn)",
                       "image");
 
   insert_key_mapping (GRL_METADATA_KEY_ISO_SPEED,
+                      "isoSpeed",
                       "nmm:isoSpeed",
                       "nmm:isoSpeed(?urn)",
                       "image");
 
   insert_key_mapping_with_setter (GRL_METADATA_KEY_ORIENTATION,
+                                  "orientation",
                                   "nfo:orientation",
                                   "nfo:orientation(?urn)",
                                   "image",
                                   set_orientation);
 
   insert_key_mapping (GRL_METADATA_KEY_PLAY_COUNT,
+                      "playCount",
                       "nie:usageCounter",
                       "nie:usageCounter(?urn)",
                       "media");
 
   insert_key_mapping_with_setter (GRL_METADATA_KEY_LAST_PLAYED,
+                                  "lastPlayed",
                                   "nie:contentAccessed",
                                   "nie:contentAccessed(?urn)",
                                   "media",
                                   set_date);
 
   insert_key_mapping (GRL_METADATA_KEY_LAST_POSITION,
+                      "lastPlayPosition",
                       "nfo:lastPlayedPosition",
                       "nfo:lastPlayedPosition(?urn)",
                       "media");
 
   insert_key_mapping (GRL_METADATA_KEY_START_TIME,
+                      "startTime",
                       "nfo:audioOffset",
                       "nfo:audioOffset(?urn)",
                       "media");
 
   insert_key_mapping_with_setter (GRL_METADATA_KEY_TRACK_NUMBER,
+                                  "trackNumber",
                                   "nmm:trackNumber",
                                   "nmm:trackNumber(?urn)",
                                   "audio",
                                   set_int_metadata_keys);
 
   insert_key_mapping_with_setter (GRL_METADATA_KEY_FAVOURITE,
+                                  "favorite",
                                   "nao:hasTag",
                                   "nao:hasTag(?urn)",
                                   "audio",
@@ -800,3 +847,18 @@ grl_tracker_supported_keys (GrlSource *source)
 
   return supported_keys;
 }
+
+const gchar *
+grl_tracker_key_get_variable_name (const GrlKeyID key)
+{
+  tracker_grl_sparql_t *assoc;
+  GList *assoc_list;
+
+  assoc_list = g_hash_table_lookup (grl_to_sparql_mapping,
+                                    GRLKEYID_TO_POINTER (key));
+  if (!assoc_list)
+    return NULL;
+  assoc = assoc_list->data;
+
+  return assoc->sparql_var_name;
+}
diff --git a/src/tracker3/grl-tracker-utils.h b/src/tracker3/grl-tracker-utils.h
index 35ef0939..35e615c3 100644
--- a/src/tracker3/grl-tracker-utils.h
+++ b/src/tracker3/grl-tracker-utils.h
@@ -53,6 +53,7 @@ typedef void (*tracker_grl_sparql_setter_cb_t) (TrackerSparqlCursor *cursor,
 
 typedef struct {
   GrlKeyID     grl_key;
+  const gchar *sparql_var_name;
   const gchar *sparql_key_name;
   const gchar *sparql_key_name_canon;
   const gchar *sparql_key_attr;
@@ -68,6 +69,8 @@ const GList *grl_tracker_supported_keys (GrlSource *source);
 
 gboolean grl_tracker_key_is_supported (const GrlKeyID key);
 
+const gchar * grl_tracker_key_get_variable_name (const GrlKeyID key);
+
 void grl_tracker_setup_key_mappings (void);
 
 tracker_grl_sparql_t *grl_tracker_get_mapping_from_sparql (const gchar *key);


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