[grilo-plugins] flickr: Add EXIF tags to grilo keys
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] flickr: Add EXIF tags to grilo keys
- Date: Thu, 29 Jun 2017 15:30:21 +0000 (UTC)
commit 40a9efd76b77427ed12b78213961482d1b975093
Author: Rafael Fonseca <r4f4rfs gmail com>
Date: Fri Jun 17 17:16:10 2016 +0200
flickr: Add EXIF tags to grilo keys
https://bugzilla.gnome.org/show_bug.cgi?id=707643
src/flickr/grl-flickr.c | 105 +++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 101 insertions(+), 4 deletions(-)
---
diff --git a/src/flickr/grl-flickr.c b/src/flickr/grl-flickr.c
index 484b6ef..c0de3a2 100644
--- a/src/flickr/grl-flickr.c
+++ b/src/flickr/grl-flickr.c
@@ -32,6 +32,8 @@
#include <glib/gi18n-lib.h>
#include <string.h>
#include <stdlib.h>
+#include <errno.h>
+#include <math.h>
#ifdef GOA_ENABLED
#define GOA_API_IS_SUBJECT_TO_CHANGE
@@ -546,18 +548,113 @@ update_media (GrlMedia *media, GHashTable *photo)
}
static void
-getInfo_cb (GFlickr *f, GHashTable *photo, gpointer user_data)
+update_media_exif (GrlMedia *media, GHashTable *photo)
{
- GrlSourceResolveSpec *rs = (GrlSourceResolveSpec *) user_data;
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init (&iter, photo);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ GrlRelatedKeys *relkeys = NULL;
+
+ /*
+ * EXIF tags from: http://www.exif.org/Exif2-2.PDF
+ * and values from:
+ * http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html
+ */
+ if (g_strcmp0 (key, "Model") == 0) {
+ relkeys = grl_related_keys_new_with_keys (GRL_METADATA_KEY_CAMERA_MODEL,
+ value,
+ NULL);
+ } else if (g_strcmp0 (key, "Flash") == 0) {
+ gboolean used = g_str_has_prefix (value, "Fired") ||
+ g_str_has_prefix (value, "On,") ||
+ g_str_has_prefix (value, "Auto, Fired");
- if (photo) {
- update_media (rs->media, photo);
+ relkeys = grl_related_keys_new_with_keys (GRL_METADATA_KEY_FLASH_USED,
+ used,
+ NULL);
+ } else if (g_strcmp0 (key, "ExposureTime") == 0) {
+ /* ExposureTime is in the format "%d/%d" seconds */
+ gchar *endptr;
+ guint64 num, denom;
+
+ errno = 0;
+ num = g_ascii_strtoull (value, &endptr, 10);
+ if (errno == ERANGE && (num == G_MAXINT64 || num == G_MININT64))
+ continue;
+
+ if (endptr == value || *endptr != '/' || *(endptr +1) == '\0')
+ continue;
+
+ errno = 0;
+ denom = g_ascii_strtoull (endptr + 1, NULL, 10);
+ if ((errno == ERANGE && (denom == G_MAXINT64 || denom == G_MININT64)) ||
+ (errno != 0 && denom == 0))
+ continue;
+
+ relkeys = grl_related_keys_new_with_keys (GRL_METADATA_KEY_EXPOSURE_TIME,
+ num / (gdouble) denom,
+ NULL);
+ } else if (g_strcmp0 (key, "ISO") == 0) {
+ gdouble iso;
+
+ errno = 0;
+ iso = g_ascii_strtod (value, NULL);
+ if (errno != ERANGE && (fabs (iso) != HUGE_VAL))
+ relkeys = grl_related_keys_new_with_keys (GRL_METADATA_KEY_ISO_SPEED,
+ iso,
+ NULL);
+ } else if (g_strcmp0 (key, "Orientation") == 0) {
+ gint degrees;
+
+ if (g_str_match_string ("rotate 90 cw", value, FALSE))
+ degrees = 90;
+ else if (g_str_match_string ("rotate 180", value, FALSE))
+ degrees = 180;
+ else if (g_str_match_string ("rotate 270 cw", value, FALSE))
+ degrees = 270;
+ else
+ degrees = 0;
+
+ relkeys = grl_related_keys_new_with_keys (GRL_METADATA_KEY_ORIENTATION,
+ degrees,
+ NULL);
+ }
+
+ if (relkeys)
+ grl_data_add_related_keys (GRL_DATA (media), relkeys);
}
+}
+
+static void
+getExif_cb (GFlickr *f, GHashTable *photo, gpointer user_data)
+{
+ GrlSourceResolveSpec *rs = (GrlSourceResolveSpec *) user_data;
+
+ if (photo)
+ update_media_exif (rs->media, photo);
rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL);
}
static void
+getInfo_cb (GFlickr *f, GHashTable *photo, gpointer user_data)
+{
+ GrlSourceResolveSpec *rs = (GrlSourceResolveSpec *) user_data;
+
+ if (!photo)
+ rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL);
+
+ update_media (rs->media, photo);
+
+ g_flickr_photos_getExif (f,
+ grl_media_get_id (rs->media),
+ getExif_cb,
+ rs);
+}
+
+static void
search_cb (GFlickr *f, GList *photolist, gpointer user_data)
{
GrlMedia *media;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]