Commit 8cd68133 authored by Sam Thursfield's avatar Sam Thursfield Committed by Martyn Russell

libtracker-extract,tracker-extract: Return guaranteed title

When a title is generated from the filename (--enable-guarantee-metadata), return it to the
calling extractor so that it can be used for media art. This allows storing video poster art
for any video, provided guaranteed metadata is enabled.
parent 826d347d
......@@ -74,8 +74,10 @@ get_date_from_file_mtime (const gchar *uri)
* tracker_guarantee_title_from_file:
* @metadata: the metadata object to insert the data into
* @key: the key to insert into @metadata
* @current_value: the current data to check before looking at @uri
* @current_value: the current data to check before looking at @uri.
* @uri: a string representing a URI to use
* @new_value: pointer to a string which receives the new title, or
* %NULL
*
* Checks @current_value to make sure it is sane (i.e. not %NULL or an
* empty string). If it is, then @uri is parsed to guarantee a
......@@ -93,7 +95,8 @@ gboolean
tracker_guarantee_title_from_file (TrackerSparqlBuilder *metadata,
const gchar *key,
const gchar *current_value,
const gchar *uri)
const gchar *uri,
gchar **p_new_value)
{
#ifdef GUARANTEE_METADATA
g_return_val_if_fail (metadata != NULL, FALSE);
......@@ -104,17 +107,30 @@ tracker_guarantee_title_from_file (TrackerSparqlBuilder *metadata,
if (current_value && *current_value != '\0') {
tracker_sparql_builder_object_unvalidated (metadata, current_value);
if (p_new_value != NULL) {
*p_new_value = g_strdup (current_value);
}
} else {
gchar *value;
value = get_title_from_file (uri);
tracker_sparql_builder_object_unvalidated (metadata, value);
if (p_new_value != NULL) {
*p_new_value = value;
} else {
g_free (value);
}
}
#else /* GUARANTEE_METADATA */
if (current_value && *current_value != '\0') {
tracker_sparql_builder_predicate (metadata, key);
tracker_sparql_builder_object_unvalidated (metadata, current_value);
if (p_new_value != NULL) {
*p_new_value = g_strdup (current_value);
}
}
#endif /* GUARANTEE_METADATA */
......
......@@ -33,7 +33,8 @@ G_BEGIN_DECLS
gboolean tracker_guarantee_title_from_file (TrackerSparqlBuilder *metadata,
const gchar *key,
const gchar *current_value,
const gchar *uri);
const gchar *uri,
gchar **p_new_value);
gboolean tracker_guarantee_date_from_file_mtime (TrackerSparqlBuilder *metadata,
const gchar *key,
const gchar *current_value,
......
......@@ -350,7 +350,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
add_tuple (metadata, "nmm:musicAlbum", album_uri);
tracker_guarantee_title_from_file (metadata, "nie:title", fd.title, uri);
tracker_guarantee_title_from_file (metadata, "nie:title", fd.title, uri, NULL);
add_tuple (metadata, "nmm:trackNumber", fd.tracknumber);
if (fd.album && album_uri) {
......
......@@ -289,7 +289,8 @@ read_metadata (TrackerSparqlBuilder *preupdate,
tracker_guarantee_title_from_file (metadata,
"nie:title",
md.title,
uri);
uri,
NULL);
if (md.artist) {
gchar *uri = tracker_sparql_escape_uri_printf ("urn:contact:%s", md.artist);
......
......@@ -630,7 +630,7 @@ extractor_apply_general_metadata (MetadataExtractor *extractor,
tracker_sparql_builder_object_unvalidated (metadata, genre);
}
tracker_guarantee_title_from_file (metadata, "nie:title", title, file_url);
tracker_guarantee_title_from_file (metadata, "nie:title", title, file_url, p_media_title);
add_date_time_gst_tag_with_mtime_fallback (metadata,
file_url,
......@@ -648,12 +648,7 @@ extractor_apply_general_metadata (MetadataExtractor *extractor,
g_free (artist_temp);
g_free (composer);
g_free (genre);
if (p_media_title != NULL) {
*p_media_title = title;
} else {
g_free (title);
}
}
static void
......
......@@ -526,7 +526,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
tracker_guarantee_title_from_file (metadata,
"nie:title",
md.title,
uri);
uri,
NULL);
if (md.orientation) {
tracker_sparql_builder_predicate (metadata, "nfo:orientation");
......
......@@ -2380,7 +2380,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
tracker_guarantee_title_from_file (metadata,
"nie:title",
md.title,
uri);
uri,
NULL);
if (md.lyricist_uri) {
tracker_sparql_builder_predicate (metadata, "nmm:lyricist");
......
......@@ -412,7 +412,8 @@ read_metadata (TrackerSparqlBuilder *preupdate,
tracker_guarantee_title_from_file (metadata,
"nie:title",
md.title,
uri);
uri,
NULL);
if (md.make || md.model) {
gchar *equip_uri;
......
......@@ -710,7 +710,8 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
tracker_guarantee_title_from_file (metadata,
"nie:title",
md.title,
uri);
uri,
NULL);
if (md.orientation) {
tracker_sparql_builder_predicate (metadata, "nfo:orientation");
......
......@@ -54,6 +54,7 @@ internal_test_title (const gchar *uri,
{
TrackerSparqlBuilder *builder;
gchar *sparql;
gchar *title_guaranteed;
builder = tracker_sparql_builder_new_update ();
tracker_sparql_builder_insert_open (builder, "test");
......@@ -61,7 +62,8 @@ internal_test_title (const gchar *uri,
g_assert (tracker_guarantee_title_from_file (builder,
"nie:title",
value,
uri));
uri,
&title_guaranteed));
tracker_sparql_builder_insert_close (builder);
sparql = g_strdup_printf ("INSERT INTO <test> {\n<test://resource> nie:title \"%s\" .\n}\n",
......@@ -70,6 +72,10 @@ internal_test_title (const gchar *uri,
==,
tracker_sparql_builder_get_result (builder));
g_assert_cmpstr (title_guaranteed,
==,
expected);
g_object_unref (builder);
g_free (sparql);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment