[tracker/rss-enclosures: 2/4] tracker-miner-rss: corrections while building query to insert an item with an enclosure attached tra



commit 9ba4fdd0c62fe0d8c5640decbbf3210851a2ec77
Author: Roberto Guido <bob4mail gmail com>
Date:   Tue Apr 6 00:56:19 2010 +0200

    tracker-miner-rss: corrections while building query to insert an item with an enclosure attached
    tracker-miner-rss: correct access to the subject of a channel when asking for item existance
    tracker-miner-rss: fetchs also mfo:downloadPath with other FeedChannel informations

 src/miners/rss/tracker-miner-rss.c   |   71 ++++++++++++++++++++--------------
 src/miners/rss/wrap-feed-enclosure.c |    4 +-
 2 files changed, 43 insertions(+), 32 deletions(-)
---
diff --git a/src/miners/rss/tracker-miner-rss.c b/src/miners/rss/tracker-miner-rss.c
index d2362ca..c23eaa9 100644
--- a/src/miners/rss/tracker-miner-rss.c
+++ b/src/miners/rss/tracker-miner-rss.c
@@ -242,9 +242,11 @@ enclosure_downloaded_cb (SoupSession *session,
 	g_object_get (msg, "status-code", &status, NULL);
 
 	if (status < 200 || status > 299)
-		g_warning ("Unable to download enclosure in %s.", feed_enclosure_get_url (FEED_ENCLOSURE (enclosure)));
+		g_warning ("Unable to download enclosure in %s.",
+                   feed_enclosure_get_url (FEED_ENCLOSURE (enclosure)));
 	else
-		wrap_feed_enclosure_save_data (enclosure, msg->response_body->data, msg->response_body->length);
+		wrap_feed_enclosure_save_data (enclosure, msg->response_body->data,
+                                       msg->response_body->length);
 
 	g_object_unref (enclosure);
 }
@@ -279,7 +281,8 @@ manage_enclosure (TrackerMinerRSS *miner,
 	msg = soup_message_new ("GET", feed_enclosure_get_url (enclosure));
 
 	priv = GET_PRIV (miner);
-	soup_session_queue_message (feeds_pool_get_session (priv->pool), msg, enclosure_downloaded_cb, enc_wrap);
+	soup_session_queue_message (feeds_pool_get_session (priv->pool), msg,
+                                enclosure_downloaded_cb, enc_wrap);
 }
 
 static int
@@ -289,6 +292,7 @@ queue_enclosures (TrackerMinerRSS      *miner,
                   TrackerSparqlBuilder *sparql)
 {
 	int num;
+	const gchar *tmp_string;
 	gchar *subject;
 	gchar *rsubject;
 	const GList *iter;
@@ -297,32 +301,38 @@ queue_enclosures (TrackerMinerRSS      *miner,
 	for (iter = feed_item_get_enclosures (item), num = 0; iter; iter = iter->next) {
 		enc = iter->data;
 
+		tmp_string = feed_enclosure_get_url (enc);
+		if (tmp_string == NULL)
+			continue;
+
 		rsubject = g_strdup_printf ("_:enclosurefile%d", num);
 		subject = g_strdup_printf ("_:enclosure%d", num);
 
 		tracker_sparql_builder_insert_open (sparql, rsubject);
+		tracker_sparql_builder_subject (sparql, rsubject);
 		tracker_sparql_builder_predicate (sparql, "a");
 		tracker_sparql_builder_object (sparql, "nfo:RemoteDataObject");
+		tracker_sparql_builder_predicate (sparql, "a");
+		tracker_sparql_builder_object (sparql, "nie:InformationElement");
 
-		tracker_sparql_builder_predicate (sparql, "nfo:fileUrl");
-		tracker_sparql_builder_object_string (sparql, feed_enclosure_get_url (enc));
+		tracker_sparql_builder_predicate (sparql, "nie:url");
+		tracker_sparql_builder_object_string (sparql, tmp_string);
 
 		tracker_sparql_builder_predicate (sparql, "nfo:fileSize");
 		tracker_sparql_builder_object_int64 (sparql, (gint64) feed_enclosure_get_length (enc));
 
-		tracker_sparql_builder_predicate (sparql, "nfo:encoding");
-		tracker_sparql_builder_object_string (sparql, feed_enclosure_get_format (enc));
-
-		tracker_sparql_builder_insert_close (sparql);
+		tmp_string = feed_enclosure_get_format (enc);
+		if (tmp_string != NULL) {
+			tracker_sparql_builder_predicate (sparql, "nie:mimeType");
+			tracker_sparql_builder_object_string (sparql, tmp_string);
+		}
 
-		tracker_sparql_builder_insert_open (sparql, subject);
+		tracker_sparql_builder_subject (sparql, subject);
 		tracker_sparql_builder_predicate (sparql, "a");
 		tracker_sparql_builder_object (sparql, "mfo:Enclosure");
 
 		tracker_sparql_builder_predicate (sparql, "mfo:remoteLink");
-		tracker_sparql_builder_object_iri (sparql, rsubject);
-
-		tracker_sparql_builder_insert_close (sparql);
+		tracker_sparql_builder_object (sparql, rsubject);
 
 		g_free (rsubject);
 		g_free (subject);
@@ -419,6 +429,7 @@ item_verify_reply_cb (GObject      *source_object,
 	}
 
 	item = user_data;
+	feed = feed_item_get_parent (item);
 
 	url = get_message_url (item);
 
@@ -428,7 +439,6 @@ item_verify_reply_cb (GObject      *source_object,
 	enclosures_num = queue_enclosures (miner, WRAP_FEED_CHANNEL (feed), item, sparql);
 
 	has_geopoint = feed_item_get_geo_point (item, &latitude, &longitude);
-	tracker_sparql_builder_insert_open (sparql, url);
 
 	if (has_geopoint) {
 		g_message ("  Geopoint, using longitude:%f, latitude:%f", 
@@ -504,7 +514,7 @@ item_verify_reply_cb (GObject      *source_object,
 	for (i = 0; i < enclosures_num; i++) {
 		tracker_sparql_builder_predicate (sparql, "mfo:enclosureList");
 		enclosure_ref = g_strdup_printf ("_:enclosure%d", i);
-		tracker_sparql_builder_object_iri (sparql, enclosure_ref);
+		tracker_sparql_builder_object (sparql, enclosure_ref);
 		g_free (enclosure_ref);
 	}
 
@@ -521,23 +531,22 @@ item_verify_reply_cb (GObject      *source_object,
 
 static void
 check_if_save (TrackerMinerRSS *miner,
-               FeedItem        *item)
+               FeedItem        *item,
+               FeedChannel     *feed)
 {
-	FeedChannel *feed;
+	WrapFeedChannel *wfeed;
 	gchar *query;
-	gchar *communication_channel;
 	const gchar *url;
 
 	url = get_message_url (item);
-	feed = feed_item_get_parent (item);
-	communication_channel = g_object_get_data (G_OBJECT (feed), "subject");
+	wfeed = WRAP_FEED_CHANNEL (feed);
 
 	g_debug ("Verifying feed '%s' is stored", url);
 
 	query = g_strdup_printf ("ASK { ?message a mfo:FeedMessage; "
 	                         "nie:url \"%s\"; nmo:communicationChannel <%s> }",
 	                         url,
-	                         communication_channel);
+	                         wrap_feed_channel_get_subject (wfeed));
 
 	tracker_miner_execute_sparql (TRACKER_MINER (miner),
 	                              query,
@@ -578,7 +587,7 @@ feed_fetched (FeedsPool   *pool,
 
 	for (iter = items; iter; iter = iter->next) {
 		item = iter->data;
-		check_if_save (miner, item);
+		check_if_save (miner, item, feed);
 	}
 }
 
@@ -615,7 +624,7 @@ feeds_retrieve_cb (GObject      *source_object,
 	for (i = 0; i < response->len; i++) {
 		values = g_ptr_array_index (response, i);
 
-		chan = wrap_feed_channel_new (TRACKER_MINER_RSS (source_object), values [0]);
+		chan = wrap_feed_channel_new (TRACKER_MINER_RSS (source_object), values [2]);
 		feed_channel_set_source (FEED_CHANNEL (chan), values [0]);
 
 		/* TODO How to manage feeds with an update mfo:updateInterval == 0 ?
@@ -627,17 +636,20 @@ feeds_retrieve_cb (GObject      *source_object,
 			interval = 1;
 		feed_channel_set_update_interval (FEED_CHANNEL (chan), interval);
 
-		if (strcmp (values [3], "") != 0) {
+		if (values [3] != NULL && strcmp (values [3], "") != 0) {
 			int_value = strtoull (values [3], NULL, 10);
 			if (int_value > 0)
 				wrap_feed_channel_set_feeds_expiry (chan, int_value);
 		}
 
-		if (strcmp (values [4], "") != 0)
-			wrap_feed_channel_set_download_enclosures (chan, strcmp (values [4], "1") == 0);
+		if (values [4] != NULL && strcmp (values [4], "") != 0)
+			wrap_feed_channel_set_download_enclosures (chan, strcmp (values [4], "true") == 0);
+
+		if (values [5] != NULL && strcmp (values [5], "") != 0)
+			wrap_feed_channel_set_enclosures_saving_path (chan, values [5]);
 
-		if (strcmp (values [5], "") != 0) {
-			int_value = strtoull (values [5], NULL, 10);
+		if (values [6] != NULL && strcmp (values [6], "") != 0) {
+			int_value = strtoull (values [6], NULL, 10);
 			if (int_value > 0)
 				wrap_feed_channel_set_enclosures_maxsize (chan, int_value);
 		}
@@ -656,13 +668,14 @@ retrieve_and_schedule_feeds (TrackerMinerRSS *miner)
 
 	g_message ("Retrieving and scheduling feeds...");
 
-	sparql = "SELECT ?chanUrl ?interval ?chanUrn WHERE "
+	sparql = "SELECT ?chanUrl ?interval ?chanUrn ?expiry ?download ?path ?msize WHERE "
 	         "{ ?chanUrn a mfo:FeedChannel . "
 	         "?chanUrn mfo:feedSettings ?settings . "
 	         "?chanUrn nie:url ?chanUrl . "
 	         "?settings mfo:updateInterval ?interval . "
 	         "OPTIONAL { ?settings mfo:expiryInterval ?expiry } . "
 	         "OPTIONAL { ?settings mfo:downloadFlag ?download } . "
+	         "OPTIONAL { ?settings mfo:downloadPath ?path } . "
 	         "OPTIONAL { ?settings mfo:maxSize ?msize } }";
 
 	tracker_miner_execute_sparql (TRACKER_MINER (miner),
diff --git a/src/miners/rss/wrap-feed-enclosure.c b/src/miners/rss/wrap-feed-enclosure.c
index 730c639..e4739db 100644
--- a/src/miners/rss/wrap-feed-enclosure.c
+++ b/src/miners/rss/wrap-feed-enclosure.c
@@ -116,9 +116,7 @@ wrap_feed_enclosure_save_data (WrapFeedEnclosure *enclosure,
 		g_warning ("Unable to open saving location for enclosure.");
 	}
 	else {
-		if (fwrite (data, len, 1, fd) != len)
-			g_warning ("Error while saving enclosure contents.");
-
+		fwrite (data, len, 1, fd);
 		fclose (fd);
 	}
 



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