]> git.phdru.name Git - bookmarks_db.git/blobdiff - Robots/bkmk_rsimple.py
Get favicon even if it's of a wrong type.
[bookmarks_db.git] / Robots / bkmk_rsimple.py
index 63f96027c2f5d2458b22d697c6aad34797ce90ff..c2733a184ce5f6352e3b201e751b65404bf32b49 100644 (file)
@@ -176,24 +176,6 @@ class robot_simple(Robot):
                   parser = parse_html(fname, charset, self.log)
                   if parser:
                       bookmark.real_title = parser.title
-                      if parser.refresh:
-                         refresh = parser.refresh
-                         try:
-                            url = refresh.split('=', 1)[1]
-                         except IndexError:
-                            url = "self"
-                         try:
-                            timeout = float(refresh.split(';')[0])
-                         except (IndexError, ValueError):
-                            raise RedirectException("html", "Bad redirect to %s (%s)" % (url, refresh))
-                         else:
-                            try:
-                               timeout = int(refresh.split(';')[0])
-                            except ValueError:
-                               pass # float timeout
-                            raise RedirectException("html", "%s (%s sec)" % (url, timeout))
-
-                      # Get favicon.ico
                       icon = parser.icon
                   else:
                      icon = None
@@ -224,23 +206,43 @@ class robot_simple(Robot):
                      except:
                         etype, emsg, tb = sys.exc_info()
                         self.log("   no icon        : %s %s" % (etype, emsg))
-                        etype = None
-                        emsg = None
-                        tb = None
+                        etype = emsg = tb = None
                         icons[icon] = None
                      else:
                         content_type = headers["Content-Type"]
-                        if content_type.startswith("image/"):
+                        if content_type.startswith("application/") \
+                              or content_type.startswith("image/") \
+                              or content_type.startswith("text/plain"):
                            icon_file = open(icon_fname, "rb")
                            icon_data = icon_file.read()
                            icon_file.close()
                            bookmark.icon_href = icon
-                           bookmark.icon = "data:%s;base64,%s" % (content_type, b64encode(icon_data))
                            self.log("   got icon       : %s" % content_type)
+                           if content_type.startswith("application/") \
+                                 or content_type.startswith("text/plain"):
+                              self.log("   got non-image icon, assume x-icon")
+                              content_type = 'image/x-icon'
+                           bookmark.icon = "data:%s;base64,%s" % (content_type, b64encode(icon_data))
                            icons[icon] = (content_type, bookmark.icon)
                         else:
                            self.log("   no icon        : bad content type '%s'" % content_type)
                            icons[icon] = None
+                  if parser and parser.refresh:
+                     refresh = parser.refresh
+                     try:
+                        url = refresh.split('=', 1)[1]
+                     except IndexError:
+                        url = "self"
+                     try:
+                        timeout = float(refresh.split(';')[0])
+                     except (IndexError, ValueError):
+                        raise RedirectException("html", "Bad redirect to %s (%s)" % (url, refresh))
+                     else:
+                        try:
+                           timeout = int(refresh.split(';')[0])
+                        except ValueError:
+                           pass # float timeout
+                        raise RedirectException("html", "%s (%s sec)" % (url, timeout))
 
             except KeyError, key:
                self.log("   no header: %s" % key)