[PATCH 15/18] flickr: Use largest image if original can not be downloaded



Original photos from non-subscribers can not be accessed. So in this case
return the largest image available.
---
 src/flickr/gflickr.c    |   31 +++++++++++++++++++++++++++++++
 src/flickr/gflickr.h    |    3 +++
 src/flickr/grl-flickr.c |    3 +++
 3 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/src/flickr/gflickr.c b/src/flickr/gflickr.c
index 6c60488..55eeb20 100644
--- a/src/flickr/gflickr.c
+++ b/src/flickr/gflickr.c
@@ -16,6 +16,9 @@
 #define FLICKR_PHOTO_THUMB_URL                          \
   "http://farm%s.static.flickr.com/%s/%s_%s_t.jpg";
 
+#define FLICKR_PHOTO_LARGEST_URL                        \
+  "http://farm%s.static.flickr.com/%s/%s_%s_b.jpg";
+
 #define FLICKR_ENDPOINT "http://api.flickr.com/services/rest/?";
 #define FLICKR_AUTHPOINT "http://flickr.com/services/auth/?";
 
@@ -770,6 +773,34 @@ g_flickr_photo_url_thumbnail (GFlickr *f, GHashTable *photo)
   }
 }
 
+gchar *
+g_flickr_photo_url_largest (GFlickr *f, GHashTable *photo)
+{
+  gchar *farm_id;
+  gchar *secret;
+  gchar *photo_id;
+  gchar *server_id;
+
+  if (!photo) {
+    return NULL;
+  }
+
+  farm_id = g_hash_table_lookup (photo, "photo_farm");
+  secret = g_hash_table_lookup (photo, "photo_secret");
+  photo_id = g_hash_table_lookup (photo, "photo_id");
+  server_id = g_hash_table_lookup (photo, "photo_server");
+
+  if (!farm_id || !secret || !photo_id || !server_id) {
+    return NULL;
+  } else {
+    return g_strdup_printf (FLICKR_PHOTO_LARGEST_URL,
+                            farm_id,
+                            server_id,
+                            photo_id,
+                            secret);
+  }
+}
+
 void
 g_flickr_tags_getHotList (GFlickr *f,
                           gint count,
diff --git a/src/flickr/gflickr.h b/src/flickr/gflickr.h
index b0024cd..be7dfa7 100644
--- a/src/flickr/gflickr.h
+++ b/src/flickr/gflickr.h
@@ -105,6 +105,9 @@ g_flickr_photo_url_original (GFlickr *f, GHashTable *photo);
 gchar *
 g_flickr_photo_url_thumbnail (GFlickr *f, GHashTable *photo);
 
+gchar *
+g_flickr_photo_url_largest (GFlickr *f, GHashTable *photo);
+
 void
 g_flickr_tags_getHotList (GFlickr *f,
                           gint count,
diff --git a/src/flickr/grl-flickr.c b/src/flickr/grl-flickr.c
index 97240b3..bd2af15 100644
--- a/src/flickr/grl-flickr.c
+++ b/src/flickr/grl-flickr.c
@@ -301,6 +301,9 @@ update_media (GrlMedia *media, GHashTable *photo)
   url = g_strdup (g_hash_table_lookup (photo, "photo_url_o"));
   if (!url) {
     url = g_flickr_photo_url_original (NULL, photo);
+    if (!url) {
+      url = g_flickr_photo_url_largest (NULL, photo);
+    }
   }
 
   if (author) {
-- 
1.7.0.4



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