changeset 134:9e80267fe566

- changed the way of retrieving icons from twitter. now pidgin-twitter retrieves icon which is embedded in user page. - changed icon size for wassr from 64 to 128.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 22 Jul 2008 18:44:09 +0900
parents 45a1d5428d89
children cae8d5dd24d0
files pidgin-twitter.c pidgin-twitter.h
diffstat 2 files changed, 27 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Mon Jul 21 23:05:23 2008 +0900
+++ b/pidgin-twitter.c	Tue Jul 22 18:44:09 2008 +0900
@@ -23,7 +23,7 @@
 /***********/
 /* globals */
 /***********/
-#define NUM_REGP 9
+#define NUM_REGP 10
 static GRegex *regp[NUM_REGP];
 static gboolean suppress_oops = FALSE;
 static GHashTable *icon_data_by_user  = NULL; // twitter
@@ -1663,12 +1663,23 @@
 {
     got_icon_data *gotdata = (got_icon_data *)user_data;
     gchar *user_name = gotdata->user_name;
-//    gint service = gotdata->service;
+    gint service = gotdata->service;
     GMatchInfo *match_info = NULL;
     icon_data *data = NULL;
     gchar *url = NULL;
-
-    data = (icon_data *)g_hash_table_lookup(icon_data_by_user3, user_name);
+    gint regp_id = -1;
+
+    if(service == identica_service) {
+        data = (icon_data *)g_hash_table_lookup(
+            icon_data_by_user3, user_name);
+        regp_id = IMAGE_IDENTICA;
+    }
+
+    if(service == twitter_service) {
+        data = (icon_data *)g_hash_table_lookup(
+            icon_data_by_user, user_name);
+        regp_id = IMAGE_TWITTER;
+    }
 
     if(!url_text) {
         if(data) {
@@ -1681,7 +1692,7 @@
     }
 
     /* setup image url */
-    g_regex_match(regp[IMAGE_IDENTICA], url_text, 0, &match_info);
+    g_regex_match(regp[regp_id], url_text, 0, &match_info);
     if(!g_match_info_matches(match_info)) {
         twitter_debug("no image found\n");
 
@@ -1916,7 +1927,7 @@
 
     twitter_debug("path = %s\n", path);
 
-    /* build image from file, if file exists */
+    /* make image from file, if file exists */
     if(g_file_test(path, G_FILE_TEST_EXISTS)) {
         gchar *imgdata = NULL;
         size_t len;
@@ -1958,11 +1969,11 @@
      */
     switch(service) {
     case twitter_service:
-        url = g_strdup_printf("http://img.twitty.jp/twitter/user/%s/m.gif",
-                              user_name);
+        url = g_strdup_printf("http://twitter.com/%s", user_name);
+
         break;
     case wassr_service:
-        url = g_strdup_printf("http://wassr.jp/user/%s/profile_img.png.64",
+        url = g_strdup_printf("http://wassr.jp/user/%s/profile_img.png.128",
                               user_name);
         break;
     case identica_service:
@@ -1979,7 +1990,8 @@
         gotdata->service = service;
 
         /* gotdata will be released in got_icon_cb */
-        if(service == identica_service) {
+        if(service == identica_service ||
+           service == twitter_service) {
             data->fetch_data = purple_util_fetch_url(url, TRUE, NULL, TRUE,
                                                      got_page_cb, gotdata);
         }
@@ -2242,7 +2254,8 @@
     regp[USER_FIRST_LINE] = g_regex_new(P_USER_FIRST_LINE, 0, 0, NULL);
     regp[USER_FORMATTED]  = g_regex_new(P_USER_FORMATTED, G_REGEX_RAW, 0, NULL);
     regp[CHANNEL]   = g_regex_new(P_CHANNEL, 0, 0, NULL);
-    regp[IMAGE_IDENTICA]  = g_regex_new(P_IMAGE_IDENTICA, 0, 0, NULL);
+    regp[IMAGE_IDENTICA] = g_regex_new(P_IMAGE_IDENTICA, 0, 0, NULL);
+    regp[IMAGE_TWITTER]  = g_regex_new(P_IMAGE_TWITTER, 0, 0, NULL);
 
 
     icon_data_by_user = g_hash_table_new_full(g_str_hash, g_str_equal,
--- a/pidgin-twitter.h	Mon Jul 21 23:05:23 2008 +0900
+++ b/pidgin-twitter.h	Tue Jul 22 18:44:09 2008 +0900
@@ -33,7 +33,8 @@
     USER_FIRST_LINE,
     USER_FORMATTED,
     CHANNEL,
-    IMAGE_IDENTICA
+    IMAGE_IDENTICA,
+    IMAGE_TWITTER
 };
 
 /* service id */
@@ -132,6 +133,7 @@
 #define P_USER_FORMATTED    "^.*?<a .+?>([A-Za-z0-9_]+)</a>:"
 #define P_CHANNEL           "^(.*?<a .+?>[A-Za-z0-9_]+</a>: \\r?\\n?#)([A-Za-z0-9_]+) "
 #define P_IMAGE_IDENTICA    "<img src=\"(http://avatar.identi.ca/[A-Za-z0-9-.]+)\" class=\"avatar profile\" width=\"96\" height=\"96\" alt=\"[A-Za-z0-0_]+\"/>"
+#define P_IMAGE_TWITTER     "<a href=\"/account/profile_image/.+?\"><img .+? id=\"profile-image\".*src=\"(http://[A-Za-z0-9_./]+)\" .+?/>"
 
 /* twitter API specific macros */
 #define TWITTER_BASE_URL "http://twitter.com"