[tracker/miner-flickr: 5/8] tracker-miner-flickr: User photos.getInfo



commit 82237e54b3ff423507a120adbce948d869a24165
Author: Adrien Bustany <abustany gnome org>
Date:   Fri Mar 12 13:36:53 2010 -0300

    tracker-miner-flickr: User photos.getInfo
    
    This commit makes the miner use the API function photos.getInfo which allows
    to get tags and details in on RPC call.

 src/tracker-miner-flickr/tracker-miner-flickr.vala |   81 +++++++++++---------
 1 files changed, 46 insertions(+), 35 deletions(-)
---
diff --git a/src/tracker-miner-flickr/tracker-miner-flickr.vala b/src/tracker-miner-flickr/tracker-miner-flickr.vala
index 491aa1a..e303ff2 100644
--- a/src/tracker-miner-flickr/tracker-miner-flickr.vala
+++ b/src/tracker-miner-flickr/tracker-miner-flickr.vala
@@ -227,11 +227,8 @@ public class MinerFlickr : Tracker.MinerWeb {
 			builder.predicate ("nie:url");
 			builder.object_string (photo_url);
 
-			builder.predicate ("dc:title");
-			builder.object_string (photo_node.get_attr ("title"));
-
+			insert_photo_info (photo_node, builder);
 			insert_exif_data (photo_node, builder);
-			insert_tags (photo_node, builder);
 
 			builder.insert_close ();
 
@@ -241,6 +238,51 @@ public class MinerFlickr : Tracker.MinerWeb {
 		}
 	}
 
+	private void insert_photo_info (Rest.XmlNode photo_node, SparqlBuilder builder) {
+		var info_call = rest.new_call ();
+		Rest.XmlNode root_node;
+		Rest.XmlNode title_node;
+		Rest.XmlNode description_node;
+		Rest.XmlNode tag_node;
+
+		info_call.add_params ("method", "flickr.photos.getInfo",
+		                      "photo_id", photo_node.get_attr ("id"));
+
+		try {
+			root_node = run_call (info_call);
+		} catch (Error call_error) {
+			warning ("Couldn't get info for photo %s: %s", photo_node.get_attr ("id"), call_error.message);
+			return;
+		}
+
+		title_node = root_node.find ("title");
+		if (title_node != null && title_node.content != null) {
+			builder.predicate ("dc:title");
+			builder.object_string (title_node.content);
+		}
+
+		description_node = root_node.find ("description");
+		if (description_node != null && description_node.content != null) {
+			builder.predicate ("rdfs:comment");
+			builder.object_string (description_node.content);
+		}
+
+		tag_node = root_node.find ("tags").find ("tag");
+
+		while (tag_node != null) {
+			builder.predicate ("nao:hasTag");
+
+			builder.object_blank_open ();
+			builder.predicate ("a");
+			builder.object ("nao:Tag");
+			builder.predicate ("nao:prefLabel");
+			builder.object_string (tag_node.get_attr ("raw"));
+			builder.object_blank_close ();
+
+			tag_node = tag_node.next;
+		}
+	}
+
 	private void insert_exif_data (Rest.XmlNode photo_node, SparqlBuilder builder) {
 		var exif_call = rest.new_call ();
 		Rest.XmlNode root_node;
@@ -327,37 +369,6 @@ public class MinerFlickr : Tracker.MinerWeb {
 		}
 	}
 
-	private void insert_tags (Rest.XmlNode photo_node, SparqlBuilder builder) {
-		var tags_call = rest.new_call ();
-		Rest.XmlNode root_node;
-		Rest.XmlNode tag_node;
-
-		tags_call.add_params ("method", "flickr.tags.getListPhoto",
-		                      "photo_id", photo_node.get_attr ("id"));
-
-		try {
-			root_node = run_call (tags_call);
-		} catch (Error call_error) {
-			warning ("Couldn't get tags for photo %s: %s", photo_node.get_attr ("id"), call_error.message);
-			return;
-		}
-
-		tag_node = root_node.find ("tag");
-
-		while (tag_node != null) {
-			builder.predicate ("nao:hasTag");
-
-			builder.object_blank_open ();
-			builder.predicate ("a");
-			builder.object ("nao:Tag");
-			builder.predicate ("nao:prefLabel");
-			builder.object_string (tag_node.get_attr ("raw"));
-			builder.object_blank_close ();
-
-			tag_node = tag_node.next;
-		}
-	}
-
 	private double ratioToDouble (string ratio) {
 		string[] tokens = ratio.split ("/");
         if (tokens[1].to_int () == 0) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]