## How to use libtracker-extract How to use libtracker-extract — The essentials by example |

## Stability Level

Stable, unless otherwise indicated

## Synopsis

    #include <libtracker-extract/tracker-extract.h>

## Description

The libtracker-extract library is the foundation for Tracker metadata extraction of embedded data in files.

Tracker comes with extractors written for the most common file types (like MP3, JPEG, PNG, etc.), however, for more special cases, 3rd party applications may want to write their own plugin to extract their own file formats. This documentation describes how to do that.

Example 1. Basic extractor example

An example of how to write an extractor to retrieve PNG embedded metadata.

     /* Set functions to use to extract different mime types. */
     static TrackerExtractData extract_data[] = {
             { "image/png",  extract_png },
             { "sketch/png", extract_png },
             { NULL, NULL }
     };

     G_MODULE_EXPORT gboolean
     tracker_extract_get_metadata (const gchar          *uri,
                                   const gchar          *mimetype,
                                   TrackerSparqlBuilder *preupdate,
                                   TrackerSparqlBuilder *metadata,
                                   GString              *where)
     {
             gint height, width;

             /* Do data extraction. */
             height = ...
             width = ...

             /* Insert data into TrackerSparqlBuilder object. */
             tracker_sparql_builder_predicate (metadata, "a");
             tracker_sparql_builder_object (metadata, "nfo:Image");
             tracker_sparql_builder_object (metadata, "nmm:Photo");

             tracker_sparql_builder_predicate (metadata, "nfo:width");
             tracker_sparql_builder_object_int64 (metadata, width);

             tracker_sparql_builder_predicate (metadata, "nfo:height");
             tracker_sparql_builder_object_int64 (metadata, height);

             g_free (filename);

             /* Were we successful or not? */
             return TRUE;
     }

NOTE: This example has changed subtly since 0.10. For details see `tracker_extract_get_metadata()`.

## Details