[tracker/wip/resource: 10/11] WIP: porting more extractors to use TrackerResource
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/resource: 10/11] WIP: porting more extractors to use TrackerResource
- Date: Sun, 27 Mar 2016 00:57:23 +0000 (UTC)
commit c593b219a958d88142b068c8c1d23326663d3e8a
Author: Sam Thursfield <ssssam gmail com>
Date: Sun Mar 27 00:16:49 2016 +0000
WIP: porting more extractors to use TrackerResource
src/tracker-extract/tracker-extract-abw.c | 51 ++++-------
src/tracker-extract/tracker-extract-bmp.c | 18 ++--
src/tracker-extract/tracker-extract-gstreamer.c | 110 +++++++++++------------
3 files changed, 79 insertions(+), 100 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-abw.c b/src/tracker-extract/tracker-extract-abw.c
index 621e534..0428a1d 100644
--- a/src/tracker-extract/tracker-extract-abw.c
+++ b/src/tracker-extract/tracker-extract-abw.c
@@ -47,8 +47,7 @@ typedef enum {
} AbwParserTag;
struct AbwParserData {
- TrackerSparqlBuilder *metadata;
- TrackerSparqlBuilder *preupdate;
+ TrackerResource *resource;
GString *content;
gchar *uri;
@@ -109,8 +108,7 @@ abw_parser_text (GMarkupParseContext *context,
str, data->uri);
} else {
data->has_title = TRUE;
- tracker_sparql_builder_predicate (data->metadata, "nie:title");
- tracker_sparql_builder_object_unvalidated (data->metadata, str);
+ tracker_resource_set_property_string (data->resource, "nie:title", str);
}
break;
case ABW_PARSER_TAG_SUBJECT:
@@ -119,29 +117,27 @@ abw_parser_text (GMarkupParseContext *context,
str, data->uri);
} else {
data->has_subject = TRUE;
- tracker_sparql_builder_predicate (data->metadata, "nie:subject");
- tracker_sparql_builder_object_unvalidated (data->metadata, str);
+ tracker_resource_set_property_string (data->resource, "nie:subject", str);
}
break;
- case ABW_PARSER_TAG_CREATOR:
- tracker_sparql_builder_predicate (data->metadata, "nco:creator");
+ case ABW_PARSER_TAG_CREATOR: {
+ TrackerResource *creator;
+ creator = tracker_resource_new (NULL);
+ tracker_resource_set_property_uri (creator, "rdf:type", "nco:Contact");
+ tracker_resource_set_property_string (creator, "nco:fullname", str);
- tracker_sparql_builder_object_blank_open (data->metadata);
- tracker_sparql_builder_predicate (data->metadata, "a");
- tracker_sparql_builder_object (data->metadata, "nco:Contact");
+ tracker_resource_set_property_resource (data->resource, "nco:creator", creator);
+ g_object_unref (creator);
- tracker_sparql_builder_predicate (data->metadata, "nco:fullname");
- tracker_sparql_builder_object_unvalidated (data->metadata, str);
- tracker_sparql_builder_object_blank_close (data->metadata);
break;
+ }
case ABW_PARSER_TAG_DESCRIPTION:
if (data->has_comment) {
g_warning ("Avoiding additional comment (%s) in Abiword document '%s'",
str, data->uri);
} else {
data->has_comment = TRUE;
- tracker_sparql_builder_predicate (data->metadata, "nie:comment");
- tracker_sparql_builder_object_unvalidated (data->metadata, str);
+ tracker_resource_set_property_string (data->resource, "nie:comment", str);
}
break;
case ABW_PARSER_TAG_GENERATOR:
@@ -150,8 +146,7 @@ abw_parser_text (GMarkupParseContext *context,
str, data->uri);
} else {
data->has_generator = TRUE;
- tracker_sparql_builder_predicate (data->metadata, "nie:generator");
- tracker_sparql_builder_object_unvalidated (data->metadata, str);
+ tracker_resource_set_property_string (data->resource, "nie:generator", str);
}
break;
case ABW_PARSER_TAG_KEYWORDS:
@@ -160,8 +155,7 @@ abw_parser_text (GMarkupParseContext *context,
for (keyword = strtok_r (str, ",; ", &lasts); keyword;
keyword = strtok_r (NULL, ",; ", &lasts)) {
- tracker_sparql_builder_predicate (data->metadata, "nie:keyword");
- tracker_sparql_builder_object_unvalidated (data->metadata, keyword);
+ tracker_resource_add_property_string (data->resource, "nie:keyword", keyword);
}
}
break;
@@ -191,7 +185,6 @@ static GMarkupParser parser = {
G_MODULE_EXPORT gboolean
tracker_extract_get_metadata (TrackerExtractInfo *info)
{
- TrackerSparqlBuilder *preupdate, *metadata;
int fd;
gchar *filename, *contents;
gboolean retval = FALSE;
@@ -199,9 +192,6 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
gsize len;
struct stat st;
- preupdate = tracker_extract_info_get_preupdate_builder (info);
- metadata = tracker_extract_info_get_metadata_builder (info);
-
f = tracker_extract_info_get_file (info);
filename = g_file_get_path (f);
@@ -248,11 +238,9 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
AbwParserData data = { 0 };
data.uri = g_file_get_uri (f);
- data.metadata = metadata;
- data.preupdate = preupdate;
+ data.resource = tracker_resource_new (NULL);
- tracker_sparql_builder_predicate (metadata, "a");
- tracker_sparql_builder_object (metadata, "nfo:Document");
+ tracker_resource_set_property_uri (data.resource, "rdf:type", "nfo:Document");
context = g_markup_parse_context_new (&parser, 0, &data, NULL);
g_markup_parse_context_parse (context, contents, len, &error);
@@ -262,8 +250,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
g_error_free (error);
} else {
if (data.content) {
- tracker_sparql_builder_predicate (metadata, "nie:plainTextContent");
- tracker_sparql_builder_object_unvalidated (metadata, data.content->str);
+ tracker_resource_set_property_string (data.resource, "nie:plainTextContent",
data.content->str);
g_string_free (data.content, TRUE);
}
@@ -272,8 +259,10 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
g_markup_parse_context_free (context);
g_free (data.uri);
- }
+ tracker_extract_info_add_resource (info, data.resource);
+ g_object_unref (data.resource);
+ }
if (contents) {
munmap (contents, len);
diff --git a/src/tracker-extract/tracker-extract-bmp.c b/src/tracker-extract/tracker-extract-bmp.c
index 1f3e41e..17183a5 100644
--- a/src/tracker-extract/tracker-extract-bmp.c
+++ b/src/tracker-extract/tracker-extract-bmp.c
@@ -105,14 +105,12 @@ get_img_resolution (const GFile *file,
G_MODULE_EXPORT gboolean
tracker_extract_get_metadata (TrackerExtractInfo *info)
{
- TrackerSparqlBuilder *metadata;
+ TrackerResource *image;
goffset size;
gchar *filename;
GFile *file;
gint64 width = 0, height = 0;
- metadata = tracker_extract_info_get_metadata_builder (info);
-
file = tracker_extract_info_get_file (info);
if (!file) {
return FALSE;
@@ -127,21 +125,21 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
return FALSE;
}
- tracker_sparql_builder_predicate (metadata, "a");
- tracker_sparql_builder_object (metadata, "nfo:Image");
- tracker_sparql_builder_object (metadata, "nmm:Photo");
+ image = tracker_resource_new (NULL);
+ tracker_resource_set_property_uri (image, "rdf:type", "nfo:Image");
+ tracker_resource_add_property_uri (image, "rdf:type", "nmm:Photo");
if (get_img_resolution (file, &width, &height)) {
if (width > 0) {
- tracker_sparql_builder_predicate (metadata, "nfo:width");
- tracker_sparql_builder_object_int64 (metadata, width);
+ tracker_resource_set_property_int64 (image, "nfo:width", width);
}
if (height > 0) {
- tracker_sparql_builder_predicate (metadata, "nfo:height");
- tracker_sparql_builder_object_int64 (metadata, height);
+ tracker_resource_set_property_int64 (image, "nfo:height", height);
}
}
+ tracker_extract_info_add_resource (info, image);
+
return TRUE;
}
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index de3de76..f0c501e 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -158,6 +158,7 @@ static TrackerResource *
intern_artist (MetadataExtractor *extractor,
const gchar *artist_name)
{
+ GSList *node;
TrackerResource *artist;
gchar *artist_uri;
@@ -165,12 +166,13 @@ intern_artist (MetadataExtractor *extractor,
artist_uri = tracker_sparql_escape_uri_printf ("urn:artist:%s", artist_name);
- artist = g_slist_find_custom (extractor->artist_list, artist_uri,
- tracker_resource_identifier_compare_func);
- if (artist) {
- return artist;
- } else {
- artist = tracker_resource_new (artist_uri);
+ node = g_slist_find_custom (extractor->artist_list, artist_uri,
+ (GCompareFunc) tracker_resource_identifier_compare_func);
+ if (node) {
+ return node->data;
+ }
+
+ artist = tracker_resource_new (artist_uri);
tracker_resource_set_property_uri(artist, "rdf:type", "nmm:Artist");
tracker_resource_set_property_string(artist, "nmm:artistName", artist_name);
@@ -186,13 +188,11 @@ set_property_from_gst_tag (TrackerResource *resource,
GstTagList *tag_list,
const gchar *tag)
{
- gboolean ret;
- GValue *value;
-
- ret = gst_tag_list_copy_value (&value, tag_list, tag);
+ GValue *value = NULL;
- if (ret) {
- tracker_resource_set_property_gvalue (property_uri, value);
+ if (gst_tag_list_copy_value (value, tag_list, tag)) {
+ tracker_resource_set_property_gvalue (resource, property_uri, value);
+ g_value_unset (value);
}
}
@@ -327,7 +327,7 @@ set_keywords_from_gst_tag (TrackerResource *resource,
keywords = g_strsplit_set (str, " ,", -1);
while (keywords[i]) {
- tracker_resource_add_property_string (resource, "nie:keyword", g_strstrip
(keywords[i]);
+ tracker_resource_add_property_string (resource, "nie:keyword", g_strstrip
(keywords[i]));
i++;
}
@@ -336,23 +336,6 @@ set_keywords_from_gst_tag (TrackerResource *resource,
}
}
-static void
-replace_gst_tag (TrackerSparqlBuilder *preupdate,
- const gchar *key,
- GstTagList *tag_list,
- const gchar *tag)
-{
- GValue *value;
- gboolean has_it;
-
- has_it = gst_tag_list_copy_value (tag_list, tag, &value);
-
- if (! has_it)
- return;
-
- tracker_resource_set_property (key, value);
-}
-
static gchar *
get_embedded_cue_sheet_data (GstTagList *tag_list)
{
@@ -556,7 +539,7 @@ extractor_apply_general_metadata (MetadataExtractor *extractor,
gst_tag_list_get_string (tag_list, GST_TAG_PERFORMER, &performer_temp);
gst_tag_list_get_string (tag_list, GST_TAG_ARTIST, &artist_temp);
- gst_tag_list_get_string (tag_list, GST_TAG_COMPOSER, &composer);
+ gst_tag_list_get_string (tag_list, GST_TAG_COMPOSER, &composer_name);
performer_name = tracker_coalesce_strip (2, performer_temp, artist_temp);
@@ -572,7 +555,7 @@ extractor_apply_general_metadata (MetadataExtractor *extractor,
gst_tag_list_get_string (tag_list, GST_TAG_TITLE, &title);
if (genre && g_strcmp0 (genre, "Unknown") != 0) {
- tracker_resource_add_property_string ("nfo:genre", genre);
+ tracker_resource_add_property_string (resource, "nfo:genre", genre);
}
tracker_guarantee_resource_title_from_file (resource,
@@ -615,7 +598,7 @@ extractor_get_album_disc (MetadataExtractor *extractor,
GstTagList *tag_list)
{
TrackerResource *album = NULL, *album_artist = NULL, *album_disc = NULL;
- gchar *album_uri, *album_artist_uri, *album_disc_uri;
+ gchar *album_uri, *album_disc_uri;
gchar *album_artist_name;
gchar *album_title = NULL;
gchar *album_artist_temp = NULL;
@@ -665,9 +648,9 @@ extractor_get_album_disc (MetadataExtractor *extractor,
}
album_disc = tracker_resource_new (album_disc_uri);
- tracker_resource_set_property_resource (album_disc, "rdf:type", "nmm:MusicAlbumDisc");
+ tracker_resource_set_property_uri (album_disc, "rdf:type", "nmm:MusicAlbumDisc");
tracker_resource_set_property_int64 (album_disc, "nmm:setNumber", has_it ? volume_number : 1);
- tracker_resource_set_resource (album_disc, "nmm:albumDiscAlbum", album);
+ tracker_resource_set_property_resource (album_disc, "nmm:albumDiscAlbum", album);
set_property_from_gst_tag (album, "nmm:albumGain", extractor->tagcache, GST_TAG_ALBUM_GAIN);
set_property_from_gst_tag (album, "nmm:albumPeakGain", extractor->tagcache, GST_TAG_ALBUM_PEAK);
@@ -702,7 +685,7 @@ extractor_get_equipment (MetadataExtractor *extractor,
model ? model : "");
equipment = tracker_resource_new (equip_uri);
- tracker_resource_set_property_uri (resource, "rdf:type", "nfo:Equipment");
+ tracker_resource_set_property_uri (equipment, "rdf:type", "nfo:Equipment");
if (manuf) {
tracker_resource_set_property_string (equipment, "nfo:manufacturer", manuf);
@@ -739,12 +722,12 @@ extractor_apply_audio_metadata (MetadataExtractor *extractor,
tracker_resource_set_property_resource (audio, "nmm:composer", composer);
}
- if (album) {
- tracker_resource_set_property_resource (audio, "nmm:musicAlbum", album);
- }
-
if (album_disc) {
+ TrackerResource *album;
+ album = tracker_resource_get_property_resource (album_disc, "nmm:albumDiscAlbum");
+
tracker_resource_set_property_resource (audio, "nmm:musicAlbumDisc", album_disc);
+ tracker_resource_set_property_resource (audio, "nmm:musicAlbum", album);
}
}
@@ -771,7 +754,8 @@ extractor_apply_video_metadata (MetadataExtractor *extractor,
static TrackerResource *
extract_track (MetadataExtractor *extractor,
TrackerTocEntry *toc_entry,
- const gchar *file_url)
+ const gchar *file_url,
+ TrackerResource *album_disc)
{
TrackerResource *track;
TrackerResource *track_performer = NULL, *track_composer = NULL;
@@ -811,10 +795,12 @@ extract_track (MetadataExtractor *extractor,
tracker_resource_set_property_double (track, "nfo:audioOffset", toc_entry->start);
- g_free (track_performer_uri);
- g_free (track_composer_uri);
+ g_object_unref (track_performer);
+ g_object_unref (track_composer);
g_free (track_uri);
+
+ return track;
}
#define CHUNK_N_BYTES (2 << 15)
@@ -872,8 +858,12 @@ static TrackerResource *
extract_metadata (MetadataExtractor *extractor,
const gchar *file_url)
{
+ TrackerResource *resource;
+
g_return_if_fail (extractor != NULL);
+ resource = tracker_resource_new (NULL);
+
#ifdef HAVE_LIBMEDIAART
extractor->media_art_type = MEDIA_ART_NONE;
#endif
@@ -942,8 +932,8 @@ extract_metadata (MetadataExtractor *extractor,
extractor->media_art_type = MEDIA_ART_VIDEO;
#endif
} else {
- tracker_resource_set_property_uri_list (resource, "rdf:type",
- "nfo:Image", "nmm:Photo", NULL);
+ tracker_resource_set_property_uri (resource, "rdf:type", "nfo:Image");
+ tracker_resource_add_property_uri (resource, "rdf:type", "nmm:Photo");
}
}
@@ -957,31 +947,32 @@ extract_metadata (MetadataExtractor *extractor,
extractor_apply_general_metadata (extractor,
extractor->tagcache,
file_url,
+ resource,
&performer,
&composer);
equipment = extractor_get_equipment (extractor, extractor->tagcache);
if (equipment) {
- tracker_resource_set_property_resource (main_resource, "nfo:equipment", equipment);
+ tracker_resource_set_property_resource (resource, "nfo:equipment", equipment);
g_object_unref (equipment);
}
geolocation = extractor_get_geolocation (extractor, extractor->tagcache);
if (geolocation) {
- tracker_resource_set_property (main_resource, "slo:location", geolocation);
+ tracker_resource_set_property_resource (resource, "slo:location", geolocation);
g_object_unref (geolocation);
}
address = extractor_get_address (extractor, extractor->tagcache);
if (address) {
- tracker_resource_set_property (main_resource, "slo:postalAddress", address);
+ tracker_resource_set_property_resource (resource, "slo:postalAddress", address);
g_object_unref (address);
}
if (extractor->mime == EXTRACT_MIME_VIDEO) {
extractor_apply_video_metadata (extractor,
extractor->tagcache,
- main_resource,
+ resource,
performer,
composer);
}
@@ -991,10 +982,9 @@ extract_metadata (MetadataExtractor *extractor,
extractor_apply_audio_metadata (extractor,
extractor->tagcache,
- metadata,
+ resource,
performer,
composer,
- album,
album_disc);
/* If the audio file contains multiple tracks, we create the tracks
@@ -1005,12 +995,12 @@ extract_metadata (MetadataExtractor *extractor,
for (node = extractor->toc->entry_list; node; node = node->next) {
TrackerResource *track;
- track = extract_track_metadata (extractor, node->data, file_url,
album_disc);
- tracker_resource_set_property_resource (track, "nie:isStoredAs",
main_resource);
+ track = extract_track (extractor, node->data, file_url, album_disc);
+ tracker_resource_set_property_resource (track, "nie:isStoredAs",
resource);
g_object_unref (track);
}
- tracker_resource_set_property_string (main_resource, "nie:url", file_url);
+ tracker_resource_set_property_string (resource, "nie:url", file_url);
}
g_object_unref (album_disc);
@@ -1047,7 +1037,7 @@ extract_metadata (MetadataExtractor *extractor,
tracker_resource_set_property_string (resource, "nfo:hashAlgorithm", "gibest");
- tracker_resource_set_property_string_resource (main_resource, "nfo:hasHash",
hash_resource);
+ tracker_resource_set_property_resource (resource, "nfo:hasHash", hash_resource);
g_object_unref (hash_resource);
}
@@ -1056,13 +1046,15 @@ extract_metadata (MetadataExtractor *extractor,
/* If content was encrypted, set it. */
/* #warning TODO: handle encrypted content with the Discoverer/GUPnP-DLNA backends */
- common_extract_stream_metadata (extractor, file_url, main_resource);
+ common_extract_stream_metadata (extractor, file_url, resource);
#ifdef HAVE_LIBMEDIAART
if (extractor->mime == EXTRACT_MIME_AUDIO) {
get_embedded_media_art (extractor);
}
#endif
+
+ return resource;
}
#if defined(GSTREAMER_BACKEND_DISCOVERER) || \
@@ -1316,7 +1308,7 @@ tracker_extract_gstreamer (const gchar *uri,
TrackerExtractInfo *info,
ExtractMime type)
{
- TrackerResource *main_resource;
+ TrackerResource *main_resource = NULL;
MetadataExtractor *extractor;
GstBuffer *buffer;
gchar *cue_sheet;
@@ -1421,7 +1413,7 @@ tracker_extract_gstreamer (const gchar *uri,
g_slice_free (MetadataExtractor, extractor);
- return main)resource;
+ return main_resource;
}
G_MODULE_EXPORT gboolean
@@ -1459,7 +1451,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
return FALSE;
}
- tracker_extract_info_add_resource (main_resource);
+ tracker_extract_info_add_resource (info, main_resource);
g_object_unref (main_resource);
g_free (uri);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]