[grilo-plugins/wip/carlosg/tracker3: 17/37] tracker3: Add a getter for the property path/subselect for a metadata key
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins/wip/carlosg/tracker3: 17/37] tracker3: Add a getter for the property path/subselect for a metadata key
- Date: Mon, 25 May 2020 13:20:08 +0000 (UTC)
commit eeab97b38edbd8d0c5a90d62db69b956a15f1862
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat May 23 19:34:37 2020 +0200
tracker3: Add a getter for the property path/subselect for a metadata key
We match by GrlTypeFilter, so it's easy to discard those that don't apply.
src/tracker3/grl-tracker-utils.c | 144 ++++++++++++++++++++++++++++-----------
src/tracker3/grl-tracker-utils.h | 3 +
2 files changed, 108 insertions(+), 39 deletions(-)
---
diff --git a/src/tracker3/grl-tracker-utils.c b/src/tracker3/grl-tracker-utils.c
index 74ccc629..6bd86063 100644
--- a/src/tracker3/grl-tracker-utils.c
+++ b/src/tracker3/grl-tracker-utils.c
@@ -152,11 +152,12 @@ 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)
+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,
+ GrlTypeFilter filter)
{
tracker_grl_sparql_t *assoc;
GList *assoc_list;
@@ -177,6 +178,7 @@ insert_key_mapping (GrlKeyID grl_key,
assoc->sparql_key_attr = sparql_key_attr;
assoc->sparql_key_attr_call = sparql_key_attr_call;
assoc->sparql_key_flavor = sparql_key_flavor;
+ assoc->filter = filter;
assoc_list = g_list_append (assoc_list, assoc);
@@ -211,6 +213,7 @@ insert_key_mapping_with_setter (GrlKeyID grl_key,
const gchar *sparql_key_attr,
const gchar *sparql_key_attr_call,
const gchar *sparql_key_flavor,
+ GrlTypeFilter filter,
tracker_grl_sparql_setter_cb_t setter)
{
tracker_grl_sparql_t *assoc;
@@ -219,7 +222,8 @@ insert_key_mapping_with_setter (GrlKeyID grl_key,
sparql_var_name,
sparql_key_attr,
sparql_key_attr_call,
- sparql_key_flavor);
+ sparql_key_flavor,
+ filter);
assoc->set_value = setter;
@@ -248,110 +252,128 @@ grl_tracker_setup_key_mappings (void)
"urn",
NULL,
"?urn",
- "file");
+ "file",
+ GRL_TYPE_FILTER_ALL);
insert_key_mapping (GRL_METADATA_KEY_ALBUM,
"album",
NULL,
"nie:title(nmm:musicAlbum(?urn))",
- "audio");
+ "audio",
+ GRL_TYPE_FILTER_AUDIO);
insert_key_mapping (GRL_METADATA_KEY_ALBUM_DISC_NUMBER,
"albumDiscNumber",
NULL,
"nmm:setNumber(nmm:musicAlbumDisc(?urn))",
- "audio");
+ "audio",
+ GRL_TYPE_FILTER_AUDIO);
insert_key_mapping (GRL_METADATA_KEY_ARTIST,
"artist",
NULL,
"nmm:artistName(nmm:performer(?urn))",
- "audio");
+ "audio",
+ GRL_TYPE_FILTER_AUDIO);
insert_key_mapping (GRL_METADATA_KEY_ALBUM_ARTIST,
"albumArtist",
NULL,
"nmm:artistName(nmm:albumArtist(nmm:musicAlbum(?urn)))",
- "audio");
+ "audio",
+ GRL_TYPE_FILTER_AUDIO);
insert_key_mapping (GRL_METADATA_KEY_AUTHOR,
"author",
NULL,
"nmm:artistName(nmm:performer(?urn))",
- "audio");
+ "audio",
+ GRL_TYPE_FILTER_AUDIO);
insert_key_mapping (GRL_METADATA_KEY_BITRATE,
"bitrate",
"nfo:averageBitrate",
"nfo:averageBitrate(?urn)",
- "audio");
+ "audio",
+ GRL_TYPE_FILTER_AUDIO | GRL_TYPE_FILTER_VIDEO);
insert_key_mapping (GRL_METADATA_KEY_CHILDCOUNT,
"childCount",
"nfo:entryCounter",
"nfo:entryCounter(?urn)",
- "directory");
+ "directory",
+ GRL_TYPE_FILTER_ALL);
insert_key_mapping (GRL_METADATA_KEY_COMPOSER,
"composer",
NULL,
"nmm:artistName(nmm:composer(?urn))",
- "audio");
+ "audio",
+ GRL_TYPE_FILTER_AUDIO);
insert_key_mapping (GRL_METADATA_KEY_SIZE,
"size",
NULL,
"nfo:fileSize(?urn)",
- "file");
+ "file",
+ GRL_TYPE_FILTER_ALL);
insert_key_mapping (grl_metadata_key_gibest_hash,
"gibestHash",
NULL,
"(select nfo:hashValue(?h) { ?urn nfo:hasHash ?h . ?h nfo:hashAlgorithm \"gibest\" })",
- "video");
+ "video",
+ GRL_TYPE_FILTER_VIDEO);
insert_key_mapping_with_setter (GRL_METADATA_KEY_MODIFICATION_DATE,
"lastModified",
"nfo:fileLastModified",
"nfo:fileLastModified(?urn)",
"file",
+ GRL_TYPE_FILTER_ALL,
set_date);
insert_key_mapping (GRL_METADATA_KEY_DURATION,
"duration",
"nfo:duration",
"nfo:duration(?urn)",
- "audio");
+ "audio",
+ GRL_TYPE_FILTER_AUDIO | GRL_TYPE_FILTER_VIDEO);
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");
+ "audio",
+ GRL_TYPE_FILTER_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");
+ "audio",
+ GRL_TYPE_FILTER_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");
+ "audio",
+ GRL_TYPE_FILTER_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");
+ "audio",
+ GRL_TYPE_FILTER_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");
+ "audio",
+ GRL_TYPE_FILTER_AUDIO);
if (grl_metadata_key_chromaprint != 0) {
insert_key_mapping_with_setter (grl_metadata_key_chromaprint,
@@ -359,6 +381,7 @@ grl_tracker_setup_key_mappings (void)
NULL,
"(select nfo:hashValue(?h) { ?urn nfo:hasHash ?h . ?h nfo:hashAlgorithm
\"chromaprint\" })",
"audio",
+ GRL_TYPE_FILTER_AUDIO,
set_string_metadata_keys);
};
@@ -366,44 +389,51 @@ grl_tracker_setup_key_mappings (void)
"frameRate",
"nfo:frameRate",
"nfo:frameRate(?urn)",
- "video");
+ "video",
+ GRL_TYPE_FILTER_VIDEO);
insert_key_mapping (GRL_METADATA_KEY_HEIGHT,
"height",
"nfo:height",
"nfo:height(?urn)",
- "video");
+ "video",
+ GRL_TYPE_FILTER_VIDEO | GRL_TYPE_FILTER_IMAGE);
insert_key_mapping (GRL_METADATA_KEY_ID,
"id",
"tracker:id",
"tracker:id(?urn)",
- "file");
+ "file",
+ GRL_TYPE_FILTER_ALL);
insert_key_mapping_with_setter (GRL_METADATA_KEY_LAST_PLAYED,
"fileLastAccessed",
"nfo:fileLastAccessed",
"nfo:fileLastAccessed(?urn)",
"file",
+ GRL_TYPE_FILTER_ALL,
set_date);
insert_key_mapping (GRL_METADATA_KEY_MIME,
"mimeType",
"nie:mimeType",
"nie:mimeType(?urn)",
- "file");
+ "file",
+ GRL_TYPE_FILTER_ALL);
insert_key_mapping (GRL_METADATA_KEY_SITE,
"siteUrl",
"nie:url",
"nie:url(?urn)",
- "file");
+ "file",
+ GRL_TYPE_FILTER_ALL);
insert_key_mapping_with_setter (GRL_METADATA_KEY_TITLE,
"title",
"nie:title",
"nie:title(?urn)",
"audio",
+ GRL_TYPE_FILTER_ALL,
set_title);
insert_key_mapping_with_setter (GRL_METADATA_KEY_TITLE,
@@ -411,100 +441,116 @@ grl_tracker_setup_key_mappings (void)
"nfo:fileName",
"nfo:fileName(?urn)",
"file",
+ GRL_TYPE_FILTER_ALL,
set_title_from_filename);
insert_key_mapping (GRL_METADATA_KEY_URL,
"url",
"nie:url",
"nie:url(?urn)",
- "file");
+ "file",
+ GRL_TYPE_FILTER_ALL);
insert_key_mapping (GRL_METADATA_KEY_WIDTH,
"width",
"nfo:width",
"nfo:width(?urn)",
- "video");
+ "video",
+ GRL_TYPE_FILTER_VIDEO | GRL_TYPE_FILTER_IMAGE);
insert_key_mapping (GRL_METADATA_KEY_SEASON,
"season",
NULL,
"nmm:seasonNumber(nmm:isPartOfSeason(?urn))",
- "video");
+ "video",
+ GRL_TYPE_FILTER_VIDEO);
insert_key_mapping (GRL_METADATA_KEY_EPISODE,
"episode",
"nmm:episodeNumber",
"nmm:episodeNumber(?urn)",
- "video");
+ "video",
+ GRL_TYPE_FILTER_VIDEO);
insert_key_mapping_with_setter (GRL_METADATA_KEY_CREATION_DATE,
"creationDate",
"nie:contentCreated",
"nie:contentCreated(?urn)",
"image",
+ GRL_TYPE_FILTER_ALL,
set_date);
insert_key_mapping (GRL_METADATA_KEY_CAMERA_MODEL,
"cameraModel",
NULL,
"nfo:model(nfo:equipment(?urn))",
- "image");
+ "image",
+ GRL_TYPE_FILTER_IMAGE);
insert_key_mapping (GRL_METADATA_KEY_FLASH_USED,
"flashUsed",
"nmm:flash",
"nmm:flash(?urn)",
- "image");
+ "image",
+ GRL_TYPE_FILTER_IMAGE);
insert_key_mapping (GRL_METADATA_KEY_EXPOSURE_TIME,
"exposureTime",
"nmm:exposureTime",
"nmm:exposureTime(?urn)",
- "image");
+ "image",
+ GRL_TYPE_FILTER_IMAGE);
insert_key_mapping (GRL_METADATA_KEY_ISO_SPEED,
"isoSpeed",
"nmm:isoSpeed",
"nmm:isoSpeed(?urn)",
- "image");
+ "image",
+ GRL_TYPE_FILTER_IMAGE);
insert_key_mapping_with_setter (GRL_METADATA_KEY_ORIENTATION,
"orientation",
"nfo:orientation",
"nfo:orientation(?urn)",
"image",
+ GRL_TYPE_FILTER_IMAGE,
set_orientation);
insert_key_mapping (GRL_METADATA_KEY_PLAY_COUNT,
"playCount",
"nie:usageCounter",
"nie:usageCounter(?urn)",
- "media");
+ "media",
+ GRL_TYPE_FILTER_AUDIO | GRL_TYPE_FILTER_VIDEO);
insert_key_mapping_with_setter (GRL_METADATA_KEY_LAST_PLAYED,
"lastPlayed",
"nie:contentAccessed",
"nie:contentAccessed(?urn)",
"media",
+ GRL_TYPE_FILTER_ALL,
set_date);
insert_key_mapping (GRL_METADATA_KEY_LAST_POSITION,
"lastPlayPosition",
"nfo:lastPlayedPosition",
"nfo:lastPlayedPosition(?urn)",
- "media");
+ "media",
+ GRL_TYPE_FILTER_AUDIO | GRL_TYPE_FILTER_VIDEO);
insert_key_mapping (GRL_METADATA_KEY_START_TIME,
"startTime",
"nfo:audioOffset",
"nfo:audioOffset(?urn)",
- "media");
+ "media",
+ GRL_TYPE_FILTER_AUDIO);
insert_key_mapping_with_setter (GRL_METADATA_KEY_TRACK_NUMBER,
"trackNumber",
"nmm:trackNumber",
"nmm:trackNumber(?urn)",
"audio",
+ GRL_TYPE_FILTER_AUDIO,
set_int_metadata_keys);
insert_key_mapping_with_setter (GRL_METADATA_KEY_FAVOURITE,
@@ -512,6 +558,7 @@ grl_tracker_setup_key_mappings (void)
"nao:hasTag",
"nao:hasTag(?urn)",
"audio",
+ GRL_TYPE_FILTER_ALL,
set_favourite);
}
@@ -862,3 +909,22 @@ grl_tracker_key_get_variable_name (const GrlKeyID key)
return assoc->sparql_var_name;
}
+
+const gchar *
+grl_tracker_key_get_sparql_statement (const GrlKeyID key,
+ GrlTypeFilter filter)
+{
+ 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;
+ if ((assoc->filter & filter) == 0)
+ return NULL;
+
+ return assoc->sparql_key_attr_call;
+}
diff --git a/src/tracker3/grl-tracker-utils.h b/src/tracker3/grl-tracker-utils.h
index 35e615c3..7db23331 100644
--- a/src/tracker3/grl-tracker-utils.h
+++ b/src/tracker3/grl-tracker-utils.h
@@ -59,6 +59,7 @@ typedef struct {
const gchar *sparql_key_attr;
const gchar *sparql_key_attr_call;
const gchar *sparql_key_flavor;
+ GrlTypeFilter filter;
tracker_grl_sparql_setter_cb_t set_value;
} tracker_grl_sparql_t;
@@ -70,6 +71,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);
+const gchar * grl_tracker_key_get_sparql_statement (const GrlKeyID key,
+ GrlTypeFilter filter);
void grl_tracker_setup_key_mappings (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]